2
* dhcpcd - DHCP client daemon -
3
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
4
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
5
* Copyright (C) 2005 Roy Marples <uberlord@gentoo.org>
6
* Copyright (C) 2005 Simon Kelley <simon@thekelleys.org.uk>
8
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
10
* This is free software; you can redistribute it and/or modify it
11
* under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful, but
16
* WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
* See the GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31
#include <net/ethernet.h>
32
#include <linux/types.h>
33
#include <linux/if_tr.h>
35
#include <linux/if_ether.h>
36
#define ETHERTYPE_IP 0x0800
37
#define ETHERTYPE_ARP 0x0806
40
#define IPPACKET_SIZE 1500
41
#define MAGIC_COOKIE 0x63825363
42
#define BROADCAST_FLAG 0x8000
43
#define MAC_BCAST_ADDR "\xff\xff\xff\xff\xff\xff"
45
#define AF_PACKET 17 /* should have been in socketbits.h */
47
#define CLASS_ID_MAX_LEN 48
48
#define CLIENT_ID_MAX_LEN 48
49
#define HOSTNAME_MAX_LEN 64
50
#define HWADDR_TRIES 3
52
/* UDP port numbers for DHCP */
53
#define DHCP_SERVER_PORT 67 /* from client to server */
54
#define DHCP_CLIENT_PORT 68 /* from server to client */
56
/* DHCP message OP code */
57
#define DHCP_BOOTREQUEST 1
58
#define DHCP_BOOTREPLY 2
60
/* DHCP message type */
61
#define DHCP_DISCOVER 1
63
#define DHCP_REQUEST 3
64
#define DHCP_DECLINE 4
67
#define DHCP_RELEASE 7
69
/* DHCP RETRANSMISSION TIMEOUT (microseconds) */
70
#define DHCP_INITIAL_RTO (4*1000000)
71
#define DHCP_MAX_RTO (64*1000000)
73
/* DHCP option and value (cf. RFC1533) */
87
resourceLocationServer = 11,
96
nonLocalSourceRouting = 20,
98
maxDgramReasmSize = 22,
100
pathMTUagingTimeout = 24,
101
pathMTUplateauTable = 25,
103
allSubnetsLocal = 27,
105
performMaskDiscovery = 29,
107
performRouterDiscovery = 31,
108
routerSolicitationAddr = 32,
110
trailerEncapsulation = 34,
111
arpCacheTimeout = 35,
112
ethernetEncapsulation = 36,
114
tcpKeepaliveInterval = 38,
115
tcpKeepaliveGarbage = 39,
119
vendorSpecificInfo = 43,
120
netBIOSnameServer = 44,
121
netBIOSdgramDistServer = 45,
122
netBIOSnodeType = 46,
125
xDisplayManager = 49,
126
dhcpRequestedIPaddr = 50,
127
dhcpIPaddrLeaseTime = 51,
128
dhcpOptionOverload = 52,
129
dhcpMessageType = 53,
130
dhcpServerIdentifier = 54,
131
dhcpParamRequest = 55,
136
dhcpClassIdentifier = 60,
137
dhcpClientIdentifier = 61,
138
dhcpFQDNHostName = 81,
139
dnsSearchPath = 119, /* RFC 3397 */
143
/* SetFQDNHostName values - lsnybble used in flags
144
* byte (see buildmsg.c), hsnybble to create order
145
* and to allow 0x00 to mean disable
154
typedef struct dhcpInterface
156
unsigned char version[11];
162
unsigned char shaddr[ETH_ALEN];
163
unsigned char class_id[CLASS_ID_MAX_LEN];
164
unsigned char client_id[CLIENT_ID_MAX_LEN];
166
unsigned char chaddr[ETH_ALEN];
170
typedef struct dhcpMessage
172
u_char op; /* message type */
173
u_char htype; /* hardware address type */
174
u_char hlen; /* hardware address length */
175
u_char hops; /* should be zero in client's message */
176
u_int xid; /* transaction id */
177
u_short secs; /* elapsed time in sec. from trying to boot */
179
u_int ciaddr; /* (previously allocated) client IP address */
180
u_int yiaddr; /* 'your' client IP address */
181
u_int siaddr; /* should be zero in client's messages */
182
u_int giaddr; /* should be zero in client's messages */
183
u_char chaddr[16]; /* client's hardware address */
184
u_char sname[64]; /* server host name, null terminated string */
185
u_char file[128]; /* boot file name, null terminated string */
186
u_char options[312]; /* message options */
187
} __attribute__((packed)) dhcpMessage;
189
struct packed_ether_header {
190
u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */
191
u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */
192
u_int16_t ether_type; /* packet type ID field */
193
} __attribute__((packed));
195
typedef struct udpipMessage
197
struct packed_ether_header ethhdr;
198
char udpipmsg[IPPACKET_SIZE];
199
char pad_for_tokenring_header[sizeof(struct trh_hdr) + sizeof(struct trllc)];
200
} __attribute__((packed)) udpipMessage;
202
typedef struct dhcpOptions
207
} __attribute__((packed)) dhcpOptions;
209
int peekfd(int s,int tv_usec);
213
void *dhcpRequest(unsigned xid,void (*buildDhcpMsg)(unsigned));