X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=udp.c;h=bb82026c144d0df1f56f9f52e9401dd2fae91691;hp=42fbb1f697dbcfc6491a5c6b56886a9ed670098c;hb=4fb0f88d53fc60395a4a87b7a9ca1245ba033ee7;hpb=3abd18e85781e00e2b7fc641f29c99e130238abf diff --git a/udp.c b/udp.c index 42fbb1f..bb82026 100644 --- a/udp.c +++ b/udp.c @@ -19,6 +19,7 @@ #include #include #include "util.h" +#include "magic.h" #include "unaligned.h" #include "ipaddr.h" #include "magic.h" @@ -102,8 +103,10 @@ static void udp_afterpoll(void *state, struct pollfd *fds, int nfds) fromlen=sizeof(from); BUF_ASSERT_FREE(st->rbuf); BUF_ALLOC(st->rbuf,"udp_afterpoll"); - rv=recvfrom(st->fd, st->rbuf->start, st->rbuf->len, 0, - (struct sockaddr *)&from, &fromlen); + buffer_init(st->rbuf,calculate_max_start_pad()); + 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) { @@ -221,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;