Specialize init_header() to only handle client packets, move it to

clientpacket.c, and make it static.
This commit is contained in:
Nicholas J. Kain 2010-11-14 00:52:32 -05:00
parent 1cc648b5ad
commit 6a3b004eee
3 changed files with 12 additions and 23 deletions

View File

@ -69,6 +69,18 @@ uint32_t random_xid(void)
return rand(); 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 */ /* initialize a packet with the proper defaults */
static void init_packet(struct dhcpMessage *packet, char type) static void init_packet(struct dhcpMessage *packet, char type)
{ {

View File

@ -14,28 +14,6 @@
#include "dhcpd.h" #include "dhcpd.h"
#include "options.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 */ /* read a packet from socket fd, return -1 on read error, -2 on packet error */
int get_packet(struct dhcpMessage *packet, int fd) int get_packet(struct dhcpMessage *packet, int fd)
{ {

View File

@ -29,7 +29,6 @@ struct udp_dhcp_packet {
struct dhcpMessage data; struct dhcpMessage data;
}; };
void init_header(struct dhcpMessage *packet, char type);
int get_packet(struct dhcpMessage *packet, int fd); int get_packet(struct dhcpMessage *packet, int fd);
uint16_t checksum(void *addr, int count); uint16_t checksum(void *addr, int count);
int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,