diff --git a/ndhc/clientpacket.c b/ndhc/clientpacket.c index 9a3b20f..bca9e76 100644 --- a/ndhc/clientpacket.c +++ b/ndhc/clientpacket.c @@ -69,6 +69,18 @@ uint32_t random_xid(void) return rand(); } +/* Initializes dhcp packet header for a -client- packet. */ +static void init_header(struct dhcpMessage *packet, char type) +{ + memset(packet, 0, sizeof(struct dhcpMessage)); + packet->op = BOOTREQUEST; /* client */ + packet->htype = ETH_10MB; + packet->hlen = ETH_10MB_LEN; + packet->cookie = htonl(DHCP_MAGIC); + packet->options[0] = DHCP_END; + add_simple_option(packet->options, DHCP_MESSAGE_TYPE, type); +} + /* initialize a packet with the proper defaults */ static void init_packet(struct dhcpMessage *packet, char type) { diff --git a/ndhc/packet.c b/ndhc/packet.c index a03c4c9..dfb7549 100644 --- a/ndhc/packet.c +++ b/ndhc/packet.c @@ -14,28 +14,6 @@ #include "dhcpd.h" #include "options.h" -void init_header(struct dhcpMessage *packet, char type) -{ - memset(packet, 0, sizeof(struct dhcpMessage)); - switch (type) { - case DHCPDISCOVER: - case DHCPREQUEST: - case DHCPRELEASE: - case DHCPINFORM: - packet->op = BOOTREQUEST; - break; - case DHCPOFFER: - case DHCPACK: - case DHCPNAK: - packet->op = BOOTREPLY; - } - packet->htype = ETH_10MB; - packet->hlen = ETH_10MB_LEN; - packet->cookie = htonl(DHCP_MAGIC); - packet->options[0] = DHCP_END; - add_simple_option(packet->options, DHCP_MESSAGE_TYPE, type); -} - /* read a packet from socket fd, return -1 on read error, -2 on packet error */ int get_packet(struct dhcpMessage *packet, int fd) { diff --git a/ndhc/packet.h b/ndhc/packet.h index 3e88bdf..86c4b9c 100644 --- a/ndhc/packet.h +++ b/ndhc/packet.h @@ -29,7 +29,6 @@ struct udp_dhcp_packet { struct dhcpMessage data; }; -void init_header(struct dhcpMessage *packet, char type); int get_packet(struct dhcpMessage *packet, int fd); uint16_t checksum(void *addr, int count); int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,