aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrent Cook <bcook@openbsd.org>2015-09-13 11:56:41 -0500
committerBrent Cook <bcook@openbsd.org>2015-09-13 18:42:15 -0500
commit8c90be2a29053ac613dfe0c11a423da16c7c4520 (patch)
treecf31a8e35cd9793f5f6f622b0ffcce61bbad8652
parent627b0261a81bb18ef95156baa37101ddcb14e356 (diff)
downloadportable-8c90be2a29053ac613dfe0c11a423da16c7c4520.tar.gz
portable-8c90be2a29053ac613dfe0c11a423da16c7c4520.tar.bz2
portable-8c90be2a29053ac613dfe0c11a423da16c7c4520.zip
allow nc to build on linux and os x
-rw-r--r--.gitignore1
-rw-r--r--apps/nc/Makefile.am19
-rw-r--r--apps/nc/compat/accept4.c17
-rw-r--r--apps/nc/compat/readpassphrase.c205
-rw-r--r--apps/nc/compat/socket.c29
-rw-r--r--apps/nc/compat/strtonum.c65
-rw-r--r--apps/nc/compat/sys/socket.h31
-rw-r--r--configure.ac2
-rw-r--r--include/Makefile.am2
-rw-r--r--include/compat/netinet/ip.h43
-rw-r--r--include/compat/readpassphrase.h48
-rw-r--r--include/compat/sys/socket.h10
-rw-r--r--m4/check-libc.m46
-rw-r--r--m4/check-os-options.m46
-rw-r--r--patches/netcat.c.patch137
-rwxr-xr-xupdate.sh2
16 files changed, 603 insertions, 20 deletions
diff --git a/.gitignore b/.gitignore
index 353b48d..499205f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -111,6 +111,7 @@ include/pqueue.h
111include/tls.h 111include/tls.h
112include/openssl/*.h 112include/openssl/*.h
113 113
114!/apps/nc/readpassphrase.c
114/apps/nc/*.h 115/apps/nc/*.h
115/apps/nc/*.c 116/apps/nc/*.c
116/apps/nc/nc* 117/apps/nc/nc*
diff --git a/apps/nc/Makefile.am b/apps/nc/Makefile.am
index 916681b..89fe266 100644
--- a/apps/nc/Makefile.am
+++ b/apps/nc/Makefile.am
@@ -1,8 +1,6 @@
1include $(top_srcdir)/Makefile.am.common 1include $(top_srcdir)/Makefile.am.common
2 2
3if HOST_OPENBSD 3if BUILD_NC
4
5if HAVE_POLL
6 4
7noinst_PROGRAMS = nc 5noinst_PROGRAMS = nc
8 6
@@ -11,15 +9,26 @@ EXTRA_DIST = nc.1
11nc_LDADD = $(PLATFORM_LDADD) $(PROG_LDADD) 9nc_LDADD = $(PLATFORM_LDADD) $(PROG_LDADD)
12nc_LDADD += $(top_builddir)/tls/libtls.la 10nc_LDADD += $(top_builddir)/tls/libtls.la
13 11
12CPPFLAGS += -I$(top_srcdir)/apps/nc/compat
13
14nc_SOURCES = atomicio.c 14nc_SOURCES = atomicio.c
15nc_SOURCES += netcat.c 15nc_SOURCES += netcat.c
16nc_SOURCES += socks.c 16nc_SOURCES += socks.c
17noinst_HEADERS = atomicio.h 17noinst_HEADERS = atomicio.h
18noinst_HEADERS += compat/sys/socket.h
18 19
19if !HAVE_STRTONUM 20nc_SOURCES += compat/socket.c
20nc_SOURCES += strtonum.c 21
22if !HAVE_ACCEPT4
23nc_SOURCES += compat/accept4.c
21endif 24endif
22 25
26if !HAVE_READPASSPHRASE
27nc_SOURCES += compat/readpassphrase.c
28endif
29
30if !HAVE_STRTONUM
31nc_SOURCES += compat/strtonum.c
23endif 32endif
24 33
25endif 34endif
diff --git a/apps/nc/compat/accept4.c b/apps/nc/compat/accept4.c
new file mode 100644
index 0000000..278198b
--- /dev/null
+++ b/apps/nc/compat/accept4.c
@@ -0,0 +1,17 @@
1#include <sys/socket.h>
2#include <fcntl.h>
3
4int
5accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
6{
7 int rets = accept(s, addr, addrlen);
8 if (rets == -1)
9 return s;
10
11 if (flags & SOCK_CLOEXEC) {
12 flags = fcntl(s, F_GETFD);
13 fcntl(rets, F_SETFD, flags | FD_CLOEXEC);
14 }
15
16 return rets;
17}
diff --git a/apps/nc/compat/readpassphrase.c b/apps/nc/compat/readpassphrase.c
new file mode 100644
index 0000000..0d04134
--- /dev/null
+++ b/apps/nc/compat/readpassphrase.c
@@ -0,0 +1,205 @@
1/* $OpenBSD: readpassphrase.c,v 1.22 2010/01/13 10:20:54 dtucker Exp $ */
2
3/*
4 * Copyright (c) 2000-2002, 2007 Todd C. Miller <Todd.Miller@courtesan.com>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * Sponsored in part by the Defense Advanced Research Projects
19 * Agency (DARPA) and Air Force Research Laboratory, Air Force
20 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
21 */
22
23/* OPENBSD ORIGINAL: lib/libc/gen/readpassphrase.c */
24
25#include <termios.h>
26#include <signal.h>
27#include <ctype.h>
28#include <fcntl.h>
29#include <errno.h>
30#include <string.h>
31#include <unistd.h>
32
33#include <readpassphrase.h>
34
35#ifndef _PATH_TTY
36# define _PATH_TTY "/dev/tty"
37#endif
38
39#ifdef TCSASOFT
40# define _T_FLUSH (TCSAFLUSH|TCSASOFT)
41#else
42# define _T_FLUSH (TCSAFLUSH)
43#endif
44
45/* SunOS 4.x which lacks _POSIX_VDISABLE, but has VDISABLE */
46#if !defined(_POSIX_VDISABLE) && defined(VDISABLE)
47# define _POSIX_VDISABLE VDISABLE
48#endif
49
50#ifndef _NSIG
51# ifdef NSIG
52# define _NSIG NSIG
53# else
54# define _NSIG 128
55# endif
56#endif
57
58static volatile sig_atomic_t signo[_NSIG];
59
60static void handler(int);
61
62char *
63readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
64{
65 ssize_t bytes_written = 0;
66 ssize_t nr;
67 int input, output, save_errno, i, need_restart;
68 char ch, *p, *end;
69 struct termios term, oterm;
70 struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
71 struct sigaction savetstp, savettin, savettou, savepipe;
72
73 /* I suppose we could alloc on demand in this case (XXX). */
74 if (bufsiz == 0) {
75 errno = EINVAL;
76 return(NULL);
77 }
78
79restart:
80 for (i = 0; i < _NSIG; i++)
81 signo[i] = 0;
82 nr = -1;
83 save_errno = 0;
84 need_restart = 0;
85 /*
86 * Read and write to /dev/tty if available. If not, read from
87 * stdin and write to stderr unless a tty is required.
88 */
89 if ((flags & RPP_STDIN) ||
90 (input = output = open(_PATH_TTY, O_RDWR)) == -1) {
91 if (flags & RPP_REQUIRE_TTY) {
92 errno = ENOTTY;
93 return(NULL);
94 }
95 input = STDIN_FILENO;
96 output = STDERR_FILENO;
97 }
98
99 /*
100 * Catch signals that would otherwise cause the user to end
101 * up with echo turned off in the shell. Don't worry about
102 * things like SIGXCPU and SIGVTALRM for now.
103 */
104 sigemptyset(&sa.sa_mask);
105 sa.sa_flags = 0; /* don't restart system calls */
106 sa.sa_handler = handler;
107 (void)sigaction(SIGALRM, &sa, &savealrm);
108 (void)sigaction(SIGHUP, &sa, &savehup);
109 (void)sigaction(SIGINT, &sa, &saveint);
110 (void)sigaction(SIGPIPE, &sa, &savepipe);
111 (void)sigaction(SIGQUIT, &sa, &savequit);
112 (void)sigaction(SIGTERM, &sa, &saveterm);
113 (void)sigaction(SIGTSTP, &sa, &savetstp);
114 (void)sigaction(SIGTTIN, &sa, &savettin);
115 (void)sigaction(SIGTTOU, &sa, &savettou);
116
117 /* Turn off echo if possible. */
118 if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) {
119 memcpy(&term, &oterm, sizeof(term));
120 if (!(flags & RPP_ECHO_ON))
121 term.c_lflag &= ~(ECHO | ECHONL);
122#ifdef VSTATUS
123 if (term.c_cc[VSTATUS] != _POSIX_VDISABLE)
124 term.c_cc[VSTATUS] = _POSIX_VDISABLE;
125#endif
126 (void)tcsetattr(input, _T_FLUSH, &term);
127 } else {
128 memset(&term, 0, sizeof(term));
129 term.c_lflag |= ECHO;
130 memset(&oterm, 0, sizeof(oterm));
131 oterm.c_lflag |= ECHO;
132 }
133
134 /* No I/O if we are already backgrounded. */
135 if (signo[SIGTTOU] != 1 && signo[SIGTTIN] != 1) {
136 if (!(flags & RPP_STDIN))
137 bytes_written = write(output, prompt, strlen(prompt));
138 end = buf + bufsiz - 1;
139 p = buf;
140 while ((nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') {
141 if (p < end) {
142 if ((flags & RPP_SEVENBIT))
143 ch &= 0x7f;
144 if (isalpha(ch)) {
145 if ((flags & RPP_FORCELOWER))
146 ch = (char)tolower(ch);
147 if ((flags & RPP_FORCEUPPER))
148 ch = (char)toupper(ch);
149 }
150 *p++ = ch;
151 }
152 }
153 *p = '\0';
154 save_errno = errno;
155 if (!(term.c_lflag & ECHO))
156 bytes_written = write(output, "\n", 1);
157 }
158
159 (void) bytes_written;
160
161 /* Restore old terminal settings and signals. */
162 if (memcmp(&term, &oterm, sizeof(term)) != 0) {
163 while (tcsetattr(input, _T_FLUSH, &oterm) == -1 &&
164 errno == EINTR)
165 continue;
166 }
167 (void)sigaction(SIGALRM, &savealrm, NULL);
168 (void)sigaction(SIGHUP, &savehup, NULL);
169 (void)sigaction(SIGINT, &saveint, NULL);
170 (void)sigaction(SIGQUIT, &savequit, NULL);
171 (void)sigaction(SIGPIPE, &savepipe, NULL);
172 (void)sigaction(SIGTERM, &saveterm, NULL);
173 (void)sigaction(SIGTSTP, &savetstp, NULL);
174 (void)sigaction(SIGTTIN, &savettin, NULL);
175 (void)sigaction(SIGTTOU, &savettou, NULL);
176 if (input != STDIN_FILENO)
177 (void)close(input);
178
179 /*
180 * If we were interrupted by a signal, resend it to ourselves
181 * now that we have restored the signal handlers.
182 */
183 for (i = 0; i < _NSIG; i++) {
184 if (signo[i]) {
185 kill(getpid(), i);
186 switch (i) {
187 case SIGTSTP:
188 case SIGTTIN:
189 case SIGTTOU:
190 need_restart = 1;
191 }
192 }
193 }
194 if (need_restart)
195 goto restart;
196
197 if (save_errno)
198 errno = save_errno;
199 return(nr == -1 ? NULL : buf);
200}
201
202static void handler(int s)
203{
204 signo[s] = 1;
205}
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
9int
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
diff --git a/apps/nc/compat/strtonum.c b/apps/nc/compat/strtonum.c
new file mode 100644
index 0000000..1aeee34
--- /dev/null
+++ b/apps/nc/compat/strtonum.c
@@ -0,0 +1,65 @@
1/* $OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $ */
2
3/*
4 * Copyright (c) 2004 Ted Unangst and Todd Miller
5 * All rights reserved.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include <errno.h>
21#include <limits.h>
22#include <stdlib.h>
23
24#define INVALID 1
25#define TOOSMALL 2
26#define TOOLARGE 3
27
28long long
29strtonum(const char *numstr, long long minval, long long maxval,
30 const char **errstrp)
31{
32 long long ll = 0;
33 int error = 0;
34 char *ep;
35 struct errval {
36 const char *errstr;
37 int err;
38 } ev[4] = {
39 { NULL, 0 },
40 { "invalid", EINVAL },
41 { "too small", ERANGE },
42 { "too large", ERANGE },
43 };
44
45 ev[0].err = errno;
46 errno = 0;
47 if (minval > maxval) {
48 error = INVALID;
49 } else {
50 ll = strtoll(numstr, &ep, 10);
51 if (numstr == ep || *ep != '\0')
52 error = INVALID;
53 else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
54 error = TOOSMALL;
55 else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
56 error = TOOLARGE;
57 }
58 if (errstrp != NULL)
59 *errstrp = ev[error].errstr;
60 errno = ev[error].err;
61 if (error)
62 ll = 0;
63
64 return (ll);
65}
diff --git a/apps/nc/compat/sys/socket.h b/apps/nc/compat/sys/socket.h
new file mode 100644
index 0000000..13eb380
--- /dev/null
+++ b/apps/nc/compat/sys/socket.h
@@ -0,0 +1,31 @@
1/*
2 * Public domain
3 * sys/socket.h compatibility shim
4 */
5
6#ifndef _WIN32
7#include_next <sys/socket.h>
8
9#if !defined(SOCK_NONBLOCK) || !defined(SOCK_CLOEXEC)
10#define NEED_SOCKET_FLAGS
11int _socket(int domain, int type, int protocol);
12#ifndef SOCKET_FLAGS_PRIV
13#define socket(d, t, p) _socket(d, t, p)
14#endif
15#endif
16
17#ifndef SOCK_NONBLOCK
18#define SOCK_NONBLOCK 0x4000 /* set O_NONBLOCK */
19#endif
20
21#ifndef SOCK_CLOEXEC
22#define SOCK_CLOEXEC 0x8000 /* set FD_CLOEXEC */
23#endif
24
25#ifndef HAVE_ACCEPT4
26int accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags);
27#endif
28
29#else
30#include <win32netcompat.h>
31#endif
diff --git a/configure.ac b/configure.ac
index 09bc9f1..9f3d636 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,8 +52,6 @@ CHECK_LIBC_COMPAT
52CHECK_LIBC_CRYPTO_COMPAT 52CHECK_LIBC_CRYPTO_COMPAT
53CHECK_VA_COPY 53CHECK_VA_COPY
54 54
55AC_CHECK_HEADERS([err.h])
56
57AC_ARG_WITH([openssldir], 55AC_ARG_WITH([openssldir],
58 AS_HELP_STRING([--with-openssldir], 56 AS_HELP_STRING([--with-openssldir],
59 [Set the default openssl directory]), 57 [Set the default openssl directory]),
diff --git a/include/Makefile.am b/include/Makefile.am
index 3978af7..929ff7d 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -23,6 +23,7 @@ noinst_HEADERS += compat/arpa/nameser.h
23noinst_HEADERS += compat/machine/endian.h 23noinst_HEADERS += compat/machine/endian.h
24 24
25noinst_HEADERS += compat/netinet/in.h 25noinst_HEADERS += compat/netinet/in.h
26noinst_HEADERS += compat/netinet/ip.h
26noinst_HEADERS += compat/netinet/tcp.h 27noinst_HEADERS += compat/netinet/tcp.h
27 28
28noinst_HEADERS += compat/sys/cdefs.h 29noinst_HEADERS += compat/sys/cdefs.h
@@ -31,7 +32,6 @@ noinst_HEADERS += compat/sys/mman.h
31noinst_HEADERS += compat/sys/param.h 32noinst_HEADERS += compat/sys/param.h
32noinst_HEADERS += compat/sys/select.h 33noinst_HEADERS += compat/sys/select.h
33noinst_HEADERS += compat/sys/stat.h 34noinst_HEADERS += compat/sys/stat.h
34noinst_HEADERS += compat/sys/socket.h
35noinst_HEADERS += compat/sys/time.h 35noinst_HEADERS += compat/sys/time.h
36noinst_HEADERS += compat/sys/types.h 36noinst_HEADERS += compat/sys/types.h
37noinst_HEADERS += compat/sys/uio.h 37noinst_HEADERS += compat/sys/uio.h
diff --git a/include/compat/netinet/ip.h b/include/compat/netinet/ip.h
new file mode 100644
index 0000000..405bbcf
--- /dev/null
+++ b/include/compat/netinet/ip.h
@@ -0,0 +1,43 @@
1/*
2 * Public domain
3 * netinet/ip.h compatibility shim
4 */
5
6#ifndef _WIN32
7#include_next <netinet/ip.h>
8#else
9#include <win32netcompat.h>
10#endif
11
12/*
13 * Definitions for DiffServ Codepoints as per RFC2474
14 */
15#ifndef IPTOS_DSCP_CS0
16#define IPTOS_DSCP_CS0 0x00
17#define IPTOS_DSCP_CS1 0x20
18#define IPTOS_DSCP_CS2 0x40
19#define IPTOS_DSCP_CS3 0x60
20#define IPTOS_DSCP_CS4 0x80
21#define IPTOS_DSCP_CS5 0xa0
22#define IPTOS_DSCP_CS6 0xc0
23#define IPTOS_DSCP_CS7 0xe0
24#endif
25
26#ifndef IPTOS_DSCP_AF11
27#define IPTOS_DSCP_AF11 0x28
28#define IPTOS_DSCP_AF12 0x30
29#define IPTOS_DSCP_AF13 0x38
30#define IPTOS_DSCP_AF21 0x48
31#define IPTOS_DSCP_AF22 0x50
32#define IPTOS_DSCP_AF23 0x58
33#define IPTOS_DSCP_AF31 0x68
34#define IPTOS_DSCP_AF32 0x70
35#define IPTOS_DSCP_AF33 0x78
36#define IPTOS_DSCP_AF41 0x88
37#define IPTOS_DSCP_AF42 0x90
38#define IPTOS_DSCP_AF43 0x98
39#endif
40
41#ifndef IPTOS_DSCP_EF
42#define IPTOS_DSCP_EF 0xb8
43#endif
diff --git a/include/compat/readpassphrase.h b/include/compat/readpassphrase.h
new file mode 100644
index 0000000..aedf16c
--- /dev/null
+++ b/include/compat/readpassphrase.h
@@ -0,0 +1,48 @@
1/* $OpenBSD: readpassphrase.h,v 1.5 2003/06/17 21:56:23 millert Exp $ */
2
3/*
4 * Copyright (c) 2000, 2002 Todd C. Miller <Todd.Miller@courtesan.com>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * Sponsored in part by the Defense Advanced Research Projects
19 * Agency (DARPA) and Air Force Research Laboratory, Air Force
20 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
21 */
22
23#ifdef HAVE_READPASSPHRASE_H
24
25#include_next <readpassphrase.h>
26
27#else
28
29#ifndef _READPASSPHRASE_H_
30#define _READPASSPHRASE_H_
31
32#define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */
33#define RPP_ECHO_ON 0x01 /* Leave echo on. */
34#define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */
35#define RPP_FORCELOWER 0x04 /* Force input to lower case. */
36#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */
37#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */
38#define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */
39
40#include <sys/cdefs.h>
41
42__BEGIN_DECLS
43char * readpassphrase(const char *, char *, size_t, int);
44__END_DECLS
45
46#endif /* !_READPASSPHRASE_H_ */
47
48#endif
diff --git a/include/compat/sys/socket.h b/include/compat/sys/socket.h
deleted file mode 100644
index 17e84f1..0000000
--- a/include/compat/sys/socket.h
+++ /dev/null
@@ -1,10 +0,0 @@
1/*
2 * Public domain
3 * sys/socket.h compatibility shim
4 */
5
6#ifndef _WIN32
7#include_next <sys/socket.h>
8#else
9#include <win32netcompat.h>
10#endif
diff --git a/m4/check-libc.m4 b/m4/check-libc.m4
index f1ba611..c189ac9 100644
--- a/m4/check-libc.m4
+++ b/m4/check-libc.m4
@@ -1,11 +1,15 @@
1AC_DEFUN([CHECK_LIBC_COMPAT], [ 1AC_DEFUN([CHECK_LIBC_COMPAT], [
2# Check for libc headers
3AC_CHECK_HEADERS([err.h readpassphrase.h])
2# Check for general libc functions 4# Check for general libc functions
3AC_CHECK_FUNCS([asprintf inet_pton memmem poll reallocarray]) 5AC_CHECK_FUNCS([accept4 asprintf inet_pton memmem poll readpassphrase reallocarray])
4AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum]) 6AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum])
7AM_CONDITIONAL([HAVE_ACCEPT4], [test "x$ac_cv_func_accept4" = xyes])
5AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) 8AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
6AM_CONDITIONAL([HAVE_INET_PTON], [test "x$ac_cv_func_inet_pton" = xyes]) 9AM_CONDITIONAL([HAVE_INET_PTON], [test "x$ac_cv_func_inet_pton" = xyes])
7AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes]) 10AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
8AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes]) 11AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
12AM_CONDITIONAL([HAVE_READPASSPHRASE], [test "x$ac_cv_func_readpassphrase" = xyes])
9AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes]) 13AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
10AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes]) 14AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
11AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes]) 15AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
diff --git a/m4/check-os-options.m4 b/m4/check-os-options.m4
index 895d22b..9835cd8 100644
--- a/m4/check-os-options.m4
+++ b/m4/check-os-options.m4
@@ -15,8 +15,10 @@ case $host_os in
15 HOST_OS=cygwin 15 HOST_OS=cygwin
16 ;; 16 ;;
17 *darwin*) 17 *darwin*)
18 BUILD_NC=yes
18 HOST_OS=darwin 19 HOST_OS=darwin
19 HOST_ABI=macosx 20 HOST_ABI=macosx
21 AC_SUBST([PROG_LDADD], ['-lresolv'])
20 ;; 22 ;;
21 *freebsd*) 23 *freebsd*)
22 HOST_OS=freebsd 24 HOST_OS=freebsd
@@ -34,15 +36,18 @@ case $host_os in
34 AC_SUBST([PLATFORM_LDADD], ['-lpthread']) 36 AC_SUBST([PLATFORM_LDADD], ['-lpthread'])
35 ;; 37 ;;
36 *linux*) 38 *linux*)
39 BUILD_NC=yes
37 HOST_OS=linux 40 HOST_OS=linux
38 HOST_ABI=elf 41 HOST_ABI=elf
39 CPPFLAGS="$CPPFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE" 42 CPPFLAGS="$CPPFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE"
43 AC_SUBST([PROG_LDADD], ['-lresolv'])
40 ;; 44 ;;
41 *netbsd*) 45 *netbsd*)
42 HOST_OS=netbsd 46 HOST_OS=netbsd
43 CPPFLAGS="$CPPFLAGS -D_OPENBSD_SOURCE" 47 CPPFLAGS="$CPPFLAGS -D_OPENBSD_SOURCE"
44 ;; 48 ;;
45 *openbsd* | *bitrig*) 49 *openbsd* | *bitrig*)
50 BUILD_NC=yes
46 HOST_OS=openbsd 51 HOST_OS=openbsd
47 HOST_ABI=elf 52 HOST_ABI=elf
48 AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD gcc has bounded]) 53 AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD gcc has bounded])
@@ -66,6 +71,7 @@ case $host_os in
66 *) ;; 71 *) ;;
67esac 72esac
68 73
74AM_CONDITIONAL([BUILD_NC], [test x$BUILD_NC = xyes])
69AM_CONDITIONAL([HOST_AIX], [test x$HOST_OS = xaix]) 75AM_CONDITIONAL([HOST_AIX], [test x$HOST_OS = xaix])
70AM_CONDITIONAL([HOST_CYGWIN], [test x$HOST_OS = xcygwin]) 76AM_CONDITIONAL([HOST_CYGWIN], [test x$HOST_OS = xcygwin])
71AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin]) 77AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
diff --git a/patches/netcat.c.patch b/patches/netcat.c.patch
new file mode 100644
index 0000000..c5206f6
--- /dev/null
+++ b/patches/netcat.c.patch
@@ -0,0 +1,137 @@
1--- apps/nc/netcat.c.orig Sun Sep 13 08:12:39 2015
2+++ apps/nc/netcat.c Sun Sep 13 16:39:51 2015
3@@ -98,9 +98,13 @@
4 int Dflag; /* sodebug */
5 int Iflag; /* TCP receive buffer size */
6 int Oflag; /* TCP send buffer size */
7+#ifdef TCP_MD5SIG
8 int Sflag; /* TCP MD5 signature option */
9+#endif
10 int Tflag = -1; /* IP Type of Service */
11+#ifdef SO_RTABLE
12 int rtableid = -1;
13+#endif
14
15 int usetls; /* use TLS */
16 char *Cflag; /* Public cert file */
17@@ -150,7 +154,7 @@
18 struct servent *sv;
19 socklen_t len;
20 struct sockaddr_storage cliaddr;
21- char *proxy;
22+ char *proxy = NULL;
23 const char *errstr, *proxyhost = "", *proxyport = NULL;
24 struct addrinfo proxyhints;
25 char unix_dg_tmp_socket_buf[UNIX_DG_TMP_SOCKET_SIZE];
26@@ -251,12 +255,14 @@
27 case 'u':
28 uflag = 1;
29 break;
30+#ifdef SO_RTABLE
31 case 'V':
32 rtableid = (int)strtonum(optarg, 0,
33 RT_TABLEID_MAX, &errstr);
34 if (errstr)
35 errx(1, "rtable %s: %s", errstr, optarg);
36 break;
37+#endif
38 case 'v':
39 vflag = 1;
40 break;
41@@ -289,9 +295,11 @@
42 errx(1, "TCP send window %s: %s",
43 errstr, optarg);
44 break;
45+#ifdef TCP_MD5SIG
46 case 'S':
47 Sflag = 1;
48 break;
49+#endif
50 case 'T':
51 errstr = NULL;
52 errno = 0;
53@@ -776,7 +784,10 @@
54 remote_connect(const char *host, const char *port, struct addrinfo hints)
55 {
56 struct addrinfo *res, *res0;
57- int s, error, on = 1;
58+ int s, error;
59+#ifdef SO_BINDANY
60+ int on = 1;
61+#endif
62
63 if ((error = getaddrinfo(host, port, &hints, &res)))
64 errx(1, "getaddrinfo: %s", gai_strerror(error));
65@@ -787,16 +798,20 @@
66 SOCK_NONBLOCK, res0->ai_protocol)) < 0)
67 continue;
68
69+#ifdef SO_RTABLE
70 if (rtableid >= 0 && (setsockopt(s, SOL_SOCKET, SO_RTABLE,
71 &rtableid, sizeof(rtableid)) == -1))
72 err(1, "setsockopt SO_RTABLE");
73+#endif
74
75 /* Bind to a local port or source address if specified. */
76 if (sflag || pflag) {
77 struct addrinfo ahints, *ares;
78
79+#ifdef SO_BINDANY
80 /* try SO_BINDANY, but don't insist */
81 setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on));
82+#endif
83 memset(&ahints, 0, sizeof(struct addrinfo));
84 ahints.ai_family = res0->ai_family;
85 ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
86@@ -887,9 +902,11 @@
87 res0->ai_protocol)) < 0)
88 continue;
89
90+#ifdef SO_RTABLE
91 if (rtableid >= 0 && (setsockopt(s, SOL_SOCKET, SO_RTABLE,
92 &rtableid, sizeof(rtableid)) == -1))
93 err(1, "setsockopt SO_RTABLE");
94+#endif
95
96 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
97 if (ret == -1)
98@@ -1337,11 +1354,13 @@
99 {
100 int x = 1;
101
102+#ifdef TCP_MD5SIG
103 if (Sflag) {
104 if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
105 &x, sizeof(x)) == -1)
106 err(1, NULL);
107 }
108+#endif
109 if (Dflag) {
110 if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
111 &x, sizeof(x)) == -1)
112@@ -1516,15 +1535,19 @@
113 \t-P proxyuser\tUsername for proxy authentication\n\
114 \t-p port\t Specify local port for remote connects\n\
115 \t-R CAfile CA bundle\n\
116- \t-r Randomize remote ports\n\
117- \t-S Enable the TCP MD5 signature option\n\
118- \t-s source Local source address\n\
119+ \t-r Randomize remote ports\n"
120+#ifdef TCP_MD5SIG
121+ "\t-S Enable the TCP MD5 signature option\n"
122+#endif
123+ "\t-s source Local source address\n\
124 \t-T keyword TOS value or TLS options\n\
125 \t-t Answer TELNET negotiation\n\
126 \t-U Use UNIX domain socket\n\
127- \t-u UDP mode\n\
128- \t-V rtable Specify alternate routing table\n\
129- \t-v Verbose\n\
130+ \t-u UDP mode\n"
131+#ifdef SO_RTABLE
132+ "\t-V rtable Specify alternate routing table\n"
133+#endif
134+ "\t-v Verbose\n\
135 \t-w timeout Timeout for connects and final net reads\n\
136 \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\
137 \t-x addr[:port]\tSpecify proxy address and port\n\
diff --git a/update.sh b/update.sh
index 83468a6..6df4290 100755
--- a/update.sh
+++ b/update.sh
@@ -213,7 +213,7 @@ sed -e "s/compat\///" crypto/Makefile.am.arc4random > \
213echo "copying nc(1) source" 213echo "copying nc(1) source"
214$CP $app_src/nc/nc.1 apps/nc 214$CP $app_src/nc/nc.1 apps/nc
215rm -f apps/nc/*.c apps/nc/*.h 215rm -f apps/nc/*.c apps/nc/*.h
216$CP_LIBC $libc_src/stdlib/strtonum.c apps/nc 216$CP_LIBC $libc_src/stdlib/strtonum.c apps/nc/compat
217for i in `awk '/SOURCES|HEADERS|MANS/ { print $3 }' apps/nc/Makefile.am` ; do 217for i in `awk '/SOURCES|HEADERS|MANS/ { print $3 }' apps/nc/Makefile.am` ; do
218 if [ -e $app_src/nc/$i ]; then 218 if [ -e $app_src/nc/$i ]; then
219 $CP $app_src/nc/$i apps/nc 219 $CP $app_src/nc/$i apps/nc