Mirror of git://git.busybox.net/busybox with our patches on top
Source
/* vi: set sw=4 ts=4: */
/* clientpacket.c
*
* Packet generation and dispatching functions for the DHCP client.
*
* Russ Dill <Russ.Dill@asu.edu> July 2001
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/* Create a random xid */
unsigned long random_xid(void)
{
static int initialized;
if (!initialized) {
unsigned long seed;
if (open_read_close("/dev/urandom", &seed, sizeof(seed)) < 0) {
bb_info_msg("Cannot load seed "
"from /dev/urandom: %s", strerror(errno));
seed = time(0);
}
srand(seed);
initialized++;
}
return rand();
}
/* initialize a packet with the proper defaults */
static void init_packet(struct dhcpMessage *packet, char type)
{
udhcp_init_header(packet, type);
memcpy(packet->chaddr, client_config.arp, 6);
if (client_config.clientid)
add_option_string(packet->options, client_config.clientid);
if (client_config.hostname) add_option_string(packet->options, client_config.hostname);
if (client_config.fqdn) add_option_string(packet->options, client_config.fqdn);
add_option_string(packet->options, client_config.vendorclass);
}
/* Add a parameter request list for stubborn DHCP servers. Pull the data
* from the struct in options.c. Don't do bounds checking here because it
* goes towards the head of the packet. */
static void add_requests(struct dhcpMessage *packet)
{