chiark / gitweb /
fds: Provide cloexec() and use it in udp.c and tun.c
[secnet.git] / udp.c
diff --git a/udp.c b/udp.c
index fa42ba4..bb82026 100644 (file)
--- a/udp.c
+++ b/udp.c
@@ -105,7 +105,7 @@ static void udp_afterpoll(void *state, struct pollfd *fds, int nfds)
            BUF_ALLOC(st->rbuf,"udp_afterpoll");
            buffer_init(st->rbuf,calculate_max_start_pad());
            rv=recvfrom(st->fd, st->rbuf->start,
-                       (st->rbuf->base + st->rbuf->len) - st->rbuf->start,
+                       buf_remaining_space(st->rbuf),
                        0, (struct sockaddr *)&from, &fromlen);
            if (rv>0) {
                st->rbuf->size=rv;
@@ -224,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;