2 * Copyright 2008, The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/types.h>
22 #define PORT_BOOTP_SERVER 67
23 #define PORT_BOOTP_CLIENT 68
26 typedef struct dhcp_msg dhcp_msg;
28 #define OP_BOOTREQUEST 1
29 #define OP_BOOTREPLY 2
31 #define FLAGS_BROADCAST 0x8000
37 uint8_t op; /* BOOTREQUEST / BOOTREPLY */
38 uint8_t htype; /* hw addr type */
39 uint8_t hlen; /* hw addr len */
40 uint8_t hops; /* client set to 0 */
42 uint32_t xid; /* transaction id */
44 uint16_t secs; /* seconds since start of acq */
47 uint32_t ciaddr; /* client IP addr */
48 uint32_t yiaddr; /* your (client) IP addr */
49 uint32_t siaddr; /* ip addr of next server */
50 /* (DHCPOFFER and DHCPACK) */
51 uint32_t giaddr; /* relay agent IP addr */
53 uint8_t chaddr[16]; /* client hw addr */
54 char sname[64]; /* asciiz server hostname */
55 char file[128]; /* asciiz boot file name */
57 uint8_t options[1024]; /* optional parameters */
60 #define DHCP_MSG_FIXED_SIZE 236
62 /* first four bytes of options are a cookie to indicate that
63 ** the payload are DHCP options as opposed to some other BOOTP
66 #define OPT_COOKIE1 0x63
67 #define OPT_COOKIE2 0x82
68 #define OPT_COOKIE3 0x53
69 #define OPT_COOKIE4 0x63
71 /* BOOTP/DHCP options - see RFC 2132 */
74 #define OPT_SUBNET_MASK 1 /* 4 <ipaddr> */
75 #define OPT_TIME_OFFSET 2 /* 4 <seconds> */
76 #define OPT_GATEWAY 3 /* 4*n <ipaddr> * n */
77 #define OPT_DNS 6 /* 4*n <ipaddr> * n */
78 #define OPT_DOMAIN_NAME 15 /* n <domainnamestring> */
79 #define OPT_BROADCAST_ADDR 28 /* 4 <ipaddr> */
81 #define OPT_REQUESTED_IP 50 /* 4 <ipaddr> */
82 #define OPT_LEASE_TIME 51 /* 4 <seconds> */
83 #define OPT_MESSAGE_TYPE 53 /* 1 <msgtype> */
84 #define OPT_SERVER_ID 54 /* 4 <ipaddr> */
85 #define OPT_PARAMETER_LIST 55 /* n <optcode> * n */
86 #define OPT_MESSAGE 56 /* n <errorstring> */
87 #define OPT_CLASS_ID 60 /* n <opaque> */
88 #define OPT_CLIENT_ID 61 /* n <opaque> */
91 /* DHCP message types */
92 #define DHCPDISCOVER 1
101 int init_dhcp_discover_msg(dhcp_msg *msg, void *hwaddr, uint32_t xid);
103 int init_dhcp_request_msg(dhcp_msg *msg, void *hwaddr, uint32_t xid,
104 uint32_t ipaddr, uint32_t serveraddr);