chiark / gitweb /
site: transport peers: Formalise interface to transport peers
[secnet.git] / udp.c
diff --git a/udp.c b/udp.c
index 1e637b6e5be7740ccb53f3678496298a8f31ffe2..bb82026c144d0df1f56f9f52e9401dd2fae91691 100644 (file)
--- a/udp.c
+++ b/udp.c
@@ -19,6 +19,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include "util.h"
+#include "magic.h"
 #include "unaligned.h"
 #include "ipaddr.h"
 #include "magic.h"
@@ -103,8 +104,9 @@ static void udp_afterpoll(void *state, struct pollfd *fds, int nfds)
            BUF_ASSERT_FREE(st->rbuf);
            BUF_ALLOC(st->rbuf,"udp_afterpoll");
            buffer_init(st->rbuf,calculate_max_start_pad());
-           rv=recvfrom(st->fd, st->rbuf->start, st->rbuf->len, 0,
-                       (struct sockaddr *)&from, &fromlen);
+           rv=recvfrom(st->fd, st->rbuf->start,
+                       buf_remaining_space(st->rbuf),
+                       0, (struct sockaddr *)&from, &fromlen);
            if (rv>0) {
                st->rbuf->size=rv;
                if (st->use_proxy) {
@@ -222,10 +224,7 @@ static void udp_phase_hook(void *sst, uint32_t new_phase)
        fatal_perror("udp (%s:%d): fcntl(set O_NONBLOCK)",
                     st->loc.file,st->loc.line);
     }
-    if (fcntl(st->fd, F_SETFD, FD_CLOEXEC)==-1) {
-       fatal_perror("udp (%s:%d): fcntl(set FD_CLOEXEC)",
-                    st->loc.file,st->loc.line);
-    }
+    setcloexec(st->fd);
 
     FILLZERO(addr);
     addr.sin_family=AF_INET;