diff options
author | Brent Cook <bcook@openbsd.org> | 2015-09-13 11:56:41 -0500 |
---|---|---|
committer | Brent Cook <bcook@openbsd.org> | 2015-09-13 18:42:15 -0500 |
commit | 8c90be2a29053ac613dfe0c11a423da16c7c4520 (patch) | |
tree | cf31a8e35cd9793f5f6f622b0ffcce61bbad8652 /apps/nc/compat/socket.c | |
parent | 627b0261a81bb18ef95156baa37101ddcb14e356 (diff) | |
download | portable-8c90be2a29053ac613dfe0c11a423da16c7c4520.tar.gz portable-8c90be2a29053ac613dfe0c11a423da16c7c4520.tar.bz2 portable-8c90be2a29053ac613dfe0c11a423da16c7c4520.zip |
allow nc to build on linux and os x
Diffstat (limited to 'apps/nc/compat/socket.c')
-rw-r--r-- | apps/nc/compat/socket.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/apps/nc/compat/socket.c b/apps/nc/compat/socket.c new file mode 100644 index 0000000..fd699f9 --- /dev/null +++ b/apps/nc/compat/socket.c | |||
@@ -0,0 +1,29 @@ | |||
1 | #define SOCKET_FLAGS_PRIV | ||
2 | |||
3 | #include <sys/socket.h> | ||
4 | |||
5 | #ifdef NEED_SOCKET_FLAGS | ||
6 | |||
7 | #include <fcntl.h> | ||
8 | |||
9 | int | ||
10 | _socket(int domain, int type, int protocol) | ||
11 | { | ||
12 | int s = socket(domain, type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK), protocol); | ||
13 | int flags; | ||
14 | if (s == -1) | ||
15 | return s; | ||
16 | |||
17 | if (type & SOCK_CLOEXEC) { | ||
18 | flags = fcntl(s, F_GETFD); | ||
19 | fcntl(s, F_SETFD, flags | FD_CLOEXEC); | ||
20 | } | ||
21 | |||
22 | if (type & SOCK_NONBLOCK) { | ||
23 | flags = fcntl(s, F_GETFL); | ||
24 | fcntl(s, F_SETFL, flags | O_NONBLOCK); | ||
25 | } | ||
26 | return s; | ||
27 | } | ||
28 | |||
29 | #endif | ||