diff --git a/ndhc/clientpacket.c b/ndhc/clientpacket.c index b2ff2d7..a4eb325 100644 --- a/ndhc/clientpacket.c +++ b/ndhc/clientpacket.c @@ -20,6 +20,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include #include #include @@ -42,12 +43,12 @@ #include "log.h" /* Create a random xid */ -unsigned long random_xid(void) +uint32_t random_xid(void) { static int initialized; if (!initialized) { int fd; - unsigned long seed; + uint32_t seed; fd = open("/dev/urandom", O_RDONLY); if (fd == -1 || read(fd, &seed, sizeof seed) < 0) { @@ -98,7 +99,7 @@ static void add_requests(struct dhcpMessage *packet) /* Broadcast a DHCP discover packet to the network, with an optionally * requested IP */ -int send_discover(unsigned long xid, unsigned long requested) +int send_discover(uint32_t xid, uint32_t requested) { struct dhcpMessage packet; @@ -107,6 +108,8 @@ int send_discover(unsigned long xid, unsigned long requested) if (requested) add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); + /* Request a RFC-specified max size to work around buggy servers. */ + add_simple_option(packet.options, DHCP_MAX_SIZE, htons(576)); add_requests(&packet); log_line("Sending discover..."); return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, @@ -114,8 +117,7 @@ int send_discover(unsigned long xid, unsigned long requested) } /* Broadcasts a DHCP request message */ -int send_selecting(unsigned long xid, unsigned long server, - unsigned long requested) +int send_selecting(uint32_t xid, uint32_t server, uint32_t requested) { struct dhcpMessage packet; struct in_addr addr; @@ -134,7 +136,7 @@ int send_selecting(unsigned long xid, unsigned long server, } /* Unicasts or broadcasts a DHCP renew message */ -int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr) +int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) { struct dhcpMessage packet; int ret = 0; @@ -154,7 +156,7 @@ int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr) } /* Unicasts a DHCP release message */ -int send_release(unsigned long server, unsigned long ciaddr) +int send_release(uint32_t server, uint32_t ciaddr) { struct dhcpMessage packet; diff --git a/ndhc/clientpacket.h b/ndhc/clientpacket.h index 2a6facb..089bf36 100644 --- a/ndhc/clientpacket.h +++ b/ndhc/clientpacket.h @@ -1,12 +1,14 @@ #ifndef _CLIENTPACKET_H #define _CLIENTPACKET_H -unsigned long random_xid(void); -int send_discover(unsigned long xid, unsigned long requested); -int send_selecting(unsigned long xid, unsigned long server, unsigned long requested); -int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr); -int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr); -int send_release(unsigned long server, unsigned long ciaddr); +#include + +uint32_t random_xid(void); +int send_discover(uint32_t xid, uint32_t requested); +int send_selecting(uint32_t xid, uint32_t server, uint32_t requested); +int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr); +int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr); +int send_release(uint32_t server, uint32_t ciaddr); int get_raw_packet(struct dhcpMessage *payload, int fd); #endif diff --git a/ndhc/dhcpd.h b/ndhc/dhcpd.h index f9d3606..f463258 100644 --- a/ndhc/dhcpd.h +++ b/ndhc/dhcpd.h @@ -2,6 +2,7 @@ #ifndef _DHCPD_H #define _DHCPD_H +#include #include #include @@ -101,32 +102,31 @@ struct option_set { struct server_config_t { uint32_t server; /* Our IP, in network order */ - uint32_t start; /* Start address of leases, network order */ + uint32_t start; /* Start address of leases, network order */ uint32_t end; /* End of leases, network order */ struct option_set *options; /* List of DHCP options loaded from the config file */ char *interface; /* The name of the interface to use */ int ifindex; /* Index number of the interface to use */ unsigned char arp[6]; /* Our arp address */ - unsigned long lease; /* lease time in seconds (host order) */ - unsigned long max_leases; /* maximum number of leases (including reserved address) */ + uint32_t lease; /* lease time in seconds (host order) */ + uint32_t max_leases; /* maximum number of leases (including reserved address) */ char remaining; /* should the lease file be interpreted as lease time remaining, or * as the time the lease expires */ - unsigned long auto_time; /* how long should udhcpd wait before writing a config file. + uint32_t auto_time; /* how long should udhcpd wait before writing a config file. * if this is zero, it will only write one on SIGUSR1 */ - unsigned long decline_time; /* how long an address is reserved if a client returns a + uint32_t decline_time; /* how long an address is reserved if a client returns a * decline message */ - unsigned long conflict_time; /* how long an arp conflict offender is leased for */ - unsigned long offer_time; /* how long an offered address is reserved */ - unsigned long min_lease; /* minimum lease a client can request*/ + uint32_t conflict_time; /* how long an arp conflict offender is leased for */ + uint32_t offer_time; /* how long an offered address is reserved */ + uint32_t min_lease; /* minimum lease a client can request*/ char *lease_file; char *notify_file; /* What to run whenever leases are written */ uint32_t siaddr; /* next server bootp option */ char *sname; /* bootp server name */ char *boot_file; /* bootp boot file option */ -}; +}; extern struct server_config_t server_config; extern struct dhcpOfferedAddr *leases; - #endif diff --git a/ndhc/leases.h b/ndhc/leases.h index aa0a233..bc3221f 100644 --- a/ndhc/leases.h +++ b/ndhc/leases.h @@ -12,7 +12,7 @@ struct dhcpOfferedAddr { extern unsigned char blank_chaddr[]; void clear_lease(uint8_t *chaddr, uint32_t yiaddr); -struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned long lease); +struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, uint32_t lease); int lease_expired(struct dhcpOfferedAddr *lease); struct dhcpOfferedAddr *oldest_expired_lease(void); struct dhcpOfferedAddr *find_lease_by_chaddr(uint8_t *chaddr); diff --git a/ndhc/ndhc.c b/ndhc/ndhc.c index c5590f3..f224282 100644 --- a/ndhc/ndhc.c +++ b/ndhc/ndhc.c @@ -60,8 +60,8 @@ static char pidfile[MAX_PATH_LENGTH] = PID_FILE_DEFAULT; -static unsigned long requested_ip, server_addr, timeout; -static unsigned long lease, t1, t2, xid, start; +static uint32_t requested_ip, server_addr, timeout; +static uint32_t lease, t1, t2, xid, start; static int state, packet_num, fd, listen_mode; static sig_atomic_t pending_exit, pending_renew, pending_release; @@ -323,7 +323,7 @@ static void handle_packet(void) if (packet.xid != xid) { log_line("Ignoring XID %lx (our xid is %lx).", - (unsigned long) packet.xid, xid); + (uint32_t) packet.xid, xid); return; } diff --git a/ndhc/script.c b/ndhc/script.c index 15e4ad1..8536acb 100644 --- a/ndhc/script.c +++ b/ndhc/script.c @@ -109,12 +109,12 @@ static int fill_options(char *dest, unsigned char *option, case OPTION_U32: memcpy(&val_u32, option, 4); dest += snprintf(dest, maxlen - (dest - odest), - "%lu ", (unsigned long) ntohl(val_u32)); + "%u ", (uint32_t) ntohl(val_u32)); break; case OPTION_S32: memcpy(&val_s32, option, 4); dest += snprintf(dest, maxlen - (dest - odest), - "%ld ", (long) ntohl(val_s32)); + "%d ", (int32_t) ntohl(val_s32)); break; case OPTION_STRING: if ( (maxlen - (dest - odest)) < (unsigned)len)