Allow compilation on Darwin diff --git a/netcat.c b/netcat.c index a0fb51b..bbb5dd1 100644 --- a/netcat.c +++ b/netcat.c @@ -51,11 +51,16 @@ # include #endif +#ifndef IPTOS_LOWCOST +# define IPTOS_LOWCOST 0x02 +#endif #ifndef IPTOS_LOWDELAY # define IPTOS_LOWDELAY 0x10 # define IPTOS_THROUGHPUT 0x08 # define IPTOS_RELIABILITY 0x04 -# define IPTOS_LOWCOST 0x02 # define IPTOS_MINCOST IPTOS_LOWCOST #endif /* IPTOS_LOWDELAY */ +#ifndef SOCK_CLOEXEC +# define SOCK_CLOEXEC 0 +#endif @@ -108,8 +110,9 @@ # include #endif #include -#include -#include +#include +#include +#include #include "atomicio.h" @@ -814,9 +814,8 @@ # endif } else { len = sizeof(cliaddr); - connfd = accept4(s, (struct sockaddr *)&cliaddr, - &len, SOCK_NONBLOCK); - if (connfd == -1) { + connfd = accept(s, (struct sockaddr *)&cliaddr, &len); + if (connfd == -1 || fcntl(connfd, F_SETFL, O_NONBLOCK) == -1) { /* For now, all errnos are fatal */ err(1, "accept"); } @@ -1100,6 +1099,8 @@ return -1; } } + if (fcntl(s, F_SETFD, FD_CLOEXEC) == -1) + return -1; memset(&s_un, 0, sizeof(struct sockaddr_un)); s_un.sun_family = AF_UNIX; @@ -1174,9 +1175,13 @@ port, gai_strerror(error)); for (res = res0; res; res = res->ai_next) { - if ((s = socket(res->ai_family, res->ai_socktype | - SOCK_NONBLOCK, res->ai_protocol)) < 0) + if ((s = socket(res->ai_family, res->ai_socktype, + res->ai_protocol)) < 0) + continue; + if (fcntl(s, F_SETFL, O_NONBLOCK) == -1) { + close(s); continue; + } /* Bind to a local port or source address if specified. */ if (sflag || pflag) { diff --git a/socks.c b/socks.c index 9068f39..68b68e3 100644 --- a/socks.c +++ b/socks.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include "atomicio.h" #define SOCKS_PORT "1080"