summaryrefslogtreecommitdiffstats
path: root/socket.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-05-15 14:16:47 +0000
committerRoy Marples <roy@marples.name>2008-05-15 14:16:47 +0000
commit3528961fc661b258de615673b26ebe47198f8b31 (patch)
treead64fcb80b88e9936e735a373447954e859f9a82 /socket.c
parent57220ee0629f8c1ad3aad80aa43cf2b8878e1fbc (diff)
downloaddhcpcd-3528961fc661b258de615673b26ebe47198f8b31.tar.xz
Use non blocking sockets so read errors with EAGAIN.
Diffstat (limited to 'socket.c')
-rw-r--r--socket.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/socket.c b/socket.c
index a41d46ab..0e0b2cf7 100644
--- a/socket.c
+++ b/socket.c
@@ -96,6 +96,7 @@ open_socket(struct interface *iface, int protocol)
struct sockaddr_storage ss;
} su;
struct sock_fprog pf;
+ int flags;
if ((s = socket(PF_PACKET, SOCK_DGRAM, htons(protocol))) == -1)
return -1;
@@ -119,7 +120,9 @@ open_socket(struct interface *iface, int protocol)
}
if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &pf, sizeof(pf)) != 0)
goto eexit;
-
+ if ((flags = fcntl(s, F_GETFL, 0)) == -1
+ || fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1)
+ goto eexit;
if (bind(s, &su.sa, sizeof(su)) == -1)
goto eexit;
if (close_on_exec(s) == -1)
@@ -174,20 +177,10 @@ get_packet(struct interface *iface, void *data, ssize_t len)
ssize_t bytes;
const uint8_t *p;
- if (iface->buffer_pos > iface->buffer_len) {
- iface->buffer_len = iface->buffer_pos = 0;
- return 0;
- }
-
bytes = read(iface->fd, iface->buffer, iface->buffer_size);
-
if (bytes == -1)
return errno == EAGAIN ? 0 : -1;
- /* So our loops to us work correctly */
- iface->buffer_len = bytes;
- iface->buffer_pos = iface->buffer_len + 1;
-
/* If it's an ARP reply, then just send it back */
if (iface->socket_protocol == ETHERTYPE_ARP)
return bytes;