Cosmetic cleanups in packet.c.

This commit is contained in:
Nicholas J. Kain 2011-07-01 04:38:38 -04:00
parent 42f81ecd33
commit 09b5c08b5b

View File

@ -266,13 +266,12 @@ static int get_raw_packet_validate_bpf(struct ip_udp_dhcp_packet *packet)
// Read a packet from a raw socket. Returns -1 on fatal error, -2 on // Read a packet from a raw socket. Returns -1 on fatal error, -2 on
// transient error. // transient error.
static int get_raw_packet(struct client_state_t *cs, struct dhcpmsg *payload, static int get_raw_packet(struct client_state_t *cs, struct dhcpmsg *payload)
int fd)
{ {
struct ip_udp_dhcp_packet packet; struct ip_udp_dhcp_packet packet;
memset(&packet, 0, sizeof packet); memset(&packet, 0, sizeof packet);
ssize_t inc = safe_read(fd, (char *)&packet, sizeof packet); ssize_t inc = safe_read(cs->listenFd, (char *)&packet, sizeof packet);
if (inc == -1) { if (inc == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) if (errno == EAGAIN || errno == EWOULDBLOCK)
return -2; return -2;
@ -500,12 +499,10 @@ void handle_packet(struct client_state_t *cs)
struct dhcpmsg packet; struct dhcpmsg packet;
ssize_t optlen; ssize_t optlen;
if (cs->listenMode == LM_COOKED) if (cs->listenMode == LM_NONE)
len = get_cooked_packet(&packet, cs->listenFd);
else if (cs->listenMode == LM_RAW)
len = get_raw_packet(cs, &packet, cs->listenFd);
else // LM_NONE
return; return;
len = cs->listenMode == LM_RAW ?
get_raw_packet(cs, &packet) : get_cooked_packet(&packet, cs->listenFd);
if (len < 0) { if (len < 0) {
// Transient issue handled by packet collection functions. // Transient issue handled by packet collection functions.