aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-03-15 08:29:22 +0000
committerEric Andersen <andersen@codepoet.org>2004-03-15 08:29:22 +0000
commitc7bda1ce659294d6e22c06e087f6f265983c7578 (patch)
tree4c6d2217f4d8306c59cf1096f8664e1cfd167213 /networking/udhcp
parent8854004b41065b3d081af7f3df13a100b0c8bfbe (diff)
downloadbusybox-w32-c7bda1ce659294d6e22c06e087f6f265983c7578.tar.gz
busybox-w32-c7bda1ce659294d6e22c06e087f6f265983c7578.tar.bz2
busybox-w32-c7bda1ce659294d6e22c06e087f6f265983c7578.zip
Remove trailing whitespace. Update copyright to include 2004.
Diffstat (limited to 'networking/udhcp')
-rw-r--r--networking/udhcp/AUTHORS1
-rw-r--r--networking/udhcp/ChangeLog2
-rw-r--r--networking/udhcp/Makefile2
-rw-r--r--networking/udhcp/Makefile.in2
-rw-r--r--networking/udhcp/README16
-rw-r--r--networking/udhcp/README.udhcpc10
-rw-r--r--networking/udhcp/README.udhcpd8
-rw-r--r--networking/udhcp/arpping.c16
-rw-r--r--networking/udhcp/arpping.h2
-rw-r--r--networking/udhcp/clientpacket.c32
-rw-r--r--networking/udhcp/common.c2
-rw-r--r--networking/udhcp/common.h2
-rw-r--r--networking/udhcp/dhcpc.c48
-rw-r--r--networking/udhcp/dhcpd.c34
-rw-r--r--networking/udhcp/dhcpd.h4
-rw-r--r--networking/udhcp/dumpleases.c10
-rw-r--r--networking/udhcp/files.c44
-rw-r--r--networking/udhcp/frontend.c4
-rw-r--r--networking/udhcp/leases.c30
-rw-r--r--networking/udhcp/options.c30
-rw-r--r--networking/udhcp/packet.c18
-rw-r--r--networking/udhcp/packet.h2
-rw-r--r--networking/udhcp/script.c10
-rw-r--r--networking/udhcp/serverpacket.c48
-rw-r--r--networking/udhcp/socket.c8
25 files changed, 192 insertions, 193 deletions
diff --git a/networking/udhcp/AUTHORS b/networking/udhcp/AUTHORS
index bb58de13e..f3f43364a 100644
--- a/networking/udhcp/AUTHORS
+++ b/networking/udhcp/AUTHORS
@@ -8,7 +8,6 @@ Chris Trew <christ@moreton.com.au>
8Other Credits: 8Other Credits:
9-------------- 9--------------
10Moreton Bay (http://www.moretonbay.com/) 10Moreton Bay (http://www.moretonbay.com/)
11Lineo (http://opensource.lineo.com)
12Vladimir Oleynik <dzo@simtrea.ru> Size optimizations 11Vladimir Oleynik <dzo@simtrea.ru> Size optimizations
13 12
14 13
diff --git a/networking/udhcp/ChangeLog b/networking/udhcp/ChangeLog
index f1aac060e..2feffc776 100644
--- a/networking/udhcp/ChangeLog
+++ b/networking/udhcp/ChangeLog
@@ -39,7 +39,7 @@
39 (Ted Lemon <Ted.Lemon@nominum.com>) 39 (Ted Lemon <Ted.Lemon@nominum.com>)
40+ Improved (hopefully) NAKing behavior (me) 40+ Improved (hopefully) NAKing behavior (me)
41+ Added -b option (Jouni Malinen) 41+ Added -b option (Jouni Malinen)
42+ Compute checksums correctly on big endian hosts 42+ Compute checksums correctly on big endian hosts
43 (Jouni Malinen <jkmaline@cc.hut.fi>) 43 (Jouni Malinen <jkmaline@cc.hut.fi>)
44 44
450.9.7 (020526) 450.9.7 (020526)
diff --git a/networking/udhcp/Makefile b/networking/udhcp/Makefile
index ee34d48ff..2b79d2293 100644
--- a/networking/udhcp/Makefile
+++ b/networking/udhcp/Makefile
@@ -1,6 +1,6 @@
1# Makefile for busybox 1# Makefile for busybox
2# 2#
3# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> 3# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
4# 4#
5# This program is free software; you can redistribute it and/or modify 5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by 6# it under the terms of the GNU General Public License as published by
diff --git a/networking/udhcp/Makefile.in b/networking/udhcp/Makefile.in
index 4d3f27093..b48079429 100644
--- a/networking/udhcp/Makefile.in
+++ b/networking/udhcp/Makefile.in
@@ -1,6 +1,6 @@
1# Makefile for busybox 1# Makefile for busybox
2# 2#
3# Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org> 3# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
4# 4#
5# This program is free software; you can redistribute it and/or modify 5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by 6# it under the terms of the GNU General Public License as published by
diff --git a/networking/udhcp/README b/networking/udhcp/README
index eddb24be7..dd992949a 100644
--- a/networking/udhcp/README
+++ b/networking/udhcp/README
@@ -10,30 +10,30 @@ compile time options
10------------------- 10-------------------
11 11
12The Makefile contains three of the compile time options: 12The Makefile contains three of the compile time options:
13 13
14 UDHCP_DEBUG: If UDHCP_DEBUG is defined, udhcpd will output extra 14 UDHCP_DEBUG: If UDHCP_DEBUG is defined, udhcpd will output extra
15 debugging output, compile with -g, and not fork to the background when 15 debugging output, compile with -g, and not fork to the background when
16 run. 16 run.
17 UDHCP_SYSLOG: If UDHCP_SYSLOG is defined, udhcpd will log all its 17 UDHCP_SYSLOG: If UDHCP_SYSLOG is defined, udhcpd will log all its
18 messages syslog, otherwise, it will attempt to log them to stdout. 18 messages syslog, otherwise, it will attempt to log them to stdout.
19 19
20 COMBINED_BINARY: If COMBINED_BINARY is define, one binary, udhcpd, 20 COMBINED_BINARY: If COMBINED_BINARY is define, one binary, udhcpd,
21 is created. If called as udhcpd, the dhcp server will be started. 21 is created. If called as udhcpd, the dhcp server will be started.
22 If called as udhcpc, the dhcp client will be started. 22 If called as udhcpc, the dhcp client will be started.
23 23
24dhcpd.h contains the other three compile time options: 24dhcpd.h contains the other three compile time options:
25 25
26 LEASE_TIME: The default lease time if not specified in the config 26 LEASE_TIME: The default lease time if not specified in the config
27 file. 27 file.
28 28
29 LEASES_FILE: The default file for storing leases. 29 LEASES_FILE: The default file for storing leases.
30 30
31 DHCPD_CONFIG_FILE: The defualt config file to use. 31 DHCPD_CONFIG_FILE: The defualt config file to use.
32 32
33options.c contains a set of dhcp options for the client: 33options.c contains a set of dhcp options for the client:
34 34
35 name[10]: The name of the option as it will appear in scripts 35 name[10]: The name of the option as it will appear in scripts
36 36
37 flags: The type of option, as well as if it will be requested 37 flags: The type of option, as well as if it will be requested
38 by the client (OPTION_REQ) 38 by the client (OPTION_REQ)
39 39
@@ -45,7 +45,7 @@ busybox drop-in
45udhcp is now a drop-in component for busybox (http://busybox.net). 45udhcp is now a drop-in component for busybox (http://busybox.net).
46To update busybox to the latest revision, simply do a: 46To update busybox to the latest revision, simply do a:
47 47
48cp *.[ch] README AUTHORS COPYING ChangeLog TODO \ 48cp *.[ch] README AUTHORS COPYING ChangeLog TODO \
49 <busybox_source>/networking/udhcp 49 <busybox_source>/networking/udhcp
50 50
51The only two files udhcp does not provide are config.in and 51The only two files udhcp does not provide are config.in and
diff --git a/networking/udhcp/README.udhcpc b/networking/udhcp/README.udhcpc
index 8aee9814b..d720a37cf 100644
--- a/networking/udhcp/README.udhcpc
+++ b/networking/udhcp/README.udhcpc
@@ -36,20 +36,20 @@ udhcp client scripts
36 36
37When an event occurs, udhcpc calls the action script. udhcpc never does 37When an event occurs, udhcpc calls the action script. udhcpc never does
38any configuration of the network interface itself, but instead relies on 38any configuration of the network interface itself, but instead relies on
39a set of scripts. The script by default is 39a set of scripts. The script by default is
40/usr/share/udhcpc/default.script but this can be changed via the command 40/usr/share/udhcpc/default.script but this can be changed via the command
41line arguments. The three possible arguments to the script are: 41line arguments. The three possible arguments to the script are:
42 42
43 deconfig: This argument is used when udhcpc starts, and 43 deconfig: This argument is used when udhcpc starts, and
44 when a leases is lost. The script must put the interface in an 44 when a leases is lost. The script must put the interface in an
45 up, but deconfigured state, ie: ifconfig $interface 0.0.0.0. 45 up, but deconfigured state, ie: ifconfig $interface 0.0.0.0.
46 46
47 bound: This argument is used when udhcpc moves from an 47 bound: This argument is used when udhcpc moves from an
48 unbound, to a bound state. All of the paramaters are set in 48 unbound, to a bound state. All of the paramaters are set in
49 enviromental variables, The script should configure the interface, 49 enviromental variables, The script should configure the interface,
50 and set any other relavent parameters (default gateway, dns server, 50 and set any other relavent parameters (default gateway, dns server,
51 etc). 51 etc).
52 52
53 renew: This argument is used when a DHCP lease is renewed. All of 53 renew: This argument is used when a DHCP lease is renewed. All of
54 the paramaters are set in enviromental variables. This argument is 54 the paramaters are set in enviromental variables. This argument is
55 used when the interface is already configured, so the IP address, 55 used when the interface is already configured, so the IP address,
@@ -133,7 +133,7 @@ compile time options
133options.c contains a set of dhcp options for the client: 133options.c contains a set of dhcp options for the client:
134 134
135 name[10]: The name of the option as it will appear in scripts 135 name[10]: The name of the option as it will appear in scripts
136 136
137 flags: The type of option, as well as if it will be requested 137 flags: The type of option, as well as if it will be requested
138 by the client (OPTION_REQ) 138 by the client (OPTION_REQ)
139 139
diff --git a/networking/udhcp/README.udhcpd b/networking/udhcp/README.udhcpd
index bc6137de3..169de78ec 100644
--- a/networking/udhcp/README.udhcpd
+++ b/networking/udhcp/README.udhcpd
@@ -14,7 +14,7 @@ udhcpd.leases
14 14
15The udhcpd.leases behavior is designed for an embedded system. The 15The udhcpd.leases behavior is designed for an embedded system. The
16file is written either every auto_time seconds, or when a SIGUSR1 16file is written either every auto_time seconds, or when a SIGUSR1
17is received (the auto_time timer restarts if a SIGUSR1 is received). 17is received (the auto_time timer restarts if a SIGUSR1 is received).
18If you send a SIGTERM to udhcpd directly after a SIGUSR1, udhcpd will 18If you send a SIGTERM to udhcpd directly after a SIGUSR1, udhcpd will
19finish writing the leases file and wait for the aftermentioned script 19finish writing the leases file and wait for the aftermentioned script
20to be executed and finish before quiting, so you do not need to sleep 20to be executed and finish before quiting, so you do not need to sleep
@@ -50,10 +50,10 @@ available options and comments describing them in samples/udhcpd.conf
50 50
51compile time options 51compile time options
52------------------- 52-------------------
53 53
54dhcpd.h contains the other two compile time options: 54dhcpd.h contains the other two compile time options:
55 55
56 LEASE_TIME: The default lease time if not specified in the config 56 LEASE_TIME: The default lease time if not specified in the config
57 file. 57 file.
58 58
59 DHCPD_CONFIG_FILE: The defualt config file to use. 59 DHCPD_CONFIG_FILE: The defualt config file to use.
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c
index 23c7d46b3..ab4c6d20c 100644
--- a/networking/udhcp/arpping.c
+++ b/networking/udhcp/arpping.c
@@ -25,8 +25,8 @@
25 * interface - interface to use 25 * interface - interface to use
26 * retn: 1 addr free 26 * retn: 1 addr free
27 * 0 addr used 27 * 0 addr used
28 * -1 error 28 * -1 error
29 */ 29 */
30 30
31/* FIXME: match response against chaddr */ 31/* FIXME: match response against chaddr */
32int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface) 32int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
@@ -51,7 +51,7 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
51#endif 51#endif
52 return -1; 52 return -1;
53 } 53 }
54 54
55 if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) { 55 if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) {
56 LOG(LOG_ERR, "Could not setsocketopt on raw socket"); 56 LOG(LOG_ERR, "Could not setsocketopt on raw socket");
57 close(s); 57 close(s);
@@ -71,12 +71,12 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
71 memcpy(arp.sInaddr, &ip, sizeof(ip)); /* source IP address */ 71 memcpy(arp.sInaddr, &ip, sizeof(ip)); /* source IP address */
72 memcpy(arp.sHaddr, mac, 6); /* source hardware address */ 72 memcpy(arp.sHaddr, mac, 6); /* source hardware address */
73 memcpy(arp.tInaddr, &yiaddr, sizeof(yiaddr)); /* target IP address */ 73 memcpy(arp.tInaddr, &yiaddr, sizeof(yiaddr)); /* target IP address */
74 74
75 memset(&addr, 0, sizeof(addr)); 75 memset(&addr, 0, sizeof(addr));
76 strcpy(addr.sa_data, interface); 76 strcpy(addr.sa_data, interface);
77 if (sendto(s, &arp, sizeof(arp), 0, &addr, sizeof(addr)) < 0) 77 if (sendto(s, &arp, sizeof(arp), 0, &addr, sizeof(addr)) < 0)
78 rv = 0; 78 rv = 0;
79 79
80 /* wait arp reply, and check it */ 80 /* wait arp reply, and check it */
81 tm.tv_usec = 0; 81 tm.tv_usec = 0;
82 time(&prevTime); 82 time(&prevTime);
@@ -89,8 +89,8 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
89 if (errno != EINTR) rv = 0; 89 if (errno != EINTR) rv = 0;
90 } else if (FD_ISSET(s, &fdset)) { 90 } else if (FD_ISSET(s, &fdset)) {
91 if (recv(s, &arp, sizeof(arp), 0) < 0 ) rv = 0; 91 if (recv(s, &arp, sizeof(arp), 0) < 0 ) rv = 0;
92 if (arp.operation == htons(ARPOP_REPLY) && 92 if (arp.operation == htons(ARPOP_REPLY) &&
93 bcmp(arp.tHaddr, mac, 6) == 0 && 93 bcmp(arp.tHaddr, mac, 6) == 0 &&
94 *((uint32_t *) arp.sInaddr) == yiaddr) { 94 *((uint32_t *) arp.sInaddr) == yiaddr) {
95 DEBUG(LOG_INFO, "Valid arp reply receved for this address"); 95 DEBUG(LOG_INFO, "Valid arp reply receved for this address");
96 rv = 0; 96 rv = 0;
@@ -101,6 +101,6 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
101 time(&prevTime); 101 time(&prevTime);
102 } 102 }
103 close(s); 103 close(s);
104 DEBUG(LOG_INFO, "%salid arp replies for this address", rv ? "No v" : "V"); 104 DEBUG(LOG_INFO, "%salid arp replies for this address", rv ? "No v" : "V");
105 return rv; 105 return rv;
106} 106}
diff --git a/networking/udhcp/arpping.h b/networking/udhcp/arpping.h
index 6cbd2979f..6f27d9f75 100644
--- a/networking/udhcp/arpping.h
+++ b/networking/udhcp/arpping.h
@@ -15,7 +15,7 @@ struct arpMsg {
15 u_char h_dest[6]; /* destination ether addr */ 15 u_char h_dest[6]; /* destination ether addr */
16 u_char h_source[6]; /* source ether addr */ 16 u_char h_source[6]; /* source ether addr */
17 u_short h_proto; /* packet type ID field */ 17 u_short h_proto; /* packet type ID field */
18 18
19 /* ARP packet */ 19 /* ARP packet */
20 uint16_t htype; /* hardware type (must be ARPHRD_ETHER) */ 20 uint16_t htype; /* hardware type (must be ARPHRD_ETHER) */
21 uint16_t ptype; /* protocol type (must be ETH_P_IP) */ 21 uint16_t ptype; /* protocol type (must be ETH_P_IP) */
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index 6838c07e8..5b27004f9 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -18,7 +18,7 @@
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#include <string.h> 22#include <string.h>
23#include <sys/socket.h> 23#include <sys/socket.h>
24#include <features.h> 24#include <features.h>
@@ -73,7 +73,7 @@ static void init_packet(struct dhcpMessage *packet, char type)
73 char vendor, length; 73 char vendor, length;
74 char str[sizeof("udhcp "VERSION)]; 74 char str[sizeof("udhcp "VERSION)];
75 } vendor_id = { DHCP_VENDOR, sizeof("udhcp "VERSION) - 1, "udhcp "VERSION}; 75 } vendor_id = { DHCP_VENDOR, sizeof("udhcp "VERSION) - 1, "udhcp "VERSION};
76 76
77 init_header(packet, type); 77 init_header(packet, type);
78 memcpy(packet->chaddr, client_config.arp, 6); 78 memcpy(packet->chaddr, client_config.arp, 6);
79 add_option_string(packet->options, client_config.clientid); 79 add_option_string(packet->options, client_config.clientid);
@@ -112,7 +112,7 @@ int send_discover(unsigned long xid, unsigned long requested)
112 112
113 add_requests(&packet); 113 add_requests(&packet);
114 LOG(LOG_DEBUG, "Sending discover..."); 114 LOG(LOG_DEBUG, "Sending discover...");
115 return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 115 return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
116 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 116 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
117} 117}
118 118
@@ -128,11 +128,11 @@ int send_selecting(unsigned long xid, unsigned long server, unsigned long reques
128 128
129 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); 129 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested);
130 add_simple_option(packet.options, DHCP_SERVER_ID, server); 130 add_simple_option(packet.options, DHCP_SERVER_ID, server);
131 131
132 add_requests(&packet); 132 add_requests(&packet);
133 addr.s_addr = requested; 133 addr.s_addr = requested;
134 LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr)); 134 LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr));
135 return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 135 return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
136 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 136 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
137} 137}
138 138
@@ -149,12 +149,12 @@ int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr)
149 149
150 add_requests(&packet); 150 add_requests(&packet);
151 LOG(LOG_DEBUG, "Sending renew..."); 151 LOG(LOG_DEBUG, "Sending renew...");
152 if (server) 152 if (server)
153 ret = kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); 153 ret = kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
154 else ret = raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 154 else ret = raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
155 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 155 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
156 return ret; 156 return ret;
157} 157}
158 158
159 159
160/* Unicasts a DHCP release message */ 160/* Unicasts a DHCP release message */
@@ -165,7 +165,7 @@ int send_release(unsigned long server, unsigned long ciaddr)
165 init_packet(&packet, DHCPRELEASE); 165 init_packet(&packet, DHCPRELEASE);
166 packet.xid = random_xid(); 166 packet.xid = random_xid();
167 packet.ciaddr = ciaddr; 167 packet.ciaddr = ciaddr;
168 168
169 add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr); 169 add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr);
170 add_simple_option(packet.options, DHCP_SERVER_ID, server); 170 add_simple_option(packet.options, DHCP_SERVER_ID, server);
171 171
@@ -189,20 +189,20 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
189 usleep(500000); /* possible down interface, looping condition */ 189 usleep(500000); /* possible down interface, looping condition */
190 return -1; 190 return -1;
191 } 191 }
192 192
193 if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) { 193 if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) {
194 DEBUG(LOG_INFO, "message too short, ignoring"); 194 DEBUG(LOG_INFO, "message too short, ignoring");
195 return -2; 195 return -2;
196 } 196 }
197 197
198 if (bytes < ntohs(packet.ip.tot_len)) { 198 if (bytes < ntohs(packet.ip.tot_len)) {
199 DEBUG(LOG_INFO, "Truncated packet"); 199 DEBUG(LOG_INFO, "Truncated packet");
200 return -2; 200 return -2;
201 } 201 }
202 202
203 /* ignore any extra garbage bytes */ 203 /* ignore any extra garbage bytes */
204 bytes = ntohs(packet.ip.tot_len); 204 bytes = ntohs(packet.ip.tot_len);
205 205
206 /* Make sure its the right packet for us, and that it passes sanity checks */ 206 /* Make sure its the right packet for us, and that it passes sanity checks */
207 if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION || 207 if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION ||
208 packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) || 208 packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) ||
@@ -219,7 +219,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
219 DEBUG(LOG_INFO, "bad IP header checksum, ignoring"); 219 DEBUG(LOG_INFO, "bad IP header checksum, ignoring");
220 return -1; 220 return -1;
221 } 221 }
222 222
223 /* verify the UDP checksum by replacing the header with a psuedo header */ 223 /* verify the UDP checksum by replacing the header with a psuedo header */
224 source = packet.ip.saddr; 224 source = packet.ip.saddr;
225 dest = packet.ip.daddr; 225 dest = packet.ip.daddr;
@@ -235,14 +235,14 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
235 DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring"); 235 DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring");
236 return -2; 236 return -2;
237 } 237 }
238 238
239 memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp))); 239 memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp)));
240 240
241 if (ntohl(payload->cookie) != DHCP_MAGIC) { 241 if (ntohl(payload->cookie) != DHCP_MAGIC) {
242 LOG(LOG_ERR, "received bogus message (bad magic) -- ignoring"); 242 LOG(LOG_ERR, "received bogus message (bad magic) -- ignoring");
243 return -2; 243 return -2;
244 } 244 }
245 DEBUG(LOG_INFO, "oooooh!!! got some!"); 245 DEBUG(LOG_INFO, "oooooh!!! got some!");
246 return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); 246 return bytes - (sizeof(packet.ip) + sizeof(packet.udp));
247 247
248} 248}
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index 8542c664c..5dad7d51c 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -55,7 +55,7 @@ static inline void sanitize_fds(void)
55void background(const char *pidfile) 55void background(const char *pidfile)
56{ 56{
57#ifdef __uClinux__ 57#ifdef __uClinux__
58 LOG(LOG_ERR, "Cannot background in uclinux (yet)"); 58 LOG(LOG_ERR, "Cannot background in uclinux (yet)");
59#else /* __uClinux__ */ 59#else /* __uClinux__ */
60 int pid_fd; 60 int pid_fd;
61 61
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index 78eb1c147..677bbfd17 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -43,7 +43,7 @@ void background(const char *pidfile);
43void start_log_and_pid(const char *client_server, const char *pidfile); 43void start_log_and_pid(const char *client_server, const char *pidfile);
44void background(const char *pidfile); 44void background(const char *pidfile);
45void udhcp_logging(int level, const char *fmt, ...); 45void udhcp_logging(int level, const char *fmt, ...);
46 46
47#define LOG(level, str, args...) udhcp_logging(level, str, ## args) 47#define LOG(level, str, args...) udhcp_logging(level, str, ## args)
48 48
49#ifdef UDHCP_DEBUG 49#ifdef UDHCP_DEBUG
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 2ba42d295..dda678933 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -18,7 +18,7 @@
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#include <sys/time.h> 22#include <sys/time.h>
23#include <sys/file.h> 23#include <sys/file.h>
24#include <unistd.h> 24#include <unistd.h>
@@ -152,7 +152,7 @@ static void perform_release(void)
152 temp_addr.s_addr = server_addr; 152 temp_addr.s_addr = server_addr;
153 sprintf(buffer, "%s", inet_ntoa(temp_addr)); 153 sprintf(buffer, "%s", inet_ntoa(temp_addr));
154 temp_addr.s_addr = requested_ip; 154 temp_addr.s_addr = requested_ip;
155 LOG(LOG_INFO, "Unicasting a release of %s to %s", 155 LOG(LOG_INFO, "Unicasting a release of %s to %s",
156 inet_ntoa(temp_addr), buffer); 156 inet_ntoa(temp_addr), buffer);
157 send_release(server_addr, requested_ip); /* unicast */ 157 send_release(server_addr, requested_ip); /* unicast */
158 run_script(NULL, "deconfig"); 158 run_script(NULL, "deconfig");
@@ -213,7 +213,7 @@ int main(int argc, char *argv[])
213 int option_index = 0; 213 int option_index = 0;
214 c = getopt_long(argc, argv, "c:fbH:h:i:np:qr:s:v", arg_options, &option_index); 214 c = getopt_long(argc, argv, "c:fbH:h:i:np:qr:s:v", arg_options, &option_index);
215 if (c == -1) break; 215 if (c == -1) break;
216 216
217 switch (c) { 217 switch (c) {
218 case 'c': 218 case 'c':
219 len = strlen(optarg) > 255 ? 255 : strlen(optarg); 219 len = strlen(optarg) > 255 ? 255 : strlen(optarg);
@@ -269,10 +269,10 @@ int main(int argc, char *argv[])
269 /* Start the log, sanitize fd's, and write a pid file */ 269 /* Start the log, sanitize fd's, and write a pid file */
270 start_log_and_pid("udhcpc", client_config.pidfile); 270 start_log_and_pid("udhcpc", client_config.pidfile);
271 271
272 if (read_interface(client_config.interface, &client_config.ifindex, 272 if (read_interface(client_config.interface, &client_config.ifindex,
273 NULL, client_config.arp) < 0) 273 NULL, client_config.arp) < 0)
274 return 1; 274 return 1;
275 275
276 if (!client_config.clientid) { 276 if (!client_config.clientid) {
277 client_config.clientid = xmalloc(6 + 3); 277 client_config.clientid = xmalloc(6 + 3);
278 client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID; 278 client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID;
@@ -282,8 +282,8 @@ int main(int argc, char *argv[])
282 } 282 }
283 283
284 /* setup the signal pipe */ 284 /* setup the signal pipe */
285 udhcp_sp_setup(); 285 udhcp_sp_setup();
286 286
287 state = INIT_SELECTING; 287 state = INIT_SELECTING;
288 run_script(NULL, "deconfig"); 288 run_script(NULL, "deconfig");
289 change_mode(LISTEN_RAW); 289 change_mode(LISTEN_RAW);
@@ -321,7 +321,7 @@ int main(int argc, char *argv[])
321 321
322 /* send discover packet */ 322 /* send discover packet */
323 send_discover(xid, requested_ip); /* broadcast */ 323 send_discover(xid, requested_ip); /* broadcast */
324 324
325 timeout = now + ((packet_num == 2) ? 4 : 2); 325 timeout = now + ((packet_num == 2) ? 4 : 2);
326 packet_num++; 326 packet_num++;
327 } else { 327 } else {
@@ -345,7 +345,7 @@ int main(int argc, char *argv[])
345 if (state == RENEW_REQUESTED) 345 if (state == RENEW_REQUESTED)
346 send_renew(xid, server_addr, requested_ip); /* unicast */ 346 send_renew(xid, server_addr, requested_ip); /* unicast */
347 else send_selecting(xid, server_addr, requested_ip); /* broadcast */ 347 else send_selecting(xid, server_addr, requested_ip); /* broadcast */
348 348
349 timeout = now + ((packet_num == 2) ? 10 : 2); 349 timeout = now + ((packet_num == 2) ? 10 : 2);
350 packet_num++; 350 packet_num++;
351 } else { 351 } else {
@@ -373,7 +373,7 @@ int main(int argc, char *argv[])
373 } else { 373 } else {
374 /* send a request packet */ 374 /* send a request packet */
375 send_renew(xid, server_addr, requested_ip); /* unicast */ 375 send_renew(xid, server_addr, requested_ip); /* unicast */
376 376
377 t1 = (t2 - t1) / 2 + t1; 377 t1 = (t2 - t1) / 2 + t1;
378 timeout = t1 + start; 378 timeout = t1 + start;
379 } 379 }
@@ -403,28 +403,28 @@ int main(int argc, char *argv[])
403 } 403 }
404 } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(fd, &rfds)) { 404 } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(fd, &rfds)) {
405 /* a packet is ready, read it */ 405 /* a packet is ready, read it */
406 406
407 if (listen_mode == LISTEN_KERNEL) 407 if (listen_mode == LISTEN_KERNEL)
408 len = get_packet(&packet, fd); 408 len = get_packet(&packet, fd);
409 else len = get_raw_packet(&packet, fd); 409 else len = get_raw_packet(&packet, fd);
410 410
411 if (len == -1 && errno != EINTR) { 411 if (len == -1 && errno != EINTR) {
412 DEBUG(LOG_INFO, "error on read, %m, reopening socket"); 412 DEBUG(LOG_INFO, "error on read, %m, reopening socket");
413 change_mode(listen_mode); /* just close and reopen */ 413 change_mode(listen_mode); /* just close and reopen */
414 } 414 }
415 if (len < 0) continue; 415 if (len < 0) continue;
416 416
417 if (packet.xid != xid) { 417 if (packet.xid != xid) {
418 DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)", 418 DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)",
419 (unsigned long) packet.xid, xid); 419 (unsigned long) packet.xid, xid);
420 continue; 420 continue;
421 } 421 }
422 422
423 if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { 423 if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) {
424 DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring"); 424 DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring");
425 continue; 425 continue;
426 } 426 }
427 427
428 switch (state) { 428 switch (state) {
429 case INIT_SELECTING: 429 case INIT_SELECTING:
430 /* Must be a DHCPOFFER to one of our xid's */ 430 /* Must be a DHCPOFFER to one of our xid's */
@@ -433,7 +433,7 @@ int main(int argc, char *argv[])
433 memcpy(&server_addr, temp, 4); 433 memcpy(&server_addr, temp, 4);
434 xid = packet.xid; 434 xid = packet.xid;
435 requested_ip = packet.yiaddr; 435 requested_ip = packet.yiaddr;
436 436
437 /* enter requesting state */ 437 /* enter requesting state */
438 state = REQUESTING; 438 state = REQUESTING;
439 timeout = now; 439 timeout = now;
@@ -455,14 +455,14 @@ int main(int argc, char *argv[])
455 memcpy(&lease, temp, 4); 455 memcpy(&lease, temp, 4);
456 lease = ntohl(lease); 456 lease = ntohl(lease);
457 } 457 }
458 458
459 /* enter bound state */ 459 /* enter bound state */
460 t1 = lease / 2; 460 t1 = lease / 2;
461 461
462 /* little fixed point for n * .875 */ 462 /* little fixed point for n * .875 */
463 t2 = (lease * 0x7) >> 3; 463 t2 = (lease * 0x7) >> 3;
464 temp_addr.s_addr = packet.yiaddr; 464 temp_addr.s_addr = packet.yiaddr;
465 LOG(LOG_INFO, "Lease of %s obtained, lease time %ld", 465 LOG(LOG_INFO, "Lease of %s obtained, lease time %ld",
466 inet_ntoa(temp_addr), lease); 466 inet_ntoa(temp_addr), lease);
467 start = now; 467 start = now;
468 timeout = t1 + start; 468 timeout = t1 + start;
@@ -472,7 +472,7 @@ int main(int argc, char *argv[])
472 472
473 state = BOUND; 473 state = BOUND;
474 change_mode(LISTEN_NONE); 474 change_mode(LISTEN_NONE);
475 if (client_config.quit_after_lease) 475 if (client_config.quit_after_lease)
476 return 0; 476 return 0;
477 if (!client_config.foreground) 477 if (!client_config.foreground)
478 client_background(); 478 client_background();
@@ -492,10 +492,10 @@ int main(int argc, char *argv[])
492 } 492 }
493 break; 493 break;
494 /* case BOUND, RELEASED: - ignore all packets */ 494 /* case BOUND, RELEASED: - ignore all packets */
495 } 495 }
496 } else if (retval > 0 && (sig = udhcp_sp_read(&rfds))) { 496 } else if (retval > 0 && (sig = udhcp_sp_read(&rfds))) {
497 switch (sig) { 497 switch (sig) {
498 case SIGUSR1: 498 case SIGUSR1:
499 perform_renew(); 499 perform_renew();
500 break; 500 break;
501 case SIGUSR2: 501 case SIGUSR2:
@@ -506,12 +506,12 @@ int main(int argc, char *argv[])
506 return 0; 506 return 0;
507 } 507 }
508 } else if (retval == -1 && errno == EINTR) { 508 } else if (retval == -1 && errno == EINTR) {
509 /* a signal was caught */ 509 /* a signal was caught */
510 } else { 510 } else {
511 /* An error occured */ 511 /* An error occured */
512 DEBUG(LOG_ERR, "Error on select"); 512 DEBUG(LOG_ERR, "Error on select");
513 } 513 }
514 514
515 } 515 }
516 return 0; 516 return 0;
517} 517}
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 8c944f243..6f38f07f7 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -51,12 +51,12 @@ struct dhcpOfferedAddr *leases;
51struct server_config_t server_config; 51struct server_config_t server_config;
52 52
53 53
54#ifdef COMBINED_BINARY 54#ifdef COMBINED_BINARY
55int udhcpd_main(int argc, char *argv[]) 55int udhcpd_main(int argc, char *argv[])
56#else 56#else
57int main(int argc, char *argv[]) 57int main(int argc, char *argv[])
58#endif 58#endif
59{ 59{
60 fd_set rfds; 60 fd_set rfds;
61 struct timeval tv; 61 struct timeval tv;
62 int server_socket = -1; 62 int server_socket = -1;
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
70 struct dhcpOfferedAddr *lease; 70 struct dhcpOfferedAddr *lease;
71 int max_sock; 71 int max_sock;
72 unsigned long num_ips; 72 unsigned long num_ips;
73 73
74 memset(&server_config, 0, sizeof(struct server_config_t)); 74 memset(&server_config, 0, sizeof(struct server_config_t));
75 read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]); 75 read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]);
76 76
@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
82 server_config.lease = ntohl(server_config.lease); 82 server_config.lease = ntohl(server_config.lease);
83 } 83 }
84 else server_config.lease = LEASE_TIME; 84 else server_config.lease = LEASE_TIME;
85 85
86 /* Sanity check */ 86 /* Sanity check */
87 num_ips = ntohl(server_config.end) - ntohl(server_config.start); 87 num_ips = ntohl(server_config.end) - ntohl(server_config.start);
88 if (server_config.max_leases > num_ips) { 88 if (server_config.max_leases > num_ips) {
@@ -113,7 +113,7 @@ int main(int argc, char *argv[])
113 if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) { 113 if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) {
114 LOG(LOG_ERR, "FATAL: couldn't create server socket, %m"); 114 LOG(LOG_ERR, "FATAL: couldn't create server socket, %m");
115 return 2; 115 return 2;
116 } 116 }
117 117
118 max_sock = udhcp_sp_fd_set(&rfds, server_socket); 118 max_sock = udhcp_sp_fd_set(&rfds, server_socket);
119 if (server_config.auto_time) { 119 if (server_config.auto_time) {
@@ -121,7 +121,7 @@ int main(int argc, char *argv[])
121 tv.tv_usec = 0; 121 tv.tv_usec = 0;
122 } 122 }
123 if (!server_config.auto_time || tv.tv_sec > 0) { 123 if (!server_config.auto_time || tv.tv_sec > 0) {
124 retval = select(max_sock + 1, &rfds, NULL, NULL, 124 retval = select(max_sock + 1, &rfds, NULL, NULL,
125 server_config.auto_time ? &tv : NULL); 125 server_config.auto_time ? &tv : NULL);
126 } else retval = 0; /* If we already timed out, fall through */ 126 } else retval = 0; /* If we already timed out, fall through */
127 127
@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
133 DEBUG(LOG_INFO, "error on select"); 133 DEBUG(LOG_INFO, "error on select");
134 continue; 134 continue;
135 } 135 }
136 136
137 switch (udhcp_sp_read(&rfds)) { 137 switch (udhcp_sp_read(&rfds)) {
138 case SIGUSR1: 138 case SIGUSR1:
139 LOG(LOG_INFO, "Received a SIGUSR1"); 139 LOG(LOG_INFO, "Received a SIGUSR1");
@@ -161,17 +161,17 @@ int main(int argc, char *argv[])
161 DEBUG(LOG_ERR, "couldn't get option from packet, ignoring"); 161 DEBUG(LOG_ERR, "couldn't get option from packet, ignoring");
162 continue; 162 continue;
163 } 163 }
164 164
165 /* ADDME: look for a static lease */ 165 /* ADDME: look for a static lease */
166 lease = find_lease_by_chaddr(packet.chaddr); 166 lease = find_lease_by_chaddr(packet.chaddr);
167 switch (state[0]) { 167 switch (state[0]) {
168 case DHCPDISCOVER: 168 case DHCPDISCOVER:
169 DEBUG(LOG_INFO,"received DISCOVER"); 169 DEBUG(LOG_INFO,"received DISCOVER");
170 170
171 if (sendOffer(&packet) < 0) { 171 if (sendOffer(&packet) < 0) {
172 LOG(LOG_ERR, "send OFFER failed"); 172 LOG(LOG_ERR, "send OFFER failed");
173 } 173 }
174 break; 174 break;
175 case DHCPREQUEST: 175 case DHCPREQUEST:
176 DEBUG(LOG_INFO, "received REQUEST"); 176 DEBUG(LOG_INFO, "received REQUEST");
177 177
@@ -180,12 +180,12 @@ int main(int argc, char *argv[])
180 180
181 if (requested) memcpy(&requested_align, requested, 4); 181 if (requested) memcpy(&requested_align, requested, 4);
182 if (server_id) memcpy(&server_id_align, server_id, 4); 182 if (server_id) memcpy(&server_id_align, server_id, 4);
183 183
184 if (lease) { /*ADDME: or static lease */ 184 if (lease) { /*ADDME: or static lease */
185 if (server_id) { 185 if (server_id) {
186 /* SELECTING State */ 186 /* SELECTING State */
187 DEBUG(LOG_INFO, "server_id = %08x", ntohl(server_id_align)); 187 DEBUG(LOG_INFO, "server_id = %08x", ntohl(server_id_align));
188 if (server_id_align == server_config.server && requested && 188 if (server_id_align == server_config.server && requested &&
189 requested_align == lease->yiaddr) { 189 requested_align == lease->yiaddr) {
190 sendACK(&packet, lease->yiaddr); 190 sendACK(&packet, lease->yiaddr);
191 } 191 }
@@ -203,9 +203,9 @@ int main(int argc, char *argv[])
203 /* don't know what to do!!!! */ 203 /* don't know what to do!!!! */
204 sendNAK(&packet); 204 sendNAK(&packet);
205 } 205 }
206 } 206 }
207 } 207 }
208 208
209 /* what to do if we have no record of the client */ 209 /* what to do if we have no record of the client */
210 } else if (server_id) { 210 } else if (server_id) {
211 /* SELECTING State */ 211 /* SELECTING State */
@@ -218,7 +218,7 @@ int main(int argc, char *argv[])
218 memset(lease->chaddr, 0, 16); 218 memset(lease->chaddr, 0, 16);
219 /* make some contention for this address */ 219 /* make some contention for this address */
220 } else sendNAK(&packet); 220 } else sendNAK(&packet);
221 } else if (requested_align < server_config.start || 221 } else if (requested_align < server_config.start ||
222 requested_align > server_config.end) { 222 requested_align > server_config.end) {
223 sendNAK(&packet); 223 sendNAK(&packet);
224 } /* else remain silent */ 224 } /* else remain silent */
@@ -232,7 +232,7 @@ int main(int argc, char *argv[])
232 if (lease) { 232 if (lease) {
233 memset(lease->chaddr, 0, 16); 233 memset(lease->chaddr, 0, 16);
234 lease->expires = time(0) + server_config.decline_time; 234 lease->expires = time(0) + server_config.decline_time;
235 } 235 }
236 break; 236 break;
237 case DHCPRELEASE: 237 case DHCPRELEASE:
238 DEBUG(LOG_INFO,"received RELEASE"); 238 DEBUG(LOG_INFO,"received RELEASE");
@@ -241,7 +241,7 @@ int main(int argc, char *argv[])
241 case DHCPINFORM: 241 case DHCPINFORM:
242 DEBUG(LOG_INFO,"received INFORM"); 242 DEBUG(LOG_INFO,"received INFORM");
243 send_inform(&packet); 243 send_inform(&packet);
244 break; 244 break;
245 default: 245 default:
246 LOG(LOG_WARNING, "unsupported DHCP message (%02x) -- ignoring", state[0]); 246 LOG(LOG_WARNING, "unsupported DHCP message (%02x) -- ignoring", state[0]);
247 } 247 }
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h
index 925634461..39658a8ff 100644
--- a/networking/udhcp/dhcpd.h
+++ b/networking/udhcp/dhcpd.h
@@ -124,10 +124,10 @@ struct server_config_t {
124 uint32_t siaddr; /* next server bootp option */ 124 uint32_t siaddr; /* next server bootp option */
125 char *sname; /* bootp server name */ 125 char *sname; /* bootp server name */
126 char *boot_file; /* bootp boot file option */ 126 char *boot_file; /* bootp boot file option */
127}; 127};
128 128
129extern struct server_config_t server_config; 129extern struct server_config_t server_config;
130extern struct dhcpOfferedAddr *leases; 130extern struct dhcpOfferedAddr *leases;
131 131
132 132
133#endif 133#endif
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c
index e2b19315d..a9036dfbd 100644
--- a/networking/udhcp/dumpleases.c
+++ b/networking/udhcp/dumpleases.c
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
47 const char *file = LEASES_FILE; 47 const char *file = LEASES_FILE;
48 struct dhcpOfferedAddr lease; 48 struct dhcpOfferedAddr lease;
49 struct in_addr addr; 49 struct in_addr addr;
50 50
51 static const struct option options[] = { 51 static const struct option options[] = {
52 {"absolute", 0, 0, 'a'}, 52 {"absolute", 0, 0, 'a'},
53 {"remaining", 0, 0, 'r'}, 53 {"remaining", 0, 0, 'r'},
@@ -59,7 +59,7 @@ int main(int argc, char *argv[])
59 int option_index = 0; 59 int option_index = 0;
60 c = getopt_long(argc, argv, "arf:", options, &option_index); 60 c = getopt_long(argc, argv, "arf:", options, &option_index);
61 if (c == -1) break; 61 if (c == -1) break;
62 62
63 switch (c) { 63 switch (c) {
64 case 'a': mode = ABSOLUTE; break; 64 case 'a': mode = ABSOLUTE; break;
65 case 'r': mode = REMAINING; break; 65 case 'r': mode = REMAINING; break;
@@ -70,10 +70,10 @@ int main(int argc, char *argv[])
70 show_usage(); 70 show_usage();
71 } 71 }
72 } 72 }
73 73
74 fp = xfopen(file, "r"); 74 fp = xfopen(file, "r");
75 75
76 printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at"); 76 printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at");
77 /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ 77 /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */
78 while (fread(&lease, sizeof(lease), 1, fp)) { 78 while (fread(&lease, sizeof(lease), 1, fp)) {
79 79
@@ -105,6 +105,6 @@ int main(int argc, char *argv[])
105 } else printf("%s", ctime(&expires)); 105 } else printf("%s", ctime(&expires));
106 } 106 }
107 fclose(fp); 107 fclose(fp);
108 108
109 return 0; 109 return 0;
110} 110}
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 0802bb316..89287ca2d 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * files.c -- DHCP server file manipulation * 2 * files.c -- DHCP server file manipulation *
3 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 3 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
4 */ 4 */
5 5
6#include <sys/socket.h> 6#include <sys/socket.h>
7#include <arpa/inet.h> 7#include <arpa/inet.h>
8#include <string.h> 8#include <string.h>
@@ -16,7 +16,7 @@
16#include "options.h" 16#include "options.h"
17#include "common.h" 17#include "common.h"
18 18
19/* 19/*
20 * Domain names may have 254 chars, and string options can be 254 20 * Domain names may have 254 chars, and string options can be 254
21 * chars long. However, 80 bytes will be enough for most, and won't 21 * chars long. However, 80 bytes will be enough for most, and won't
22 * hog up memory. If you have a special application, change it 22 * hog up memory. If you have a special application, change it
@@ -31,7 +31,7 @@ static int read_ip(const char *line, void *arg)
31 int retval = 1; 31 int retval = 1;
32 32
33 if (!inet_aton(line, addr)) { 33 if (!inet_aton(line, addr)) {
34 if ((host = gethostbyname(line))) 34 if ((host = gethostbyname(line)))
35 addr->s_addr = *((unsigned long *) host->h_addr_list[0]); 35 addr->s_addr = *((unsigned long *) host->h_addr_list[0]);
36 else retval = 0; 36 else retval = 0;
37 } 37 }
@@ -42,10 +42,10 @@ static int read_ip(const char *line, void *arg)
42static int read_str(const char *line, void *arg) 42static int read_str(const char *line, void *arg)
43{ 43{
44 char **dest = arg; 44 char **dest = arg;
45 45
46 if (*dest) free(*dest); 46 if (*dest) free(*dest);
47 *dest = strdup(line); 47 *dest = strdup(line);
48 48
49 return 1; 49 return 1;
50} 50}
51 51
@@ -69,7 +69,7 @@ static int read_yn(const char *line, void *arg)
69 else if (!strcasecmp("no", line)) 69 else if (!strcasecmp("no", line))
70 *dest = 0; 70 *dest = 0;
71 else retval = 0; 71 else retval = 0;
72 72
73 return retval; 73 return retval;
74} 74}
75 75
@@ -89,11 +89,11 @@ static int read_opt(const char *const_line, void *arg)
89 /* Cheat, the only const line we'll actually get is "" */ 89 /* Cheat, the only const line we'll actually get is "" */
90 line = (char *) const_line; 90 line = (char *) const_line;
91 if (!(opt = strtok(line, " \t="))) return 0; 91 if (!(opt = strtok(line, " \t="))) return 0;
92 92
93 for (option = dhcp_options; option->code; option++) 93 for (option = dhcp_options; option->code; option++)
94 if (!strcasecmp(option->name, opt)) 94 if (!strcasecmp(option->name, opt))
95 break; 95 break;
96 96
97 if (!option->code) return 0; 97 if (!option->code) return 0;
98 98
99 do { 99 do {
@@ -134,17 +134,17 @@ static int read_opt(const char *const_line, void *arg)
134 retval = (endptr[0] == '\0'); 134 retval = (endptr[0] == '\0');
135 break; 135 break;
136 case OPTION_U32: 136 case OPTION_U32:
137 *result_u32 = htonl(strtoul(val, &endptr, 0)); 137 *result_u32 = htonl(strtoul(val, &endptr, 0));
138 retval = (endptr[0] == '\0'); 138 retval = (endptr[0] == '\0');
139 break; 139 break;
140 case OPTION_S32: 140 case OPTION_S32:
141 *result_u32 = htonl(strtol(val, &endptr, 0)); 141 *result_u32 = htonl(strtol(val, &endptr, 0));
142 retval = (endptr[0] == '\0'); 142 retval = (endptr[0] == '\0');
143 break; 143 break;
144 default: 144 default:
145 break; 145 break;
146 } 146 }
147 if (retval) 147 if (retval)
148 attach_option(opt_list, option, opt, length); 148 attach_option(opt_list, option, opt, length);
149 } while (retval && option->flags & OPTION_LIST); 149 } while (retval && option->flags & OPTION_LIST);
150 return retval; 150 return retval;
@@ -193,7 +193,7 @@ int read_config(const char *file)
193 LOG(LOG_ERR, "unable to open config file: %s", file); 193 LOG(LOG_ERR, "unable to open config file: %s", file);
194 return 0; 194 return 0;
195 } 195 }
196 196
197 while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) { 197 while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) {
198 lm++; 198 lm++;
199 if (strchr(buffer, '\n')) *(strchr(buffer, '\n')) = '\0'; 199 if (strchr(buffer, '\n')) *(strchr(buffer, '\n')) = '\0';
@@ -203,14 +203,14 @@ int read_config(const char *file)
203 if (strchr(buffer, '#')) *(strchr(buffer, '#')) = '\0'; 203 if (strchr(buffer, '#')) *(strchr(buffer, '#')) = '\0';
204 204
205 if (!(token = strtok(buffer, " \t"))) continue; 205 if (!(token = strtok(buffer, " \t"))) continue;
206 if (!(line = strtok(NULL, ""))) continue; 206 if (!(line = strtok(NULL, ""))) continue;
207 207
208 /* eat leading whitespace */ 208 /* eat leading whitespace */
209 line = line + strspn(line, " \t="); 209 line = line + strspn(line, " \t=");
210 /* eat trailing whitespace */ 210 /* eat trailing whitespace */
211 for (i = strlen(line); i > 0 && isspace(line[i - 1]); i--); 211 for (i = strlen(line); i > 0 && isspace(line[i - 1]); i--);
212 line[i] = '\0'; 212 line[i] = '\0';
213 213
214 for (i = 0; keywords[i].keyword[0]; i++) 214 for (i = 0; keywords[i].keyword[0]; i++)
215 if (!strcasecmp(token, keywords[i].keyword)) 215 if (!strcasecmp(token, keywords[i].keyword))
216 if (!keywords[i].handler(line, keywords[i].var)) { 216 if (!keywords[i].handler(line, keywords[i].var)) {
@@ -232,12 +232,12 @@ void write_leases(void)
232 char buf[255]; 232 char buf[255];
233 time_t curr = time(0); 233 time_t curr = time(0);
234 unsigned long tmp_time; 234 unsigned long tmp_time;
235 235
236 if (!(fp = fopen(server_config.lease_file, "w"))) { 236 if (!(fp = fopen(server_config.lease_file, "w"))) {
237 LOG(LOG_ERR, "Unable to open %s for writing", server_config.lease_file); 237 LOG(LOG_ERR, "Unable to open %s for writing", server_config.lease_file);
238 return; 238 return;
239 } 239 }
240 240
241 for (i = 0; i < server_config.max_leases; i++) { 241 for (i = 0; i < server_config.max_leases; i++) {
242 if (leases[i].yiaddr != 0) { 242 if (leases[i].yiaddr != 0) {
243 243
@@ -257,7 +257,7 @@ void write_leases(void)
257 } 257 }
258 } 258 }
259 fclose(fp); 259 fclose(fp);
260 260
261 if (server_config.notify_file) { 261 if (server_config.notify_file) {
262 sprintf(buf, "%s %s", server_config.notify_file, server_config.lease_file); 262 sprintf(buf, "%s %s", server_config.notify_file, server_config.lease_file);
263 system(buf); 263 system(buf);
@@ -270,12 +270,12 @@ void read_leases(const char *file)
270 FILE *fp; 270 FILE *fp;
271 unsigned int i = 0; 271 unsigned int i = 0;
272 struct dhcpOfferedAddr lease; 272 struct dhcpOfferedAddr lease;
273 273
274 if (!(fp = fopen(file, "r"))) { 274 if (!(fp = fopen(file, "r"))) {
275 LOG(LOG_ERR, "Unable to open %s for reading", file); 275 LOG(LOG_ERR, "Unable to open %s for reading", file);
276 return; 276 return;
277 } 277 }
278 278
279 while (i < server_config.max_leases && (fread(&lease, sizeof lease, 1, fp) == 1)) { 279 while (i < server_config.max_leases && (fread(&lease, sizeof lease, 1, fp) == 1)) {
280 /* ADDME: is it a static lease */ 280 /* ADDME: is it a static lease */
281 if (lease.yiaddr >= server_config.start && lease.yiaddr <= server_config.end) { 281 if (lease.yiaddr >= server_config.start && lease.yiaddr <= server_config.end) {
@@ -284,7 +284,7 @@ void read_leases(const char *file)
284 if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) { 284 if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) {
285 LOG(LOG_WARNING, "Too many leases while loading %s\n", file); 285 LOG(LOG_WARNING, "Too many leases while loading %s\n", file);
286 break; 286 break;
287 } 287 }
288 i++; 288 i++;
289 } 289 }
290 } 290 }
diff --git a/networking/udhcp/frontend.c b/networking/udhcp/frontend.c
index de5779508..fa77ab977 100644
--- a/networking/udhcp/frontend.c
+++ b/networking/udhcp/frontend.c
@@ -7,10 +7,10 @@ int main(int argc, char *argv[])
7{ 7{
8 int ret = 0; 8 int ret = 0;
9 char *base = strrchr(argv[0], '/'); 9 char *base = strrchr(argv[0], '/');
10 10
11 if (strstr(base ? (base + 1) : argv[0], "dhcpd")) 11 if (strstr(base ? (base + 1) : argv[0], "dhcpd"))
12 ret = udhcpd_main(argc, argv); 12 ret = udhcpd_main(argc, argv);
13 else ret = udhcpc_main(argc, argv); 13 else ret = udhcpc_main(argc, argv);
14 14
15 return ret; 15 return ret;
16} 16}
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c
index dce056654..d478880a3 100644
--- a/networking/udhcp/leases.c
+++ b/networking/udhcp/leases.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * leases.c -- tools to manage DHCP leases 2 * leases.c -- tools to manage DHCP leases
3 * Russ Dill <Russ.Dill@asu.edu> July 2001 3 * Russ Dill <Russ.Dill@asu.edu> July 2001
4 */ 4 */
5 5
@@ -23,9 +23,9 @@ uint8_t blank_chaddr[] = {[0 ... 15] = 0};
23void clear_lease(uint8_t *chaddr, uint32_t yiaddr) 23void clear_lease(uint8_t *chaddr, uint32_t yiaddr)
24{ 24{
25 unsigned int i, j; 25 unsigned int i, j;
26 26
27 for (j = 0; j < 16 && !chaddr[j]; j++); 27 for (j = 0; j < 16 && !chaddr[j]; j++);
28 28
29 for (i = 0; i < server_config.max_leases; i++) 29 for (i = 0; i < server_config.max_leases; i++)
30 if ((j != 16 && !memcmp(leases[i].chaddr, chaddr, 16)) || 30 if ((j != 16 && !memcmp(leases[i].chaddr, chaddr, 16)) ||
31 (yiaddr && leases[i].yiaddr == yiaddr)) { 31 (yiaddr && leases[i].yiaddr == yiaddr)) {
@@ -38,18 +38,18 @@ void clear_lease(uint8_t *chaddr, uint32_t yiaddr)
38struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned long lease) 38struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned long lease)
39{ 39{
40 struct dhcpOfferedAddr *oldest; 40 struct dhcpOfferedAddr *oldest;
41 41
42 /* clean out any old ones */ 42 /* clean out any old ones */
43 clear_lease(chaddr, yiaddr); 43 clear_lease(chaddr, yiaddr);
44 44
45 oldest = oldest_expired_lease(); 45 oldest = oldest_expired_lease();
46 46
47 if (oldest) { 47 if (oldest) {
48 memcpy(oldest->chaddr, chaddr, 16); 48 memcpy(oldest->chaddr, chaddr, 16);
49 oldest->yiaddr = yiaddr; 49 oldest->yiaddr = yiaddr;
50 oldest->expires = time(0) + lease; 50 oldest->expires = time(0) + lease;
51 } 51 }
52 52
53 return oldest; 53 return oldest;
54} 54}
55 55
@@ -58,7 +58,7 @@ struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned lon
58int lease_expired(struct dhcpOfferedAddr *lease) 58int lease_expired(struct dhcpOfferedAddr *lease)
59{ 59{
60 return (lease->expires < (unsigned long) time(0)); 60 return (lease->expires < (unsigned long) time(0));
61} 61}
62 62
63 63
64/* Find the oldest expired lease, NULL if there are no expired leases */ 64/* Find the oldest expired lease, NULL if there are no expired leases */
@@ -68,14 +68,14 @@ struct dhcpOfferedAddr *oldest_expired_lease(void)
68 unsigned long oldest_lease = time(0); 68 unsigned long oldest_lease = time(0);
69 unsigned int i; 69 unsigned int i;
70 70
71 71
72 for (i = 0; i < server_config.max_leases; i++) 72 for (i = 0; i < server_config.max_leases; i++)
73 if (oldest_lease > leases[i].expires) { 73 if (oldest_lease > leases[i].expires) {
74 oldest_lease = leases[i].expires; 74 oldest_lease = leases[i].expires;
75 oldest = &(leases[i]); 75 oldest = &(leases[i]);
76 } 76 }
77 return oldest; 77 return oldest;
78 78
79} 79}
80 80
81 81
@@ -86,7 +86,7 @@ struct dhcpOfferedAddr *find_lease_by_chaddr(uint8_t *chaddr)
86 86
87 for (i = 0; i < server_config.max_leases; i++) 87 for (i = 0; i < server_config.max_leases; i++)
88 if (!memcmp(leases[i].chaddr, chaddr, 16)) return &(leases[i]); 88 if (!memcmp(leases[i].chaddr, chaddr, 16)) return &(leases[i]);
89 89
90 return NULL; 90 return NULL;
91} 91}
92 92
@@ -98,7 +98,7 @@ struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr)
98 98
99 for (i = 0; i < server_config.max_leases; i++) 99 for (i = 0; i < server_config.max_leases; i++)
100 if (leases[i].yiaddr == yiaddr) return &(leases[i]); 100 if (leases[i].yiaddr == yiaddr) return &(leases[i]);
101 101
102 return NULL; 102 return NULL;
103} 103}
104 104
@@ -120,10 +120,10 @@ static int check_ip(uint32_t addr)
120 120
121/* find an assignable address, it check_expired is true, we check all the expired leases as well. 121/* find an assignable address, it check_expired is true, we check all the expired leases as well.
122 * Maybe this should try expired leases by age... */ 122 * Maybe this should try expired leases by age... */
123uint32_t find_address(int check_expired) 123uint32_t find_address(int check_expired)
124{ 124{
125 uint32_t addr, ret; 125 uint32_t addr, ret;
126 struct dhcpOfferedAddr *lease = NULL; 126 struct dhcpOfferedAddr *lease = NULL;
127 127
128 addr = ntohl(server_config.start); /* addr is in host order here */ 128 addr = ntohl(server_config.start); /* addr is in host order here */
129 for (;addr <= ntohl(server_config.end); addr++) { 129 for (;addr <= ntohl(server_config.end); addr++) {
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 1bdf25708..d75bc5aff 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * options.c -- DHCP server option packet tools 2 * options.c -- DHCP server option packet tools
3 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 3 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
4 */ 4 */
5 5
6#include <stdlib.h> 6#include <stdlib.h>
7#include <string.h> 7#include <string.h>
8 8
@@ -64,7 +64,7 @@ uint8_t *get_option(struct dhcpMessage *packet, int code)
64 int i, length; 64 int i, length;
65 uint8_t *optionptr; 65 uint8_t *optionptr;
66 int over = 0, done = 0, curr = OPTION_FIELD; 66 int over = 0, done = 0, curr = OPTION_FIELD;
67 67
68 optionptr = packet->options; 68 optionptr = packet->options;
69 i = 0; 69 i = 0;
70 length = 308; 70 length = 308;
@@ -79,7 +79,7 @@ uint8_t *get_option(struct dhcpMessage *packet, int code)
79 return NULL; 79 return NULL;
80 } 80 }
81 return optionptr + i + 2; 81 return optionptr + i + 2;
82 } 82 }
83 switch (optionptr[i + OPT_CODE]) { 83 switch (optionptr[i + OPT_CODE]) {
84 case DHCP_PADDING: 84 case DHCP_PADDING:
85 i++; 85 i++;
@@ -114,10 +114,10 @@ uint8_t *get_option(struct dhcpMessage *packet, int code)
114 114
115 115
116/* return the position of the 'end' option (no bounds checking) */ 116/* return the position of the 'end' option (no bounds checking) */
117int end_option(uint8_t *optionptr) 117int end_option(uint8_t *optionptr)
118{ 118{
119 int i = 0; 119 int i = 0;
120 120
121 while (optionptr[i] != DHCP_END) { 121 while (optionptr[i] != DHCP_END) {
122 if (optionptr[i] == DHCP_PADDING) i++; 122 if (optionptr[i] == DHCP_PADDING) i++;
123 else i += optionptr[i + OPT_LEN] + 2; 123 else i += optionptr[i + OPT_LEN] + 2;
@@ -131,7 +131,7 @@ int end_option(uint8_t *optionptr)
131int add_option_string(uint8_t *optionptr, uint8_t *string) 131int add_option_string(uint8_t *optionptr, uint8_t *string)
132{ 132{
133 int end = end_option(optionptr); 133 int end = end_option(optionptr);
134 134
135 /* end position + string length + option code/length + end option */ 135 /* end position + string length + option code/length + end option */
136 if (end + string[OPT_LEN] + 2 + 1 >= 308) { 136 if (end + string[OPT_LEN] + 2 + 1 >= 308) {
137 LOG(LOG_ERR, "Option 0x%02x did not fit into the packet!", string[OPT_CODE]); 137 LOG(LOG_ERR, "Option 0x%02x did not fit into the packet!", string[OPT_CODE]);
@@ -162,12 +162,12 @@ int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
162 if (dhcp_options[i].code == code) { 162 if (dhcp_options[i].code == code) {
163 length = option_lengths[dhcp_options[i].flags & TYPE_MASK]; 163 length = option_lengths[dhcp_options[i].flags & TYPE_MASK];
164 } 164 }
165 165
166 if (!length) { 166 if (!length) {
167 DEBUG(LOG_ERR, "Could not add option 0x%02x", code); 167 DEBUG(LOG_ERR, "Could not add option 0x%02x", code);
168 return 0; 168 return 0;
169 } 169 }
170 170
171 option[OPT_CODE] = code; 171 option[OPT_CODE] = code;
172 option[OPT_LEN] = length; 172 option[OPT_LEN] = length;
173 173
@@ -202,7 +202,7 @@ void attach_option(struct option_set **opt_list, struct dhcp_option *option, cha
202 DEBUG(LOG_INFO, "Attaching option %s to existing member of list", option->name); 202 DEBUG(LOG_INFO, "Attaching option %s to existing member of list", option->name);
203 if (option->flags & OPTION_LIST) { 203 if (option->flags & OPTION_LIST) {
204 if (existing->data[OPT_LEN] + length <= 255) { 204 if (existing->data[OPT_LEN] + length <= 255) {
205 existing->data = realloc(existing->data, 205 existing->data = realloc(existing->data,
206 existing->data[OPT_LEN] + length + 2); 206 existing->data[OPT_LEN] + length + 2);
207 memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer, length); 207 memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer, length);
208 existing->data[OPT_LEN] += length; 208 existing->data[OPT_LEN] += length;
@@ -210,19 +210,19 @@ void attach_option(struct option_set **opt_list, struct dhcp_option *option, cha
210 } /* else, ignore the new data */ 210 } /* else, ignore the new data */
211 } else { 211 } else {
212 DEBUG(LOG_INFO, "Attaching option %s to list", option->name); 212 DEBUG(LOG_INFO, "Attaching option %s to list", option->name);
213 213
214 /* make a new option */ 214 /* make a new option */
215 new = xmalloc(sizeof(struct option_set)); 215 new = xmalloc(sizeof(struct option_set));
216 new->data = xmalloc(length + 2); 216 new->data = xmalloc(length + 2);
217 new->data[OPT_CODE] = option->code; 217 new->data[OPT_CODE] = option->code;
218 new->data[OPT_LEN] = length; 218 new->data[OPT_LEN] = length;
219 memcpy(new->data + 2, buffer, length); 219 memcpy(new->data + 2, buffer, length);
220 220
221 curr = opt_list; 221 curr = opt_list;
222 while (*curr && (*curr)->data[OPT_CODE] < option->code) 222 while (*curr && (*curr)->data[OPT_CODE] < option->code)
223 curr = &(*curr)->next; 223 curr = &(*curr)->next;
224 224
225 new->next = *curr; 225 new->next = *curr;
226 *curr = new; 226 *curr = new;
227 } 227 }
228} 228}
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index a3c7ae153..7cbd83a35 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -66,7 +66,7 @@ int get_packet(struct dhcpMessage *packet, int fd)
66 return -2; 66 return -2;
67 } 67 }
68 DEBUG(LOG_INFO, "Received a packet"); 68 DEBUG(LOG_INFO, "Received a packet");
69 69
70 if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) { 70 if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) {
71 for (i = 0; broken_vendors[i][0]; i++) { 71 for (i = 0; broken_vendors[i][0]; i++) {
72 if (vendor[OPT_LEN - 2] == (uint8_t) strlen(broken_vendors[i]) && 72 if (vendor[OPT_LEN - 2] == (uint8_t) strlen(broken_vendors[i]) &&
@@ -77,7 +77,7 @@ int get_packet(struct dhcpMessage *packet, int fd)
77 } 77 }
78 } 78 }
79 } 79 }
80 80
81 81
82 return bytes; 82 return bytes;
83} 83}
@@ -126,10 +126,10 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
126 DEBUG(LOG_ERR, "socket call failed: %m"); 126 DEBUG(LOG_ERR, "socket call failed: %m");
127 return -1; 127 return -1;
128 } 128 }
129 129
130 memset(&dest, 0, sizeof(dest)); 130 memset(&dest, 0, sizeof(dest));
131 memset(&packet, 0, sizeof(packet)); 131 memset(&packet, 0, sizeof(packet));
132 132
133 dest.sll_family = AF_PACKET; 133 dest.sll_family = AF_PACKET;
134 dest.sll_protocol = htons(ETH_P_IP); 134 dest.sll_protocol = htons(ETH_P_IP);
135 dest.sll_ifindex = ifindex; 135 dest.sll_ifindex = ifindex;
@@ -150,7 +150,7 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
150 packet.ip.tot_len = packet.udp.len; 150 packet.ip.tot_len = packet.udp.len;
151 memcpy(&(packet.data), payload, sizeof(struct dhcpMessage)); 151 memcpy(&(packet.data), payload, sizeof(struct dhcpMessage));
152 packet.udp.check = checksum(&packet, sizeof(struct udp_dhcp_packet)); 152 packet.udp.check = checksum(&packet, sizeof(struct udp_dhcp_packet));
153 153
154 packet.ip.tot_len = htons(sizeof(struct udp_dhcp_packet)); 154 packet.ip.tot_len = htons(sizeof(struct udp_dhcp_packet));
155 packet.ip.ihl = sizeof(packet.ip) >> 2; 155 packet.ip.ihl = sizeof(packet.ip) >> 2;
156 packet.ip.version = IPVERSION; 156 packet.ip.version = IPVERSION;
@@ -173,10 +173,10 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_po
173 int n = 1; 173 int n = 1;
174 int fd, result; 174 int fd, result;
175 struct sockaddr_in client; 175 struct sockaddr_in client;
176 176
177 if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) 177 if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
178 return -1; 178 return -1;
179 179
180 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) 180 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1)
181 return -1; 181 return -1;
182 182
@@ -191,7 +191,7 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_po
191 memset(&client, 0, sizeof(client)); 191 memset(&client, 0, sizeof(client));
192 client.sin_family = AF_INET; 192 client.sin_family = AF_INET;
193 client.sin_port = htons(dest_port); 193 client.sin_port = htons(dest_port);
194 client.sin_addr.s_addr = dest_ip; 194 client.sin_addr.s_addr = dest_ip;
195 195
196 if (connect(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1) 196 if (connect(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1)
197 return -1; 197 return -1;
@@ -199,4 +199,4 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_po
199 result = write(fd, payload, sizeof(struct dhcpMessage)); 199 result = write(fd, payload, sizeof(struct dhcpMessage));
200 close(fd); 200 close(fd);
201 return result; 201 return result;
202} 202}
diff --git a/networking/udhcp/packet.h b/networking/udhcp/packet.h
index 22c4d09c3..f5859e824 100644
--- a/networking/udhcp/packet.h
+++ b/networking/udhcp/packet.h
@@ -20,7 +20,7 @@ struct dhcpMessage {
20 uint8_t sname[64]; 20 uint8_t sname[64];
21 uint8_t file[128]; 21 uint8_t file[128];
22 uint32_t cookie; 22 uint32_t cookie;
23 uint8_t options[308]; /* 312 - cookie */ 23 uint8_t options[308]; /* 312 - cookie */
24}; 24};
25 25
26struct udp_dhcp_packet { 26struct udp_dhcp_packet {
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index b7d78624c..cae4db7af 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -1,6 +1,6 @@
1/* script.c 1/* script.c
2 * 2 *
3 * Functions to call the DHCP client notification scripts 3 * Functions to call the DHCP client notification scripts
4 * 4 *
5 * Russ Dill <Russ.Dill@asu.edu> July 2001 5 * Russ Dill <Russ.Dill@asu.edu> July 2001
6 * 6 *
@@ -157,7 +157,7 @@ static char **fill_envp(struct dhcpMessage *packet)
157 if (!(over & FILE_FIELD) && packet->file[0]) num_options++; 157 if (!(over & FILE_FIELD) && packet->file[0]) num_options++;
158 if (!(over & SNAME_FIELD) && packet->sname[0]) num_options++; 158 if (!(over & SNAME_FIELD) && packet->sname[0]) num_options++;
159 } 159 }
160 160
161 envp = xcalloc(sizeof(char *), num_options + 5); 161 envp = xcalloc(sizeof(char *), num_options + 5);
162 j = 0; 162 j = 0;
163 asprintf(&envp[j++], "interface=%s", client_config.interface); 163 asprintf(&envp[j++], "interface=%s", client_config.interface);
@@ -220,13 +220,13 @@ void run_script(struct dhcpMessage *packet, const char *name)
220 return; 220 return;
221 } else if (pid == 0) { 221 } else if (pid == 0) {
222 envp = fill_envp(packet); 222 envp = fill_envp(packet);
223 223
224 /* close fd's? */ 224 /* close fd's? */
225 225
226 /* exec script */ 226 /* exec script */
227 execle(client_config.script, client_config.script, 227 execle(client_config.script, client_config.script,
228 name, NULL, envp); 228 name, NULL, envp);
229 LOG(LOG_ERR, "script %s failed: %m", client_config.script); 229 LOG(LOG_ERR, "script %s failed: %m", client_config.script);
230 exit(1); 230 exit(1);
231 } 231 }
232} 232}
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c
index d39e6ba17..937436a11 100644
--- a/networking/udhcp/serverpacket.c
+++ b/networking/udhcp/serverpacket.c
@@ -45,7 +45,7 @@ static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcas
45{ 45{
46 uint8_t *chaddr; 46 uint8_t *chaddr;
47 uint32_t ciaddr; 47 uint32_t ciaddr;
48 48
49 if (force_broadcast) { 49 if (force_broadcast) {
50 DEBUG(LOG_INFO, "broadcasting packet to client (NAK)"); 50 DEBUG(LOG_INFO, "broadcasting packet to client (NAK)");
51 ciaddr = INADDR_BROADCAST; 51 ciaddr = INADDR_BROADCAST;
@@ -63,7 +63,7 @@ static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcas
63 ciaddr = payload->yiaddr; 63 ciaddr = payload->yiaddr;
64 chaddr = payload->chaddr; 64 chaddr = payload->chaddr;
65 } 65 }
66 return raw_packet(payload, server_config.server, SERVER_PORT, 66 return raw_packet(payload, server_config.server, SERVER_PORT,
67 ciaddr, CLIENT_PORT, chaddr, server_config.ifindex); 67 ciaddr, CLIENT_PORT, chaddr, server_config.ifindex);
68} 68}
69 69
@@ -101,7 +101,7 @@ static void add_bootp_options(struct dhcpMessage *packet)
101 if (server_config.boot_file) 101 if (server_config.boot_file)
102 strncpy(packet->file, server_config.boot_file, sizeof(packet->file) - 1); 102 strncpy(packet->file, server_config.boot_file, sizeof(packet->file) - 1);
103} 103}
104 104
105 105
106/* send a DHCP OFFER to a DHCP DISCOVER */ 106/* send a DHCP OFFER to a DHCP DISCOVER */
107int sendOffer(struct dhcpMessage *oldpacket) 107int sendOffer(struct dhcpMessage *oldpacket)
@@ -114,14 +114,14 @@ int sendOffer(struct dhcpMessage *oldpacket)
114 struct in_addr addr; 114 struct in_addr addr;
115 115
116 init_packet(&packet, oldpacket, DHCPOFFER); 116 init_packet(&packet, oldpacket, DHCPOFFER);
117 117
118 /* ADDME: if static, short circuit */ 118 /* ADDME: if static, short circuit */
119 /* the client is in our lease/offered table */ 119 /* the client is in our lease/offered table */
120 if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) { 120 if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) {
121 if (!lease_expired(lease)) 121 if (!lease_expired(lease))
122 lease_time_align = lease->expires - time(0); 122 lease_time_align = lease->expires - time(0);
123 packet.yiaddr = lease->yiaddr; 123 packet.yiaddr = lease->yiaddr;
124 124
125 /* Or the client has a requested ip */ 125 /* Or the client has a requested ip */
126 } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) && 126 } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) &&
127 127
@@ -131,10 +131,10 @@ int sendOffer(struct dhcpMessage *oldpacket)
131 /* and the ip is in the lease range */ 131 /* and the ip is in the lease range */
132 ntohl(req_align) >= ntohl(server_config.start) && 132 ntohl(req_align) >= ntohl(server_config.start) &&
133 ntohl(req_align) <= ntohl(server_config.end) && 133 ntohl(req_align) <= ntohl(server_config.end) &&
134 134
135 /* and its not already taken/offered */ /* ADDME: check that its not a static lease */ 135 /* and its not already taken/offered */ /* ADDME: check that its not a static lease */
136 ((!(lease = find_lease_by_yiaddr(req_align)) || 136 ((!(lease = find_lease_by_yiaddr(req_align)) ||
137 137
138 /* or its taken, but expired */ /* ADDME: or maybe in here */ 138 /* or its taken, but expired */ /* ADDME: or maybe in here */
139 lease_expired(lease)))) { 139 lease_expired(lease)))) {
140 packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */ 140 packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
@@ -142,32 +142,32 @@ int sendOffer(struct dhcpMessage *oldpacket)
142 /* otherwise, find a free IP */ /*ADDME: is it a static lease? */ 142 /* otherwise, find a free IP */ /*ADDME: is it a static lease? */
143 } else { 143 } else {
144 packet.yiaddr = find_address(0); 144 packet.yiaddr = find_address(0);
145 145
146 /* try for an expired lease */ 146 /* try for an expired lease */
147 if (!packet.yiaddr) packet.yiaddr = find_address(1); 147 if (!packet.yiaddr) packet.yiaddr = find_address(1);
148 } 148 }
149 149
150 if(!packet.yiaddr) { 150 if(!packet.yiaddr) {
151 LOG(LOG_WARNING, "no IP addresses to give -- OFFER abandoned"); 151 LOG(LOG_WARNING, "no IP addresses to give -- OFFER abandoned");
152 return -1; 152 return -1;
153 } 153 }
154 154
155 if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) { 155 if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
156 LOG(LOG_WARNING, "lease pool is full -- OFFER abandoned"); 156 LOG(LOG_WARNING, "lease pool is full -- OFFER abandoned");
157 return -1; 157 return -1;
158 } 158 }
159 159
160 if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) { 160 if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) {
161 memcpy(&lease_time_align, lease_time, 4); 161 memcpy(&lease_time_align, lease_time, 4);
162 lease_time_align = ntohl(lease_time_align); 162 lease_time_align = ntohl(lease_time_align);
163 if (lease_time_align > server_config.lease) 163 if (lease_time_align > server_config.lease)
164 lease_time_align = server_config.lease; 164 lease_time_align = server_config.lease;
165 } 165 }
166 166
167 /* Make sure we aren't just using the lease time from the previous offer */ 167 /* Make sure we aren't just using the lease time from the previous offer */
168 if (lease_time_align < server_config.min_lease) 168 if (lease_time_align < server_config.min_lease)
169 lease_time_align = server_config.lease; 169 lease_time_align = server_config.lease;
170 /* ADDME: end of short circuit */ 170 /* ADDME: end of short circuit */
171 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align)); 171 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align));
172 172
173 curr = server_config.options; 173 curr = server_config.options;
@@ -178,7 +178,7 @@ int sendOffer(struct dhcpMessage *oldpacket)
178 } 178 }
179 179
180 add_bootp_options(&packet); 180 add_bootp_options(&packet);
181 181
182 addr.s_addr = packet.yiaddr; 182 addr.s_addr = packet.yiaddr;
183 LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(addr)); 183 LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(addr));
184 return send_packet(&packet, 0); 184 return send_packet(&packet, 0);
@@ -190,7 +190,7 @@ int sendNAK(struct dhcpMessage *oldpacket)
190 struct dhcpMessage packet; 190 struct dhcpMessage packet;
191 191
192 init_packet(&packet, oldpacket, DHCPNAK); 192 init_packet(&packet, oldpacket, DHCPNAK);
193 193
194 DEBUG(LOG_INFO, "sending NAK"); 194 DEBUG(LOG_INFO, "sending NAK");
195 return send_packet(&packet, 1); 195 return send_packet(&packet, 1);
196} 196}
@@ -206,18 +206,18 @@ int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
206 206
207 init_packet(&packet, oldpacket, DHCPACK); 207 init_packet(&packet, oldpacket, DHCPACK);
208 packet.yiaddr = yiaddr; 208 packet.yiaddr = yiaddr;
209 209
210 if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) { 210 if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) {
211 memcpy(&lease_time_align, lease_time, 4); 211 memcpy(&lease_time_align, lease_time, 4);
212 lease_time_align = ntohl(lease_time_align); 212 lease_time_align = ntohl(lease_time_align);
213 if (lease_time_align > server_config.lease) 213 if (lease_time_align > server_config.lease)
214 lease_time_align = server_config.lease; 214 lease_time_align = server_config.lease;
215 else if (lease_time_align < server_config.min_lease) 215 else if (lease_time_align < server_config.min_lease)
216 lease_time_align = server_config.lease; 216 lease_time_align = server_config.lease;
217 } 217 }
218 218
219 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align)); 219 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align));
220 220
221 curr = server_config.options; 221 curr = server_config.options;
222 while (curr) { 222 while (curr) {
223 if (curr->data[OPT_CODE] != DHCP_LEASE_TIME) 223 if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
@@ -230,7 +230,7 @@ int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
230 addr.s_addr = packet.yiaddr; 230 addr.s_addr = packet.yiaddr;
231 LOG(LOG_INFO, "sending ACK to %s", inet_ntoa(addr)); 231 LOG(LOG_INFO, "sending ACK to %s", inet_ntoa(addr));
232 232
233 if (send_packet(&packet, 0) < 0) 233 if (send_packet(&packet, 0) < 0)
234 return -1; 234 return -1;
235 235
236 add_lease(packet.chaddr, packet.yiaddr, lease_time_align); 236 add_lease(packet.chaddr, packet.yiaddr, lease_time_align);
@@ -245,7 +245,7 @@ int send_inform(struct dhcpMessage *oldpacket)
245 struct option_set *curr; 245 struct option_set *curr;
246 246
247 init_packet(&packet, oldpacket, DHCPACK); 247 init_packet(&packet, oldpacket, DHCPACK);
248 248
249 curr = server_config.options; 249 curr = server_config.options;
250 while (curr) { 250 while (curr) {
251 if (curr->data[OPT_CODE] != DHCP_LEASE_TIME) 251 if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index 582f0fce5..7b057523a 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -55,7 +55,7 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp)
55 ifr.ifr_addr.sa_family = AF_INET; 55 ifr.ifr_addr.sa_family = AF_INET;
56 strcpy(ifr.ifr_name, interface); 56 strcpy(ifr.ifr_name, interface);
57 57
58 if (addr) { 58 if (addr) {
59 if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { 59 if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
60 our_ip = (struct sockaddr_in *) &ifr.ifr_addr; 60 our_ip = (struct sockaddr_in *) &ifr.ifr_addr;
61 *addr = our_ip->sin_addr.s_addr; 61 *addr = our_ip->sin_addr.s_addr;
@@ -65,7 +65,7 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp)
65 return -1; 65 return -1;
66 } 66 }
67 } 67 }
68 68
69 if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) { 69 if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) {
70 DEBUG(LOG_INFO, "adapter index %d", ifr.ifr_ifindex); 70 DEBUG(LOG_INFO, "adapter index %d", ifr.ifr_ifindex);
71 *ifindex = ifr.ifr_ifindex; 71 *ifindex = ifr.ifr_ifindex;
@@ -102,7 +102,7 @@ int listen_socket(uint32_t ip, int port, char *inf)
102 DEBUG(LOG_ERR, "socket call failed: %m"); 102 DEBUG(LOG_ERR, "socket call failed: %m");
103 return -1; 103 return -1;
104 } 104 }
105 105
106 memset(&addr, 0, sizeof(addr)); 106 memset(&addr, 0, sizeof(addr));
107 addr.sin_family = AF_INET; 107 addr.sin_family = AF_INET;
108 addr.sin_port = htons(port); 108 addr.sin_port = htons(port);
@@ -127,6 +127,6 @@ int listen_socket(uint32_t ip, int port, char *inf)
127 close(fd); 127 close(fd);
128 return -1; 128 return -1;
129 } 129 }
130 130
131 return fd; 131 return fd;
132} 132}