-/* $OpenBSD: tftp-proxy.c,v 1.11 2015/01/16 06:40:22 deraadt Exp $
+/* $OpenBSD: tftp-proxy.c,v 1.12 2015/10/10 23:06:32 guenther Exp $
*
* Copyright (c) 2005 DLS Internet Services
* Copyright (c) 2004, 2005 Camiel Dobbelaar, <cd@sentia.nl>
if (!debug && daemon(1, 0) == -1)
err(1, "daemon");
- if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) == -1)
+ if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, PF_UNSPEC, pair)
+ == -1)
lerr(1, "socketpair");
pw = getpwnam(NOPRIV_USER);
proxy_listener_events();
- if (ioctl(pair[1], FIONBIO, &on) == -1)
- lerr(1, "ioctl(FIONBIO)");
-
event_set(&child->pop_ev, pair[1], EV_READ | EV_PERSIST,
unprivproc_pop, NULL);
event_set(&child->push_ev, pair[1], EV_WRITE,
logger = &syslogger;
}
- if (ioctl(s, FIONBIO, &on) == -1)
- lerr(1, "ioctl(FIONBIO)");
-
if (chroot(CHROOT_DIR) == -1)
lerr(1, "chroot to %s", CHROOT_DIR);
if (rep == NULL)
lerr(1, "reply calloc");
- rep->fd = socket(req.src.ss_family, SOCK_DGRAM, IPPROTO_UDP);
+ rep->fd = socket(req.src.ss_family, SOCK_DGRAM | SOCK_NONBLOCK,
+ IPPROTO_UDP);
if (rep->fd == -1)
lerr(1, "privproc socket");
- if (ioctl(rep->fd, FIONBIO, &on) == -1)
- err(1, "privproc ioctl(FIONBIO)");
-
if (setsockopt(rep->fd, SOL_SOCKET, SO_BINDANY,
&on, sizeof(on)) == -1)
lerr(1, "privproc setsockopt(BINDANY)");
errx(1, "%s:%s: %s", addr, port, gai_strerror(error));
for (res = res0; res != NULL; res = res->ai_next) {
- s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ s = socket(res->ai_family, res->ai_socktype | SOCK_NONBLOCK,
+ res->ai_protocol);
if (s == -1) {
cause = "socket";
continue;
if (l == NULL)
err(1, "listener alloc");
- if (ioctl(s, FIONBIO, &on) == -1)
- err(1, "ioctl(FIONBIO)");
-
switch (res->ai_family) {
case AF_INET:
l->cmsg2dst = proxy_dst4;