From 7d206e45b616a976977800f107d6e47e2a0a9060 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Sat, 25 Jun 2011 10:18:14 -0400 Subject: [PATCH] Make raw listen sockets nonblocking. They should have been so all along. Minor constant correction: PF_PACKET -> AF_PACKET --- ndhc/packet.c | 4 +++- ndhc/socket.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ndhc/packet.c b/ndhc/packet.c index 1162e31..c89ddbc 100644 --- a/ndhc/packet.c +++ b/ndhc/packet.c @@ -169,7 +169,7 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int fd, r = -1; unsigned int padding; - if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { + if ((fd = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { log_error("raw_packet: socket failed: %s", strerror(errno)); goto out; } @@ -178,6 +178,8 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, memset(&packet, 0, offsetof(struct ip_udp_dhcp_packet, data)); packet.data = *payload; /* struct copy */ + set_sock_nonblock(fd); + dest.sll_family = AF_PACKET; dest.sll_protocol = htons(ETH_P_IP); dest.sll_ifindex = ifindex; diff --git a/ndhc/socket.c b/ndhc/socket.c index b8a3734..1dee9b7 100644 --- a/ndhc/socket.c +++ b/ndhc/socket.c @@ -126,7 +126,7 @@ int raw_socket(int ifindex) memset(&sock, 0, sizeof sock); log_line("Opening raw socket on ifindex %d", ifindex); - if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { + if ((fd = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { log_error("socket call failed: %s", strerror(errno)); return -1; }