Merge lp:~gandelman-a/ubuntu/quantal/netcat-openbsd/merge into lp:ubuntu/quantal/netcat-openbsd
- Quantal (12.10)
- merge
- Merge into quantal
Proposed by
Adam Gandelman
Status: | Merged |
---|---|
Merge reported by: | James Page |
Merged at revision: | not available |
Proposed branch: | lp:~gandelman-a/ubuntu/quantal/netcat-openbsd/merge |
Merge into: | lp:ubuntu/quantal/netcat-openbsd |
Diff against target: |
5336 lines (+2456/-2095) 52 files modified
.pc/.version (+1/-0) Makefile (+3/-18) atomicio.c (+18/-13) atomicio.h (+7/-1) debian/changelog (+83/-0) debian/compat (+1/-1) debian/control (+7/-5) debian/copyright (+46/-130) debian/netcat-openbsd.README.Debian (+13/-0) debian/netcat-openbsd.dirs (+0/-2) debian/netcat-openbsd.examples (+1/-0) debian/netcat-openbsd.install (+2/-0) debian/netcat-openbsd.links (+1/-0) debian/patches/0001-port-to-linux-with-libsd.patch (+466/-0) debian/patches/0002-connect-timeout.patch (+118/-0) debian/patches/0003-get-sev-by-name.patch (+34/-0) debian/patches/0004-poll-hup.patch (+59/-0) debian/patches/0005-send-crlf.patch (+103/-0) debian/patches/0006-quit-timer.patch (+128/-0) debian/patches/0007-udp-scan-timeout.patch (+56/-0) debian/patches/0008-verbose-numeric-port.patch (+103/-0) debian/patches/0009-dccp-support.patch (+299/-0) debian/patches/0010-serialized-handling-multiple-clients.patch (+73/-0) debian/patches/0011-misc-failures-and-features.patch (+443/-0) debian/patches/connect-timeout.patch (+0/-120) debian/patches/dccp.patch (+0/-191) debian/patches/gcc-warnings.patch (+0/-157) debian/patches/getservbyname.patch (+0/-24) debian/patches/glib-strlcpy.patch (+0/-96) debian/patches/help-version-exit.patch (+0/-21) debian/patches/nc-1.84-udp_stop.patch (+0/-14) debian/patches/netcat-info.patch (+8/-7) debian/patches/no-strtonum.patch (+0/-107) debian/patches/openbsd-compat.patch (+0/-54) debian/patches/pollhup.patch (+0/-50) debian/patches/quit-timer.patch (+0/-84) debian/patches/reuseaddr.patch (+0/-15) debian/patches/send-crlf.patch (+0/-109) debian/patches/series (+11/-17) debian/patches/silence-z.patch (+0/-13) debian/patches/socks-b64-prototype.patch (+0/-13) debian/patches/udp-scan-timeout.patch (+0/-50) debian/patches/verbose-message-to-stderr.patch (+0/-17) debian/patches/verbose-numeric-port.patch (+0/-54) debian/rules (+12/-60) debian/source/format (+1/-0) nc.1 (+85/-36) netcat.c (+249/-78) openbsd-compat/base64.c (+0/-308) openbsd-compat/readpassphrase.c (+0/-179) openbsd-compat/readpassphrase.h (+0/-40) socks.c (+25/-11) |
To merge this branch: | bzr merge lp:~gandelman-a/ubuntu/quantal/netcat-openbsd/merge |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Oliver Grawert | Approve | ||
Ubuntu branches | Pending | ||
Review via email: mp+108072@code.launchpad.net |
Commit message
Description of the change
netcat-openbsd (1.105-6ubuntu1) quantal; urgency=low
* Merge from Debian unstable (LP: #1006631).
* debian/
applied upstream.
* debian/
* debian/control: Update XSBC-Original-
* debian/
* Remaining changes:
- debian/
if you are looking for an option when it is not available.
(LP: #590925)
-- Adam Gandelman <email address hidden> Wed, 30 May 2012 14:38:36 -0700
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory '.pc' | |||
2 | === added file '.pc/.version' | |||
3 | --- .pc/.version 1970-01-01 00:00:00 +0000 | |||
4 | +++ .pc/.version 2012-05-30 22:10:23 +0000 | |||
5 | @@ -0,0 +1,1 @@ | |||
6 | 1 | 2 | ||
7 | 0 | 2 | ||
8 | === modified file 'Makefile' | |||
9 | --- Makefile 2010-11-19 14:40:32 +0000 | |||
10 | +++ Makefile 2012-05-30 22:10:23 +0000 | |||
11 | @@ -1,21 +1,6 @@ | |||
12 | 1 | # $OpenBSD: Makefile,v 1.6 2001/09/02 18:45:41 jakob Exp $ | 1 | # $OpenBSD: Makefile,v 1.6 2001/09/02 18:45:41 jakob Exp $ |
13 | 2 | 2 | ||
14 | 3 | PROG= nc | 3 | PROG= nc |
33 | 4 | SRCS= netcat.c atomicio.c socks.c \ | 4 | SRCS= netcat.c atomicio.c socks.c |
34 | 5 | openbsd-compat/base64.c openbsd-compat/readpassphrase.c | 5 | |
35 | 6 | 6 | .include <bsd.prog.mk> | |
18 | 7 | CC = gcc | ||
19 | 8 | override CFLAGS += `pkg-config --cflags glib-2.0` | ||
20 | 9 | INC = -Iopenbsd-compat | ||
21 | 10 | LIBS = `pkg-config --libs glib-2.0` | ||
22 | 11 | OBJS = $(SRCS:.c=.o) | ||
23 | 12 | |||
24 | 13 | all: nc | ||
25 | 14 | nc: $(OBJS) | ||
26 | 15 | $(CC) $(OBJS) $(LIBS) -o nc | ||
27 | 16 | |||
28 | 17 | $(OBJS): %.o: %.c | ||
29 | 18 | $(CC) $(CFLAGS) $(INC) -c $< -o $@ | ||
30 | 19 | |||
31 | 20 | clean: | ||
32 | 21 | rm -f $(OBJS) nc | ||
36 | 22 | 7 | ||
37 | === modified file 'atomicio.c' | |||
38 | --- atomicio.c 2008-01-30 18:24:46 +0000 | |||
39 | +++ atomicio.c 2012-05-30 22:10:23 +0000 | |||
40 | @@ -1,7 +1,7 @@ | |||
43 | 1 | /* $OpenBSD: atomicio.c,v 1.8 2006/02/11 19:31:18 otto Exp $ */ | 1 | /* $OpenBSD: atomicio.c,v 1.10 2011/01/08 00:47:19 jeremy Exp $ */ |
42 | 2 | |||
44 | 3 | /* | 2 | /* |
46 | 4 | * Copyright (c) 2005 Anil Madhavapeddy. All rights served. | 3 | * Copyright (c) 2006 Damien Miller. All rights reserved. |
47 | 4 | * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved. | ||
48 | 5 | * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. | 5 | * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. |
49 | 6 | * All rights reserved. | 6 | * All rights reserved. |
50 | 7 | * | 7 | * |
51 | @@ -26,32 +26,37 @@ | |||
52 | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
53 | 27 | */ | 27 | */ |
54 | 28 | 28 | ||
57 | 29 | #include <sys/types.h> | 29 | #include <sys/param.h> |
58 | 30 | #include <sys/uio.h> | 30 | |
59 | 31 | #include <errno.h> | 31 | #include <errno.h> |
60 | 32 | #include <poll.h> | ||
61 | 32 | #include <unistd.h> | 33 | #include <unistd.h> |
62 | 34 | |||
63 | 33 | #include "atomicio.h" | 35 | #include "atomicio.h" |
64 | 34 | 36 | ||
65 | 35 | /* | 37 | /* |
66 | 36 | * ensure all of data on socket comes through. f==read || f==vwrite | 38 | * ensure all of data on socket comes through. f==read || f==vwrite |
67 | 37 | */ | 39 | */ |
68 | 38 | size_t | 40 | size_t |
74 | 39 | atomicio(f, fd, _s, n) | 41 | atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n) |
70 | 40 | ssize_t (*f) (int, void *, size_t); | ||
71 | 41 | int fd; | ||
72 | 42 | void *_s; | ||
73 | 43 | size_t n; | ||
75 | 44 | { | 42 | { |
76 | 45 | char *s = _s; | 43 | char *s = _s; |
77 | 46 | size_t pos = 0; | 44 | size_t pos = 0; |
78 | 47 | ssize_t res; | 45 | ssize_t res; |
79 | 46 | struct pollfd pfd; | ||
80 | 48 | 47 | ||
81 | 48 | pfd.fd = fd; | ||
82 | 49 | pfd.events = f == read ? POLLIN : POLLOUT; | ||
83 | 49 | while (n > pos) { | 50 | while (n > pos) { |
84 | 50 | res = (f) (fd, s + pos, n - pos); | 51 | res = (f) (fd, s + pos, n - pos); |
85 | 51 | switch (res) { | 52 | switch (res) { |
86 | 52 | case -1: | 53 | case -1: |
89 | 53 | if (errno == EINTR || errno == EAGAIN) | 54 | if (errno == EINTR) |
90 | 54 | continue; | 55 | continue; |
91 | 56 | if ((errno == EAGAIN) || (errno == ENOBUFS)) { | ||
92 | 57 | (void)poll(&pfd, 1, -1); | ||
93 | 58 | continue; | ||
94 | 59 | } | ||
95 | 55 | return 0; | 60 | return 0; |
96 | 56 | case 0: | 61 | case 0: |
97 | 57 | errno = EPIPE; | 62 | errno = EPIPE; |
98 | @@ -60,5 +65,5 @@ | |||
99 | 60 | pos += (size_t)res; | 65 | pos += (size_t)res; |
100 | 61 | } | 66 | } |
101 | 62 | } | 67 | } |
103 | 63 | return pos; | 68 | return (pos); |
104 | 64 | } | 69 | } |
105 | 65 | 70 | ||
106 | === modified file 'atomicio.h' | |||
107 | --- atomicio.h 2008-01-30 18:24:46 +0000 | |||
108 | +++ atomicio.h 2012-05-30 22:10:23 +0000 | |||
109 | @@ -1,6 +1,7 @@ | |||
111 | 1 | /* $OpenBSD: atomicio.h,v 1.1 2005/05/24 20:13:28 avsm Exp $ */ | 1 | /* $OpenBSD: atomicio.h,v 1.2 2007/09/07 14:50:44 tobias Exp $ */ |
112 | 2 | 2 | ||
113 | 3 | /* | 3 | /* |
114 | 4 | * Copyright (c) 2006 Damien Miller. All rights reserved. | ||
115 | 4 | * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. | 5 | * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. |
116 | 5 | * All rights reserved. | 6 | * All rights reserved. |
117 | 6 | * | 7 | * |
118 | @@ -25,9 +26,14 @@ | |||
119 | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
120 | 26 | */ | 27 | */ |
121 | 27 | 28 | ||
122 | 29 | #ifndef _ATOMICIO_H | ||
123 | 30 | #define _ATOMICIO_H | ||
124 | 31 | |||
125 | 28 | /* | 32 | /* |
126 | 29 | * Ensure all of data on socket comes through. f==read || f==vwrite | 33 | * Ensure all of data on socket comes through. f==read || f==vwrite |
127 | 30 | */ | 34 | */ |
128 | 31 | size_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t); | 35 | size_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t); |
129 | 32 | 36 | ||
130 | 33 | #define vwrite (ssize_t (*)(int, void *, size_t))write | 37 | #define vwrite (ssize_t (*)(int, void *, size_t))write |
131 | 38 | |||
132 | 39 | #endif /* _ATOMICIO_H */ | ||
133 | 34 | 40 | ||
134 | === modified file 'debian/changelog' | |||
135 | --- debian/changelog 2011-07-01 21:39:53 +0000 | |||
136 | +++ debian/changelog 2012-05-30 22:10:23 +0000 | |||
137 | @@ -1,3 +1,86 @@ | |||
138 | 1 | netcat-openbsd (1.105-6ubuntu1) quantal; urgency=low | ||
139 | 2 | |||
140 | 3 | * Merge from Debian unstable (LP: #1006631). | ||
141 | 4 | * debian/patches/verbose-message-to-stderr.patch: Dropped, | ||
142 | 5 | applied upstream. | ||
143 | 6 | * debian/patches/dccp.patch: Dropped, applied in Debian. | ||
144 | 7 | * debian/control: Update XSBC-Original-Maintainer. | ||
145 | 8 | * debian/patches/netcat-info.patch: Refresh. | ||
146 | 9 | * Remaining changes: | ||
147 | 10 | - debian/patches/netcat-info.patch: Add info about netcat-traditional | ||
148 | 11 | if you are looking for an option when it is not available. | ||
149 | 12 | (LP: #590925) | ||
150 | 13 | |||
151 | 14 | -- Adam Gandelman <adamg@canonical.com> Wed, 30 May 2012 14:38:36 -0700 | ||
152 | 15 | |||
153 | 16 | netcat-openbsd (1.105-6) unstable; urgency=low | ||
154 | 17 | |||
155 | 18 | * Fix segfaults when using -Ulv (Closes: #668558). | ||
156 | 19 | * Do not continue to listen on port after accepting connection. | ||
157 | 20 | |||
158 | 21 | -- Aron Xu <aron@debian.org> Thu, 03 May 2012 07:38:59 +0800 | ||
159 | 22 | |||
160 | 23 | netcat-openbsd (1.105-5) unstable; urgency=low | ||
161 | 24 | |||
162 | 25 | * Add $LDFLAGS from environment (Closes: #665321). | ||
163 | 26 | |||
164 | 27 | -- Aron Xu <aron@debian.org> Mon, 26 Mar 2012 01:37:16 +0800 | ||
165 | 28 | |||
166 | 29 | netcat-openbsd (1.105-4) unstable; urgency=high | ||
167 | 30 | |||
168 | 31 | * High urgency for fixing RC bug. | ||
169 | 32 | * Fix readwrite() behaviour (Closes: #662741). | ||
170 | 33 | |||
171 | 34 | -- Aron Xu <aron@debian.org> Tue, 06 Mar 2012 15:18:26 +0800 | ||
172 | 35 | |||
173 | 36 | netcat-openbsd (1.105-3) unstable; urgency=low | ||
174 | 37 | |||
175 | 38 | * Clear up symlink of man page. | ||
176 | 39 | * Use Breaks instead of Conflicts. | ||
177 | 40 | * Fix minor warnings from man. | ||
178 | 41 | |||
179 | 42 | -- Aron Xu <aron@debian.org> Sun, 19 Feb 2012 14:28:46 +0800 | ||
180 | 43 | |||
181 | 44 | netcat-openbsd (1.105-2) unstable; urgency=low | ||
182 | 45 | |||
183 | 46 | * Add missing Build-Depends: pkg-config. | ||
184 | 47 | |||
185 | 48 | -- Aron Xu <aron@debian.org> Sun, 19 Feb 2012 03:59:37 +0800 | ||
186 | 49 | |||
187 | 50 | netcat-openbsd (1.105-1) unstable; urgency=low | ||
188 | 51 | |||
189 | 52 | * New upstream CVS snapshot, new maintainer. | ||
190 | 53 | - Verbose message to strerr (Closes: #570765). | ||
191 | 54 | - Can use packet's content > 1024 (Closes: #607003). | ||
192 | 55 | - Replace non-portable echo with printf (Closes: #510372). | ||
193 | 56 | * debian/patches: | ||
194 | 57 | - Rearrange existing patches, fix new porting issues. | ||
195 | 58 | - Option -l and -p are now compatible (Closes: #540073). | ||
196 | 59 | - Use libbsd instead of glib for strlcpy (Closes: #550611). | ||
197 | 60 | - Fix build with -Wl,--as-needed (Closes: #604781). | ||
198 | 61 | - Handling multiple clients subsquently when -k (Closes: #514792). | ||
199 | 62 | - Replace inet_ntoa with inet_ntop to support IPv6 | ||
200 | 63 | (Closes: #512992). | ||
201 | 64 | - Modify -q behavior to be compatible with nc.traditional | ||
202 | 65 | (Closes: #508722, #594614, #606925, #611964). | ||
203 | 66 | - DCCP and broadcast support. | ||
204 | 67 | - Arbitrary port list to scan. | ||
205 | 68 | - Fix misc connection failures | ||
206 | 69 | (Closes: #579485, #579486, #579487, #579488, #633948). | ||
207 | 70 | - Improve verbose information and documentations. | ||
208 | 71 | * debian/rules: | ||
209 | 72 | - Link nc.openbsd.1 from nc.1 (Closes: #535951). | ||
210 | 73 | - Enable optional hardening build flags. | ||
211 | 74 | * debian/control: | ||
212 | 75 | - Replace glib with libbsd. | ||
213 | 76 | - Update to use debhelper 8, std-ver 3.9.2. | ||
214 | 77 | - Priority: important, to make it into base system. | ||
215 | 78 | - Add Vcs-*. | ||
216 | 79 | * debian/compat: | ||
217 | 80 | - Update to 8 from 4. | ||
218 | 81 | |||
219 | 82 | -- Aron Xu <aron@debian.org> Wed, 15 Feb 2012 01:39:04 +0800 | ||
220 | 83 | |||
221 | 1 | netcat-openbsd (1.89-4ubuntu1) oneiric; urgency=low | 84 | netcat-openbsd (1.89-4ubuntu1) oneiric; urgency=low |
222 | 2 | 85 | ||
223 | 3 | * Merge from Debian unstable (LP: #803856). Remaining changes: | 86 | * Merge from Debian unstable (LP: #803856). Remaining changes: |
224 | 4 | 87 | ||
225 | === modified file 'debian/compat' | |||
226 | --- debian/compat 2008-01-30 18:24:46 +0000 | |||
227 | +++ debian/compat 2012-05-30 22:10:23 +0000 | |||
228 | @@ -1,1 +1,1 @@ | |||
230 | 1 | 4 | 1 | 8 |
231 | 2 | 2 | ||
232 | === modified file 'debian/control' | |||
233 | --- debian/control 2010-02-09 10:42:03 +0000 | |||
234 | +++ debian/control 2012-05-30 22:10:23 +0000 | |||
235 | @@ -2,15 +2,17 @@ | |||
236 | 2 | Section: net | 2 | Section: net |
237 | 3 | Priority: optional | 3 | Priority: optional |
238 | 4 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> | 4 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> |
242 | 5 | XSBC-Original-Maintainer: Decklin Foster <decklin@red-bean.com> | 5 | XSBC-Original-Maintainer: Aron Xu <aron@debian.org> |
243 | 6 | Standards-Version: 3.7.3 | 6 | Standards-Version: 3.9.3 |
244 | 7 | Build-Depends: quilt, debhelper (>= 4.0.0), libglib2.0-dev | 7 | Build-Depends: debhelper (>= 8), quilt, libbsd-dev, pkg-config |
245 | 8 | Vcs-Browser: http://git.debian.org/?p=collab-maint/netcat-openbsd.git | ||
246 | 9 | Vcs-Git: git://anonscm.debian.org/collab-maint/netcat-openbsd.git | ||
247 | 8 | 10 | ||
248 | 9 | Package: netcat-openbsd | 11 | Package: netcat-openbsd |
249 | 10 | Architecture: any | 12 | Architecture: any |
251 | 11 | Depends: ${shlibs:Depends} | 13 | Depends: ${shlibs:Depends}, ${misc:Depends} |
252 | 12 | Provides: netcat | 14 | Provides: netcat |
254 | 13 | Conflicts: netcat (<< 1.10-35) | 15 | Breaks: netcat (<< 1.10-35) |
255 | 14 | Replaces: netcat (<< 1.10-35) | 16 | Replaces: netcat (<< 1.10-35) |
256 | 15 | Description: TCP/IP swiss army knife | 17 | Description: TCP/IP swiss army knife |
257 | 16 | A simple Unix utility which reads and writes data across network | 18 | A simple Unix utility which reads and writes data across network |
258 | 17 | 19 | ||
259 | === modified file 'debian/copyright' | |||
260 | --- debian/copyright 2008-01-30 18:24:46 +0000 | |||
261 | +++ debian/copyright 2012-05-30 22:10:23 +0000 | |||
262 | @@ -1,130 +1,46 @@ | |||
393 | 1 | The netcat-openbsd Debian package was created by Soren Hansen | 1 | Format: http://dep.debian.net/deps/dep5/ |
394 | 2 | <soren@ubuntu.com> and by Decklin Foster <decklin@red-bean.com>, based | 2 | Source: http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/nc/ |
395 | 3 | loosely on the original netcat package. The code itself was rewritten | 3 | |
396 | 4 | by the OpenBSD project, from the original implementation by Hobbit | 4 | Files: netcat.c |
397 | 5 | <hobbit@atstake.com>. | 5 | Copyright: 2001 Eric Jackson <ericj@monkey.org> |
398 | 6 | 6 | License: BSD-3-Clause | |
399 | 7 | Sources can be found at: | 7 | |
400 | 8 | 8 | Files: atomicio.* | |
401 | 9 | http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/nc/ | 9 | Copyright: 2005 Anil Madhavapeddy |
402 | 10 | 10 | 1995,1999 Theo de Raadt | |
403 | 11 | Copyright and license of netcat.c: | 11 | License: BSD-3-Clause |
404 | 12 | 12 | ||
405 | 13 | Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 13 | Files: socks.c |
406 | 14 | 14 | Copyright: 1999 Niklas Hallqvist | |
407 | 15 | Redistribution and use in source and binary forms, with or without | 15 | 2004, 2005 Damien Miller |
408 | 16 | modification, are permitted provided that the following conditions | 16 | License: BSD-3-Clause |
409 | 17 | are met: | 17 | |
410 | 18 | 18 | Files: debian/* | |
411 | 19 | 1. Redistributions of source code must retain the above copyright | 19 | Copyright: 2008, 2009, 2010 Decklin Foster <decklin@red-bean.com> |
412 | 20 | notice, this list of conditions and the following disclaimer. | 20 | 2008, 2009, 2010 Soren Hansen <soren@ubuntu.com> |
413 | 21 | 2. Redistributions in binary form must reproduce the above copyright | 21 | 2012 Aron Xu <aron@debian.org> |
414 | 22 | notice, this list of conditions and the following disclaimer in the | 22 | License: BSD-3-Clause |
415 | 23 | documentation and/or other materials provided with the distribution. | 23 | |
416 | 24 | 3. The name of the author may not be used to endorse or promote products | 24 | License: BSD-3-Clause |
417 | 25 | derived from this software without specific prior written permission. | 25 | Redistribution and use in source and binary forms, with or without |
418 | 26 | 26 | modification, are permitted provided that the following conditions | |
419 | 27 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 27 | are met: |
420 | 28 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 28 | . |
421 | 29 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 29 | 1. Redistributions of source code must retain the above copyright |
422 | 30 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 30 | notice, this list of conditions and the following disclaimer. |
423 | 31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 31 | 2. Redistributions in binary form must reproduce the above copyright |
424 | 32 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 32 | notice, this list of conditions and the following disclaimer in the |
425 | 33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 33 | documentation and/or other materials provided with the distribution. |
426 | 34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 34 | 3. The name of the author may not be used to endorse or promote products |
427 | 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 35 | derived from this software without specific prior written permission. |
428 | 36 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 36 | . |
429 | 37 | 37 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
430 | 38 | Copyright and license of atomicio.c: | 38 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
431 | 39 | 39 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
432 | 40 | Copyright (c) 2005 Anil Madhavapeddy. All rights served. | 40 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
433 | 41 | Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. | 41 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
434 | 42 | All rights reserved. | 42 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
435 | 43 | 43 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
436 | 44 | Redistribution and use in source and binary forms, with or without | 44 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
437 | 45 | modification, are permitted provided that the following conditions | 45 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
438 | 46 | are met: | 46 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
309 | 47 | 1. Redistributions of source code must retain the above copyright | ||
310 | 48 | notice, this list of conditions and the following disclaimer. | ||
311 | 49 | 2. Redistributions in binary form must reproduce the above copyright | ||
312 | 50 | notice, this list of conditions and the following disclaimer in the | ||
313 | 51 | documentation and/or other materials provided with the distribution. | ||
314 | 52 | |||
315 | 53 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
316 | 54 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
317 | 55 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
318 | 56 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
319 | 57 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
320 | 58 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
321 | 59 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
322 | 60 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
323 | 61 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
324 | 62 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
325 | 63 | |||
326 | 64 | Copyright (c) 2005 Anil Madhavapeddy. All rights served. | ||
327 | 65 | Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. | ||
328 | 66 | |||
329 | 67 | Copyright of socks.c (license is identical to that of atomicio.c): | ||
330 | 68 | |||
331 | 69 | Copyright (c) 1999 Niklas Hallqvist. All rights reserved. | ||
332 | 70 | Copyright (c) 2004, 2005 Damien Miller. All rights reserved. | ||
333 | 71 | |||
334 | 72 | Copyright and license of readpassphrase.c: | ||
335 | 73 | |||
336 | 74 | Copyright (c) 2000-2002, 2007 Todd C. Miller <Todd.Miller@courtesan.com> | ||
337 | 75 | |||
338 | 76 | Permission to use, copy, modify, and distribute this software for any | ||
339 | 77 | purpose with or without fee is hereby granted, provided that the above | ||
340 | 78 | copyright notice and this permission notice appear in all copies. | ||
341 | 79 | |||
342 | 80 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
343 | 81 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
344 | 82 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
345 | 83 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
346 | 84 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
347 | 85 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
348 | 86 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
349 | 87 | |||
350 | 88 | Sponsored in part by the Defense Advanced Research Projects | ||
351 | 89 | Agency (DARPA) and Air Force Research Laboratory, Air Force | ||
352 | 90 | Materiel Command, USAF, under agreement number F39502-99-1-0512. | ||
353 | 91 | |||
354 | 92 | Copyright and license of base64.c: | ||
355 | 93 | |||
356 | 94 | Copyright (c) 1996 by Internet Software Consortium. | ||
357 | 95 | |||
358 | 96 | Permission to use, copy, modify, and distribute this software for any | ||
359 | 97 | purpose with or without fee is hereby granted, provided that the above | ||
360 | 98 | copyright notice and this permission notice appear in all copies. | ||
361 | 99 | |||
362 | 100 | THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
363 | 101 | ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
364 | 102 | OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
365 | 103 | CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
366 | 104 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
367 | 105 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
368 | 106 | ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
369 | 107 | SOFTWARE. | ||
370 | 108 | |||
371 | 109 | Portions Copyright (c) 1995 by International Business Machines, Inc. | ||
372 | 110 | |||
373 | 111 | International Business Machines, Inc. (hereinafter called IBM) grants | ||
374 | 112 | permission under its copyrights to use, copy, modify, and distribute this | ||
375 | 113 | Software with or without fee, provided that the above copyright notice and | ||
376 | 114 | all paragraphs of this notice appear in all copies, and that the name of IBM | ||
377 | 115 | not be used in connection with the marketing of any product incorporating | ||
378 | 116 | the Software or modifications thereof, without specific, written prior | ||
379 | 117 | permission. | ||
380 | 118 | |||
381 | 119 | To the extent it has a right to do so, IBM grants an immunity from suit | ||
382 | 120 | under its patents, if any, for the use, sale or manufacture of products to | ||
383 | 121 | the extent that such products are used for performing Domain Name System | ||
384 | 122 | dynamic updates in TCP/IP networks by means of the Software. No immunity is | ||
385 | 123 | granted for any product per se or for any other function of any product. | ||
386 | 124 | |||
387 | 125 | THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, | ||
388 | 126 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
389 | 127 | PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, | ||
390 | 128 | DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING | ||
391 | 129 | OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN | ||
392 | 130 | IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. | ||
439 | 131 | 47 | ||
440 | === modified file 'debian/netcat-openbsd.README.Debian' | |||
441 | --- debian/netcat-openbsd.README.Debian 2008-01-30 18:24:46 +0000 | |||
442 | +++ debian/netcat-openbsd.README.Debian 2012-05-30 22:10:23 +0000 | |||
443 | @@ -1,6 +1,19 @@ | |||
444 | 1 | OpenBSD netcat for Debian | 1 | OpenBSD netcat for Debian |
445 | 2 | ------------------------- | 2 | ------------------------- |
446 | 3 | 3 | ||
447 | 4 | Merge with upstream again, now it links against -lresov and -lbsd. The | ||
448 | 5 | former one is from libc, and the latter provides a good strlcpy(). Now | ||
449 | 6 | the package has a much saner dependency to make its way into base system. | ||
450 | 7 | A lot of bug fixes and some new features are also applied. | ||
451 | 8 | |||
452 | 9 | For record, the reason of not implementing features like -c or -e in this | ||
453 | 10 | cat is about security. These options enable anyone on the system to open | ||
454 | 11 | port and execute arbitrary command on local host from remote very easily, | ||
455 | 12 | which is not desired for ordinary multi-user systems. If you do need such | ||
456 | 13 | function, please try nc.traditional or nc6. | ||
457 | 14 | |||
458 | 15 | -- Aron Xu <aron@debian.org> Wed, 15 Feb 2012 01:39:04 +0800 | ||
459 | 16 | |||
460 | 4 | This package has been rebased on OpenBSD's implementation of netcat. The | 17 | This package has been rebased on OpenBSD's implementation of netcat. The |
461 | 5 | code has been massively cleaned up, and important functionality has been | 18 | code has been massively cleaned up, and important functionality has been |
462 | 6 | added. | 19 | added. |
463 | 7 | 20 | ||
464 | === removed file 'debian/netcat-openbsd.dirs' | |||
465 | --- debian/netcat-openbsd.dirs 2008-01-30 18:24:46 +0000 | |||
466 | +++ debian/netcat-openbsd.dirs 1970-01-01 00:00:00 +0000 | |||
467 | @@ -1,2 +0,0 @@ | |||
468 | 1 | bin | ||
469 | 2 | usr/share/man/man1 | ||
470 | 3 | 0 | ||
471 | === added file 'debian/netcat-openbsd.examples' | |||
472 | --- debian/netcat-openbsd.examples 1970-01-01 00:00:00 +0000 | |||
473 | +++ debian/netcat-openbsd.examples 2012-05-30 22:10:23 +0000 | |||
474 | @@ -0,0 +1,1 @@ | |||
475 | 1 | debian/examples/* | ||
476 | 0 | 2 | ||
477 | === added file 'debian/netcat-openbsd.install' | |||
478 | --- debian/netcat-openbsd.install 1970-01-01 00:00:00 +0000 | |||
479 | +++ debian/netcat-openbsd.install 2012-05-30 22:10:23 +0000 | |||
480 | @@ -0,0 +1,2 @@ | |||
481 | 1 | nc.openbsd bin/ | ||
482 | 2 | nc_openbsd.1 usr/share/man/man1/ | ||
483 | 0 | 3 | ||
484 | === added file 'debian/netcat-openbsd.links' | |||
485 | --- debian/netcat-openbsd.links 1970-01-01 00:00:00 +0000 | |||
486 | +++ debian/netcat-openbsd.links 2012-05-30 22:10:23 +0000 | |||
487 | @@ -0,0 +1,1 @@ | |||
488 | 1 | usr/share/man/man1/nc_openbsd.1 usr/share/man/man1/nc.openbsd.1 | ||
489 | 0 | 2 | ||
490 | === added file 'debian/patches/0001-port-to-linux-with-libsd.patch' | |||
491 | --- debian/patches/0001-port-to-linux-with-libsd.patch 1970-01-01 00:00:00 +0000 | |||
492 | +++ debian/patches/0001-port-to-linux-with-libsd.patch 2012-05-30 22:10:23 +0000 | |||
493 | @@ -0,0 +1,466 @@ | |||
494 | 1 | From: Aron Xu <aron@debian.org> | ||
495 | 2 | Date: Mon, 13 Feb 2012 15:59:31 +0800 | ||
496 | 3 | Subject: [PATCH] port to linux with libsd | ||
497 | 4 | |||
498 | 5 | --- | ||
499 | 6 | Makefile | 17 +++++++++- | ||
500 | 7 | nc.1 | 2 +- | ||
501 | 8 | netcat.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------- | ||
502 | 9 | socks.c | 46 +++++++++++++------------- | ||
503 | 10 | 4 files changed, 130 insertions(+), 40 deletions(-) | ||
504 | 11 | |||
505 | 12 | --- a/Makefile | ||
506 | 13 | +++ b/Makefile | ||
507 | 14 | @@ -1,6 +1,19 @@ | ||
508 | 15 | -# $OpenBSD: Makefile,v 1.6 2001/09/02 18:45:41 jakob Exp $ | ||
509 | 16 | +# $OpenBSD: Makefile,v 1.6 2001/09/02 18:45:41 jakob Exp $ | ||
510 | 17 | |||
511 | 18 | PROG= nc | ||
512 | 19 | SRCS= netcat.c atomicio.c socks.c | ||
513 | 20 | |||
514 | 21 | -.include <bsd.prog.mk> | ||
515 | 22 | +LIBS= `pkg-config --libs libbsd` -lresolv | ||
516 | 23 | +OBJS= $(SRCS:.c=.o) | ||
517 | 24 | +CFLAGS= -g -O2 | ||
518 | 25 | +LDFLAGS= -Wl,--no-add-needed | ||
519 | 26 | + | ||
520 | 27 | +all: nc | ||
521 | 28 | +nc: $(OBJS) | ||
522 | 29 | + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o nc | ||
523 | 30 | + | ||
524 | 31 | +$(OBJS): %.o: %.c | ||
525 | 32 | + $(CC) $(CFLAGS) -c $< -o $@ | ||
526 | 33 | + | ||
527 | 34 | +clean: | ||
528 | 35 | + rm -f $(OBJS) nc | ||
529 | 36 | --- a/nc.1 | ||
530 | 37 | +++ b/nc.1 | ||
531 | 38 | @@ -146,9 +146,6 @@ | ||
532 | 39 | Specifies the source port | ||
533 | 40 | .Nm | ||
534 | 41 | should use, subject to privilege restrictions and availability. | ||
535 | 42 | -It is an error to use this option in conjunction with the | ||
536 | 43 | -.Fl l | ||
537 | 44 | -option. | ||
538 | 45 | .It Fl r | ||
539 | 46 | Specifies that source and/or destination ports should be chosen randomly | ||
540 | 47 | instead of sequentially within a range or in the order that the system | ||
541 | 48 | @@ -170,6 +167,7 @@ | ||
542 | 49 | may be one of | ||
543 | 50 | .Ar critical , | ||
544 | 51 | .Ar inetcontrol , | ||
545 | 52 | +.Ar lowcost , | ||
546 | 53 | .Ar lowdelay , | ||
547 | 54 | .Ar netcontrol , | ||
548 | 55 | .Ar throughput , | ||
549 | 56 | --- a/netcat.c | ||
550 | 57 | +++ b/netcat.c | ||
551 | 58 | @@ -42,6 +42,46 @@ | ||
552 | 59 | #include <netinet/ip.h> | ||
553 | 60 | #include <arpa/telnet.h> | ||
554 | 61 | |||
555 | 62 | +#ifndef IPTOS_LOWDELAY | ||
556 | 63 | +# define IPTOS_LOWDELAY 0x10 | ||
557 | 64 | +# define IPTOS_THROUGHPUT 0x08 | ||
558 | 65 | +# define IPTOS_RELIABILITY 0x04 | ||
559 | 66 | +# define IPTOS_LOWCOST 0x02 | ||
560 | 67 | +# define IPTOS_MINCOST IPTOS_LOWCOST | ||
561 | 68 | +#endif /* IPTOS_LOWDELAY */ | ||
562 | 69 | + | ||
563 | 70 | +# ifndef IPTOS_DSCP_AF11 | ||
564 | 71 | +# define IPTOS_DSCP_AF11 0x28 | ||
565 | 72 | +# define IPTOS_DSCP_AF12 0x30 | ||
566 | 73 | +# define IPTOS_DSCP_AF13 0x38 | ||
567 | 74 | +# define IPTOS_DSCP_AF21 0x48 | ||
568 | 75 | +# define IPTOS_DSCP_AF22 0x50 | ||
569 | 76 | +# define IPTOS_DSCP_AF23 0x58 | ||
570 | 77 | +# define IPTOS_DSCP_AF31 0x68 | ||
571 | 78 | +# define IPTOS_DSCP_AF32 0x70 | ||
572 | 79 | +# define IPTOS_DSCP_AF33 0x78 | ||
573 | 80 | +# define IPTOS_DSCP_AF41 0x88 | ||
574 | 81 | +# define IPTOS_DSCP_AF42 0x90 | ||
575 | 82 | +# define IPTOS_DSCP_AF43 0x98 | ||
576 | 83 | +# define IPTOS_DSCP_EF 0xb8 | ||
577 | 84 | +#endif /* IPTOS_DSCP_AF11 */ | ||
578 | 85 | + | ||
579 | 86 | +#ifndef IPTOS_DSCP_CS0 | ||
580 | 87 | +# define IPTOS_DSCP_CS0 0x00 | ||
581 | 88 | +# define IPTOS_DSCP_CS1 0x20 | ||
582 | 89 | +# define IPTOS_DSCP_CS2 0x40 | ||
583 | 90 | +# define IPTOS_DSCP_CS3 0x60 | ||
584 | 91 | +# define IPTOS_DSCP_CS4 0x80 | ||
585 | 92 | +# define IPTOS_DSCP_CS5 0xa0 | ||
586 | 93 | +# define IPTOS_DSCP_CS6 0xc0 | ||
587 | 94 | +# define IPTOS_DSCP_CS7 0xe0 | ||
588 | 95 | +#endif /* IPTOS_DSCP_CS0 */ | ||
589 | 96 | + | ||
590 | 97 | +#ifndef IPTOS_DSCP_EF | ||
591 | 98 | +# define IPTOS_DSCP_EF 0xb8 | ||
592 | 99 | +#endif /* IPTOS_DSCP_EF */ | ||
593 | 100 | + | ||
594 | 101 | + | ||
595 | 102 | #include <err.h> | ||
596 | 103 | #include <errno.h> | ||
597 | 104 | #include <netdb.h> | ||
598 | 105 | @@ -53,6 +93,8 @@ | ||
599 | 106 | #include <unistd.h> | ||
600 | 107 | #include <fcntl.h> | ||
601 | 108 | #include <limits.h> | ||
602 | 109 | +#include <bsd/stdlib.h> | ||
603 | 110 | +#include <bsd/string.h> | ||
604 | 111 | #include "atomicio.h" | ||
605 | 112 | |||
606 | 113 | #ifndef SUN_LEN | ||
607 | 114 | @@ -118,7 +160,7 @@ | ||
608 | 115 | struct servent *sv; | ||
609 | 116 | socklen_t len; | ||
610 | 117 | struct sockaddr_storage cliaddr; | ||
611 | 118 | - char *proxy; | ||
612 | 119 | + char *proxy = NULL; | ||
613 | 120 | const char *errstr, *proxyhost = "", *proxyport = NULL; | ||
614 | 121 | struct addrinfo proxyhints; | ||
615 | 122 | char unix_dg_tmp_socket_buf[UNIX_DG_TMP_SOCKET_SIZE]; | ||
616 | 123 | @@ -164,7 +206,11 @@ | ||
617 | 124 | errx(1, "interval %s: %s", errstr, optarg); | ||
618 | 125 | break; | ||
619 | 126 | case 'j': | ||
620 | 127 | +# if defined(SO_JUMBO) | ||
621 | 128 | jflag = 1; | ||
622 | 129 | +# else | ||
623 | 130 | + errx(1, "no jumbo frame support available"); | ||
624 | 131 | +# endif | ||
625 | 132 | break; | ||
626 | 133 | case 'k': | ||
627 | 134 | kflag = 1; | ||
628 | 135 | @@ -194,10 +240,14 @@ | ||
629 | 136 | uflag = 1; | ||
630 | 137 | break; | ||
631 | 138 | case 'V': | ||
632 | 139 | +# if defined(RT_TABLEID_MAX) | ||
633 | 140 | rtableid = (unsigned int)strtonum(optarg, 0, | ||
634 | 141 | RT_TABLEID_MAX, &errstr); | ||
635 | 142 | if (errstr) | ||
636 | 143 | errx(1, "rtable %s: %s", errstr, optarg); | ||
637 | 144 | +# else | ||
638 | 145 | + errx(1, "no alternate routing table support available"); | ||
639 | 146 | +# endif | ||
640 | 147 | break; | ||
641 | 148 | case 'v': | ||
642 | 149 | vflag = 1; | ||
643 | 150 | @@ -232,7 +282,11 @@ | ||
644 | 151 | errstr, optarg); | ||
645 | 152 | break; | ||
646 | 153 | case 'S': | ||
647 | 154 | +# if defined(TCP_MD5SIG) | ||
648 | 155 | Sflag = 1; | ||
649 | 156 | +# else | ||
650 | 157 | + errx(1, "no TCP MD5 signature support available"); | ||
651 | 158 | +# endif | ||
652 | 159 | break; | ||
653 | 160 | case 'T': | ||
654 | 161 | errstr = NULL; | ||
655 | 162 | @@ -259,6 +313,15 @@ | ||
656 | 163 | if (argv[0] && !argv[1] && family == AF_UNIX) { | ||
657 | 164 | host = argv[0]; | ||
658 | 165 | uport = NULL; | ||
659 | 166 | + } else if (!argv[0] && lflag) { | ||
660 | 167 | + if (sflag) | ||
661 | 168 | + errx(1, "cannot use -s and -l"); | ||
662 | 169 | + if (zflag) | ||
663 | 170 | + errx(1, "cannot use -z and -l"); | ||
664 | 171 | + if (pflag) | ||
665 | 172 | + uport=pflag; | ||
666 | 173 | + } else if (!lflag && kflag) { | ||
667 | 174 | + errx(1, "cannot use -k without -l"); | ||
668 | 175 | } else if (argv[0] && !argv[1]) { | ||
669 | 176 | if (!lflag) | ||
670 | 177 | usage(1); | ||
671 | 178 | @@ -270,14 +333,7 @@ | ||
672 | 179 | } else | ||
673 | 180 | usage(1); | ||
674 | 181 | |||
675 | 182 | - if (lflag && sflag) | ||
676 | 183 | - errx(1, "cannot use -s and -l"); | ||
677 | 184 | - if (lflag && pflag) | ||
678 | 185 | - errx(1, "cannot use -p and -l"); | ||
679 | 186 | - if (lflag && zflag) | ||
680 | 187 | - errx(1, "cannot use -z and -l"); | ||
681 | 188 | - if (!lflag && kflag) | ||
682 | 189 | - errx(1, "must use -l with -k"); | ||
683 | 190 | + | ||
684 | 191 | |||
685 | 192 | /* Get name of temporary socket for unix datagram client */ | ||
686 | 193 | if ((family == AF_UNIX) && uflag && !lflag) { | ||
687 | 194 | @@ -286,8 +342,8 @@ | ||
688 | 195 | } else { | ||
689 | 196 | strlcpy(unix_dg_tmp_socket_buf, "/tmp/nc.XXXXXXXXXX", | ||
690 | 197 | UNIX_DG_TMP_SOCKET_SIZE); | ||
691 | 198 | - if (mktemp(unix_dg_tmp_socket_buf) == NULL) | ||
692 | 199 | - err(1, "mktemp"); | ||
693 | 200 | + if (mkstemp(unix_dg_tmp_socket_buf) == -1) | ||
694 | 201 | + err(1, "mkstemp"); | ||
695 | 202 | unix_dg_tmp_socket = unix_dg_tmp_socket_buf; | ||
696 | 203 | } | ||
697 | 204 | } | ||
698 | 205 | @@ -563,18 +619,22 @@ | ||
699 | 206 | res0->ai_protocol)) < 0) | ||
700 | 207 | continue; | ||
701 | 208 | |||
702 | 209 | +# if defined(RT_TABLEID_MAX) | ||
703 | 210 | if (rtableid) { | ||
704 | 211 | if (setsockopt(s, SOL_SOCKET, SO_RTABLE, &rtableid, | ||
705 | 212 | sizeof(rtableid)) == -1) | ||
706 | 213 | err(1, "setsockopt SO_RTABLE"); | ||
707 | 214 | } | ||
708 | 215 | +# endif | ||
709 | 216 | |||
710 | 217 | /* Bind to a local port or source address if specified. */ | ||
711 | 218 | if (sflag || pflag) { | ||
712 | 219 | struct addrinfo ahints, *ares; | ||
713 | 220 | |||
714 | 221 | +# if defined (SO_BINDANY) | ||
715 | 222 | /* try SO_BINDANY, but don't insist */ | ||
716 | 223 | setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on)); | ||
717 | 224 | +# endif | ||
718 | 225 | memset(&ahints, 0, sizeof(struct addrinfo)); | ||
719 | 226 | ahints.ai_family = res0->ai_family; | ||
720 | 227 | ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM; | ||
721 | 228 | @@ -674,15 +734,23 @@ | ||
722 | 229 | res0->ai_protocol)) < 0) | ||
723 | 230 | continue; | ||
724 | 231 | |||
725 | 232 | +# if defined(RT_TABLEID_MAX) | ||
726 | 233 | if (rtableid) { | ||
727 | 234 | if (setsockopt(s, IPPROTO_IP, SO_RTABLE, &rtableid, | ||
728 | 235 | sizeof(rtableid)) == -1) | ||
729 | 236 | err(1, "setsockopt SO_RTABLE"); | ||
730 | 237 | } | ||
731 | 238 | +# endif | ||
732 | 239 | + | ||
733 | 240 | + ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)); | ||
734 | 241 | + if (ret == -1) | ||
735 | 242 | + err(1, NULL); | ||
736 | 243 | |||
737 | 244 | +# if defined(SO_REUSEPORT) | ||
738 | 245 | ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); | ||
739 | 246 | if (ret == -1) | ||
740 | 247 | err(1, NULL); | ||
741 | 248 | +# endif | ||
742 | 249 | |||
743 | 250 | set_common_sockopts(s); | ||
744 | 251 | |||
745 | 252 | @@ -886,21 +954,25 @@ | ||
746 | 253 | { | ||
747 | 254 | int x = 1; | ||
748 | 255 | |||
749 | 256 | +# if defined(TCP_MD5SIG) | ||
750 | 257 | if (Sflag) { | ||
751 | 258 | if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG, | ||
752 | 259 | &x, sizeof(x)) == -1) | ||
753 | 260 | err(1, NULL); | ||
754 | 261 | } | ||
755 | 262 | +# endif | ||
756 | 263 | if (Dflag) { | ||
757 | 264 | if (setsockopt(s, SOL_SOCKET, SO_DEBUG, | ||
758 | 265 | &x, sizeof(x)) == -1) | ||
759 | 266 | err(1, NULL); | ||
760 | 267 | } | ||
761 | 268 | +# if defined(SO_JUMBO) | ||
762 | 269 | if (jflag) { | ||
763 | 270 | if (setsockopt(s, SOL_SOCKET, SO_JUMBO, | ||
764 | 271 | &x, sizeof(x)) == -1) | ||
765 | 272 | err(1, NULL); | ||
766 | 273 | } | ||
767 | 274 | +# endif | ||
768 | 275 | if (Tflag != -1) { | ||
769 | 276 | if (setsockopt(s, IPPROTO_IP, IP_TOS, | ||
770 | 277 | &Tflag, sizeof(Tflag)) == -1) | ||
771 | 278 | @@ -949,6 +1021,7 @@ | ||
772 | 279 | { "cs7", IPTOS_DSCP_CS7 }, | ||
773 | 280 | { "ef", IPTOS_DSCP_EF }, | ||
774 | 281 | { "inetcontrol", IPTOS_PREC_INTERNETCONTROL }, | ||
775 | 282 | + { "lowcost", IPTOS_LOWCOST }, | ||
776 | 283 | { "lowdelay", IPTOS_LOWDELAY }, | ||
777 | 284 | { "netcontrol", IPTOS_PREC_NETCONTROL }, | ||
778 | 285 | { "reliability", IPTOS_RELIABILITY }, | ||
779 | 286 | @@ -969,6 +1042,9 @@ | ||
780 | 287 | void | ||
781 | 288 | help(void) | ||
782 | 289 | { | ||
783 | 290 | +# if defined(DEBIAN_VERSION) | ||
784 | 291 | + fprintf(stderr, "OpenBSD netcat (Debian patchlevel " DEBIAN_VERSION ")\n"); | ||
785 | 292 | +# endif | ||
786 | 293 | usage(0); | ||
787 | 294 | fprintf(stderr, "\tCommand Summary:\n\ | ||
788 | 295 | \t-4 Use IPv4\n\ | ||
789 | 296 | @@ -978,6 +1054,7 @@ | ||
790 | 297 | \t-h This help text\n\ | ||
791 | 298 | \t-I length TCP receive buffer length\n\ | ||
792 | 299 | \t-i secs\t Delay interval for lines sent, ports scanned\n\ | ||
793 | 300 | + \t-j Use jumbo frame\n\ | ||
794 | 301 | \t-k Keep inbound sockets open for multiple connects\n\ | ||
795 | 302 | \t-l Listen mode, for inbound connects\n\ | ||
796 | 303 | \t-n Suppress name/port resolutions\n\ | ||
797 | 304 | @@ -998,15 +1075,15 @@ | ||
798 | 305 | \t-x addr[:port]\tSpecify proxy address and port\n\ | ||
799 | 306 | \t-z Zero-I/O mode [used for scanning]\n\ | ||
800 | 307 | Port numbers can be individual or ranges: lo-hi [inclusive]\n"); | ||
801 | 308 | - exit(1); | ||
802 | 309 | + exit(0); | ||
803 | 310 | } | ||
804 | 311 | |||
805 | 312 | void | ||
806 | 313 | usage(int ret) | ||
807 | 314 | { | ||
808 | 315 | fprintf(stderr, | ||
809 | 316 | - "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n" | ||
810 | 317 | - "\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n" | ||
811 | 318 | + "usage: nc [-46DdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n" | ||
812 | 319 | + "\t [-P proxy_username] [-p source_port] [-s source] [-T toskeyword]\n" | ||
813 | 320 | "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n" | ||
814 | 321 | "\t [-x proxy_address[:port]] [destination] [port]\n"); | ||
815 | 322 | if (ret) | ||
816 | 323 | --- a/socks.c | ||
817 | 324 | +++ b/socks.c | ||
818 | 325 | @@ -38,7 +38,7 @@ | ||
819 | 326 | #include <string.h> | ||
820 | 327 | #include <unistd.h> | ||
821 | 328 | #include <resolv.h> | ||
822 | 329 | -#include <readpassphrase.h> | ||
823 | 330 | +#include <bsd/readpassphrase.h> | ||
824 | 331 | #include "atomicio.h" | ||
825 | 332 | |||
826 | 333 | #define SOCKS_PORT "1080" | ||
827 | 334 | @@ -167,11 +167,11 @@ | ||
828 | 335 | buf[2] = SOCKS_NOAUTH; | ||
829 | 336 | cnt = atomicio(vwrite, proxyfd, buf, 3); | ||
830 | 337 | if (cnt != 3) | ||
831 | 338 | - err(1, "write failed (%zu/3)", cnt); | ||
832 | 339 | + err(1, "write failed (%zu/3)", (size_t)cnt); | ||
833 | 340 | |||
834 | 341 | cnt = atomicio(read, proxyfd, buf, 2); | ||
835 | 342 | if (cnt != 2) | ||
836 | 343 | - err(1, "read failed (%zu/3)", cnt); | ||
837 | 344 | + err(1, "read failed (%zu/3)", (size_t)cnt); | ||
838 | 345 | |||
839 | 346 | if (buf[1] == SOCKS_NOMETHOD) | ||
840 | 347 | errx(1, "authentication method negotiation failed"); | ||
841 | 348 | @@ -220,23 +220,23 @@ | ||
842 | 349 | |||
843 | 350 | cnt = atomicio(vwrite, proxyfd, buf, wlen); | ||
844 | 351 | if (cnt != wlen) | ||
845 | 352 | - err(1, "write failed (%zu/%zu)", cnt, wlen); | ||
846 | 353 | + err(1, "write failed (%zu/%zu)", (size_t)cnt, (size_t)wlen); | ||
847 | 354 | |||
848 | 355 | cnt = atomicio(read, proxyfd, buf, 4); | ||
849 | 356 | if (cnt != 4) | ||
850 | 357 | - err(1, "read failed (%zu/4)", cnt); | ||
851 | 358 | + err(1, "read failed (%zu/4)", (size_t)cnt); | ||
852 | 359 | if (buf[1] != 0) | ||
853 | 360 | errx(1, "connection failed, SOCKS error %d", buf[1]); | ||
854 | 361 | switch (buf[3]) { | ||
855 | 362 | case SOCKS_IPV4: | ||
856 | 363 | cnt = atomicio(read, proxyfd, buf + 4, 6); | ||
857 | 364 | if (cnt != 6) | ||
858 | 365 | - err(1, "read failed (%d/6)", cnt); | ||
859 | 366 | + err(1, "read failed (%lu/6)", (unsigned long)cnt); | ||
860 | 367 | break; | ||
861 | 368 | case SOCKS_IPV6: | ||
862 | 369 | cnt = atomicio(read, proxyfd, buf + 4, 18); | ||
863 | 370 | if (cnt != 18) | ||
864 | 371 | - err(1, "read failed (%d/18)", cnt); | ||
865 | 372 | + err(1, "read failed (%lu/18)", (unsigned long)cnt); | ||
866 | 373 | break; | ||
867 | 374 | default: | ||
868 | 375 | errx(1, "connection failed, unsupported address type"); | ||
869 | 376 | @@ -256,11 +256,11 @@ | ||
870 | 377 | |||
871 | 378 | cnt = atomicio(vwrite, proxyfd, buf, wlen); | ||
872 | 379 | if (cnt != wlen) | ||
873 | 380 | - err(1, "write failed (%zu/%zu)", cnt, wlen); | ||
874 | 381 | + err(1, "write failed (%zu/%zu)", (size_t)cnt, (size_t)wlen); | ||
875 | 382 | |||
876 | 383 | cnt = atomicio(read, proxyfd, buf, 8); | ||
877 | 384 | if (cnt != 8) | ||
878 | 385 | - err(1, "read failed (%zu/8)", cnt); | ||
879 | 386 | + err(1, "read failed (%zu/8)", (size_t)cnt); | ||
880 | 387 | if (buf[1] != 90) | ||
881 | 388 | errx(1, "connection failed, SOCKS error %d", buf[1]); | ||
882 | 389 | } else if (socksv == -1) { | ||
883 | 390 | @@ -272,39 +272,39 @@ | ||
884 | 391 | |||
885 | 392 | /* Try to be sane about numeric IPv6 addresses */ | ||
886 | 393 | if (strchr(host, ':') != NULL) { | ||
887 | 394 | - r = snprintf(buf, sizeof(buf), | ||
888 | 395 | + r = snprintf((char*)buf, sizeof(buf), | ||
889 | 396 | "CONNECT [%s]:%d HTTP/1.0\r\n", | ||
890 | 397 | host, ntohs(serverport)); | ||
891 | 398 | } else { | ||
892 | 399 | - r = snprintf(buf, sizeof(buf), | ||
893 | 400 | + r = snprintf((char*)buf, sizeof(buf), | ||
894 | 401 | "CONNECT %s:%d HTTP/1.0\r\n", | ||
895 | 402 | host, ntohs(serverport)); | ||
896 | 403 | } | ||
897 | 404 | if (r == -1 || (size_t)r >= sizeof(buf)) | ||
898 | 405 | errx(1, "hostname too long"); | ||
899 | 406 | - r = strlen(buf); | ||
900 | 407 | + r = strlen((char*)buf); | ||
901 | 408 | |||
902 | 409 | cnt = atomicio(vwrite, proxyfd, buf, r); | ||
903 | 410 | if (cnt != r) | ||
904 | 411 | - err(1, "write failed (%zu/%d)", cnt, r); | ||
905 | 412 | + err(1, "write failed (%zu/%d)", (size_t)cnt, (int)r); | ||
906 | 413 | |||
907 | 414 | if (authretry > 1) { | ||
908 | 415 | char resp[1024]; | ||
909 | 416 | |||
910 | 417 | proxypass = getproxypass(proxyuser, proxyhost); | ||
911 | 418 | - r = snprintf(buf, sizeof(buf), "%s:%s", | ||
912 | 419 | + r = snprintf((char*)buf, sizeof(buf), "%s:%s", | ||
913 | 420 | proxyuser, proxypass); | ||
914 | 421 | if (r == -1 || (size_t)r >= sizeof(buf) || | ||
915 | 422 | - b64_ntop(buf, strlen(buf), resp, | ||
916 | 423 | + b64_ntop(buf, strlen((char*)buf), resp, | ||
917 | 424 | sizeof(resp)) == -1) | ||
918 | 425 | errx(1, "Proxy username/password too long"); | ||
919 | 426 | - r = snprintf(buf, sizeof(buf), "Proxy-Authorization: " | ||
920 | 427 | + r = snprintf((char*)buf, sizeof((char*)buf), "Proxy-Authorization: " | ||
921 | 428 | "Basic %s\r\n", resp); | ||
922 | 429 | if (r == -1 || (size_t)r >= sizeof(buf)) | ||
923 | 430 | errx(1, "Proxy auth response too long"); | ||
924 | 431 | - r = strlen(buf); | ||
925 | 432 | + r = strlen((char*)buf); | ||
926 | 433 | if ((cnt = atomicio(vwrite, proxyfd, buf, r)) != r) | ||
927 | 434 | - err(1, "write failed (%zu/%d)", cnt, r); | ||
928 | 435 | + err(1, "write failed (%zu/%d)", (size_t)cnt, r); | ||
929 | 436 | } | ||
930 | 437 | |||
931 | 438 | /* Terminate headers */ | ||
932 | 439 | @@ -312,22 +312,22 @@ | ||
933 | 440 | err(1, "write failed (2/%d)", r); | ||
934 | 441 | |||
935 | 442 | /* Read status reply */ | ||
936 | 443 | - proxy_read_line(proxyfd, buf, sizeof(buf)); | ||
937 | 444 | + proxy_read_line(proxyfd, (char*)buf, sizeof(buf)); | ||
938 | 445 | if (proxyuser != NULL && | ||
939 | 446 | - strncmp(buf, "HTTP/1.0 407 ", 12) == 0) { | ||
940 | 447 | + strncmp((char*)buf, "HTTP/1.0 407 ", 12) == 0) { | ||
941 | 448 | if (authretry > 1) { | ||
942 | 449 | fprintf(stderr, "Proxy authentication " | ||
943 | 450 | "failed\n"); | ||
944 | 451 | } | ||
945 | 452 | close(proxyfd); | ||
946 | 453 | goto again; | ||
947 | 454 | - } else if (strncmp(buf, "HTTP/1.0 200 ", 12) != 0 && | ||
948 | 455 | - strncmp(buf, "HTTP/1.1 200 ", 12) != 0) | ||
949 | 456 | + } else if (strncmp((char*)buf, "HTTP/1.0 200 ", 12) != 0 && | ||
950 | 457 | + strncmp((char*)buf, "HTTP/1.1 200 ", 12) != 0) | ||
951 | 458 | errx(1, "Proxy error: \"%s\"", buf); | ||
952 | 459 | |||
953 | 460 | /* Headers continue until we hit an empty line */ | ||
954 | 461 | for (r = 0; r < HTTP_MAXHDRS; r++) { | ||
955 | 462 | - proxy_read_line(proxyfd, buf, sizeof(buf)); | ||
956 | 463 | + proxy_read_line(proxyfd, (char*)buf, sizeof(buf)); | ||
957 | 464 | if (*buf == '\0') | ||
958 | 465 | break; | ||
959 | 466 | } | ||
960 | 0 | 467 | ||
961 | === added file 'debian/patches/0002-connect-timeout.patch' | |||
962 | --- debian/patches/0002-connect-timeout.patch 1970-01-01 00:00:00 +0000 | |||
963 | +++ debian/patches/0002-connect-timeout.patch 2012-05-30 22:10:23 +0000 | |||
964 | @@ -0,0 +1,118 @@ | |||
965 | 1 | From: Aron Xu <aron@debian.org> | ||
966 | 2 | Date: Mon, 13 Feb 2012 14:43:56 +0800 | ||
967 | 3 | Subject: [PATCH] connect timeout | ||
968 | 4 | |||
969 | 5 | --- | ||
970 | 6 | netcat.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- | ||
971 | 7 | 1 files changed, 75 insertions(+), 2 deletions(-) | ||
972 | 8 | |||
973 | 9 | --- a/netcat.c | ||
974 | 10 | +++ b/netcat.c | ||
975 | 11 | @@ -106,6 +106,10 @@ | ||
976 | 12 | #define PORT_MAX_LEN 6 | ||
977 | 13 | #define UNIX_DG_TMP_SOCKET_SIZE 19 | ||
978 | 14 | |||
979 | 15 | +#define CONNECTION_SUCCESS 0 | ||
980 | 16 | +#define CONNECTION_FAILED 1 | ||
981 | 17 | +#define CONNECTION_TIMEOUT 2 | ||
982 | 18 | + | ||
983 | 19 | /* Command Line Options */ | ||
984 | 20 | int dflag; /* detached, no stdin */ | ||
985 | 21 | unsigned int iflag; /* Interval Flag */ | ||
986 | 22 | @@ -151,6 +155,9 @@ | ||
987 | 23 | int map_tos(char *, int *); | ||
988 | 24 | void usage(int); | ||
989 | 25 | |||
990 | 26 | +static int connect_with_timeout(int fd, const struct sockaddr *sa, | ||
991 | 27 | + socklen_t salen, int ctimeout); | ||
992 | 28 | + | ||
993 | 29 | int | ||
994 | 30 | main(int argc, char *argv[]) | ||
995 | 31 | { | ||
996 | 32 | @@ -651,11 +658,14 @@ | ||
997 | 33 | |||
998 | 34 | set_common_sockopts(s); | ||
999 | 35 | |||
1000 | 36 | - if (timeout_connect(s, res0->ai_addr, res0->ai_addrlen) == 0) | ||
1001 | 37 | + if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout))== CONNECTION_SUCCESS) | ||
1002 | 38 | break; | ||
1003 | 39 | - else if (vflag) | ||
1004 | 40 | + else if (vflag && error == CONNECTION_FAILED) | ||
1005 | 41 | warn("connect to %s port %s (%s) failed", host, port, | ||
1006 | 42 | uflag ? "udp" : "tcp"); | ||
1007 | 43 | + else if (vflag && error == CONNECTION_TIMEOUT) | ||
1008 | 44 | + warn("connect to %s port %s (%s) timed out", host, port, | ||
1009 | 45 | + uflag ? "udp" : "tcp"); | ||
1010 | 46 | |||
1011 | 47 | close(s); | ||
1012 | 48 | s = -1; | ||
1013 | 49 | @@ -703,6 +713,69 @@ | ||
1014 | 50 | return (ret); | ||
1015 | 51 | } | ||
1016 | 52 | |||
1017 | 53 | +static int connect_with_timeout(int fd, const struct sockaddr *sa, | ||
1018 | 54 | + socklen_t salen, int ctimeout) | ||
1019 | 55 | +{ | ||
1020 | 56 | + int err; | ||
1021 | 57 | + struct timeval tv, *tvp = NULL; | ||
1022 | 58 | + fd_set connect_fdset; | ||
1023 | 59 | + socklen_t len; | ||
1024 | 60 | + int orig_flags; | ||
1025 | 61 | + | ||
1026 | 62 | + orig_flags = fcntl(fd, F_GETFL, 0); | ||
1027 | 63 | + if (fcntl(fd, F_SETFL, orig_flags | O_NONBLOCK) < 0 ) { | ||
1028 | 64 | + warn("can't set O_NONBLOCK - timeout not available"); | ||
1029 | 65 | + if (connect(fd, sa, salen) == 0) | ||
1030 | 66 | + return CONNECTION_SUCCESS; | ||
1031 | 67 | + else | ||
1032 | 68 | + return CONNECTION_FAILED; | ||
1033 | 69 | + } | ||
1034 | 70 | + | ||
1035 | 71 | + /* set connect timeout */ | ||
1036 | 72 | + if (ctimeout > 0) { | ||
1037 | 73 | + tv.tv_sec = (time_t)ctimeout/1000; | ||
1038 | 74 | + tv.tv_usec = 0; | ||
1039 | 75 | + tvp = &tv; | ||
1040 | 76 | + } | ||
1041 | 77 | + | ||
1042 | 78 | + /* attempt the connection */ | ||
1043 | 79 | + err = connect(fd, sa, salen); | ||
1044 | 80 | + if (err != 0 && errno == EINPROGRESS) { | ||
1045 | 81 | + /* connection is proceeding | ||
1046 | 82 | + * it is complete (or failed) when select returns */ | ||
1047 | 83 | + | ||
1048 | 84 | + /* initialize connect_fdset */ | ||
1049 | 85 | + FD_ZERO(&connect_fdset); | ||
1050 | 86 | + FD_SET(fd, &connect_fdset); | ||
1051 | 87 | + | ||
1052 | 88 | + /* call select */ | ||
1053 | 89 | + do { | ||
1054 | 90 | + err = select(fd + 1, NULL, &connect_fdset, | ||
1055 | 91 | + NULL, tvp); | ||
1056 | 92 | + } while (err < 0 && errno == EINTR); | ||
1057 | 93 | + | ||
1058 | 94 | + /* select error */ | ||
1059 | 95 | + if (err < 0) | ||
1060 | 96 | + errx(1,"select error: %s", strerror(errno)); | ||
1061 | 97 | + /* we have reached a timeout */ | ||
1062 | 98 | + if (err == 0) | ||
1063 | 99 | + return CONNECTION_TIMEOUT; | ||
1064 | 100 | + /* select returned successfully, but we must test socket | ||
1065 | 101 | + * error for result */ | ||
1066 | 102 | + len = sizeof(err); | ||
1067 | 103 | + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len) < 0) | ||
1068 | 104 | + errx(1, "getsockopt error: %s", strerror(errno)); | ||
1069 | 105 | + /* setup errno according to the result returned by | ||
1070 | 106 | + * getsockopt */ | ||
1071 | 107 | + if (err != 0) | ||
1072 | 108 | + errno = err; | ||
1073 | 109 | + } | ||
1074 | 110 | + | ||
1075 | 111 | + /* return aborted if an error occured, and valid otherwise */ | ||
1076 | 112 | + fcntl(fd, F_SETFL, orig_flags); | ||
1077 | 113 | + return (err != 0)? CONNECTION_FAILED : CONNECTION_SUCCESS; | ||
1078 | 114 | +} | ||
1079 | 115 | + | ||
1080 | 116 | /* | ||
1081 | 117 | * local_listen() | ||
1082 | 118 | * Returns a socket listening on a local port, binds to specified source | ||
1083 | 0 | 119 | ||
1084 | === added file 'debian/patches/0003-get-sev-by-name.patch' | |||
1085 | --- debian/patches/0003-get-sev-by-name.patch 1970-01-01 00:00:00 +0000 | |||
1086 | +++ debian/patches/0003-get-sev-by-name.patch 2012-05-30 22:10:23 +0000 | |||
1087 | @@ -0,0 +1,34 @@ | |||
1088 | 1 | From: Aron Xu <aron@debian.org> | ||
1089 | 2 | Date: Mon, 13 Feb 2012 14:45:08 +0800 | ||
1090 | 3 | Subject: [PATCH] get sev by name | ||
1091 | 4 | |||
1092 | 5 | --- | ||
1093 | 6 | netcat.c | 9 ++++++++- | ||
1094 | 7 | 1 files changed, 8 insertions(+), 1 deletions(-) | ||
1095 | 8 | |||
1096 | 9 | diff --git a/netcat.c b/netcat.c | ||
1097 | 10 | index 51a5729..28e871e 100644 | ||
1098 | 11 | --- a/netcat.c | ||
1099 | 12 | +++ b/netcat.c | ||
1100 | 13 | @@ -949,12 +949,19 @@ atelnet(int nfd, unsigned char *buf, unsigned int size) | ||
1101 | 14 | void | ||
1102 | 15 | build_ports(char *p) | ||
1103 | 16 | { | ||
1104 | 17 | + struct servent *sv; | ||
1105 | 18 | const char *errstr; | ||
1106 | 19 | char *n; | ||
1107 | 20 | int hi, lo, cp; | ||
1108 | 21 | int x = 0; | ||
1109 | 22 | |||
1110 | 23 | - if ((n = strchr(p, '-')) != NULL) { | ||
1111 | 24 | + sv = getservbyname(p, uflag ? "udp" : "tcp"); | ||
1112 | 25 | + if (sv) { | ||
1113 | 26 | + portlist[0] = calloc(1, PORT_MAX_LEN); | ||
1114 | 27 | + if (portlist[0] == NULL) | ||
1115 | 28 | + err(1, NULL); | ||
1116 | 29 | + snprintf(portlist[0], PORT_MAX_LEN, "%d", ntohs(sv->s_port)); | ||
1117 | 30 | + } else if ((n = strchr(p, '-')) != NULL) { | ||
1118 | 31 | *n = '\0'; | ||
1119 | 32 | n++; | ||
1120 | 33 | |||
1121 | 34 | -- | ||
1122 | 0 | 35 | ||
1123 | === added file 'debian/patches/0004-poll-hup.patch' | |||
1124 | --- debian/patches/0004-poll-hup.patch 1970-01-01 00:00:00 +0000 | |||
1125 | +++ debian/patches/0004-poll-hup.patch 2012-05-30 22:10:23 +0000 | |||
1126 | @@ -0,0 +1,59 @@ | |||
1127 | 1 | From: Aron Xu <aron@debian.org> | ||
1128 | 2 | Date: Mon, 13 Feb 2012 15:08:33 +0800 | ||
1129 | 3 | Subject: [PATCH] poll hup | ||
1130 | 4 | |||
1131 | 5 | --- | ||
1132 | 6 | netcat.c | 24 +++++++++++++++++------- | ||
1133 | 7 | 1 files changed, 17 insertions(+), 7 deletions(-) | ||
1134 | 8 | |||
1135 | 9 | diff --git a/netcat.c b/netcat.c | ||
1136 | 10 | index 28e871e..b36583f 100644 | ||
1137 | 11 | --- a/netcat.c | ||
1138 | 12 | +++ b/netcat.c | ||
1139 | 13 | @@ -884,9 +884,7 @@ readwrite(int nfd) | ||
1140 | 14 | if ((n = read(nfd, buf, plen)) < 0) | ||
1141 | 15 | return; | ||
1142 | 16 | else if (n == 0) { | ||
1143 | 17 | - shutdown(nfd, SHUT_RD); | ||
1144 | 18 | - pfd[0].fd = -1; | ||
1145 | 19 | - pfd[0].events = 0; | ||
1146 | 20 | + goto shutdown_rd; | ||
1147 | 21 | } else { | ||
1148 | 22 | if (tflag) | ||
1149 | 23 | atelnet(nfd, buf, n); | ||
1150 | 24 | @@ -894,18 +892,30 @@ readwrite(int nfd) | ||
1151 | 25 | return; | ||
1152 | 26 | } | ||
1153 | 27 | } | ||
1154 | 28 | + else if (pfd[0].revents & POLLHUP) { | ||
1155 | 29 | + shutdown_rd: | ||
1156 | 30 | + shutdown(nfd, SHUT_RD); | ||
1157 | 31 | + pfd[0].fd = -1; | ||
1158 | 32 | + pfd[0].events = 0; | ||
1159 | 33 | + } | ||
1160 | 34 | |||
1161 | 35 | - if (!dflag && pfd[1].revents & POLLIN) { | ||
1162 | 36 | + if (!dflag) { | ||
1163 | 37 | + if(pfd[1].revents & POLLIN) { | ||
1164 | 38 | if ((n = read(wfd, buf, plen)) < 0) | ||
1165 | 39 | return; | ||
1166 | 40 | else if (n == 0) { | ||
1167 | 41 | - shutdown(nfd, SHUT_WR); | ||
1168 | 42 | - pfd[1].fd = -1; | ||
1169 | 43 | - pfd[1].events = 0; | ||
1170 | 44 | + goto shutdown_wr; | ||
1171 | 45 | } else { | ||
1172 | 46 | if (atomicio(vwrite, nfd, buf, n) != n) | ||
1173 | 47 | return; | ||
1174 | 48 | } | ||
1175 | 49 | + } | ||
1176 | 50 | + else if (pfd[1].revents & POLLHUP) { | ||
1177 | 51 | + shutdown_wr: | ||
1178 | 52 | + shutdown(nfd, SHUT_WR); | ||
1179 | 53 | + pfd[1].fd = -1; | ||
1180 | 54 | + pfd[1].events = 0; | ||
1181 | 55 | + } | ||
1182 | 56 | } | ||
1183 | 57 | } | ||
1184 | 58 | } | ||
1185 | 59 | -- | ||
1186 | 0 | 60 | ||
1187 | === added file 'debian/patches/0005-send-crlf.patch' | |||
1188 | --- debian/patches/0005-send-crlf.patch 1970-01-01 00:00:00 +0000 | |||
1189 | +++ debian/patches/0005-send-crlf.patch 2012-05-30 22:10:23 +0000 | |||
1190 | @@ -0,0 +1,103 @@ | |||
1191 | 1 | From: Aron Xu <aron@debian.org> | ||
1192 | 2 | Date: Mon, 13 Feb 2012 14:57:45 +0800 | ||
1193 | 3 | Subject: [PATCH] send crlf | ||
1194 | 4 | |||
1195 | 5 | --- | ||
1196 | 6 | nc.1 | 6 ++++-- | ||
1197 | 7 | netcat.c | 21 +++++++++++++++++---- | ||
1198 | 8 | 2 files changed, 21 insertions(+), 6 deletions(-) | ||
1199 | 9 | |||
1200 | 10 | --- a/nc.1 | ||
1201 | 11 | +++ b/nc.1 | ||
1202 | 12 | @@ -34,7 +34,7 @@ | ||
1203 | 13 | .Sh SYNOPSIS | ||
1204 | 14 | .Nm nc | ||
1205 | 15 | .Bk -words | ||
1206 | 16 | -.Op Fl 46DdhklnrStUuvz | ||
1207 | 17 | +.Op Fl 46CDdhklnrStUuvz | ||
1208 | 18 | .Op Fl I Ar length | ||
1209 | 19 | .Op Fl i Ar interval | ||
1210 | 20 | .Op Fl O Ar length | ||
1211 | 21 | @@ -98,6 +98,8 @@ | ||
1212 | 22 | Forces | ||
1213 | 23 | .Nm | ||
1214 | 24 | to use IPv6 addresses only. | ||
1215 | 25 | +.It Fl C | ||
1216 | 26 | +Send CRLF as line-ending. | ||
1217 | 27 | .It Fl D | ||
1218 | 28 | Enable debugging on the socket. | ||
1219 | 29 | .It Fl d | ||
1220 | 30 | @@ -355,7 +357,7 @@ | ||
1221 | 31 | of requests required by the server. | ||
1222 | 32 | As another example, an email may be submitted to an SMTP server using: | ||
1223 | 33 | .Bd -literal -offset indent | ||
1224 | 34 | -$ nc localhost 25 \*(Lt\*(Lt EOF | ||
1225 | 35 | +$ nc [\-C] localhost 25 \*(Lt\*(Lt EOF | ||
1226 | 36 | HELO host.example.com | ||
1227 | 37 | MAIL FROM:\*(Ltuser@host.example.com\*(Gt | ||
1228 | 38 | RCPT TO:\*(Ltuser2@host.example.com\*(Gt | ||
1229 | 39 | --- a/netcat.c | ||
1230 | 40 | +++ b/netcat.c | ||
1231 | 41 | @@ -111,6 +111,7 @@ | ||
1232 | 42 | #define CONNECTION_TIMEOUT 2 | ||
1233 | 43 | |||
1234 | 44 | /* Command Line Options */ | ||
1235 | 45 | +int Cflag = 0; /* CRLF line-ending */ | ||
1236 | 46 | int dflag; /* detached, no stdin */ | ||
1237 | 47 | unsigned int iflag; /* Interval Flag */ | ||
1238 | 48 | int jflag; /* use jumbo frames if we can */ | ||
1239 | 49 | @@ -180,7 +181,7 @@ | ||
1240 | 50 | sv = NULL; | ||
1241 | 51 | |||
1242 | 52 | while ((ch = getopt(argc, argv, | ||
1243 | 53 | - "46DdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) { | ||
1244 | 54 | + "46CDdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) { | ||
1245 | 55 | switch (ch) { | ||
1246 | 56 | case '4': | ||
1247 | 57 | family = AF_INET; | ||
1248 | 58 | @@ -309,6 +310,9 @@ | ||
1249 | 59 | if (Tflag < 0 || Tflag > 255 || errstr || errno) | ||
1250 | 60 | errx(1, "illegal tos value %s", optarg); | ||
1251 | 61 | break; | ||
1252 | 62 | + case 'C': | ||
1253 | 63 | + Cflag = 1; | ||
1254 | 64 | + break; | ||
1255 | 65 | default: | ||
1256 | 66 | usage(1); | ||
1257 | 67 | } | ||
1258 | 68 | @@ -906,8 +910,16 @@ | ||
1259 | 69 | else if (n == 0) { | ||
1260 | 70 | goto shutdown_wr; | ||
1261 | 71 | } else { | ||
1262 | 72 | - if (atomicio(vwrite, nfd, buf, n) != n) | ||
1263 | 73 | - return; | ||
1264 | 74 | + if ((Cflag) && (buf[n-1]=='\n')) { | ||
1265 | 75 | + if (atomicio(vwrite, nfd, buf, n-1) != (n-1)) | ||
1266 | 76 | + return; | ||
1267 | 77 | + if (atomicio(vwrite, nfd, "\r\n", 2) != 2) | ||
1268 | 78 | + return; | ||
1269 | 79 | + } | ||
1270 | 80 | + else { | ||
1271 | 81 | + if (atomicio(vwrite, nfd, buf, n) != n) | ||
1272 | 82 | + return; | ||
1273 | 83 | + } | ||
1274 | 84 | } | ||
1275 | 85 | } | ||
1276 | 86 | else if (pfd[1].revents & POLLHUP) { | ||
1277 | 87 | @@ -1139,6 +1151,7 @@ | ||
1278 | 88 | fprintf(stderr, "\tCommand Summary:\n\ | ||
1279 | 89 | \t-4 Use IPv4\n\ | ||
1280 | 90 | \t-6 Use IPv6\n\ | ||
1281 | 91 | + \t-C Send CRLF as line-ending\n\ | ||
1282 | 92 | \t-D Enable the debug socket option\n\ | ||
1283 | 93 | \t-d Detach from stdin\n\ | ||
1284 | 94 | \t-h This help text\n\ | ||
1285 | 95 | @@ -1172,7 +1185,7 @@ | ||
1286 | 96 | usage(int ret) | ||
1287 | 97 | { | ||
1288 | 98 | fprintf(stderr, | ||
1289 | 99 | - "usage: nc [-46DdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n" | ||
1290 | 100 | + "usage: nc [-46CDdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n" | ||
1291 | 101 | "\t [-P proxy_username] [-p source_port] [-s source] [-T toskeyword]\n" | ||
1292 | 102 | "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n" | ||
1293 | 103 | "\t [-x proxy_address[:port]] [destination] [port]\n"); | ||
1294 | 0 | 104 | ||
1295 | === added file 'debian/patches/0006-quit-timer.patch' | |||
1296 | --- debian/patches/0006-quit-timer.patch 1970-01-01 00:00:00 +0000 | |||
1297 | +++ debian/patches/0006-quit-timer.patch 2012-05-30 22:10:23 +0000 | |||
1298 | @@ -0,0 +1,128 @@ | |||
1299 | 1 | From: Aron Xu <aron@debian.org> | ||
1300 | 2 | Date: Mon, 13 Feb 2012 15:16:04 +0800 | ||
1301 | 3 | Subject: [PATCH] quit timer | ||
1302 | 4 | |||
1303 | 5 | --- | ||
1304 | 6 | nc.1 | 5 +++++ | ||
1305 | 7 | netcat.c | 39 ++++++++++++++++++++++++++++++++++----- | ||
1306 | 8 | 2 files changed, 39 insertions(+), 5 deletions(-) | ||
1307 | 9 | |||
1308 | 10 | --- a/nc.1 | ||
1309 | 11 | +++ b/nc.1 | ||
1310 | 12 | @@ -40,6 +40,7 @@ | ||
1311 | 13 | .Op Fl O Ar length | ||
1312 | 14 | .Op Fl P Ar proxy_username | ||
1313 | 15 | .Op Fl p Ar source_port | ||
1314 | 16 | +.Op Fl q Ar seconds | ||
1315 | 17 | .Op Fl s Ar source | ||
1316 | 18 | .Op Fl T Ar toskeyword | ||
1317 | 19 | .Op Fl V Ar rtable | ||
1318 | 20 | @@ -148,6 +149,10 @@ | ||
1319 | 21 | Specifies the source port | ||
1320 | 22 | .Nm | ||
1321 | 23 | should use, subject to privilege restrictions and availability. | ||
1322 | 24 | +.It Fl q Ar seconds | ||
1323 | 25 | +after EOF on stdin, wait the specified number of seconds and then quit. If | ||
1324 | 26 | +.Ar seconds | ||
1325 | 27 | +is negative, wait forever. | ||
1326 | 28 | .It Fl r | ||
1327 | 29 | Specifies that source and/or destination ports should be chosen randomly | ||
1328 | 30 | instead of sequentially within a range or in the order that the system | ||
1329 | 31 | --- a/netcat.c | ||
1330 | 32 | +++ b/netcat.c | ||
1331 | 33 | @@ -86,6 +86,7 @@ | ||
1332 | 34 | #include <errno.h> | ||
1333 | 35 | #include <netdb.h> | ||
1334 | 36 | #include <poll.h> | ||
1335 | 37 | +#include <signal.h> | ||
1336 | 38 | #include <stdarg.h> | ||
1337 | 39 | #include <stdio.h> | ||
1338 | 40 | #include <stdlib.h> | ||
1339 | 41 | @@ -120,6 +121,7 @@ | ||
1340 | 42 | int nflag; /* Don't do name look up */ | ||
1341 | 43 | char *Pflag; /* Proxy username */ | ||
1342 | 44 | char *pflag; /* Localport flag */ | ||
1343 | 45 | +int qflag = 0; /* Quit after some secs */ | ||
1344 | 46 | int rflag; /* Random ports flag */ | ||
1345 | 47 | char *sflag; /* Source Address */ | ||
1346 | 48 | int tflag; /* Telnet Emulation */ | ||
1347 | 49 | @@ -158,6 +160,7 @@ | ||
1348 | 50 | |||
1349 | 51 | static int connect_with_timeout(int fd, const struct sockaddr *sa, | ||
1350 | 52 | socklen_t salen, int ctimeout); | ||
1351 | 53 | +static void quit(); | ||
1352 | 54 | |||
1353 | 55 | int | ||
1354 | 56 | main(int argc, char *argv[]) | ||
1355 | 57 | @@ -181,7 +184,7 @@ | ||
1356 | 58 | sv = NULL; | ||
1357 | 59 | |||
1358 | 60 | while ((ch = getopt(argc, argv, | ||
1359 | 61 | - "46CDdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) { | ||
1360 | 62 | + "46CDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:z")) != -1) { | ||
1361 | 63 | switch (ch) { | ||
1362 | 64 | case '4': | ||
1363 | 65 | family = AF_INET; | ||
1364 | 66 | @@ -235,6 +238,11 @@ | ||
1365 | 67 | case 'p': | ||
1366 | 68 | pflag = optarg; | ||
1367 | 69 | break; | ||
1368 | 70 | + case 'q': | ||
1369 | 71 | + qflag = strtonum(optarg, INT_MIN, INT_MAX, &errstr); | ||
1370 | 72 | + if (errstr) | ||
1371 | 73 | + errx(1, "quit timer %s: %s", errstr, optarg); | ||
1372 | 74 | + break; | ||
1373 | 75 | case 'r': | ||
1374 | 76 | rflag = 1; | ||
1375 | 77 | break; | ||
1376 | 78 | @@ -924,9 +932,18 @@ | ||
1377 | 79 | } | ||
1378 | 80 | else if (pfd[1].revents & POLLHUP) { | ||
1379 | 81 | shutdown_wr: | ||
1380 | 82 | + /* if the user asked to exit on EOF, do it */ | ||
1381 | 83 | + if (qflag == 0) { | ||
1382 | 84 | shutdown(nfd, SHUT_WR); | ||
1383 | 85 | - pfd[1].fd = -1; | ||
1384 | 86 | - pfd[1].events = 0; | ||
1385 | 87 | + close(wfd); | ||
1386 | 88 | + } | ||
1387 | 89 | + /* if user asked to die after a while, arrange for it */ | ||
1388 | 90 | + if (qflag > 0) { | ||
1389 | 91 | + signal(SIGALRM, quit); | ||
1390 | 92 | + alarm(qflag); | ||
1391 | 93 | + } | ||
1392 | 94 | + pfd[1].fd = -1; | ||
1393 | 95 | + pfd[1].events = 0; | ||
1394 | 96 | } | ||
1395 | 97 | } | ||
1396 | 98 | } | ||
1397 | 99 | @@ -1164,6 +1181,7 @@ | ||
1398 | 100 | \t-O length TCP send buffer length\n\ | ||
1399 | 101 | \t-P proxyuser\tUsername for proxy authentication\n\ | ||
1400 | 102 | \t-p port\t Specify local port for remote connects\n\ | ||
1401 | 103 | + \t-q secs\t quit after EOF on stdin and delay of secs\n\ | ||
1402 | 104 | \t-r Randomize remote ports\n\ | ||
1403 | 105 | \t-S Enable the TCP MD5 signature option\n\ | ||
1404 | 106 | \t-s addr\t Local source address\n\ | ||
1405 | 107 | @@ -1186,9 +1204,19 @@ | ||
1406 | 108 | { | ||
1407 | 109 | fprintf(stderr, | ||
1408 | 110 | "usage: nc [-46CDdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n" | ||
1409 | 111 | - "\t [-P proxy_username] [-p source_port] [-s source] [-T toskeyword]\n" | ||
1410 | 112 | - "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n" | ||
1411 | 113 | + "\t [-P proxy_username] [-p source_port] [-q seconds] [-s source]\n" | ||
1412 | 114 | + "\t [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]\n" | ||
1413 | 115 | "\t [-x proxy_address[:port]] [destination] [port]\n"); | ||
1414 | 116 | if (ret) | ||
1415 | 117 | exit(1); | ||
1416 | 118 | } | ||
1417 | 119 | + | ||
1418 | 120 | +/* | ||
1419 | 121 | + * quit() | ||
1420 | 122 | + * handler for a "-q" timeout (exit 0 instead of 1) | ||
1421 | 123 | + */ | ||
1422 | 124 | +static void quit() | ||
1423 | 125 | +{ | ||
1424 | 126 | + /* XXX: should explicitly close fds here */ | ||
1425 | 127 | + exit(0); | ||
1426 | 128 | +} | ||
1427 | 0 | 129 | ||
1428 | === added file 'debian/patches/0007-udp-scan-timeout.patch' | |||
1429 | --- debian/patches/0007-udp-scan-timeout.patch 1970-01-01 00:00:00 +0000 | |||
1430 | +++ debian/patches/0007-udp-scan-timeout.patch 2012-05-30 22:10:23 +0000 | |||
1431 | @@ -0,0 +1,56 @@ | |||
1432 | 1 | From: Aron Xu <aron@debian.org> | ||
1433 | 2 | Date: Mon, 13 Feb 2012 15:29:37 +0800 | ||
1434 | 3 | Subject: [PATCH] udp scan timeout | ||
1435 | 4 | |||
1436 | 5 | --- | ||
1437 | 6 | netcat.c | 25 ++++++++++++++++--------- | ||
1438 | 7 | 1 files changed, 16 insertions(+), 9 deletions(-) | ||
1439 | 8 | |||
1440 | 9 | --- a/netcat.c | ||
1441 | 10 | +++ b/netcat.c | ||
1442 | 11 | @@ -111,6 +111,8 @@ | ||
1443 | 12 | #define CONNECTION_FAILED 1 | ||
1444 | 13 | #define CONNECTION_TIMEOUT 2 | ||
1445 | 14 | |||
1446 | 15 | +#define UDP_SCAN_TIMEOUT 3 /* Seconds */ | ||
1447 | 16 | + | ||
1448 | 17 | /* Command Line Options */ | ||
1449 | 18 | int Cflag = 0; /* CRLF line-ending */ | ||
1450 | 19 | int dflag; /* detached, no stdin */ | ||
1451 | 20 | @@ -497,7 +499,7 @@ | ||
1452 | 21 | continue; | ||
1453 | 22 | |||
1454 | 23 | ret = 0; | ||
1455 | 24 | - if (vflag || zflag) { | ||
1456 | 25 | + if (vflag) { | ||
1457 | 26 | /* For UDP, make sure we are connected. */ | ||
1458 | 27 | if (uflag) { | ||
1459 | 28 | if (udptest(s) == -1) { | ||
1460 | 29 | @@ -1057,15 +1059,20 @@ | ||
1461 | 30 | int | ||
1462 | 31 | udptest(int s) | ||
1463 | 32 | { | ||
1464 | 33 | - int i, ret; | ||
1465 | 34 | + int i, t; | ||
1466 | 35 | |||
1467 | 36 | - for (i = 0; i <= 3; i++) { | ||
1468 | 37 | - if (write(s, "X", 1) == 1) | ||
1469 | 38 | - ret = 1; | ||
1470 | 39 | - else | ||
1471 | 40 | - ret = -1; | ||
1472 | 41 | + if ((write(s, "X", 1) != 1) || | ||
1473 | 42 | + ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED))) | ||
1474 | 43 | + return -1; | ||
1475 | 44 | + | ||
1476 | 45 | + /* Give the remote host some time to reply. */ | ||
1477 | 46 | + for (i = 0, t = (timeout == -1) ? UDP_SCAN_TIMEOUT : (timeout / 1000); | ||
1478 | 47 | + i < t; i++) { | ||
1479 | 48 | + sleep(1); | ||
1480 | 49 | + if ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED)) | ||
1481 | 50 | + return -1; | ||
1482 | 51 | } | ||
1483 | 52 | - return (ret); | ||
1484 | 53 | + return 1; | ||
1485 | 54 | } | ||
1486 | 55 | |||
1487 | 56 | void | ||
1488 | 0 | 57 | ||
1489 | === added file 'debian/patches/0008-verbose-numeric-port.patch' | |||
1490 | --- debian/patches/0008-verbose-numeric-port.patch 1970-01-01 00:00:00 +0000 | |||
1491 | +++ debian/patches/0008-verbose-numeric-port.patch 2012-05-30 22:10:23 +0000 | |||
1492 | @@ -0,0 +1,103 @@ | |||
1493 | 1 | From: Aron Xu <aron@debian.org> | ||
1494 | 2 | Date: Mon, 13 Feb 2012 15:38:15 +0800 | ||
1495 | 3 | Subject: [PATCH] verbose numeric port | ||
1496 | 4 | |||
1497 | 5 | --- | ||
1498 | 6 | netcat.c | 44 ++++++++++++++++++++++++++++++++++++++++---- | ||
1499 | 7 | 1 files changed, 40 insertions(+), 4 deletions(-) | ||
1500 | 8 | |||
1501 | 9 | --- a/netcat.c | ||
1502 | 10 | +++ b/netcat.c | ||
1503 | 11 | @@ -41,6 +41,7 @@ | ||
1504 | 12 | #include <netinet/tcp.h> | ||
1505 | 13 | #include <netinet/ip.h> | ||
1506 | 14 | #include <arpa/telnet.h> | ||
1507 | 15 | +#include <arpa/inet.h> | ||
1508 | 16 | |||
1509 | 17 | #ifndef IPTOS_LOWDELAY | ||
1510 | 18 | # define IPTOS_LOWDELAY 0x10 | ||
1511 | 19 | @@ -424,6 +425,18 @@ | ||
1512 | 20 | s = local_listen(host, uport, hints); | ||
1513 | 21 | if (s < 0) | ||
1514 | 22 | err(1, NULL); | ||
1515 | 23 | + | ||
1516 | 24 | + char* local; | ||
1517 | 25 | + if (family == AF_INET6 | ||
1518 | 26 | + local = "0.0.0.0"; | ||
1519 | 27 | + else if (family == AF_INET) | ||
1520 | 28 | + local = ":::"; | ||
1521 | 29 | + else | ||
1522 | 30 | + local = "unknown" | ||
1523 | 31 | + fprintf(stderr, "Listening on [%s] (family %d, port %d)\n", | ||
1524 | 32 | + host ?: local, | ||
1525 | 33 | + family, | ||
1526 | 34 | + *uport); | ||
1527 | 35 | /* | ||
1528 | 36 | * For UDP, we will use recvfrom() initially | ||
1529 | 37 | * to wait for a caller, then use the regular | ||
1530 | 38 | @@ -432,16 +445,15 @@ | ||
1531 | 39 | if (uflag) { | ||
1532 | 40 | int rv, plen; | ||
1533 | 41 | char buf[16384]; | ||
1534 | 42 | - struct sockaddr_storage z; | ||
1535 | 43 | |||
1536 | 44 | - len = sizeof(z); | ||
1537 | 45 | + len = sizeof(cliaddr); | ||
1538 | 46 | plen = jflag ? 16384 : 2048; | ||
1539 | 47 | rv = recvfrom(s, buf, plen, MSG_PEEK, | ||
1540 | 48 | - (struct sockaddr *)&z, &len); | ||
1541 | 49 | + (struct sockaddr *)&cliaddr, &len); | ||
1542 | 50 | if (rv < 0) | ||
1543 | 51 | err(1, "recvfrom"); | ||
1544 | 52 | |||
1545 | 53 | - rv = connect(s, (struct sockaddr *)&z, len); | ||
1546 | 54 | + rv = connect(s, (struct sockaddr *)&cliaddr, len); | ||
1547 | 55 | if (rv < 0) | ||
1548 | 56 | err(1, "connect"); | ||
1549 | 57 | |||
1550 | 58 | @@ -450,6 +462,45 @@ | ||
1551 | 59 | len = sizeof(cliaddr); | ||
1552 | 60 | connfd = accept(s, (struct sockaddr *)&cliaddr, | ||
1553 | 61 | &len); | ||
1554 | 62 | + if(vflag) { | ||
1555 | 63 | + /* Don't look up port if -n. */ | ||
1556 | 64 | + if (nflag) | ||
1557 | 65 | + sv = NULL; | ||
1558 | 66 | + else | ||
1559 | 67 | + sv = getservbyport(ntohs(atoi(uport)), | ||
1560 | 68 | + uflag ? "udp" : "tcp"); | ||
1561 | 69 | + | ||
1562 | 70 | + if (((struct sockaddr *)&cliaddr)->sa_family == AF_INET) { | ||
1563 | 71 | + char dst[INET_ADDRSTRLEN]; | ||
1564 | 72 | + inet_ntop(((struct sockaddr *)&cliaddr)->sa_family,&(((struct sockaddr_in *)&cliaddr)->sin_addr),dst,INET_ADDRSTRLEN); | ||
1565 | 73 | + fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n", | ||
1566 | 74 | + dst, | ||
1567 | 75 | + uport, | ||
1568 | 76 | + uflag ? "udp" : "tcp", | ||
1569 | 77 | + sv ? sv->s_name : "*", | ||
1570 | 78 | + ((struct sockaddr *)(&cliaddr))->sa_family, | ||
1571 | 79 | + ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); | ||
1572 | 80 | + } | ||
1573 | 81 | + else if(((struct sockaddr *)&cliaddr)->sa_family == AF_INET6) { | ||
1574 | 82 | + char dst[INET6_ADDRSTRLEN]; | ||
1575 | 83 | + inet_ntop(((struct sockaddr *)&cliaddr)->sa_family,&(((struct sockaddr_in6 *)&cliaddr)->sin6_addr),dst,INET6_ADDRSTRLEN); | ||
1576 | 84 | + fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n", | ||
1577 | 85 | + dst, | ||
1578 | 86 | + uport, | ||
1579 | 87 | + uflag ? "udp" : "tcp", | ||
1580 | 88 | + sv ? sv->s_name : "*", | ||
1581 | 89 | + ((struct sockaddr *)&cliaddr)->sa_family, | ||
1582 | 90 | + ntohs(((struct sockaddr_in6 *)&cliaddr)->sin6_port)); | ||
1583 | 91 | + } | ||
1584 | 92 | + else { | ||
1585 | 93 | + fprintf(stderr, "Connection from unknown port %s [%s/%s] accepted (family %d, sport %d)\n", | ||
1586 | 94 | + uport, | ||
1587 | 95 | + uflag ? "udp" : "tcp", | ||
1588 | 96 | + sv ? sv->s_name : "*", | ||
1589 | 97 | + ((struct sockaddr *)(&cliaddr))->sa_family, | ||
1590 | 98 | + ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); | ||
1591 | 99 | + } | ||
1592 | 100 | + } | ||
1593 | 101 | readwrite(connfd); | ||
1594 | 102 | close(connfd); | ||
1595 | 103 | } | ||
1596 | 0 | 104 | ||
1597 | === added file 'debian/patches/0009-dccp-support.patch' | |||
1598 | --- debian/patches/0009-dccp-support.patch 1970-01-01 00:00:00 +0000 | |||
1599 | +++ debian/patches/0009-dccp-support.patch 2012-05-30 22:10:23 +0000 | |||
1600 | @@ -0,0 +1,299 @@ | |||
1601 | 1 | From: Aron Xu <aron@debian.org> | ||
1602 | 2 | Date: Mon, 13 Feb 2012 15:56:51 +0800 | ||
1603 | 3 | Subject: [PATCH] dccp support | ||
1604 | 4 | |||
1605 | 5 | --- | ||
1606 | 6 | nc.1 | 4 ++- | ||
1607 | 7 | netcat.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- | ||
1608 | 8 | 2 files changed, 88 insertions(+), 18 deletions(-) | ||
1609 | 9 | |||
1610 | 10 | --- a/nc.1 | ||
1611 | 11 | +++ b/nc.1 | ||
1612 | 12 | @@ -34,7 +34,7 @@ | ||
1613 | 13 | .Sh SYNOPSIS | ||
1614 | 14 | .Nm nc | ||
1615 | 15 | .Bk -words | ||
1616 | 16 | -.Op Fl 46CDdhklnrStUuvz | ||
1617 | 17 | +.Op Fl 46CDdhklnrStUuvZz | ||
1618 | 18 | .Op Fl I Ar length | ||
1619 | 19 | .Op Fl i Ar interval | ||
1620 | 20 | .Op Fl O Ar length | ||
1621 | 21 | @@ -257,6 +257,8 @@ | ||
1622 | 22 | .Ar port | ||
1623 | 23 | is not specified, the well-known port for the proxy protocol is used (1080 | ||
1624 | 24 | for SOCKS, 3128 for HTTPS). | ||
1625 | 25 | +.It Fl Z | ||
1626 | 26 | +DCCP mode. | ||
1627 | 27 | .It Fl z | ||
1628 | 28 | Specifies that | ||
1629 | 29 | .Nm | ||
1630 | 30 | --- a/netcat.c | ||
1631 | 31 | +++ b/netcat.c | ||
1632 | 32 | @@ -129,6 +129,7 @@ | ||
1633 | 33 | char *sflag; /* Source Address */ | ||
1634 | 34 | int tflag; /* Telnet Emulation */ | ||
1635 | 35 | int uflag; /* UDP - Default to TCP */ | ||
1636 | 36 | +int dccpflag; /* DCCP - Default to TCP */ | ||
1637 | 37 | int vflag; /* Verbosity */ | ||
1638 | 38 | int xflag; /* Socks proxy */ | ||
1639 | 39 | int zflag; /* Port Scan Flag */ | ||
1640 | 40 | @@ -160,6 +161,7 @@ | ||
1641 | 41 | void set_common_sockopts(int); | ||
1642 | 42 | int map_tos(char *, int *); | ||
1643 | 43 | void usage(int); | ||
1644 | 44 | +char *proto_name(int uflag, int dccpflag); | ||
1645 | 45 | |||
1646 | 46 | static int connect_with_timeout(int fd, const struct sockaddr *sa, | ||
1647 | 47 | socklen_t salen, int ctimeout); | ||
1648 | 48 | @@ -187,7 +189,7 @@ | ||
1649 | 49 | sv = NULL; | ||
1650 | 50 | |||
1651 | 51 | while ((ch = getopt(argc, argv, | ||
1652 | 52 | - "46CDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:z")) != -1) { | ||
1653 | 53 | + "46CDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:Zz")) != -1) { | ||
1654 | 54 | switch (ch) { | ||
1655 | 55 | case '4': | ||
1656 | 56 | family = AF_INET; | ||
1657 | 57 | @@ -258,6 +260,13 @@ | ||
1658 | 58 | case 'u': | ||
1659 | 59 | uflag = 1; | ||
1660 | 60 | break; | ||
1661 | 61 | + case 'Z': | ||
1662 | 62 | +# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP) | ||
1663 | 63 | + dccpflag = 1; | ||
1664 | 64 | +# else | ||
1665 | 65 | + errx(1, "no DCCP support available"); | ||
1666 | 66 | +# endif | ||
1667 | 67 | + break; | ||
1668 | 68 | case 'V': | ||
1669 | 69 | # if defined(RT_TABLEID_MAX) | ||
1670 | 70 | rtableid = (unsigned int)strtonum(optarg, 0, | ||
1671 | 71 | @@ -333,6 +342,12 @@ | ||
1672 | 72 | |||
1673 | 73 | /* Cruft to make sure options are clean, and used properly. */ | ||
1674 | 74 | if (argv[0] && !argv[1] && family == AF_UNIX) { | ||
1675 | 75 | + if (uflag) | ||
1676 | 76 | + errx(1, "cannot use -u and -U"); | ||
1677 | 77 | +# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP) | ||
1678 | 78 | + if (dccpflag) | ||
1679 | 79 | + errx(1, "cannot use -Z and -U"); | ||
1680 | 80 | +# endif | ||
1681 | 81 | host = argv[0]; | ||
1682 | 82 | uport = NULL; | ||
1683 | 83 | } else if (!argv[0] && lflag) { | ||
1684 | 84 | @@ -374,8 +389,20 @@ | ||
1685 | 85 | if (family != AF_UNIX) { | ||
1686 | 86 | memset(&hints, 0, sizeof(struct addrinfo)); | ||
1687 | 87 | hints.ai_family = family; | ||
1688 | 88 | - hints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM; | ||
1689 | 89 | - hints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP; | ||
1690 | 90 | + if (uflag) { | ||
1691 | 91 | + hints.ai_socktype = SOCK_DGRAM; | ||
1692 | 92 | + hints.ai_protocol = IPPROTO_UDP; | ||
1693 | 93 | + } | ||
1694 | 94 | +# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP) | ||
1695 | 95 | + else if (dccpflag) { | ||
1696 | 96 | + hints.ai_socktype = SOCK_DCCP; | ||
1697 | 97 | + hints.ai_protocol = IPPROTO_DCCP; | ||
1698 | 98 | + } | ||
1699 | 99 | +# endif | ||
1700 | 100 | + else { | ||
1701 | 101 | + hints.ai_socktype = SOCK_STREAM; | ||
1702 | 102 | + hints.ai_protocol = IPPROTO_TCP; | ||
1703 | 103 | + } | ||
1704 | 104 | if (nflag) | ||
1705 | 105 | hints.ai_flags |= AI_NUMERICHOST; | ||
1706 | 106 | } | ||
1707 | 107 | @@ -383,7 +410,10 @@ | ||
1708 | 108 | if (xflag) { | ||
1709 | 109 | if (uflag) | ||
1710 | 110 | errx(1, "no proxy support for UDP mode"); | ||
1711 | 111 | - | ||
1712 | 112 | +# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP) | ||
1713 | 113 | + if (dccpflag) | ||
1714 | 114 | + errx(1, "no proxy support for DCCP mode"); | ||
1715 | 115 | +# endif | ||
1716 | 116 | if (lflag) | ||
1717 | 117 | errx(1, "no proxy support for listen"); | ||
1718 | 118 | |||
1719 | 119 | @@ -427,12 +457,12 @@ | ||
1720 | 120 | err(1, NULL); | ||
1721 | 121 | |||
1722 | 122 | char* local; | ||
1723 | 123 | - if (family == AF_INET6 | ||
1724 | 124 | + if (family == AF_INET6 ) | ||
1725 | 125 | local = "0.0.0.0"; | ||
1726 | 126 | else if (family == AF_INET) | ||
1727 | 127 | local = ":::"; | ||
1728 | 128 | else | ||
1729 | 129 | - local = "unknown" | ||
1730 | 130 | + local = "unknown"; | ||
1731 | 131 | fprintf(stderr, "Listening on [%s] (family %d, port %d)\n", | ||
1732 | 132 | host ?: local, | ||
1733 | 133 | family, | ||
1734 | 134 | @@ -463,12 +493,13 @@ | ||
1735 | 135 | connfd = accept(s, (struct sockaddr *)&cliaddr, | ||
1736 | 136 | &len); | ||
1737 | 137 | if(vflag) { | ||
1738 | 138 | + char *proto = proto_name(uflag, dccpflag); | ||
1739 | 139 | /* Don't look up port if -n. */ | ||
1740 | 140 | if (nflag) | ||
1741 | 141 | sv = NULL; | ||
1742 | 142 | else | ||
1743 | 143 | sv = getservbyport(ntohs(atoi(uport)), | ||
1744 | 144 | - uflag ? "udp" : "tcp"); | ||
1745 | 145 | + proto); | ||
1746 | 146 | |||
1747 | 147 | if (((struct sockaddr *)&cliaddr)->sa_family == AF_INET) { | ||
1748 | 148 | char dst[INET_ADDRSTRLEN]; | ||
1749 | 149 | @@ -476,7 +507,7 @@ | ||
1750 | 150 | fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n", | ||
1751 | 151 | dst, | ||
1752 | 152 | uport, | ||
1753 | 153 | - uflag ? "udp" : "tcp", | ||
1754 | 154 | + proto, | ||
1755 | 155 | sv ? sv->s_name : "*", | ||
1756 | 156 | ((struct sockaddr *)(&cliaddr))->sa_family, | ||
1757 | 157 | ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); | ||
1758 | 158 | @@ -487,7 +518,7 @@ | ||
1759 | 159 | fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n", | ||
1760 | 160 | dst, | ||
1761 | 161 | uport, | ||
1762 | 162 | - uflag ? "udp" : "tcp", | ||
1763 | 163 | + proto, | ||
1764 | 164 | sv ? sv->s_name : "*", | ||
1765 | 165 | ((struct sockaddr *)&cliaddr)->sa_family, | ||
1766 | 166 | ntohs(((struct sockaddr_in6 *)&cliaddr)->sin6_port)); | ||
1767 | 167 | @@ -495,7 +526,7 @@ | ||
1768 | 168 | else { | ||
1769 | 169 | fprintf(stderr, "Connection from unknown port %s [%s/%s] accepted (family %d, sport %d)\n", | ||
1770 | 170 | uport, | ||
1771 | 171 | - uflag ? "udp" : "tcp", | ||
1772 | 172 | + proto, | ||
1773 | 173 | sv ? sv->s_name : "*", | ||
1774 | 174 | ((struct sockaddr *)(&cliaddr))->sa_family, | ||
1775 | 175 | ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); | ||
1776 | 176 | @@ -559,19 +590,20 @@ | ||
1777 | 177 | } | ||
1778 | 178 | } | ||
1779 | 179 | |||
1780 | 180 | + char *proto = proto_name(uflag, dccpflag); | ||
1781 | 181 | /* Don't look up port if -n. */ | ||
1782 | 182 | if (nflag) | ||
1783 | 183 | sv = NULL; | ||
1784 | 184 | else { | ||
1785 | 185 | sv = getservbyport( | ||
1786 | 186 | ntohs(atoi(portlist[i])), | ||
1787 | 187 | - uflag ? "udp" : "tcp"); | ||
1788 | 188 | + proto); | ||
1789 | 189 | } | ||
1790 | 190 | |||
1791 | 191 | fprintf(stderr, | ||
1792 | 192 | "Connection to %s %s port [%s/%s] " | ||
1793 | 193 | "succeeded!\n", host, portlist[i], | ||
1794 | 194 | - uflag ? "udp" : "tcp", | ||
1795 | 195 | + proto, | ||
1796 | 196 | sv ? sv->s_name : "*"); | ||
1797 | 197 | } | ||
1798 | 198 | if (!zflag) | ||
1799 | 199 | @@ -671,6 +703,24 @@ | ||
1800 | 200 | return (s); | ||
1801 | 201 | } | ||
1802 | 202 | |||
1803 | 203 | +char *proto_name(uflag, dccpflag) { | ||
1804 | 204 | + | ||
1805 | 205 | + char *proto = NULL; | ||
1806 | 206 | + if (uflag) { | ||
1807 | 207 | + proto = "udp"; | ||
1808 | 208 | + } | ||
1809 | 209 | +# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP) | ||
1810 | 210 | + else if (dccpflag) { | ||
1811 | 211 | + proto = "dccp"; | ||
1812 | 212 | + } | ||
1813 | 213 | +# endif | ||
1814 | 214 | + else { | ||
1815 | 215 | + proto = "tcp"; | ||
1816 | 216 | + } | ||
1817 | 217 | + | ||
1818 | 218 | + return proto; | ||
1819 | 219 | +} | ||
1820 | 220 | + | ||
1821 | 221 | /* | ||
1822 | 222 | * remote_connect() | ||
1823 | 223 | * Returns a socket connected to a remote host. Properly binds to a local | ||
1824 | 224 | @@ -709,8 +759,21 @@ | ||
1825 | 225 | # endif | ||
1826 | 226 | memset(&ahints, 0, sizeof(struct addrinfo)); | ||
1827 | 227 | ahints.ai_family = res0->ai_family; | ||
1828 | 228 | - ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM; | ||
1829 | 229 | - ahints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP; | ||
1830 | 230 | + if (uflag) { | ||
1831 | 231 | + ahints.ai_socktype = SOCK_DGRAM; | ||
1832 | 232 | + ahints.ai_protocol = IPPROTO_UDP; | ||
1833 | 233 | + | ||
1834 | 234 | + } | ||
1835 | 235 | +# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP) | ||
1836 | 236 | + else if (dccpflag) { | ||
1837 | 237 | + hints.ai_socktype = SOCK_DCCP; | ||
1838 | 238 | + hints.ai_protocol = IPPROTO_DCCP; | ||
1839 | 239 | + } | ||
1840 | 240 | +# endif | ||
1841 | 241 | + else { | ||
1842 | 242 | + ahints.ai_socktype = SOCK_STREAM; | ||
1843 | 243 | + ahints.ai_protocol = IPPROTO_TCP; | ||
1844 | 244 | + } | ||
1845 | 245 | ahints.ai_flags = AI_PASSIVE; | ||
1846 | 246 | if ((error = getaddrinfo(sflag, pflag, &ahints, &ares))) | ||
1847 | 247 | errx(1, "getaddrinfo: %s", gai_strerror(error)); | ||
1848 | 248 | @@ -722,15 +785,19 @@ | ||
1849 | 249 | } | ||
1850 | 250 | |||
1851 | 251 | set_common_sockopts(s); | ||
1852 | 252 | + char *proto = proto_name(uflag, dccpflag); | ||
1853 | 253 | |||
1854 | 254 | - if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout))== CONNECTION_SUCCESS) | ||
1855 | 255 | + if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout))== CONNECTION_SUCCESS) { | ||
1856 | 256 | break; | ||
1857 | 257 | - else if (vflag && error == CONNECTION_FAILED) | ||
1858 | 258 | + } | ||
1859 | 259 | + else if (vflag && error == CONNECTION_FAILED) { | ||
1860 | 260 | warn("connect to %s port %s (%s) failed", host, port, | ||
1861 | 261 | - uflag ? "udp" : "tcp"); | ||
1862 | 262 | - else if (vflag && error == CONNECTION_TIMEOUT) | ||
1863 | 263 | + proto); | ||
1864 | 264 | + } | ||
1865 | 265 | + else if (vflag && error == CONNECTION_TIMEOUT) { | ||
1866 | 266 | warn("connect to %s port %s (%s) timed out", host, port, | ||
1867 | 267 | - uflag ? "udp" : "tcp"); | ||
1868 | 268 | + proto); | ||
1869 | 269 | + } | ||
1870 | 270 | |||
1871 | 271 | close(s); | ||
1872 | 272 | s = -1; | ||
1873 | 273 | @@ -1047,7 +1114,8 @@ | ||
1874 | 274 | int hi, lo, cp; | ||
1875 | 275 | int x = 0; | ||
1876 | 276 | |||
1877 | 277 | - sv = getservbyname(p, uflag ? "udp" : "tcp"); | ||
1878 | 278 | + char *proto = proto_name(uflag, dccpflag); | ||
1879 | 279 | + sv = getservbyname(p, proto); | ||
1880 | 280 | if (sv) { | ||
1881 | 281 | portlist[0] = calloc(1, PORT_MAX_LEN); | ||
1882 | 282 | if (portlist[0] == NULL) | ||
1883 | 283 | @@ -1252,6 +1320,7 @@ | ||
1884 | 284 | \t-w secs\t Timeout for connects and final net reads\n\ | ||
1885 | 285 | \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\ | ||
1886 | 286 | \t-x addr[:port]\tSpecify proxy address and port\n\ | ||
1887 | 287 | + \t-Z DCCP mode\n\ | ||
1888 | 288 | \t-z Zero-I/O mode [used for scanning]\n\ | ||
1889 | 289 | Port numbers can be individual or ranges: lo-hi [inclusive]\n"); | ||
1890 | 290 | exit(0); | ||
1891 | 291 | @@ -1261,7 +1330,7 @@ | ||
1892 | 292 | usage(int ret) | ||
1893 | 293 | { | ||
1894 | 294 | fprintf(stderr, | ||
1895 | 295 | - "usage: nc [-46CDdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n" | ||
1896 | 296 | + "usage: nc [-46CDdhjklnrStUuvZz] [-I length] [-i interval] [-O length]\n" | ||
1897 | 297 | "\t [-P proxy_username] [-p source_port] [-q seconds] [-s source]\n" | ||
1898 | 298 | "\t [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]\n" | ||
1899 | 299 | "\t [-x proxy_address[:port]] [destination] [port]\n"); | ||
1900 | 0 | 300 | ||
1901 | === added file 'debian/patches/0010-serialized-handling-multiple-clients.patch' | |||
1902 | --- debian/patches/0010-serialized-handling-multiple-clients.patch 1970-01-01 00:00:00 +0000 | |||
1903 | +++ debian/patches/0010-serialized-handling-multiple-clients.patch 2012-05-30 22:10:23 +0000 | |||
1904 | @@ -0,0 +1,73 @@ | |||
1905 | 1 | From: Aron Xu <aron@debian.org> | ||
1906 | 2 | Date: Tue, 14 Feb 2012 23:02:00 +0800 | ||
1907 | 3 | Subject: [PATCH] serialized handling multiple clients | ||
1908 | 4 | |||
1909 | 5 | --- | ||
1910 | 6 | netcat.c | 18 +++++++++--------- | ||
1911 | 7 | 1 files changed, 9 insertions(+), 9 deletions(-) | ||
1912 | 8 | |||
1913 | 9 | --- a/netcat.c | ||
1914 | 10 | +++ b/netcat.c | ||
1915 | 11 | @@ -447,26 +447,24 @@ | ||
1916 | 12 | s = unix_bind(host); | ||
1917 | 13 | else | ||
1918 | 14 | s = unix_listen(host); | ||
1919 | 15 | - } | ||
1920 | 16 | + } else | ||
1921 | 17 | + s = local_listen(host, uport, hints); | ||
1922 | 18 | + if (s < 0) | ||
1923 | 19 | + err(1, NULL); | ||
1924 | 20 | + | ||
1925 | 21 | + char* local; | ||
1926 | 22 | + if (family == AF_INET6) | ||
1927 | 23 | + local = ":::"; | ||
1928 | 24 | + else | ||
1929 | 25 | + local = "0.0.0.0"; | ||
1930 | 26 | + fprintf(stderr, "Listening on [%s] (family %d, port %d)\n", | ||
1931 | 27 | + host ?: local, | ||
1932 | 28 | + family, | ||
1933 | 29 | + *uport); | ||
1934 | 30 | |||
1935 | 31 | /* Allow only one connection at a time, but stay alive. */ | ||
1936 | 32 | for (;;) { | ||
1937 | 33 | - if (family != AF_UNIX) | ||
1938 | 34 | - s = local_listen(host, uport, hints); | ||
1939 | 35 | - if (s < 0) | ||
1940 | 36 | - err(1, NULL); | ||
1941 | 37 | - | ||
1942 | 38 | - char* local; | ||
1943 | 39 | - if (family == AF_INET6 ) | ||
1944 | 40 | - local = "0.0.0.0"; | ||
1945 | 41 | - else if (family == AF_INET) | ||
1946 | 42 | - local = ":::"; | ||
1947 | 43 | - else | ||
1948 | 44 | - local = "unknown"; | ||
1949 | 45 | - fprintf(stderr, "Listening on [%s] (family %d, port %d)\n", | ||
1950 | 46 | - host ?: local, | ||
1951 | 47 | - family, | ||
1952 | 48 | - *uport); | ||
1953 | 49 | + | ||
1954 | 50 | /* | ||
1955 | 51 | * For UDP, we will use recvfrom() initially | ||
1956 | 52 | * to wait for a caller, then use the regular | ||
1957 | 53 | @@ -536,15 +534,16 @@ | ||
1958 | 54 | close(connfd); | ||
1959 | 55 | } | ||
1960 | 56 | |||
1961 | 57 | - if (family != AF_UNIX) | ||
1962 | 58 | + if (kflag) | ||
1963 | 59 | + continue; | ||
1964 | 60 | + if (family != AF_UNIX) { | ||
1965 | 61 | close(s); | ||
1966 | 62 | + } | ||
1967 | 63 | else if (uflag) { | ||
1968 | 64 | if (connect(s, NULL, 0) < 0) | ||
1969 | 65 | err(1, "connect"); | ||
1970 | 66 | } | ||
1971 | 67 | - | ||
1972 | 68 | - if (!kflag) | ||
1973 | 69 | - break; | ||
1974 | 70 | + break; | ||
1975 | 71 | } | ||
1976 | 72 | } else if (family == AF_UNIX) { | ||
1977 | 73 | ret = 0; | ||
1978 | 0 | 74 | ||
1979 | === added file 'debian/patches/0011-misc-failures-and-features.patch' | |||
1980 | --- debian/patches/0011-misc-failures-and-features.patch 1970-01-01 00:00:00 +0000 | |||
1981 | +++ debian/patches/0011-misc-failures-and-features.patch 2012-05-30 22:10:23 +0000 | |||
1982 | @@ -0,0 +1,443 @@ | |||
1983 | 1 | From: Aron Xu <aron@debian.org> | ||
1984 | 2 | Date: Mon, 13 Feb 2012 19:06:52 +0800 | ||
1985 | 3 | Subject: [PATCH] misc connection failures | ||
1986 | 4 | |||
1987 | 5 | --- | ||
1988 | 6 | netcat.c | 22 +++++++++++++++++++--- | ||
1989 | 7 | 1 files changed, 19 insertions(+), 3 deletions(-) | ||
1990 | 8 | |||
1991 | 9 | --- a/netcat.c | ||
1992 | 10 | +++ b/netcat.c | ||
1993 | 11 | @@ -88,6 +88,7 @@ | ||
1994 | 12 | #include <netdb.h> | ||
1995 | 13 | #include <poll.h> | ||
1996 | 14 | #include <signal.h> | ||
1997 | 15 | +#include <stddef.h> | ||
1998 | 16 | #include <stdarg.h> | ||
1999 | 17 | #include <stdio.h> | ||
2000 | 18 | #include <stdlib.h> | ||
2001 | 19 | @@ -115,6 +116,7 @@ | ||
2002 | 20 | #define UDP_SCAN_TIMEOUT 3 /* Seconds */ | ||
2003 | 21 | |||
2004 | 22 | /* Command Line Options */ | ||
2005 | 23 | +int bflag; /* Allow Broadcast */ | ||
2006 | 24 | int Cflag = 0; /* CRLF line-ending */ | ||
2007 | 25 | int dflag; /* detached, no stdin */ | ||
2008 | 26 | unsigned int iflag; /* Interval Flag */ | ||
2009 | 27 | @@ -146,7 +148,7 @@ | ||
2010 | 28 | char *unix_dg_tmp_socket; | ||
2011 | 29 | |||
2012 | 30 | void atelnet(int, unsigned char *, unsigned int); | ||
2013 | 31 | -void build_ports(char *); | ||
2014 | 32 | +void build_ports(char **); | ||
2015 | 33 | void help(void); | ||
2016 | 34 | int local_listen(char *, char *, struct addrinfo); | ||
2017 | 35 | void readwrite(int); | ||
2018 | 36 | @@ -171,11 +173,14 @@ | ||
2019 | 37 | main(int argc, char *argv[]) | ||
2020 | 38 | { | ||
2021 | 39 | int ch, s, ret, socksv; | ||
2022 | 40 | - char *host, *uport; | ||
2023 | 41 | + char *host, **uport; | ||
2024 | 42 | struct addrinfo hints; | ||
2025 | 43 | struct servent *sv; | ||
2026 | 44 | socklen_t len; | ||
2027 | 45 | - struct sockaddr_storage cliaddr; | ||
2028 | 46 | + union { | ||
2029 | 47 | + struct sockaddr_storage storage; | ||
2030 | 48 | + struct sockaddr_un forunix; | ||
2031 | 49 | + } cliaddr; | ||
2032 | 50 | char *proxy = NULL; | ||
2033 | 51 | const char *errstr, *proxyhost = "", *proxyport = NULL; | ||
2034 | 52 | struct addrinfo proxyhints; | ||
2035 | 53 | @@ -189,7 +194,7 @@ | ||
2036 | 54 | sv = NULL; | ||
2037 | 55 | |||
2038 | 56 | while ((ch = getopt(argc, argv, | ||
2039 | 57 | - "46CDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:Zz")) != -1) { | ||
2040 | 58 | + "46bCDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:Zz")) != -1) { | ||
2041 | 59 | switch (ch) { | ||
2042 | 60 | case '4': | ||
2043 | 61 | family = AF_INET; | ||
2044 | 62 | @@ -197,6 +202,13 @@ | ||
2045 | 63 | case '6': | ||
2046 | 64 | family = AF_INET6; | ||
2047 | 65 | break; | ||
2048 | 66 | + case 'b': | ||
2049 | 67 | +# if defined(SO_BROADCAST) | ||
2050 | 68 | + bflag = 1; | ||
2051 | 69 | +# else | ||
2052 | 70 | + errx(1, "no broadcast frame support available"); | ||
2053 | 71 | +# endif | ||
2054 | 72 | + break; | ||
2055 | 73 | case 'U': | ||
2056 | 74 | family = AF_UNIX; | ||
2057 | 75 | break; | ||
2058 | 76 | @@ -350,27 +362,34 @@ | ||
2059 | 77 | # endif | ||
2060 | 78 | host = argv[0]; | ||
2061 | 79 | uport = NULL; | ||
2062 | 80 | - } else if (!argv[0] && lflag) { | ||
2063 | 81 | - if (sflag) | ||
2064 | 82 | - errx(1, "cannot use -s and -l"); | ||
2065 | 83 | - if (zflag) | ||
2066 | 84 | - errx(1, "cannot use -z and -l"); | ||
2067 | 85 | - if (pflag) | ||
2068 | 86 | - uport=pflag; | ||
2069 | 87 | - } else if (!lflag && kflag) { | ||
2070 | 88 | - errx(1, "cannot use -k without -l"); | ||
2071 | 89 | - } else if (argv[0] && !argv[1]) { | ||
2072 | 90 | - if (!lflag) | ||
2073 | 91 | - usage(1); | ||
2074 | 92 | - uport = argv[0]; | ||
2075 | 93 | + } else if (argv[0] && !argv[1] && lflag) { | ||
2076 | 94 | + if (pflag) { | ||
2077 | 95 | + uport = &pflag; | ||
2078 | 96 | + host = argv[0]; | ||
2079 | 97 | + } else { | ||
2080 | 98 | + uport = argv; | ||
2081 | 99 | + host = NULL; | ||
2082 | 100 | + } | ||
2083 | 101 | + } else if (!argv[0] && lflag && pflag) { | ||
2084 | 102 | + uport = &pflag; | ||
2085 | 103 | host = NULL; | ||
2086 | 104 | } else if (argv[0] && argv[1]) { | ||
2087 | 105 | host = argv[0]; | ||
2088 | 106 | - uport = argv[1]; | ||
2089 | 107 | + uport = &argv[1]; | ||
2090 | 108 | } else | ||
2091 | 109 | usage(1); | ||
2092 | 110 | |||
2093 | 111 | - | ||
2094 | 112 | + if (lflag) { | ||
2095 | 113 | + if (sflag) | ||
2096 | 114 | + errx(1, "cannot use -s and -l"); | ||
2097 | 115 | + if (zflag) | ||
2098 | 116 | + errx(1, "cannot use -z and -l"); | ||
2099 | 117 | + if (pflag) | ||
2100 | 118 | + /* This still does not work well because of getopt mess | ||
2101 | 119 | + errx(1, "cannot use -p and -l"); */ | ||
2102 | 120 | + uport = &pflag; | ||
2103 | 121 | + } else if (!lflag && kflag) | ||
2104 | 122 | + errx(1, "cannot use -k without -l"); | ||
2105 | 123 | |||
2106 | 124 | /* Get name of temporary socket for unix datagram client */ | ||
2107 | 125 | if ((family == AF_UNIX) && uflag && !lflag) { | ||
2108 | 126 | @@ -448,7 +467,7 @@ | ||
2109 | 127 | else | ||
2110 | 128 | s = unix_listen(host); | ||
2111 | 129 | } else | ||
2112 | 130 | - s = local_listen(host, uport, hints); | ||
2113 | 131 | + s = local_listen(host, *uport, hints); | ||
2114 | 132 | if (s < 0) | ||
2115 | 133 | err(1, NULL); | ||
2116 | 134 | |||
2117 | 135 | @@ -457,7 +476,8 @@ | ||
2118 | 136 | local = ":::"; | ||
2119 | 137 | else | ||
2120 | 138 | local = "0.0.0.0"; | ||
2121 | 139 | - fprintf(stderr, "Listening on [%s] (family %d, port %d)\n", | ||
2122 | 140 | + if (vflag && (family != AF_UNIX)) | ||
2123 | 141 | + fprintf(stderr, "Listening on [%s] (family %d, port %s)\n", | ||
2124 | 142 | host ?: local, | ||
2125 | 143 | family, | ||
2126 | 144 | *uport); | ||
2127 | 145 | @@ -490,13 +510,17 @@ | ||
2128 | 146 | len = sizeof(cliaddr); | ||
2129 | 147 | connfd = accept(s, (struct sockaddr *)&cliaddr, | ||
2130 | 148 | &len); | ||
2131 | 149 | - if(vflag) { | ||
2132 | 150 | + if(vflag && family == AF_UNIX) { | ||
2133 | 151 | + fprintf(stderr, "Connection from \"%.*s\" accepted\n", | ||
2134 | 152 | + (len - (int)offsetof(struct sockaddr_un, sun_path)), | ||
2135 | 153 | + ((struct sockaddr_un*)&cliaddr)->sun_path); | ||
2136 | 154 | + } else if(vflag) { | ||
2137 | 155 | char *proto = proto_name(uflag, dccpflag); | ||
2138 | 156 | /* Don't look up port if -n. */ | ||
2139 | 157 | if (nflag) | ||
2140 | 158 | sv = NULL; | ||
2141 | 159 | else | ||
2142 | 160 | - sv = getservbyport(ntohs(atoi(uport)), | ||
2143 | 161 | + sv = getservbyport(ntohs(atoi(*uport)), | ||
2144 | 162 | proto); | ||
2145 | 163 | |||
2146 | 164 | if (((struct sockaddr *)&cliaddr)->sa_family == AF_INET) { | ||
2147 | 165 | @@ -504,7 +528,7 @@ | ||
2148 | 166 | inet_ntop(((struct sockaddr *)&cliaddr)->sa_family,&(((struct sockaddr_in *)&cliaddr)->sin_addr),dst,INET_ADDRSTRLEN); | ||
2149 | 167 | fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n", | ||
2150 | 168 | dst, | ||
2151 | 169 | - uport, | ||
2152 | 170 | + *uport, | ||
2153 | 171 | proto, | ||
2154 | 172 | sv ? sv->s_name : "*", | ||
2155 | 173 | ((struct sockaddr *)(&cliaddr))->sa_family, | ||
2156 | 174 | @@ -515,7 +539,7 @@ | ||
2157 | 175 | inet_ntop(((struct sockaddr *)&cliaddr)->sa_family,&(((struct sockaddr_in6 *)&cliaddr)->sin6_addr),dst,INET6_ADDRSTRLEN); | ||
2158 | 176 | fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n", | ||
2159 | 177 | dst, | ||
2160 | 178 | - uport, | ||
2161 | 179 | + *uport, | ||
2162 | 180 | proto, | ||
2163 | 181 | sv ? sv->s_name : "*", | ||
2164 | 182 | ((struct sockaddr *)&cliaddr)->sa_family, | ||
2165 | 183 | @@ -523,17 +547,21 @@ | ||
2166 | 184 | } | ||
2167 | 185 | else { | ||
2168 | 186 | fprintf(stderr, "Connection from unknown port %s [%s/%s] accepted (family %d, sport %d)\n", | ||
2169 | 187 | - uport, | ||
2170 | 188 | + *uport, | ||
2171 | 189 | proto, | ||
2172 | 190 | sv ? sv->s_name : "*", | ||
2173 | 191 | ((struct sockaddr *)(&cliaddr))->sa_family, | ||
2174 | 192 | ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); | ||
2175 | 193 | } | ||
2176 | 194 | } | ||
2177 | 195 | + if(!kflag) | ||
2178 | 196 | + close(s); | ||
2179 | 197 | readwrite(connfd); | ||
2180 | 198 | close(connfd); | ||
2181 | 199 | } | ||
2182 | 200 | |||
2183 | 201 | + if (vflag && kflag) | ||
2184 | 202 | + fprintf(stderr, "Connection closed, listening again.\n"); | ||
2185 | 203 | if (kflag) | ||
2186 | 204 | continue; | ||
2187 | 205 | if (family != AF_UNIX) { | ||
2188 | 206 | @@ -641,6 +669,8 @@ | ||
2189 | 207 | return (-1); | ||
2190 | 208 | } | ||
2191 | 209 | |||
2192 | 210 | + unlink(path); | ||
2193 | 211 | + | ||
2194 | 212 | if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { | ||
2195 | 213 | close(s); | ||
2196 | 214 | return (-1); | ||
2197 | 215 | @@ -662,8 +692,10 @@ | ||
2198 | 216 | if ((s = unix_bind(unix_dg_tmp_socket)) < 0) | ||
2199 | 217 | return (-1); | ||
2200 | 218 | } else { | ||
2201 | 219 | - if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) | ||
2202 | 220 | + if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { | ||
2203 | 221 | + errx(1,"create unix socket failed"); | ||
2204 | 222 | return (-1); | ||
2205 | 223 | + } | ||
2206 | 224 | } | ||
2207 | 225 | (void)fcntl(s, F_SETFD, 1); | ||
2208 | 226 | |||
2209 | 227 | @@ -674,9 +706,11 @@ | ||
2210 | 228 | sizeof(sun.sun_path)) { | ||
2211 | 229 | close(s); | ||
2212 | 230 | errno = ENAMETOOLONG; | ||
2213 | 231 | + warn("unix connect abandoned"); | ||
2214 | 232 | return (-1); | ||
2215 | 233 | } | ||
2216 | 234 | if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { | ||
2217 | 235 | + warn("unix connect failed"); | ||
2218 | 236 | close(s); | ||
2219 | 237 | return (-1); | ||
2220 | 238 | } | ||
2221 | 239 | @@ -1105,22 +1139,23 @@ | ||
2222 | 240 | * that we should try to connect to. | ||
2223 | 241 | */ | ||
2224 | 242 | void | ||
2225 | 243 | -build_ports(char *p) | ||
2226 | 244 | +build_ports(char **p) | ||
2227 | 245 | { | ||
2228 | 246 | struct servent *sv; | ||
2229 | 247 | const char *errstr; | ||
2230 | 248 | char *n; | ||
2231 | 249 | int hi, lo, cp; | ||
2232 | 250 | int x = 0; | ||
2233 | 251 | + int i; | ||
2234 | 252 | |||
2235 | 253 | char *proto = proto_name(uflag, dccpflag); | ||
2236 | 254 | - sv = getservbyname(p, proto); | ||
2237 | 255 | + sv = getservbyname(*p, proto); | ||
2238 | 256 | if (sv) { | ||
2239 | 257 | portlist[0] = calloc(1, PORT_MAX_LEN); | ||
2240 | 258 | if (portlist[0] == NULL) | ||
2241 | 259 | err(1, NULL); | ||
2242 | 260 | snprintf(portlist[0], PORT_MAX_LEN, "%d", ntohs(sv->s_port)); | ||
2243 | 261 | - } else if ((n = strchr(p, '-')) != NULL) { | ||
2244 | 262 | + } else if ((n = strchr(*p, '-')) != NULL) { | ||
2245 | 263 | *n = '\0'; | ||
2246 | 264 | n++; | ||
2247 | 265 | |||
2248 | 266 | @@ -1128,9 +1163,9 @@ | ||
2249 | 267 | hi = strtonum(n, 1, PORT_MAX, &errstr); | ||
2250 | 268 | if (errstr) | ||
2251 | 269 | errx(1, "port number %s: %s", errstr, n); | ||
2252 | 270 | - lo = strtonum(p, 1, PORT_MAX, &errstr); | ||
2253 | 271 | + lo = strtonum(*p, 1, PORT_MAX, &errstr); | ||
2254 | 272 | if (errstr) | ||
2255 | 273 | - errx(1, "port number %s: %s", errstr, p); | ||
2256 | 274 | + errx(1, "port number %s: %s", errstr, *p); | ||
2257 | 275 | |||
2258 | 276 | if (lo > hi) { | ||
2259 | 277 | cp = hi; | ||
2260 | 278 | @@ -1160,10 +1195,12 @@ | ||
2261 | 279 | } | ||
2262 | 280 | } | ||
2263 | 281 | } else { | ||
2264 | 282 | - hi = strtonum(p, 1, PORT_MAX, &errstr); | ||
2265 | 283 | + hi = strtonum(*p, 1, PORT_MAX, &errstr); | ||
2266 | 284 | if (errstr) | ||
2267 | 285 | - errx(1, "port number %s: %s", errstr, p); | ||
2268 | 286 | - portlist[0] = strdup(p); | ||
2269 | 287 | + errx(1, "port number %s: %s", errstr, *p); | ||
2270 | 288 | + for (i=0;p[i];i++) { | ||
2271 | 289 | + portlist[i] = strdup(p[i]); | ||
2272 | 290 | + } | ||
2273 | 291 | if (portlist[0] == NULL) | ||
2274 | 292 | err(1, NULL); | ||
2275 | 293 | } | ||
2276 | 294 | @@ -1198,6 +1235,13 @@ | ||
2277 | 295 | { | ||
2278 | 296 | int x = 1; | ||
2279 | 297 | |||
2280 | 298 | +# if defined(SO_BROADCAST) | ||
2281 | 299 | + if (bflag) { | ||
2282 | 300 | + if (setsockopt(s, IPPROTO_TCP, SO_BROADCAST, | ||
2283 | 301 | + &x, sizeof(x)) == -1) | ||
2284 | 302 | + err(1, NULL); | ||
2285 | 303 | + } | ||
2286 | 304 | +# endif | ||
2287 | 305 | # if defined(TCP_MD5SIG) | ||
2288 | 306 | if (Sflag) { | ||
2289 | 307 | if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG, | ||
2290 | 308 | @@ -1293,6 +1337,7 @@ | ||
2291 | 309 | fprintf(stderr, "\tCommand Summary:\n\ | ||
2292 | 310 | \t-4 Use IPv4\n\ | ||
2293 | 311 | \t-6 Use IPv6\n\ | ||
2294 | 312 | + \t-b Allow broadcast\n\ | ||
2295 | 313 | \t-C Send CRLF as line-ending\n\ | ||
2296 | 314 | \t-D Enable the debug socket option\n\ | ||
2297 | 315 | \t-d Detach from stdin\n\ | ||
2298 | 316 | @@ -1329,7 +1374,7 @@ | ||
2299 | 317 | usage(int ret) | ||
2300 | 318 | { | ||
2301 | 319 | fprintf(stderr, | ||
2302 | 320 | - "usage: nc [-46CDdhjklnrStUuvZz] [-I length] [-i interval] [-O length]\n" | ||
2303 | 321 | + "usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length]\n" | ||
2304 | 322 | "\t [-P proxy_username] [-p source_port] [-q seconds] [-s source]\n" | ||
2305 | 323 | "\t [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]\n" | ||
2306 | 324 | "\t [-x proxy_address[:port]] [destination] [port]\n"); | ||
2307 | 325 | --- a/nc.1 | ||
2308 | 326 | +++ b/nc.1 | ||
2309 | 327 | @@ -34,7 +34,7 @@ | ||
2310 | 328 | .Sh SYNOPSIS | ||
2311 | 329 | .Nm nc | ||
2312 | 330 | .Bk -words | ||
2313 | 331 | -.Op Fl 46CDdhklnrStUuvZz | ||
2314 | 332 | +.Op Fl 46bCDdhklnrStUuvZz | ||
2315 | 333 | .Op Fl I Ar length | ||
2316 | 334 | .Op Fl i Ar interval | ||
2317 | 335 | .Op Fl O Ar length | ||
2318 | 336 | @@ -99,6 +99,8 @@ | ||
2319 | 337 | Forces | ||
2320 | 338 | .Nm | ||
2321 | 339 | to use IPv6 addresses only. | ||
2322 | 340 | +.It Fl b | ||
2323 | 341 | +Allow broadcast. | ||
2324 | 342 | .It Fl C | ||
2325 | 343 | Send CRLF as line-ending. | ||
2326 | 344 | .It Fl D | ||
2327 | 345 | @@ -323,6 +325,54 @@ | ||
2328 | 346 | The connection may be terminated using an | ||
2329 | 347 | .Dv EOF | ||
2330 | 348 | .Pq Sq ^D . | ||
2331 | 349 | +.Pp | ||
2332 | 350 | +There is no | ||
2333 | 351 | +.Fl c | ||
2334 | 352 | +or | ||
2335 | 353 | +.Fl e | ||
2336 | 354 | +option in this netcat, but you still can execute a command after connection | ||
2337 | 355 | +being established by redirecting file descriptors. Be cautious here because | ||
2338 | 356 | +opening a port and let anyone connected execute arbitrary command on your | ||
2339 | 357 | +site is DANGEROUS. If you really need to do this, here is an example: | ||
2340 | 358 | +.Pp | ||
2341 | 359 | +On | ||
2342 | 360 | +.Sq server | ||
2343 | 361 | +side: | ||
2344 | 362 | +.Pp | ||
2345 | 363 | +.Dl $ rm -f /tmp/f; mkfifo /tmp/f | ||
2346 | 364 | +.Dl $ cat /tmp/f | /bin/sh -i 2>&1 | nc -l 127.0.0.1 1234 > /tmp/f | ||
2347 | 365 | +.Pp | ||
2348 | 366 | +On | ||
2349 | 367 | +.Sq client | ||
2350 | 368 | +side: | ||
2351 | 369 | +.Pp | ||
2352 | 370 | +.Dl $ nc host.example.com 1234 | ||
2353 | 371 | +.Dl $ (shell prompt from host.example.com) | ||
2354 | 372 | +.Pp | ||
2355 | 373 | +By doing this, you create a fifo at /tmp/f and make nc listen at port 1234 | ||
2356 | 374 | +of address 127.0.0.1 on | ||
2357 | 375 | +.Sq server | ||
2358 | 376 | +side, when a | ||
2359 | 377 | +.Sq client | ||
2360 | 378 | +establishes a connection successfully to that port, /bin/sh gets executed | ||
2361 | 379 | +on | ||
2362 | 380 | +.Sq server | ||
2363 | 381 | +side and the shell prompt is given to | ||
2364 | 382 | +.Sq client | ||
2365 | 383 | +side. | ||
2366 | 384 | +.Pp | ||
2367 | 385 | +When connection is terminated, | ||
2368 | 386 | +.Nm | ||
2369 | 387 | +quits as well. Use | ||
2370 | 388 | +.Fl k | ||
2371 | 389 | +if you want it keep listening, but if the command quits this option won't | ||
2372 | 390 | +restart it or keep | ||
2373 | 391 | +.Nm | ||
2374 | 392 | +running. Also don't forget to remove the file descriptor once you don't need | ||
2375 | 393 | +it anymore: | ||
2376 | 394 | +.Pp | ||
2377 | 395 | +.Dl $ rm -f /tmp/f | ||
2378 | 396 | +.Pp | ||
2379 | 397 | .Sh DATA TRANSFER | ||
2380 | 398 | The example in the previous section can be expanded to build a | ||
2381 | 399 | basic data transfer model. | ||
2382 | 400 | @@ -382,15 +432,30 @@ | ||
2383 | 401 | flag can be used to tell | ||
2384 | 402 | .Nm | ||
2385 | 403 | to report open ports, | ||
2386 | 404 | -rather than initiate a connection. | ||
2387 | 405 | +rather than initiate a connection. Usually it's useful to turn on verbose | ||
2388 | 406 | +output to stderr by use this option in conjunction with | ||
2389 | 407 | +.Fl v | ||
2390 | 408 | +option. | ||
2391 | 409 | +.Pp | ||
2392 | 410 | For example: | ||
2393 | 411 | .Bd -literal -offset indent | ||
2394 | 412 | -$ nc -z host.example.com 20-30 | ||
2395 | 413 | +$ nc \-zv host.example.com 20-30 | ||
2396 | 414 | Connection to host.example.com 22 port [tcp/ssh] succeeded! | ||
2397 | 415 | Connection to host.example.com 25 port [tcp/smtp] succeeded! | ||
2398 | 416 | .Ed | ||
2399 | 417 | .Pp | ||
2400 | 418 | -The port range was specified to limit the search to ports 20 \- 30. | ||
2401 | 419 | +The port range was specified to limit the search to ports 20 \- 30, and is | ||
2402 | 420 | +scanned by increasing order. | ||
2403 | 421 | +.Pp | ||
2404 | 422 | +You can also specify a list of ports to scan, for example: | ||
2405 | 423 | +.Bd -literal -offset indent | ||
2406 | 424 | +$ nc \-zv host.example.com 80 20 22 | ||
2407 | 425 | +nc: connect to host.example.com 80 (tcp) failed: Connection refused | ||
2408 | 426 | +nc: connect to host.example.com 20 (tcp) failed: Connection refused | ||
2409 | 427 | +Connection to host.example.com port [tcp/ssh] succeeded! | ||
2410 | 428 | +.Ed | ||
2411 | 429 | +.Pp | ||
2412 | 430 | +The ports are scanned by the order you given. | ||
2413 | 431 | .Pp | ||
2414 | 432 | Alternatively, it might be useful to know which server software | ||
2415 | 433 | is running, and which versions. | ||
2416 | 434 | @@ -455,6 +520,9 @@ | ||
2417 | 435 | .br | ||
2418 | 436 | Rewritten with IPv6 support by | ||
2419 | 437 | .An Eric Jackson Aq ericj@monkey.org . | ||
2420 | 438 | +.br | ||
2421 | 439 | +Modified for Debian port by Aron Xu | ||
2422 | 440 | +.Aq aron@debian.org . | ||
2423 | 441 | .Sh CAVEATS | ||
2424 | 442 | UDP port scans using the | ||
2425 | 443 | .Fl uz | ||
2426 | 0 | 444 | ||
2427 | === removed file 'debian/patches/connect-timeout.patch' | |||
2428 | --- debian/patches/connect-timeout.patch 2008-01-30 18:24:46 +0000 | |||
2429 | +++ debian/patches/connect-timeout.patch 1970-01-01 00:00:00 +0000 | |||
2430 | @@ -1,120 +0,0 @@ | |||
2431 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
2432 | 2 | =================================================================== | ||
2433 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:27.000000000 -0500 | ||
2434 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:30.000000000 -0500 | ||
2435 | 5 | @@ -65,6 +65,10 @@ | ||
2436 | 6 | #define PORT_MAX 65535 | ||
2437 | 7 | #define PORT_MAX_LEN 6 | ||
2438 | 8 | |||
2439 | 9 | +#define CONNECTION_SUCCESS 0 | ||
2440 | 10 | +#define CONNECTION_FAILED 1 | ||
2441 | 11 | +#define CONNECTION_TIMEOUT 2 | ||
2442 | 12 | + | ||
2443 | 13 | /* Command Line Options */ | ||
2444 | 14 | int dflag; /* detached, no stdin */ | ||
2445 | 15 | int iflag; /* Interval Flag */ | ||
2446 | 16 | @@ -104,6 +108,9 @@ | ||
2447 | 17 | int parse_iptos(char *); | ||
2448 | 18 | void usage(int); | ||
2449 | 19 | |||
2450 | 20 | +static int connect_with_timeout(int fd, const struct sockaddr *sa, | ||
2451 | 21 | + socklen_t salen, int ctimeout); | ||
2452 | 22 | + | ||
2453 | 23 | int | ||
2454 | 24 | main(int argc, char *argv[]) | ||
2455 | 25 | { | ||
2456 | 26 | @@ -508,13 +515,15 @@ | ||
2457 | 27 | } | ||
2458 | 28 | |||
2459 | 29 | set_common_sockopts(s); | ||
2460 | 30 | - | ||
2461 | 31 | - if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0) | ||
2462 | 32 | + if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout)) == CONNECTION_SUCCESS) | ||
2463 | 33 | break; | ||
2464 | 34 | - else if (vflag) | ||
2465 | 35 | + else if (vflag && error == CONNECTION_FAILED) | ||
2466 | 36 | warn("connect to %s port %s (%s) failed", host, port, | ||
2467 | 37 | uflag ? "udp" : "tcp"); | ||
2468 | 38 | - | ||
2469 | 39 | + else if (vflag && error == CONNECTION_TIMEOUT) | ||
2470 | 40 | + warn("connect to %s port %s (%s) timed out", host, port, | ||
2471 | 41 | + uflag ? "udp" : "tcp"); | ||
2472 | 42 | + | ||
2473 | 43 | close(s); | ||
2474 | 44 | s = -1; | ||
2475 | 45 | } while ((res0 = res0->ai_next) != NULL); | ||
2476 | 46 | @@ -524,6 +533,74 @@ | ||
2477 | 47 | return (s); | ||
2478 | 48 | } | ||
2479 | 49 | |||
2480 | 50 | +static int connect_with_timeout(int fd, const struct sockaddr *sa, | ||
2481 | 51 | + socklen_t salen, int ctimeout) | ||
2482 | 52 | +{ | ||
2483 | 53 | + int err; | ||
2484 | 54 | + struct timeval tv, *tvp = NULL; | ||
2485 | 55 | + fd_set connect_fdset; | ||
2486 | 56 | + socklen_t len; | ||
2487 | 57 | + int orig_flags; | ||
2488 | 58 | + | ||
2489 | 59 | + orig_flags = fcntl(fd, F_GETFL, 0); | ||
2490 | 60 | + if (fcntl(fd, F_SETFL, orig_flags | O_NONBLOCK) < 0 ) { | ||
2491 | 61 | + warn("can't set O_NONBLOCK - timeout not avaliable"); | ||
2492 | 62 | + if (connect(fd, sa, salen) == 0) | ||
2493 | 63 | + return CONNECTION_SUCCESS; | ||
2494 | 64 | + else | ||
2495 | 65 | + return CONNECTION_FAILED; | ||
2496 | 66 | + } | ||
2497 | 67 | + | ||
2498 | 68 | + /* set connect timeout */ | ||
2499 | 69 | + if (ctimeout > 0) { | ||
2500 | 70 | + tv.tv_sec = (time_t)ctimeout/1000; | ||
2501 | 71 | + tv.tv_usec = 0; | ||
2502 | 72 | + tvp = &tv; | ||
2503 | 73 | + } | ||
2504 | 74 | + | ||
2505 | 75 | + /* attempt the connection */ | ||
2506 | 76 | + err = connect(fd, sa, salen); | ||
2507 | 77 | + | ||
2508 | 78 | + if (err != 0 && errno == EINPROGRESS) { | ||
2509 | 79 | + /* connection is proceeding | ||
2510 | 80 | + * it is complete (or failed) when select returns */ | ||
2511 | 81 | + | ||
2512 | 82 | + /* initialize connect_fdset */ | ||
2513 | 83 | + FD_ZERO(&connect_fdset); | ||
2514 | 84 | + FD_SET(fd, &connect_fdset); | ||
2515 | 85 | + | ||
2516 | 86 | + /* call select */ | ||
2517 | 87 | + do { | ||
2518 | 88 | + err = select(fd + 1, NULL, &connect_fdset, | ||
2519 | 89 | + NULL, tvp); | ||
2520 | 90 | + } while (err < 0 && errno == EINTR); | ||
2521 | 91 | + | ||
2522 | 92 | + /* select error */ | ||
2523 | 93 | + if (err < 0) | ||
2524 | 94 | + errx(1,"select error: %s", strerror(errno)); | ||
2525 | 95 | + | ||
2526 | 96 | + /* we have reached a timeout */ | ||
2527 | 97 | + if (err == 0) | ||
2528 | 98 | + return CONNECTION_TIMEOUT; | ||
2529 | 99 | + | ||
2530 | 100 | + /* select returned successfully, but we must test socket | ||
2531 | 101 | + * error for result */ | ||
2532 | 102 | + len = sizeof(err); | ||
2533 | 103 | + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len) < 0) | ||
2534 | 104 | + errx(1, "getsockopt error: %s", strerror(errno)); | ||
2535 | 105 | + | ||
2536 | 106 | + /* setup errno according to the result returned by | ||
2537 | 107 | + * getsockopt */ | ||
2538 | 108 | + if (err != 0) | ||
2539 | 109 | + errno = err; | ||
2540 | 110 | + } | ||
2541 | 111 | + | ||
2542 | 112 | + /* return aborted if an error occured, and valid otherwise */ | ||
2543 | 113 | + fcntl(fd, F_SETFL, orig_flags); | ||
2544 | 114 | + return (err != 0)? CONNECTION_FAILED : CONNECTION_SUCCESS; | ||
2545 | 115 | +} | ||
2546 | 116 | + | ||
2547 | 117 | + | ||
2548 | 118 | /* | ||
2549 | 119 | * local_listen() | ||
2550 | 120 | * Returns a socket listening on a local port, binds to specified source | ||
2551 | 121 | 0 | ||
2552 | === removed file 'debian/patches/dccp.patch' | |||
2553 | --- debian/patches/dccp.patch 2011-06-11 14:31:06 +0000 | |||
2554 | +++ debian/patches/dccp.patch 1970-01-01 00:00:00 +0000 | |||
2555 | @@ -1,191 +0,0 @@ | |||
2556 | 1 | Index: netcat-openbsd-oneiric/netcat.c | ||
2557 | 2 | =================================================================== | ||
2558 | 3 | --- netcat-openbsd-oneiric.orig/netcat.c 2011-06-10 22:29:16.371916860 +0300 | ||
2559 | 4 | +++ netcat-openbsd-oneiric/netcat.c 2011-06-10 22:29:16.371916860 +0300 | ||
2560 | 5 | @@ -88,6 +88,7 @@ | ||
2561 | 6 | char *sflag; /* Source Address */ | ||
2562 | 7 | int tflag; /* Telnet Emulation */ | ||
2563 | 8 | int uflag; /* UDP - Default to TCP */ | ||
2564 | 9 | +int dccpflag; /* DCCP - Default to TCP */ | ||
2565 | 10 | int vflag; /* Verbosity */ | ||
2566 | 11 | int xflag; /* Socks proxy */ | ||
2567 | 12 | int zflag; /* Port Scan Flag */ | ||
2568 | 13 | @@ -113,6 +114,7 @@ | ||
2569 | 14 | void set_common_sockopts(int); | ||
2570 | 15 | int parse_iptos(char *); | ||
2571 | 16 | void usage(int); | ||
2572 | 17 | +char *proto_name(int uflag, int dccpflag); | ||
2573 | 18 | |||
2574 | 19 | static int connect_with_timeout(int fd, const struct sockaddr *sa, | ||
2575 | 20 | socklen_t salen, int ctimeout); | ||
2576 | 21 | @@ -140,7 +142,7 @@ | ||
2577 | 22 | sv = NULL; | ||
2578 | 23 | |||
2579 | 24 | while ((ch = getopt(argc, argv, | ||
2580 | 25 | - "46Ddhi:jklnP:p:q:rSs:tT:Uuvw:X:x:zC")) != -1) { | ||
2581 | 26 | + "46Ddhi:jklnP:p:q:rSs:tT:UuZvw:X:x:zC")) != -1) { | ||
2582 | 27 | switch (ch) { | ||
2583 | 28 | case '4': | ||
2584 | 29 | family = AF_INET; | ||
2585 | 30 | @@ -205,6 +207,9 @@ | ||
2586 | 31 | case 'u': | ||
2587 | 32 | uflag = 1; | ||
2588 | 33 | break; | ||
2589 | 34 | + case 'Z': | ||
2590 | 35 | + dccpflag = 1; | ||
2591 | 36 | + break; | ||
2592 | 37 | case 'v': | ||
2593 | 38 | vflag = 1; | ||
2594 | 39 | break; | ||
2595 | 40 | @@ -247,6 +252,9 @@ | ||
2596 | 41 | if (argv[0] && !argv[1] && family == AF_UNIX) { | ||
2597 | 42 | if (uflag) | ||
2598 | 43 | errx(1, "cannot use -u and -U"); | ||
2599 | 44 | + if (dccpflag) | ||
2600 | 45 | + errx(1, "cannot use -C and -U"); | ||
2601 | 46 | + | ||
2602 | 47 | host = argv[0]; | ||
2603 | 48 | uport = NULL; | ||
2604 | 49 | } else if (argv[0] && !argv[1]) { | ||
2605 | 50 | @@ -273,8 +281,18 @@ | ||
2606 | 51 | if (family != AF_UNIX) { | ||
2607 | 52 | memset(&hints, 0, sizeof(struct addrinfo)); | ||
2608 | 53 | hints.ai_family = family; | ||
2609 | 54 | - hints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM; | ||
2610 | 55 | - hints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP; | ||
2611 | 56 | + if (uflag) { | ||
2612 | 57 | + hints.ai_socktype = SOCK_DGRAM; | ||
2613 | 58 | + hints.ai_protocol = IPPROTO_UDP; | ||
2614 | 59 | + } | ||
2615 | 60 | + else if (dccpflag) { | ||
2616 | 61 | + hints.ai_socktype = SOCK_DCCP; | ||
2617 | 62 | + hints.ai_protocol = IPPROTO_DCCP; | ||
2618 | 63 | + } | ||
2619 | 64 | + else { | ||
2620 | 65 | + hints.ai_socktype = SOCK_STREAM; | ||
2621 | 66 | + hints.ai_protocol = IPPROTO_TCP; | ||
2622 | 67 | + } | ||
2623 | 68 | if (nflag) | ||
2624 | 69 | hints.ai_flags |= AI_NUMERICHOST; | ||
2625 | 70 | } | ||
2626 | 71 | @@ -283,6 +301,9 @@ | ||
2627 | 72 | if (uflag) | ||
2628 | 73 | errx(1, "no proxy support for UDP mode"); | ||
2629 | 74 | |||
2630 | 75 | + if (dccpflag) | ||
2631 | 76 | + errx(1, "no proxy support for DCCP mode"); | ||
2632 | 77 | + | ||
2633 | 78 | if (lflag) | ||
2634 | 79 | errx(1, "no proxy support for listen"); | ||
2635 | 80 | |||
2636 | 81 | @@ -348,17 +369,19 @@ | ||
2637 | 82 | } | ||
2638 | 83 | |||
2639 | 84 | if(vflag) { | ||
2640 | 85 | + char *proto = proto_name(uflag, dccpflag); | ||
2641 | 86 | + | ||
2642 | 87 | /* Don't look up port if -n. */ | ||
2643 | 88 | if (nflag) | ||
2644 | 89 | sv = NULL; | ||
2645 | 90 | else | ||
2646 | 91 | sv = getservbyport(ntohs(atoi(uport)), | ||
2647 | 92 | - uflag ? "udp" : "tcp"); | ||
2648 | 93 | + proto); | ||
2649 | 94 | |||
2650 | 95 | fprintf(stderr, "Connection from %s port %s [%s/%s] accepted\n", | ||
2651 | 96 | inet_ntoa(((struct sockaddr_in *)(&cliaddr))->sin_addr), | ||
2652 | 97 | uport, | ||
2653 | 98 | - uflag ? "udp" : "tcp", | ||
2654 | 99 | + proto, | ||
2655 | 100 | sv ? sv->s_name : "*"); | ||
2656 | 101 | } | ||
2657 | 102 | |||
2658 | 103 | @@ -503,6 +526,22 @@ | ||
2659 | 104 | return (s); | ||
2660 | 105 | } | ||
2661 | 106 | |||
2662 | 107 | +char *proto_name(uflag, dccpflag) { | ||
2663 | 108 | + | ||
2664 | 109 | + char *proto = NULL; | ||
2665 | 110 | + if (uflag) { | ||
2666 | 111 | + proto = "udp"; | ||
2667 | 112 | + } | ||
2668 | 113 | + else if (dccpflag) { | ||
2669 | 114 | + proto = "dccp"; | ||
2670 | 115 | + } | ||
2671 | 116 | + else { | ||
2672 | 117 | + proto = "tcp"; | ||
2673 | 118 | + } | ||
2674 | 119 | + | ||
2675 | 120 | + return proto; | ||
2676 | 121 | +} | ||
2677 | 122 | + | ||
2678 | 123 | /* | ||
2679 | 124 | * remote_connect() | ||
2680 | 125 | * Returns a socket connected to a remote host. Properly binds to a local | ||
2681 | 126 | @@ -529,8 +568,19 @@ | ||
2682 | 127 | |||
2683 | 128 | memset(&ahints, 0, sizeof(struct addrinfo)); | ||
2684 | 129 | ahints.ai_family = res0->ai_family; | ||
2685 | 130 | - ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM; | ||
2686 | 131 | - ahints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP; | ||
2687 | 132 | + if (uflag) { | ||
2688 | 133 | + ahints.ai_socktype = SOCK_DGRAM; | ||
2689 | 134 | + ahints.ai_protocol = IPPROTO_UDP; | ||
2690 | 135 | + | ||
2691 | 136 | + } | ||
2692 | 137 | + else if (dccpflag) { | ||
2693 | 138 | + ahints.ai_socktype = SOCK_DCCP; | ||
2694 | 139 | + ahints.ai_protocol = IPPROTO_DCCP; | ||
2695 | 140 | + } | ||
2696 | 141 | + else { | ||
2697 | 142 | + ahints.ai_socktype = SOCK_STREAM; | ||
2698 | 143 | + ahints.ai_protocol = IPPROTO_TCP; | ||
2699 | 144 | + } | ||
2700 | 145 | ahints.ai_flags = AI_PASSIVE; | ||
2701 | 146 | if ((error = getaddrinfo(sflag, pflag, &ahints, &ares))) | ||
2702 | 147 | errx(1, "getaddrinfo: %s", gai_strerror(error)); | ||
2703 | 148 | @@ -542,14 +592,19 @@ | ||
2704 | 149 | } | ||
2705 | 150 | |||
2706 | 151 | set_common_sockopts(s); | ||
2707 | 152 | - if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout)) == CONNECTION_SUCCESS) | ||
2708 | 153 | + char *proto = proto_name(uflag, dccpflag); | ||
2709 | 154 | + | ||
2710 | 155 | + if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout)) == CONNECTION_SUCCESS) { | ||
2711 | 156 | break; | ||
2712 | 157 | - else if (vflag && error == CONNECTION_FAILED) | ||
2713 | 158 | + } | ||
2714 | 159 | + else if (vflag && error == CONNECTION_FAILED) { | ||
2715 | 160 | warn("connect to %s port %s (%s) failed", host, port, | ||
2716 | 161 | - uflag ? "udp" : "tcp"); | ||
2717 | 162 | - else if (vflag && error == CONNECTION_TIMEOUT) | ||
2718 | 163 | + proto); | ||
2719 | 164 | + } | ||
2720 | 165 | + else if (vflag && error == CONNECTION_TIMEOUT) { | ||
2721 | 166 | warn("connect to %s port %s (%s) timed out", host, port, | ||
2722 | 167 | - uflag ? "udp" : "tcp"); | ||
2723 | 168 | + proto); | ||
2724 | 169 | + } | ||
2725 | 170 | |||
2726 | 171 | close(s); | ||
2727 | 172 | s = -1; | ||
2728 | 173 | @@ -817,8 +872,8 @@ | ||
2729 | 174 | char *n, *endp; | ||
2730 | 175 | int hi, lo, cp; | ||
2731 | 176 | int x = 0; | ||
2732 | 177 | - | ||
2733 | 178 | - sv = getservbyname(p, uflag ? "udp" : "tcp"); | ||
2734 | 179 | + char *proto = proto_name(uflag, dccpflag); | ||
2735 | 180 | + sv = getservbyname(p, proto); | ||
2736 | 181 | if (sv) { | ||
2737 | 182 | portlist[0] = calloc(1, PORT_MAX_LEN); | ||
2738 | 183 | if (portlist[0] == NULL) | ||
2739 | 184 | @@ -979,6 +1034,7 @@ | ||
2740 | 185 | \t-t Answer TELNET negotiation\n\ | ||
2741 | 186 | \t-U Use UNIX domain socket\n\ | ||
2742 | 187 | \t-u UDP mode\n\ | ||
2743 | 188 | + \t-Z DCCP mode\n\ | ||
2744 | 189 | \t-v Verbose\n\ | ||
2745 | 190 | \t-w secs\t Timeout for connects and final net reads\n\ | ||
2746 | 191 | \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\ | ||
2747 | 192 | 0 | ||
2748 | === removed file 'debian/patches/gcc-warnings.patch' | |||
2749 | --- debian/patches/gcc-warnings.patch 2008-01-30 18:24:46 +0000 | |||
2750 | +++ debian/patches/gcc-warnings.patch 1970-01-01 00:00:00 +0000 | |||
2751 | @@ -1,157 +0,0 @@ | |||
2752 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
2753 | 2 | =================================================================== | ||
2754 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 20:39:46.000000000 -0500 | ||
2755 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-01-22 20:42:35.000000000 -0500 | ||
2756 | 5 | @@ -127,7 +127,7 @@ | ||
2757 | 6 | struct servent *sv; | ||
2758 | 7 | socklen_t len; | ||
2759 | 8 | struct sockaddr_storage cliaddr; | ||
2760 | 9 | - char *proxy; | ||
2761 | 10 | + char *proxy = NULL; | ||
2762 | 11 | const char *proxyhost = "", *proxyport = NULL; | ||
2763 | 12 | struct addrinfo proxyhints; | ||
2764 | 13 | |||
2765 | 14 | @@ -800,14 +800,12 @@ | ||
2766 | 15 | obuf[1] = DONT; | ||
2767 | 16 | if ((*p == DO) || (*p == DONT)) | ||
2768 | 17 | obuf[1] = WONT; | ||
2769 | 18 | - if (obuf) { | ||
2770 | 19 | - p++; | ||
2771 | 20 | - obuf[2] = *p; | ||
2772 | 21 | - obuf[3] = '\0'; | ||
2773 | 22 | - if (atomicio(vwrite, nfd, obuf, 3) != 3) | ||
2774 | 23 | - warn("Write Error!"); | ||
2775 | 24 | - obuf[0] = '\0'; | ||
2776 | 25 | - } | ||
2777 | 26 | + p++; | ||
2778 | 27 | + obuf[2] = *p; | ||
2779 | 28 | + obuf[3] = '\0'; | ||
2780 | 29 | + if (atomicio(vwrite, nfd, obuf, 3) != 3) | ||
2781 | 30 | + warn("Write Error!"); | ||
2782 | 31 | + obuf[0] = '\0'; | ||
2783 | 32 | } | ||
2784 | 33 | } | ||
2785 | 34 | |||
2786 | 35 | Index: netcat-openbsd-1.89/socks.c | ||
2787 | 36 | =================================================================== | ||
2788 | 37 | --- netcat-openbsd-1.89.orig/socks.c 2008-01-22 20:36:26.000000000 -0500 | ||
2789 | 38 | +++ netcat-openbsd-1.89/socks.c 2008-01-22 20:39:46.000000000 -0500 | ||
2790 | 39 | @@ -169,11 +169,11 @@ | ||
2791 | 40 | buf[2] = SOCKS_NOAUTH; | ||
2792 | 41 | cnt = atomicio(vwrite, proxyfd, buf, 3); | ||
2793 | 42 | if (cnt != 3) | ||
2794 | 43 | - err(1, "write failed (%d/3)", cnt); | ||
2795 | 44 | + err(1, "write failed (%d/3)", (int)cnt); | ||
2796 | 45 | |||
2797 | 46 | cnt = atomicio(read, proxyfd, buf, 2); | ||
2798 | 47 | if (cnt != 2) | ||
2799 | 48 | - err(1, "read failed (%d/3)", cnt); | ||
2800 | 49 | + err(1, "read failed (%d/3)", (int)cnt); | ||
2801 | 50 | |||
2802 | 51 | if (buf[1] == SOCKS_NOMETHOD) | ||
2803 | 52 | errx(1, "authentication method negotiation failed"); | ||
2804 | 53 | @@ -222,11 +222,11 @@ | ||
2805 | 54 | |||
2806 | 55 | cnt = atomicio(vwrite, proxyfd, buf, wlen); | ||
2807 | 56 | if (cnt != wlen) | ||
2808 | 57 | - err(1, "write failed (%d/%d)", cnt, wlen); | ||
2809 | 58 | + err(1, "write failed (%d/%d)", (int)cnt, (int)wlen); | ||
2810 | 59 | |||
2811 | 60 | cnt = atomicio(read, proxyfd, buf, 10); | ||
2812 | 61 | if (cnt != 10) | ||
2813 | 62 | - err(1, "read failed (%d/10)", cnt); | ||
2814 | 63 | + err(1, "read failed (%d/10)", (int)cnt); | ||
2815 | 64 | if (buf[1] != 0) | ||
2816 | 65 | errx(1, "connection failed, SOCKS error %d", buf[1]); | ||
2817 | 66 | } else if (socksv == 4) { | ||
2818 | 67 | @@ -244,11 +244,11 @@ | ||
2819 | 68 | |||
2820 | 69 | cnt = atomicio(vwrite, proxyfd, buf, wlen); | ||
2821 | 70 | if (cnt != wlen) | ||
2822 | 71 | - err(1, "write failed (%d/%d)", cnt, wlen); | ||
2823 | 72 | + err(1, "write failed (%d/%d)", (int)cnt, (int)wlen); | ||
2824 | 73 | |||
2825 | 74 | cnt = atomicio(read, proxyfd, buf, 8); | ||
2826 | 75 | if (cnt != 8) | ||
2827 | 76 | - err(1, "read failed (%d/8)", cnt); | ||
2828 | 77 | + err(1, "read failed (%d/8)", (int)cnt); | ||
2829 | 78 | if (buf[1] != 90) | ||
2830 | 79 | errx(1, "connection failed, SOCKS error %d", buf[1]); | ||
2831 | 80 | } else if (socksv == -1) { | ||
2832 | 81 | @@ -260,39 +260,39 @@ | ||
2833 | 82 | |||
2834 | 83 | /* Try to be sane about numeric IPv6 addresses */ | ||
2835 | 84 | if (strchr(host, ':') != NULL) { | ||
2836 | 85 | - r = snprintf(buf, sizeof(buf), | ||
2837 | 86 | + r = snprintf((char*)buf, sizeof(buf), | ||
2838 | 87 | "CONNECT [%s]:%d HTTP/1.0\r\n", | ||
2839 | 88 | host, ntohs(serverport)); | ||
2840 | 89 | } else { | ||
2841 | 90 | - r = snprintf(buf, sizeof(buf), | ||
2842 | 91 | + r = snprintf((char*)buf, sizeof(buf), | ||
2843 | 92 | "CONNECT %s:%d HTTP/1.0\r\n", | ||
2844 | 93 | host, ntohs(serverport)); | ||
2845 | 94 | } | ||
2846 | 95 | if (r == -1 || (size_t)r >= sizeof(buf)) | ||
2847 | 96 | errx(1, "hostname too long"); | ||
2848 | 97 | - r = strlen(buf); | ||
2849 | 98 | + r = strlen((char*)buf); | ||
2850 | 99 | |||
2851 | 100 | cnt = atomicio(vwrite, proxyfd, buf, r); | ||
2852 | 101 | if (cnt != r) | ||
2853 | 102 | - err(1, "write failed (%d/%d)", cnt, r); | ||
2854 | 103 | + err(1, "write failed (%d/%d)", (int)cnt, (int)r); | ||
2855 | 104 | |||
2856 | 105 | if (authretry > 1) { | ||
2857 | 106 | char resp[1024]; | ||
2858 | 107 | |||
2859 | 108 | proxypass = getproxypass(proxyuser, proxyhost); | ||
2860 | 109 | - r = snprintf(buf, sizeof(buf), "%s:%s", | ||
2861 | 110 | + r = snprintf((char*)buf, sizeof(buf), "%s:%s", | ||
2862 | 111 | proxyuser, proxypass); | ||
2863 | 112 | if (r == -1 || (size_t)r >= sizeof(buf) || | ||
2864 | 113 | - b64_ntop(buf, strlen(buf), resp, | ||
2865 | 114 | + b64_ntop(buf, strlen((char*)buf), resp, | ||
2866 | 115 | sizeof(resp)) == -1) | ||
2867 | 116 | errx(1, "Proxy username/password too long"); | ||
2868 | 117 | - r = snprintf(buf, sizeof(buf), "Proxy-Authorization: " | ||
2869 | 118 | + r = snprintf((char*)buf, sizeof((char*)buf), "Proxy-Authorization: " | ||
2870 | 119 | "Basic %s\r\n", resp); | ||
2871 | 120 | if (r == -1 || (size_t)r >= sizeof(buf)) | ||
2872 | 121 | errx(1, "Proxy auth response too long"); | ||
2873 | 122 | - r = strlen(buf); | ||
2874 | 123 | + r = strlen((char*)buf); | ||
2875 | 124 | if ((cnt = atomicio(vwrite, proxyfd, buf, r)) != r) | ||
2876 | 125 | - err(1, "write failed (%d/%d)", cnt, r); | ||
2877 | 126 | + err(1, "write failed (%d/%d)", (int)cnt, r); | ||
2878 | 127 | } | ||
2879 | 128 | |||
2880 | 129 | /* Terminate headers */ | ||
2881 | 130 | @@ -300,22 +300,22 @@ | ||
2882 | 131 | err(1, "write failed (2/%d)", r); | ||
2883 | 132 | |||
2884 | 133 | /* Read status reply */ | ||
2885 | 134 | - proxy_read_line(proxyfd, buf, sizeof(buf)); | ||
2886 | 135 | + proxy_read_line(proxyfd, (char*)buf, sizeof(buf)); | ||
2887 | 136 | if (proxyuser != NULL && | ||
2888 | 137 | - strncmp(buf, "HTTP/1.0 407 ", 12) == 0) { | ||
2889 | 138 | + strncmp((char*)buf, "HTTP/1.0 407 ", 12) == 0) { | ||
2890 | 139 | if (authretry > 1) { | ||
2891 | 140 | fprintf(stderr, "Proxy authentication " | ||
2892 | 141 | "failed\n"); | ||
2893 | 142 | } | ||
2894 | 143 | close(proxyfd); | ||
2895 | 144 | goto again; | ||
2896 | 145 | - } else if (strncmp(buf, "HTTP/1.0 200 ", 12) != 0 && | ||
2897 | 146 | - strncmp(buf, "HTTP/1.1 200 ", 12) != 0) | ||
2898 | 147 | + } else if (strncmp((char*)buf, "HTTP/1.0 200 ", 12) != 0 && | ||
2899 | 148 | + strncmp((char*)buf, "HTTP/1.1 200 ", 12) != 0) | ||
2900 | 149 | errx(1, "Proxy error: \"%s\"", buf); | ||
2901 | 150 | |||
2902 | 151 | /* Headers continue until we hit an empty line */ | ||
2903 | 152 | for (r = 0; r < HTTP_MAXHDRS; r++) { | ||
2904 | 153 | - proxy_read_line(proxyfd, buf, sizeof(buf)); | ||
2905 | 154 | + proxy_read_line(proxyfd, (char*)buf, sizeof(buf)); | ||
2906 | 155 | if (*buf == '\0') | ||
2907 | 156 | break; | ||
2908 | 157 | } | ||
2909 | 158 | 0 | ||
2910 | === removed file 'debian/patches/getservbyname.patch' | |||
2911 | --- debian/patches/getservbyname.patch 2008-01-30 18:24:46 +0000 | |||
2912 | +++ debian/patches/getservbyname.patch 1970-01-01 00:00:00 +0000 | |||
2913 | @@ -1,24 +0,0 @@ | |||
2914 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
2915 | 2 | =================================================================== | ||
2916 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 20:39:46.000000000 -0500 | ||
2917 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-01-22 20:43:36.000000000 -0500 | ||
2918 | 5 | @@ -819,11 +819,18 @@ | ||
2919 | 6 | void | ||
2920 | 7 | build_ports(char *p) | ||
2921 | 8 | { | ||
2922 | 9 | + struct servent *sv; | ||
2923 | 10 | char *n, *endp; | ||
2924 | 11 | int hi, lo, cp; | ||
2925 | 12 | int x = 0; | ||
2926 | 13 | |||
2927 | 14 | - if ((n = strchr(p, '-')) != NULL) { | ||
2928 | 15 | + sv = getservbyname(p, uflag ? "udp" : "tcp"); | ||
2929 | 16 | + if (sv) { | ||
2930 | 17 | + portlist[0] = calloc(1, PORT_MAX_LEN); | ||
2931 | 18 | + if (portlist[0] == NULL) | ||
2932 | 19 | + err(1, NULL); | ||
2933 | 20 | + snprintf(portlist[0], PORT_MAX_LEN, "%d", ntohs(sv->s_port)); | ||
2934 | 21 | + } else if ((n = strchr(p, '-')) != NULL) { | ||
2935 | 22 | if (lflag) | ||
2936 | 23 | errx(1, "Cannot use -l with multiple ports!"); | ||
2937 | 24 | |||
2938 | 25 | 0 | ||
2939 | === removed file 'debian/patches/glib-strlcpy.patch' | |||
2940 | --- debian/patches/glib-strlcpy.patch 2008-01-30 18:24:46 +0000 | |||
2941 | +++ debian/patches/glib-strlcpy.patch 1970-01-01 00:00:00 +0000 | |||
2942 | @@ -1,96 +0,0 @@ | |||
2943 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
2944 | 2 | =================================================================== | ||
2945 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2007-02-20 09:11:17.000000000 -0500 | ||
2946 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-01-21 18:48:23.000000000 -0500 | ||
2947 | 5 | @@ -55,6 +55,8 @@ | ||
2948 | 6 | #include <limits.h> | ||
2949 | 7 | #include "atomicio.h" | ||
2950 | 8 | |||
2951 | 9 | +#include <glib.h> | ||
2952 | 10 | + | ||
2953 | 11 | #ifndef SUN_LEN | ||
2954 | 12 | #define SUN_LEN(su) \ | ||
2955 | 13 | (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) | ||
2956 | 14 | @@ -414,7 +416,7 @@ | ||
2957 | 15 | memset(&sun, 0, sizeof(struct sockaddr_un)); | ||
2958 | 16 | sun.sun_family = AF_UNIX; | ||
2959 | 17 | |||
2960 | 18 | - if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= | ||
2961 | 19 | + if (g_strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= | ||
2962 | 20 | sizeof(sun.sun_path)) { | ||
2963 | 21 | close(s); | ||
2964 | 22 | errno = ENAMETOOLONG; | ||
2965 | 23 | @@ -445,7 +447,7 @@ | ||
2966 | 24 | memset(&sun, 0, sizeof(struct sockaddr_un)); | ||
2967 | 25 | sun.sun_family = AF_UNIX; | ||
2968 | 26 | |||
2969 | 27 | - if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= | ||
2970 | 28 | + if (g_strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= | ||
2971 | 29 | sizeof(sun.sun_path)) { | ||
2972 | 30 | close(s); | ||
2973 | 31 | errno = ENAMETOOLONG; | ||
2974 | 32 | @@ -549,11 +551,11 @@ | ||
2975 | 33 | if ((s = socket(res0->ai_family, res0->ai_socktype, | ||
2976 | 34 | res0->ai_protocol)) < 0) | ||
2977 | 35 | continue; | ||
2978 | 36 | - | ||
2979 | 37 | + #ifdef SO_REUSEPORT | ||
2980 | 38 | ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); | ||
2981 | 39 | if (ret == -1) | ||
2982 | 40 | err(1, NULL); | ||
2983 | 41 | - | ||
2984 | 42 | + #endif | ||
2985 | 43 | set_common_sockopts(s); | ||
2986 | 44 | |||
2987 | 45 | if (bind(s, (struct sockaddr *)res0->ai_addr, | ||
2988 | 46 | @@ -719,7 +721,8 @@ | ||
2989 | 47 | char *c; | ||
2990 | 48 | |||
2991 | 49 | for (x = 0; x <= (hi - lo); x++) { | ||
2992 | 50 | - y = (arc4random() & 0xFFFF) % (hi - lo); | ||
2993 | 51 | + /* use random instead of arc4random */ | ||
2994 | 52 | + y = (random() & 0xFFFF) % (hi - lo); | ||
2995 | 53 | c = portlist[x]; | ||
2996 | 54 | portlist[x] = portlist[y]; | ||
2997 | 55 | portlist[y] = c; | ||
2998 | 56 | @@ -761,21 +764,25 @@ | ||
2999 | 57 | { | ||
3000 | 58 | int x = 1; | ||
3001 | 59 | |||
3002 | 60 | +#ifdef TCP_MD5SIG | ||
3003 | 61 | if (Sflag) { | ||
3004 | 62 | if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG, | ||
3005 | 63 | &x, sizeof(x)) == -1) | ||
3006 | 64 | err(1, NULL); | ||
3007 | 65 | } | ||
3008 | 66 | +#endif | ||
3009 | 67 | if (Dflag) { | ||
3010 | 68 | if (setsockopt(s, SOL_SOCKET, SO_DEBUG, | ||
3011 | 69 | &x, sizeof(x)) == -1) | ||
3012 | 70 | err(1, NULL); | ||
3013 | 71 | } | ||
3014 | 72 | +#ifdef SO_JUMBO | ||
3015 | 73 | if (jflag) { | ||
3016 | 74 | if (setsockopt(s, SOL_SOCKET, SO_JUMBO, | ||
3017 | 75 | &x, sizeof(x)) == -1) | ||
3018 | 76 | err(1, NULL); | ||
3019 | 77 | } | ||
3020 | 78 | +#endif | ||
3021 | 79 | if (Tflag != -1) { | ||
3022 | 80 | if (setsockopt(s, IPPROTO_IP, IP_TOS, | ||
3023 | 81 | &Tflag, sizeof(Tflag)) == -1) | ||
3024 | 82 | @@ -816,9 +823,11 @@ | ||
3025 | 83 | \t-n Suppress name/port resolutions\n\ | ||
3026 | 84 | \t-P proxyuser\tUsername for proxy authentication\n\ | ||
3027 | 85 | \t-p port\t Specify local port for remote connects\n\ | ||
3028 | 86 | - \t-r Randomize remote ports\n\ | ||
3029 | 87 | - \t-S Enable the TCP MD5 signature option\n\ | ||
3030 | 88 | - \t-s addr\t Local source address\n\ | ||
3031 | 89 | + \t-r Randomize remote ports\n " | ||
3032 | 90 | +#ifdef TCP_MD5SIG | ||
3033 | 91 | +" \t-S Enable the TCP MD5 signature option\n" | ||
3034 | 92 | +#endif | ||
3035 | 93 | +" \t-s addr\t Local source address\n\ | ||
3036 | 94 | \t-T ToS\t Set IP Type of Service\n\ | ||
3037 | 95 | \t-t Answer TELNET negotiation\n\ | ||
3038 | 96 | \t-U Use UNIX domain socket\n\ | ||
3039 | 97 | 0 | ||
3040 | === removed file 'debian/patches/help-version-exit.patch' | |||
3041 | --- debian/patches/help-version-exit.patch 2008-01-30 18:24:46 +0000 | |||
3042 | +++ debian/patches/help-version-exit.patch 1970-01-01 00:00:00 +0000 | |||
3043 | @@ -1,21 +0,0 @@ | |||
3044 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
3045 | 2 | =================================================================== | ||
3046 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2008-01-25 13:14:34.000000000 -0500 | ||
3047 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-01-25 13:15:49.000000000 -0500 | ||
3048 | 5 | @@ -937,6 +937,7 @@ | ||
3049 | 6 | void | ||
3050 | 7 | help(void) | ||
3051 | 8 | { | ||
3052 | 9 | + fprintf(stderr, "OpenBSD netcat (Debian patchlevel " DEBIAN_VERSION ")\n"); | ||
3053 | 10 | usage(0); | ||
3054 | 11 | fprintf(stderr, "\tCommand Summary:\n\ | ||
3055 | 12 | \t-4 Use IPv4\n\ | ||
3056 | 13 | @@ -966,7 +967,7 @@ | ||
3057 | 14 | \t-x addr[:port]\tSpecify proxy address and port\n\ | ||
3058 | 15 | \t-z Zero-I/O mode [used for scanning]\n\ | ||
3059 | 16 | Port numbers can be individual or ranges: lo-hi [inclusive]\n"); | ||
3060 | 17 | - exit(1); | ||
3061 | 18 | + exit(0); | ||
3062 | 19 | } | ||
3063 | 20 | |||
3064 | 21 | void | ||
3065 | 22 | 0 | ||
3066 | === removed file 'debian/patches/nc-1.84-udp_stop.patch' | |||
3067 | --- debian/patches/nc-1.84-udp_stop.patch 2008-01-30 18:24:46 +0000 | |||
3068 | +++ debian/patches/nc-1.84-udp_stop.patch 1970-01-01 00:00:00 +0000 | |||
3069 | @@ -1,14 +0,0 @@ | |||
3070 | 1 | Index: netcat-1.84/netcat.c | ||
3071 | 2 | =================================================================== | ||
3072 | 3 | --- netcat-1.84.orig/netcat.c 2008-01-15 10:10:22.373351813 +0100 | ||
3073 | 4 | +++ netcat-1.84/netcat.c 2008-01-15 10:10:24.840730278 +0100 | ||
3074 | 5 | @@ -799,6 +799,9 @@ | ||
3075 | 6 | hi = lo; | ||
3076 | 7 | lo = cp; | ||
3077 | 8 | } | ||
3078 | 9 | + else if (pfd[0].revents & POLLERR) | ||
3079 | 10 | + if (write(nfd, "", 1) == -1) | ||
3080 | 11 | + warn("Write error"); | ||
3081 | 12 | |||
3082 | 13 | /* Load ports sequentially. */ | ||
3083 | 14 | for (cp = lo; cp <= hi; cp++) { | ||
3084 | 15 | 0 | ||
3085 | === modified file 'debian/patches/netcat-info.patch' | |||
3086 | --- debian/patches/netcat-info.patch 2011-01-04 14:31:12 +0000 | |||
3087 | +++ debian/patches/netcat-info.patch 2012-05-30 22:10:23 +0000 | |||
3088 | @@ -1,12 +1,13 @@ | |||
3093 | 1 | diff -Naurp netcat-openbsd-1.89.orig//netcat.c netcat-openbsd-1.89/netcat.c | 1 | Index: netcat-openbsd/netcat.c |
3094 | 2 | --- netcat-openbsd-1.89.orig//netcat.c 2011-01-04 13:54:23.707910134 -0500 | 2 | =================================================================== |
3095 | 3 | +++ netcat-openbsd-1.89/netcat.c 2011-01-04 14:12:50.499950473 -0500 | 3 | --- netcat-openbsd.orig/netcat.c 2012-05-30 14:44:13.000000000 -0700 |
3096 | 4 | @@ -995,6 +995,8 @@ help(void) | 4 | +++ netcat-openbsd/netcat.c 2012-05-30 14:46:35.810792514 -0700 |
3097 | 5 | @@ -1373,6 +1373,8 @@ | ||
3098 | 5 | void | 6 | void |
3099 | 6 | usage(int ret) | 7 | usage(int ret) |
3100 | 7 | { | 8 | { |
3101 | 8 | + fprintf(stderr, "This is nc from the netcat-openbsd package. An alternative nc is available\n"); | 9 | + fprintf(stderr, "This is nc from the netcat-openbsd package. An alternative nc is available\n"); |
3102 | 9 | + fprintf(stderr, "in the netcat-traditional package.\n"); | 10 | + fprintf(stderr, "in the netcat-traditional package.\n"); |
3106 | 10 | fprintf(stderr, "usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]\n"); | 11 | fprintf(stderr, |
3107 | 11 | fprintf(stderr, "\t [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]\n"); | 12 | "usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length]\n" |
3108 | 12 | fprintf(stderr, "\t [-x proxy_address[:port]] [hostname] [port[s]]\n"); | 13 | "\t [-P proxy_username] [-p source_port] [-q seconds] [-s source]\n" |
3109 | 13 | 14 | ||
3110 | === removed file 'debian/patches/no-strtonum.patch' | |||
3111 | --- debian/patches/no-strtonum.patch 2008-01-30 18:24:46 +0000 | |||
3112 | +++ debian/patches/no-strtonum.patch 1970-01-01 00:00:00 +0000 | |||
3113 | @@ -1,107 +0,0 @@ | |||
3114 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
3115 | 2 | =================================================================== | ||
3116 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:17.000000000 -0500 | ||
3117 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:18.000000000 -0500 | ||
3118 | 5 | @@ -67,7 +67,7 @@ | ||
3119 | 6 | |||
3120 | 7 | /* Command Line Options */ | ||
3121 | 8 | int dflag; /* detached, no stdin */ | ||
3122 | 9 | -unsigned int iflag; /* Interval Flag */ | ||
3123 | 10 | +int iflag; /* Interval Flag */ | ||
3124 | 11 | int jflag; /* use jumbo frames if we can */ | ||
3125 | 12 | int kflag; /* More than one connect */ | ||
3126 | 13 | int lflag; /* Bind to local port */ | ||
3127 | 14 | @@ -108,13 +108,13 @@ | ||
3128 | 15 | main(int argc, char *argv[]) | ||
3129 | 16 | { | ||
3130 | 17 | int ch, s, ret, socksv; | ||
3131 | 18 | - char *host, *uport; | ||
3132 | 19 | + char *host, *uport, *endp; | ||
3133 | 20 | struct addrinfo hints; | ||
3134 | 21 | struct servent *sv; | ||
3135 | 22 | socklen_t len; | ||
3136 | 23 | struct sockaddr_storage cliaddr; | ||
3137 | 24 | char *proxy; | ||
3138 | 25 | - const char *errstr, *proxyhost = "", *proxyport = NULL; | ||
3139 | 26 | + const char *proxyhost = "", *proxyport = NULL; | ||
3140 | 27 | struct addrinfo proxyhints; | ||
3141 | 28 | |||
3142 | 29 | ret = 1; | ||
3143 | 30 | @@ -122,6 +122,7 @@ | ||
3144 | 31 | socksv = 5; | ||
3145 | 32 | host = NULL; | ||
3146 | 33 | uport = NULL; | ||
3147 | 34 | + endp = NULL; | ||
3148 | 35 | sv = NULL; | ||
3149 | 36 | |||
3150 | 37 | while ((ch = getopt(argc, argv, | ||
3151 | 38 | @@ -153,9 +154,9 @@ | ||
3152 | 39 | help(); | ||
3153 | 40 | break; | ||
3154 | 41 | case 'i': | ||
3155 | 42 | - iflag = strtonum(optarg, 0, UINT_MAX, &errstr); | ||
3156 | 43 | - if (errstr) | ||
3157 | 44 | - errx(1, "interval %s: %s", errstr, optarg); | ||
3158 | 45 | + iflag = (int)strtoul(optarg, &endp, 10); | ||
3159 | 46 | + if (iflag < 0 || *endp != '\0') | ||
3160 | 47 | + errx(1, "interval cannot be negative"); | ||
3161 | 48 | break; | ||
3162 | 49 | case 'j': | ||
3163 | 50 | jflag = 1; | ||
3164 | 51 | @@ -191,9 +192,11 @@ | ||
3165 | 52 | vflag = 1; | ||
3166 | 53 | break; | ||
3167 | 54 | case 'w': | ||
3168 | 55 | - timeout = strtonum(optarg, 0, INT_MAX / 1000, &errstr); | ||
3169 | 56 | - if (errstr) | ||
3170 | 57 | - errx(1, "timeout %s: %s", errstr, optarg); | ||
3171 | 58 | + timeout = (int)strtoul(optarg, &endp, 10); | ||
3172 | 59 | + if (timeout < 0 || *endp != '\0') | ||
3173 | 60 | + errx(1, "timeout cannot be negative"); | ||
3174 | 61 | + if (timeout >= (INT_MAX / 1000)) | ||
3175 | 62 | + errx(1, "timeout too large"); | ||
3176 | 63 | timeout *= 1000; | ||
3177 | 64 | break; | ||
3178 | 65 | case 'x': | ||
3179 | 66 | @@ -680,8 +683,7 @@ | ||
3180 | 67 | void | ||
3181 | 68 | build_ports(char *p) | ||
3182 | 69 | { | ||
3183 | 70 | - const char *errstr; | ||
3184 | 71 | - char *n; | ||
3185 | 72 | + char *n, *endp; | ||
3186 | 73 | int hi, lo, cp; | ||
3187 | 74 | int x = 0; | ||
3188 | 75 | |||
3189 | 76 | @@ -693,12 +695,12 @@ | ||
3190 | 77 | n++; | ||
3191 | 78 | |||
3192 | 79 | /* Make sure the ports are in order: lowest->highest. */ | ||
3193 | 80 | - hi = strtonum(n, 1, PORT_MAX, &errstr); | ||
3194 | 81 | - if (errstr) | ||
3195 | 82 | - errx(1, "port number %s: %s", errstr, n); | ||
3196 | 83 | - lo = strtonum(p, 1, PORT_MAX, &errstr); | ||
3197 | 84 | - if (errstr) | ||
3198 | 85 | - errx(1, "port number %s: %s", errstr, p); | ||
3199 | 86 | + hi = (int)strtoul(n, &endp, 10); | ||
3200 | 87 | + if (hi <= 0 || hi > PORT_MAX || *endp != '\0') | ||
3201 | 88 | + errx(1, "port range not valid"); | ||
3202 | 89 | + lo = (int)strtoul(p, &endp, 10); | ||
3203 | 90 | + if (lo <= 0 || lo > PORT_MAX || *endp != '\0') | ||
3204 | 91 | + errx(1, "port range not valid"); | ||
3205 | 92 | |||
3206 | 93 | if (lo > hi) { | ||
3207 | 94 | cp = hi; | ||
3208 | 95 | @@ -729,9 +731,9 @@ | ||
3209 | 96 | } | ||
3210 | 97 | } | ||
3211 | 98 | } else { | ||
3212 | 99 | - hi = strtonum(p, 1, PORT_MAX, &errstr); | ||
3213 | 100 | - if (errstr) | ||
3214 | 101 | - errx(1, "port number %s: %s", errstr, p); | ||
3215 | 102 | + hi = (int)strtoul(p, &endp, 10); | ||
3216 | 103 | + if (hi <= 0 || hi > PORT_MAX || *endp != '\0') | ||
3217 | 104 | + errx(1, "port range not valid"); | ||
3218 | 105 | portlist[0] = calloc(1, PORT_MAX_LEN); | ||
3219 | 106 | if (portlist[0] == NULL) | ||
3220 | 107 | err(1, NULL); | ||
3221 | 108 | 0 | ||
3222 | === removed file 'debian/patches/openbsd-compat.patch' | |||
3223 | --- debian/patches/openbsd-compat.patch 2008-01-30 18:24:46 +0000 | |||
3224 | +++ debian/patches/openbsd-compat.patch 1970-01-01 00:00:00 +0000 | |||
3225 | @@ -1,54 +0,0 @@ | |||
3226 | 1 | Index: netcat-openbsd-1.89/openbsd-compat/readpassphrase.c | ||
3227 | 2 | =================================================================== | ||
3228 | 3 | --- netcat-openbsd-1.89.orig/openbsd-compat/readpassphrase.c 2008-01-22 18:21:56.000000000 -0500 | ||
3229 | 4 | +++ netcat-openbsd-1.89/openbsd-compat/readpassphrase.c 2008-01-22 18:22:58.000000000 -0500 | ||
3230 | 5 | @@ -31,6 +31,12 @@ | ||
3231 | 6 | #include <unistd.h> | ||
3232 | 7 | #include <readpassphrase.h> | ||
3233 | 8 | |||
3234 | 9 | +#ifdef TCSASOFT | ||
3235 | 10 | +# define _T_FLUSH (TCSAFLUSH|TCSASOFT) | ||
3236 | 11 | +#else | ||
3237 | 12 | +# define _T_FLUSH (TCSAFLUSH) | ||
3238 | 13 | +#endif | ||
3239 | 14 | + | ||
3240 | 15 | static volatile sig_atomic_t signo; | ||
3241 | 16 | |||
3242 | 17 | static void handler(int); | ||
3243 | 18 | @@ -92,9 +98,11 @@ | ||
3244 | 19 | memcpy(&term, &oterm, sizeof(term)); | ||
3245 | 20 | if (!(flags & RPP_ECHO_ON)) | ||
3246 | 21 | term.c_lflag &= ~(ECHO | ECHONL); | ||
3247 | 22 | +#ifdef VSTATUS | ||
3248 | 23 | if (term.c_cc[VSTATUS] != _POSIX_VDISABLE) | ||
3249 | 24 | term.c_cc[VSTATUS] = _POSIX_VDISABLE; | ||
3250 | 25 | - (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term); | ||
3251 | 26 | +#endif | ||
3252 | 27 | + (void)tcsetattr(input, _T_FLUSH, &term); | ||
3253 | 28 | } else { | ||
3254 | 29 | memset(&term, 0, sizeof(term)); | ||
3255 | 30 | term.c_lflag |= ECHO; | ||
3256 | 31 | @@ -129,7 +137,7 @@ | ||
3257 | 32 | |||
3258 | 33 | /* Restore old terminal settings and signals. */ | ||
3259 | 34 | if (memcmp(&term, &oterm, sizeof(term)) != 0) { | ||
3260 | 35 | - while (tcsetattr(input, TCSAFLUSH|TCSASOFT, &oterm) == -1 && | ||
3261 | 36 | + while (tcsetattr(input, _T_FLUSH, &oterm) == -1 && | ||
3262 | 37 | errno == EINTR) | ||
3263 | 38 | continue; | ||
3264 | 39 | } | ||
3265 | 40 | @@ -164,14 +172,6 @@ | ||
3266 | 41 | return(nr == -1 ? NULL : buf); | ||
3267 | 42 | } | ||
3268 | 43 | |||
3269 | 44 | -char * | ||
3270 | 45 | -getpass(const char *prompt) | ||
3271 | 46 | -{ | ||
3272 | 47 | - static char buf[_PASSWORD_LEN + 1]; | ||
3273 | 48 | - | ||
3274 | 49 | - return(readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF)); | ||
3275 | 50 | -} | ||
3276 | 51 | - | ||
3277 | 52 | static void handler(int s) | ||
3278 | 53 | { | ||
3279 | 54 | |||
3280 | 55 | 0 | ||
3281 | === removed file 'debian/patches/pollhup.patch' | |||
3282 | --- debian/patches/pollhup.patch 2008-01-30 18:24:46 +0000 | |||
3283 | +++ debian/patches/pollhup.patch 1970-01-01 00:00:00 +0000 | |||
3284 | @@ -1,50 +0,0 @@ | |||
3285 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
3286 | 2 | =================================================================== | ||
3287 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:18.000000000 -0500 | ||
3288 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:25.000000000 -0500 | ||
3289 | 5 | @@ -618,9 +618,7 @@ | ||
3290 | 6 | if ((n = read(nfd, buf, plen)) < 0) | ||
3291 | 7 | return; | ||
3292 | 8 | else if (n == 0) { | ||
3293 | 9 | - shutdown(nfd, SHUT_RD); | ||
3294 | 10 | - pfd[0].fd = -1; | ||
3295 | 11 | - pfd[0].events = 0; | ||
3296 | 12 | + goto shutdown_rd; | ||
3297 | 13 | } else { | ||
3298 | 14 | if (tflag) | ||
3299 | 15 | atelnet(nfd, buf, n); | ||
3300 | 16 | @@ -628,18 +626,30 @@ | ||
3301 | 17 | return; | ||
3302 | 18 | } | ||
3303 | 19 | } | ||
3304 | 20 | + else if (pfd[0].revents & POLLHUP) { | ||
3305 | 21 | + shutdown_rd: | ||
3306 | 22 | + shutdown(nfd, SHUT_RD); | ||
3307 | 23 | + pfd[0].fd = -1; | ||
3308 | 24 | + pfd[0].events = 0; | ||
3309 | 25 | + } | ||
3310 | 26 | |||
3311 | 27 | - if (!dflag && pfd[1].revents & POLLIN) { | ||
3312 | 28 | + if (!dflag) { | ||
3313 | 29 | + if(pfd[1].revents & POLLIN) { | ||
3314 | 30 | if ((n = read(wfd, buf, plen)) < 0) | ||
3315 | 31 | return; | ||
3316 | 32 | else if (n == 0) { | ||
3317 | 33 | - shutdown(nfd, SHUT_WR); | ||
3318 | 34 | - pfd[1].fd = -1; | ||
3319 | 35 | - pfd[1].events = 0; | ||
3320 | 36 | + goto shutdown_wr; | ||
3321 | 37 | } else { | ||
3322 | 38 | if (atomicio(vwrite, nfd, buf, n) != n) | ||
3323 | 39 | return; | ||
3324 | 40 | } | ||
3325 | 41 | + } | ||
3326 | 42 | + else if (pfd[1].revents & POLLHUP) { | ||
3327 | 43 | + shutdown_wr: | ||
3328 | 44 | + shutdown(nfd, SHUT_WR); | ||
3329 | 45 | + pfd[1].fd = -1; | ||
3330 | 46 | + pfd[1].events = 0; | ||
3331 | 47 | + } | ||
3332 | 48 | } | ||
3333 | 49 | } | ||
3334 | 50 | } | ||
3335 | 51 | 0 | ||
3336 | === removed file 'debian/patches/quit-timer.patch' | |||
3337 | --- debian/patches/quit-timer.patch 2011-06-30 11:55:43 +0000 | |||
3338 | +++ debian/patches/quit-timer.patch 1970-01-01 00:00:00 +0000 | |||
3339 | @@ -1,84 +0,0 @@ | |||
3340 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
3341 | 2 | =================================================================== | ||
3342 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2010-04-18 20:02:55.240980186 -0400 | ||
3343 | 4 | +++ netcat-openbsd-1.89/netcat.c 2010-04-18 20:04:41.987984568 -0400 | ||
3344 | 5 | @@ -47,6 +47,7 @@ | ||
3345 | 6 | #include <errno.h> | ||
3346 | 7 | #include <netdb.h> | ||
3347 | 8 | #include <poll.h> | ||
3348 | 9 | +#include <signal.h> | ||
3349 | 10 | #include <stdarg.h> | ||
3350 | 11 | #include <stdio.h> | ||
3351 | 12 | #include <stdlib.h> | ||
3352 | 13 | @@ -82,6 +83,7 @@ | ||
3353 | 14 | int nflag; /* Don't do name look up */ | ||
3354 | 15 | char *Pflag; /* Proxy username */ | ||
3355 | 16 | char *pflag; /* Localport flag */ | ||
3356 | 17 | +int qflag = -1; /* Quit after some secs */ | ||
3357 | 18 | int rflag; /* Random ports flag */ | ||
3358 | 19 | char *sflag; /* Source Address */ | ||
3359 | 20 | int tflag; /* Telnet Emulation */ | ||
3360 | 21 | @@ -114,6 +116,7 @@ | ||
3361 | 22 | |||
3362 | 23 | static int connect_with_timeout(int fd, const struct sockaddr *sa, | ||
3363 | 24 | socklen_t salen, int ctimeout); | ||
3364 | 25 | +static void quit(); | ||
3365 | 26 | |||
3366 | 27 | int | ||
3367 | 28 | main(int argc, char *argv[]) | ||
3368 | 29 | @@ -137,7 +140,7 @@ | ||
3369 | 30 | sv = NULL; | ||
3370 | 31 | |||
3371 | 32 | while ((ch = getopt(argc, argv, | ||
3372 | 33 | - "46Ddhi:jklnP:p:rSs:tT:Uuvw:X:x:zC")) != -1) { | ||
3373 | 34 | + "46Ddhi:jklnP:p:q:rSs:tT:Uuvw:X:x:zC")) != -1) { | ||
3374 | 35 | switch (ch) { | ||
3375 | 36 | case '4': | ||
3376 | 37 | family = AF_INET; | ||
3377 | 38 | @@ -187,6 +190,9 @@ | ||
3378 | 39 | case 'p': | ||
3379 | 40 | pflag = optarg; | ||
3380 | 41 | break; | ||
3381 | 42 | + case 'q': | ||
3382 | 43 | + qflag = (int)strtoul(optarg, &endp, 10); | ||
3383 | 44 | + break; | ||
3384 | 45 | case 'r': | ||
3385 | 46 | rflag = 1; | ||
3386 | 47 | break; | ||
3387 | 48 | @@ -756,7 +762,13 @@ | ||
3388 | 49 | } | ||
3389 | 50 | else if (pfd[1].revents & POLLHUP) { | ||
3390 | 51 | shutdown_wr: | ||
3391 | 52 | - shutdown(nfd, SHUT_WR); | ||
3392 | 53 | + /* if user asked to die after a while, arrange for it */ | ||
3393 | 54 | + if (qflag > 0) { | ||
3394 | 55 | + signal(SIGALRM, quit); | ||
3395 | 56 | + alarm(qflag); | ||
3396 | 57 | + } else { | ||
3397 | 58 | + shutdown(nfd, SHUT_WR); | ||
3398 | 59 | + } | ||
3399 | 60 | pfd[1].fd = -1; | ||
3400 | 61 | pfd[1].events = 0; | ||
3401 | 62 | } | ||
3402 | 63 | @@ -951,6 +963,7 @@ | ||
3403 | 64 | \t-n Suppress name/port resolutions\n\ | ||
3404 | 65 | \t-P proxyuser\tUsername for proxy authentication\n\ | ||
3405 | 66 | \t-p port\t Specify local port for remote connects\n\ | ||
3406 | 67 | + \t-q secs\t quit after EOF on stdin and delay of secs\n\ | ||
3407 | 68 | \t-r Randomize remote ports\n " | ||
3408 | 69 | #ifdef TCP_MD5SIG | ||
3409 | 70 | " \t-S Enable the TCP MD5 signature option\n" | ||
3410 | 71 | @@ -979,3 +992,13 @@ | ||
3411 | 72 | if (ret) | ||
3412 | 73 | exit(1); | ||
3413 | 74 | } | ||
3414 | 75 | + | ||
3415 | 76 | +/* | ||
3416 | 77 | + * quit() | ||
3417 | 78 | + * handler for a "-q" timeout (exit 0 instead of 1) | ||
3418 | 79 | + */ | ||
3419 | 80 | +static void quit() | ||
3420 | 81 | +{ | ||
3421 | 82 | + /* XXX: should explicitly close fds here */ | ||
3422 | 83 | + exit(0); | ||
3423 | 84 | +} | ||
3424 | 85 | 0 | ||
3425 | === removed file 'debian/patches/reuseaddr.patch' | |||
3426 | --- debian/patches/reuseaddr.patch 2008-01-30 18:24:46 +0000 | |||
3427 | +++ debian/patches/reuseaddr.patch 1970-01-01 00:00:00 +0000 | |||
3428 | @@ -1,15 +0,0 @@ | |||
3429 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
3430 | 2 | =================================================================== | ||
3431 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:25.000000000 -0500 | ||
3432 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:27.000000000 -0500 | ||
3433 | 5 | @@ -554,6 +554,10 @@ | ||
3434 | 6 | if ((s = socket(res0->ai_family, res0->ai_socktype, | ||
3435 | 7 | res0->ai_protocol)) < 0) | ||
3436 | 8 | continue; | ||
3437 | 9 | + | ||
3438 | 10 | + ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)); | ||
3439 | 11 | + if (ret == -1) | ||
3440 | 12 | + err(1, NULL); | ||
3441 | 13 | #ifdef SO_REUSEPORT | ||
3442 | 14 | ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); | ||
3443 | 15 | if (ret == -1) | ||
3444 | 16 | 0 | ||
3445 | === removed file 'debian/patches/send-crlf.patch' | |||
3446 | --- debian/patches/send-crlf.patch 2008-06-19 16:20:01 +0000 | |||
3447 | +++ debian/patches/send-crlf.patch 1970-01-01 00:00:00 +0000 | |||
3448 | @@ -1,109 +0,0 @@ | |||
3449 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
3450 | 2 | =================================================================== | ||
3451 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2008-06-19 16:49:57.000000000 -0400 | ||
3452 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-06-19 17:04:22.000000000 -0400 | ||
3453 | 5 | @@ -73,6 +73,7 @@ | ||
3454 | 6 | #define UDP_SCAN_TIMEOUT 3 /* Seconds */ | ||
3455 | 7 | |||
3456 | 8 | /* Command Line Options */ | ||
3457 | 9 | +int Cflag = 0; /* CRLF line-ending */ | ||
3458 | 10 | int dflag; /* detached, no stdin */ | ||
3459 | 11 | int iflag; /* Interval Flag */ | ||
3460 | 12 | int jflag; /* use jumbo frames if we can */ | ||
3461 | 13 | @@ -136,7 +137,7 @@ | ||
3462 | 14 | sv = NULL; | ||
3463 | 15 | |||
3464 | 16 | while ((ch = getopt(argc, argv, | ||
3465 | 17 | - "46Ddhi:jklnP:p:rSs:tT:Uuvw:X:x:z")) != -1) { | ||
3466 | 18 | + "46Ddhi:jklnP:p:rSs:tT:Uuvw:X:x:zC")) != -1) { | ||
3467 | 19 | switch (ch) { | ||
3468 | 20 | case '4': | ||
3469 | 21 | family = AF_INET; | ||
3470 | 22 | @@ -226,6 +227,9 @@ | ||
3471 | 23 | case 'T': | ||
3472 | 24 | Tflag = parse_iptos(optarg); | ||
3473 | 25 | break; | ||
3474 | 26 | + case 'C': | ||
3475 | 27 | + Cflag = 1; | ||
3476 | 28 | + break; | ||
3477 | 29 | default: | ||
3478 | 30 | usage(1); | ||
3479 | 31 | } | ||
3480 | 32 | @@ -738,8 +742,16 @@ | ||
3481 | 33 | else if (n == 0) { | ||
3482 | 34 | goto shutdown_wr; | ||
3483 | 35 | } else { | ||
3484 | 36 | - if (atomicio(vwrite, nfd, buf, n) != n) | ||
3485 | 37 | - return; | ||
3486 | 38 | + if ((Cflag) && (buf[n-1]=='\n')) { | ||
3487 | 39 | + if (atomicio(vwrite, nfd, buf, n-1) != (n-1)) | ||
3488 | 40 | + return; | ||
3489 | 41 | + if (atomicio(vwrite, nfd, "\r\n", 2) != 2) | ||
3490 | 42 | + return; | ||
3491 | 43 | + } | ||
3492 | 44 | + else { | ||
3493 | 45 | + if (atomicio(vwrite, nfd, buf, n) != n) | ||
3494 | 46 | + return; | ||
3495 | 47 | + } | ||
3496 | 48 | } | ||
3497 | 49 | } | ||
3498 | 50 | else if (pfd[1].revents & POLLHUP) { | ||
3499 | 51 | @@ -944,6 +956,7 @@ | ||
3500 | 52 | #endif | ||
3501 | 53 | " \t-s addr\t Local source address\n\ | ||
3502 | 54 | \t-T ToS\t Set IP Type of Service\n\ | ||
3503 | 55 | + \t-C Send CRLF as line-ending\n\ | ||
3504 | 56 | \t-t Answer TELNET negotiation\n\ | ||
3505 | 57 | \t-U Use UNIX domain socket\n\ | ||
3506 | 58 | \t-u UDP mode\n\ | ||
3507 | 59 | @@ -959,7 +972,7 @@ | ||
3508 | 60 | void | ||
3509 | 61 | usage(int ret) | ||
3510 | 62 | { | ||
3511 | 63 | - fprintf(stderr, "usage: nc [-46DdhklnrStUuvz] [-i interval] [-P proxy_username] [-p source_port]\n"); | ||
3512 | 64 | + fprintf(stderr, "usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]\n"); | ||
3513 | 65 | fprintf(stderr, "\t [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]\n"); | ||
3514 | 66 | fprintf(stderr, "\t [-x proxy_address[:port]] [hostname] [port[s]]\n"); | ||
3515 | 67 | if (ret) | ||
3516 | 68 | Index: netcat-openbsd-1.89/nc.1 | ||
3517 | 69 | =================================================================== | ||
3518 | 70 | --- netcat-openbsd-1.89.orig/nc.1 2008-06-19 16:49:39.000000000 -0400 | ||
3519 | 71 | +++ netcat-openbsd-1.89/nc.1 2008-06-19 16:54:36.000000000 -0400 | ||
3520 | 72 | @@ -34,7 +34,7 @@ | ||
3521 | 73 | .Sh SYNOPSIS | ||
3522 | 74 | .Nm nc | ||
3523 | 75 | .Bk -words | ||
3524 | 76 | -.Op Fl 46DdhklnrStUuvz | ||
3525 | 77 | +.Op Fl 46DdhklnrStUuvzC | ||
3526 | 78 | .Op Fl i Ar interval | ||
3527 | 79 | .Op Fl P Ar proxy_username | ||
3528 | 80 | .Op Fl p Ar source_port | ||
3529 | 81 | @@ -140,6 +140,10 @@ | ||
3530 | 82 | It is an error to use this option in conjunction with the | ||
3531 | 83 | .Fl l | ||
3532 | 84 | option. | ||
3533 | 85 | +.It Fl q | ||
3534 | 86 | +after EOF on stdin, wait the specified number of seconds and then quit. If | ||
3535 | 87 | +.Ar seconds | ||
3536 | 88 | +is negative, wait forever. | ||
3537 | 89 | .It Fl r | ||
3538 | 90 | Specifies that source and/or destination ports should be chosen randomly | ||
3539 | 91 | instead of sequentially within a range or in the order that the system | ||
3540 | 92 | @@ -159,6 +163,8 @@ | ||
3541 | 93 | .Dq reliability , | ||
3542 | 94 | or an 8-bit hexadecimal value preceded by | ||
3543 | 95 | .Dq 0x . | ||
3544 | 96 | +.It Fl C | ||
3545 | 97 | +Send CRLF as line-ending | ||
3546 | 98 | .It Fl t | ||
3547 | 99 | Causes | ||
3548 | 100 | .Nm | ||
3549 | 101 | @@ -317,7 +323,7 @@ | ||
3550 | 102 | of requests required by the server. | ||
3551 | 103 | As another example, an email may be submitted to an SMTP server using: | ||
3552 | 104 | .Bd -literal -offset indent | ||
3553 | 105 | -$ nc localhost 25 \*(Lt\*(Lt EOF | ||
3554 | 106 | +$ nc [-C] localhost 25 \*(Lt\*(Lt EOF | ||
3555 | 107 | HELO host.example.com | ||
3556 | 108 | MAIL FROM:\*(Ltuser@host.example.com\*(Gt | ||
3557 | 109 | RCPT TO:\*(Ltuser2@host.example.com\*(Gt | ||
3558 | 110 | 0 | ||
3559 | === modified file 'debian/patches/series' | |||
3560 | --- debian/patches/series 2011-06-11 14:31:06 +0000 | |||
3561 | +++ debian/patches/series 2012-05-30 22:10:23 +0000 | |||
3562 | @@ -1,18 +1,12 @@ | |||
3579 | 1 | openbsd-compat.patch | 1 | 0001-port-to-linux-with-libsd.patch |
3580 | 2 | socks-b64-prototype.patch | 2 | 0002-connect-timeout.patch |
3581 | 3 | silence-z.patch | 3 | 0003-get-sev-by-name.patch |
3582 | 4 | glib-strlcpy.patch | 4 | 0004-poll-hup.patch |
3583 | 5 | no-strtonum.patch | 5 | 0005-send-crlf.patch |
3584 | 6 | pollhup.patch | 6 | 0006-quit-timer.patch |
3585 | 7 | reuseaddr.patch | 7 | 0007-udp-scan-timeout.patch |
3586 | 8 | connect-timeout.patch | 8 | 0008-verbose-numeric-port.patch |
3587 | 9 | udp-scan-timeout.patch | 9 | 0009-dccp-support.patch |
3588 | 10 | verbose-numeric-port.patch | 10 | 0010-serialized-handling-multiple-clients.patch |
3589 | 11 | send-crlf.patch | 11 | 0011-misc-failures-and-features.patch |
3574 | 12 | help-version-exit.patch | ||
3575 | 13 | quit-timer.patch | ||
3576 | 14 | getservbyname.patch | ||
3577 | 15 | gcc-warnings.patch | ||
3578 | 16 | verbose-message-to-stderr.patch | ||
3590 | 17 | netcat-info.patch | 12 | netcat-info.patch |
3591 | 18 | dccp.patch | ||
3592 | 19 | 13 | ||
3593 | === removed file 'debian/patches/silence-z.patch' | |||
3594 | --- debian/patches/silence-z.patch 2008-06-19 16:20:01 +0000 | |||
3595 | +++ debian/patches/silence-z.patch 1970-01-01 00:00:00 +0000 | |||
3596 | @@ -1,13 +0,0 @@ | |||
3597 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
3598 | 2 | =================================================================== | ||
3599 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2008-06-19 16:33:52.000000000 -0400 | ||
3600 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-06-19 16:34:58.000000000 -0400 | ||
3601 | 5 | @@ -364,7 +364,7 @@ | ||
3602 | 6 | continue; | ||
3603 | 7 | |||
3604 | 8 | ret = 0; | ||
3605 | 9 | - if (vflag || zflag) { | ||
3606 | 10 | + if (vflag) { | ||
3607 | 11 | /* For UDP, make sure we are connected. */ | ||
3608 | 12 | if (uflag) { | ||
3609 | 13 | if (udptest(s) == -1) { | ||
3610 | 14 | 0 | ||
3611 | === removed file 'debian/patches/socks-b64-prototype.patch' | |||
3612 | --- debian/patches/socks-b64-prototype.patch 2008-06-19 16:20:01 +0000 | |||
3613 | +++ debian/patches/socks-b64-prototype.patch 1970-01-01 00:00:00 +0000 | |||
3614 | @@ -1,13 +0,0 @@ | |||
3615 | 1 | Index: netcat-openbsd-1.89/socks.c | ||
3616 | 2 | =================================================================== | ||
3617 | 3 | --- netcat-openbsd-1.89.orig/socks.c 2008-06-19 16:30:45.000000000 -0400 | ||
3618 | 4 | +++ netcat-openbsd-1.89/socks.c 2008-06-19 16:30:36.000000000 -0400 | ||
3619 | 5 | @@ -53,6 +53,8 @@ | ||
3620 | 6 | #define SOCKS_DOMAIN 3 | ||
3621 | 7 | #define SOCKS_IPV6 4 | ||
3622 | 8 | |||
3623 | 9 | +extern int b64_ntop(unsigned char const *, size_t, char *, size_t); | ||
3624 | 10 | + | ||
3625 | 11 | int remote_connect(const char *, const char *, struct addrinfo); | ||
3626 | 12 | int socks_connect(const char *, const char *, struct addrinfo, | ||
3627 | 13 | const char *, const char *, struct addrinfo, int, | ||
3628 | 14 | 0 | ||
3629 | === removed file 'debian/patches/udp-scan-timeout.patch' | |||
3630 | --- debian/patches/udp-scan-timeout.patch 2008-06-19 16:20:01 +0000 | |||
3631 | +++ debian/patches/udp-scan-timeout.patch 1970-01-01 00:00:00 +0000 | |||
3632 | @@ -1,50 +0,0 @@ | |||
3633 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
3634 | 2 | =================================================================== | ||
3635 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:30.000000000 -0500 | ||
3636 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:34.000000000 -0500 | ||
3637 | 5 | @@ -69,6 +69,8 @@ | ||
3638 | 6 | #define CONNECTION_FAILED 1 | ||
3639 | 7 | #define CONNECTION_TIMEOUT 2 | ||
3640 | 8 | |||
3641 | 9 | +#define UDP_SCAN_TIMEOUT 3 /* Seconds */ | ||
3642 | 10 | + | ||
3643 | 11 | /* Command Line Options */ | ||
3644 | 12 | int dflag; /* detached, no stdin */ | ||
3645 | 13 | int iflag; /* Interval Flag */ | ||
3646 | 14 | @@ -376,7 +378,7 @@ | ||
3647 | 15 | continue; | ||
3648 | 16 | |||
3649 | 17 | ret = 0; | ||
3650 | 18 | - if (vflag) { | ||
3651 | 19 | + if (vflag && !uflag) { | ||
3652 | 20 | /* For UDP, make sure we are connected. */ | ||
3653 | 21 | if (uflag) { | ||
3654 | 22 | if (udptest(s) == -1) { | ||
3655 | 23 | @@ -841,15 +843,20 @@ | ||
3656 | 24 | int | ||
3657 | 25 | udptest(int s) | ||
3658 | 26 | { | ||
3659 | 27 | - int i, ret; | ||
3660 | 28 | + int i, t; | ||
3661 | 29 | |||
3662 | 30 | - for (i = 0; i <= 3; i++) { | ||
3663 | 31 | - if (write(s, "X", 1) == 1) | ||
3664 | 32 | - ret = 1; | ||
3665 | 33 | - else | ||
3666 | 34 | - ret = -1; | ||
3667 | 35 | + if ((write(s, "X", 1) != 1) || | ||
3668 | 36 | + ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED))) | ||
3669 | 37 | + return -1; | ||
3670 | 38 | + | ||
3671 | 39 | + /* Give the remote host some time to reply. */ | ||
3672 | 40 | + for (i = 0, t = (timeout == -1) ? UDP_SCAN_TIMEOUT : (timeout / 1000); | ||
3673 | 41 | + i < t; i++) { | ||
3674 | 42 | + sleep(1); | ||
3675 | 43 | + if ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED)) | ||
3676 | 44 | + return -1; | ||
3677 | 45 | } | ||
3678 | 46 | - return (ret); | ||
3679 | 47 | + return 1; | ||
3680 | 48 | } | ||
3681 | 49 | |||
3682 | 50 | void | ||
3683 | 51 | 0 | ||
3684 | === removed file 'debian/patches/verbose-message-to-stderr.patch' | |||
3685 | --- debian/patches/verbose-message-to-stderr.patch 2010-02-09 10:42:03 +0000 | |||
3686 | +++ debian/patches/verbose-message-to-stderr.patch 1970-01-01 00:00:00 +0000 | |||
3687 | @@ -1,17 +0,0 @@ | |||
3688 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
3689 | 2 | =================================================================== | ||
3690 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2010-02-09 10:29:21.000000000 +0100 | ||
3691 | 4 | +++ netcat-openbsd-1.89/netcat.c 2010-02-09 10:29:45.000000000 +0100 | ||
3692 | 5 | @@ -421,9 +421,9 @@ main(int argc, char *argv[]) | ||
3693 | 6 | uflag ? "udp" : "tcp"); | ||
3694 | 7 | } | ||
3695 | 8 | |||
3696 | 9 | - printf("Connection to %s %s port [%s/%s] succeeded!\n", | ||
3697 | 10 | - host, portlist[i], uflag ? "udp" : "tcp", | ||
3698 | 11 | - sv ? sv->s_name : "*"); | ||
3699 | 12 | + fprintf(stderr, "Connection to %s %s port [%s/%s] " | ||
3700 | 13 | + "succeeded!\n", host, portlist[i], | ||
3701 | 14 | + uflag ? "udp" : "tcp", sv ? sv->s_name : "*"); | ||
3702 | 15 | } | ||
3703 | 16 | if (!zflag) | ||
3704 | 17 | readwrite(s); | ||
3705 | 18 | 0 | ||
3706 | === removed file 'debian/patches/verbose-numeric-port.patch' | |||
3707 | --- debian/patches/verbose-numeric-port.patch 2008-01-30 18:24:46 +0000 | |||
3708 | +++ debian/patches/verbose-numeric-port.patch 1970-01-01 00:00:00 +0000 | |||
3709 | @@ -1,54 +0,0 @@ | |||
3710 | 1 | Index: netcat-openbsd-1.89/netcat.c | ||
3711 | 2 | =================================================================== | ||
3712 | 3 | --- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:34.000000000 -0500 | ||
3713 | 4 | +++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:44.000000000 -0500 | ||
3714 | 5 | @@ -41,6 +41,7 @@ | ||
3715 | 6 | #include <netinet/tcp.h> | ||
3716 | 7 | #include <netinet/ip.h> | ||
3717 | 8 | #include <arpa/telnet.h> | ||
3718 | 9 | +#include <arpa/inet.h> | ||
3719 | 10 | |||
3720 | 11 | #include <err.h> | ||
3721 | 12 | #include <errno.h> | ||
3722 | 13 | @@ -317,16 +318,15 @@ | ||
3723 | 14 | if (uflag) { | ||
3724 | 15 | int rv, plen; | ||
3725 | 16 | char buf[8192]; | ||
3726 | 17 | - struct sockaddr_storage z; | ||
3727 | 18 | |||
3728 | 19 | - len = sizeof(z); | ||
3729 | 20 | + len = sizeof(cliaddr); | ||
3730 | 21 | plen = jflag ? 8192 : 1024; | ||
3731 | 22 | rv = recvfrom(s, buf, plen, MSG_PEEK, | ||
3732 | 23 | - (struct sockaddr *)&z, &len); | ||
3733 | 24 | + (struct sockaddr *)&cliaddr, &len); | ||
3734 | 25 | if (rv < 0) | ||
3735 | 26 | err(1, "recvfrom"); | ||
3736 | 27 | |||
3737 | 28 | - rv = connect(s, (struct sockaddr *)&z, len); | ||
3738 | 29 | + rv = connect(s, (struct sockaddr *)&cliaddr, len); | ||
3739 | 30 | if (rv < 0) | ||
3740 | 31 | err(1, "connect"); | ||
3741 | 32 | |||
3742 | 33 | @@ -337,6 +337,21 @@ | ||
3743 | 34 | &len); | ||
3744 | 35 | } | ||
3745 | 36 | |||
3746 | 37 | + if(vflag) { | ||
3747 | 38 | + /* Don't look up port if -n. */ | ||
3748 | 39 | + if (nflag) | ||
3749 | 40 | + sv = NULL; | ||
3750 | 41 | + else | ||
3751 | 42 | + sv = getservbyport(ntohs(atoi(uport)), | ||
3752 | 43 | + uflag ? "udp" : "tcp"); | ||
3753 | 44 | + | ||
3754 | 45 | + fprintf(stderr, "Connection from %s port %s [%s/%s] accepted\n", | ||
3755 | 46 | + inet_ntoa(((struct sockaddr_in *)(&cliaddr))->sin_addr), | ||
3756 | 47 | + uport, | ||
3757 | 48 | + uflag ? "udp" : "tcp", | ||
3758 | 49 | + sv ? sv->s_name : "*"); | ||
3759 | 50 | + } | ||
3760 | 51 | + | ||
3761 | 52 | readwrite(connfd); | ||
3762 | 53 | close(connfd); | ||
3763 | 54 | if (family != AF_UNIX) | ||
3764 | 55 | 0 | ||
3765 | === modified file 'debian/rules' | |||
3766 | --- debian/rules 2008-01-30 18:24:46 +0000 | |||
3767 | +++ debian/rules 2012-05-30 22:10:23 +0000 | |||
3768 | @@ -1,64 +1,16 @@ | |||
3769 | 1 | #!/usr/bin/make -f | 1 | #!/usr/bin/make -f |
3771 | 2 | #export DH_VERBOSE=1 | 2 | DPKG_EXPORT_BUILDFLAGS = 1 |
3772 | 3 | -include /usr/share/dpkg/buildflags.mk | ||
3773 | 3 | 4 | ||
3785 | 4 | DEB_CFLAGS = -g -Wall | 5 | DEB_CFLAGS = $(CPPFLAGS) $(CFLAGS) |
3786 | 5 | ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) | 6 | DEB_LDFLAGS = $(LDFLAGS) -Wl,--no-add-needed,--as-needed |
3776 | 6 | DEB_CFLAGS += -O0 | ||
3777 | 7 | else | ||
3778 | 8 | DEB_CFLAGS += -O2 | ||
3779 | 9 | endif | ||
3780 | 10 | ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) | ||
3781 | 11 | INSTALL_PROG = install -m 0755 | ||
3782 | 12 | else | ||
3783 | 13 | INSTALL_PROG = install -s -m 0755 | ||
3784 | 14 | endif | ||
3787 | 15 | DEB_VER = $(shell dpkg-parsechangelog | sed -n 's/^Version: //p') | 7 | DEB_VER = $(shell dpkg-parsechangelog | sed -n 's/^Version: //p') |
3788 | 16 | 8 | ||
3837 | 17 | patch: patch-stamp | 9 | %: |
3838 | 18 | patch-stamp: | 10 | dh $@ |
3839 | 19 | QUILT_PATCHES=debian/patches quilt push -a || test $$? = 2 | 11 | override_dh_auto_build: |
3840 | 20 | touch patch-stamp | 12 | $(MAKE) CFLAGS='$(DEB_CFLAGS) -DDEBIAN_VERSION=\"$(DEB_VER)\"' LDFLAGS="$(DEB_LDFLAGS)" |
3841 | 21 | 13 | override_dh_auto_install: | |
3842 | 22 | unpatch: | 14 | mv nc nc.openbsd |
3843 | 23 | QUILT_PATCHES=debian/patches quilt pop -a -R || test $$? = 2 | 15 | mv nc.1 nc_openbsd.1 |
3844 | 24 | rm -rf .pc patch-stamp | 16 | dh_auto_install |
3797 | 25 | |||
3798 | 26 | build: build-stamp | ||
3799 | 27 | build-stamp: patch-stamp | ||
3800 | 28 | |||
3801 | 29 | $(MAKE) CFLAGS='$(DEB_CFLAGS) -DDEBIAN_VERSION=\"$(DEB_VER)\"' | ||
3802 | 30 | touch build-stamp | ||
3803 | 31 | |||
3804 | 32 | clean: unpatch | ||
3805 | 33 | dh_testdir | ||
3806 | 34 | dh_clean patch-stamp build-stamp | ||
3807 | 35 | $(MAKE) clean | ||
3808 | 36 | |||
3809 | 37 | install: | ||
3810 | 38 | dh_testdir | ||
3811 | 39 | dh_testroot | ||
3812 | 40 | dh_clean -k | ||
3813 | 41 | dh_installdirs | ||
3814 | 42 | |||
3815 | 43 | $(INSTALL_PROG) nc $(CURDIR)/debian/netcat-openbsd/bin/nc.openbsd | ||
3816 | 44 | cp nc.1 $(CURDIR)/debian/netcat-openbsd/usr/share/man/man1/nc_openbsd.1 | ||
3817 | 45 | |||
3818 | 46 | binary-indep: build install | ||
3819 | 47 | |||
3820 | 48 | binary-arch: build install | ||
3821 | 49 | dh_testdir | ||
3822 | 50 | dh_testroot | ||
3823 | 51 | dh_installchangelogs | ||
3824 | 52 | dh_installdocs | ||
3825 | 53 | dh_installexamples debian/examples/* | ||
3826 | 54 | dh_link | ||
3827 | 55 | dh_strip | ||
3828 | 56 | dh_compress -Xexamples | ||
3829 | 57 | dh_fixperms | ||
3830 | 58 | dh_installdeb | ||
3831 | 59 | dh_shlibdeps | ||
3832 | 60 | dh_gencontrol | ||
3833 | 61 | dh_md5sums | ||
3834 | 62 | dh_builddeb | ||
3835 | 63 | |||
3836 | 64 | binary: binary-indep binary-arch | ||
3845 | 65 | 17 | ||
3846 | === added directory 'debian/source' | |||
3847 | === added file 'debian/source/format' | |||
3848 | --- debian/source/format 1970-01-01 00:00:00 +0000 | |||
3849 | +++ debian/source/format 2012-05-30 22:10:23 +0000 | |||
3850 | @@ -0,0 +1,1 @@ | |||
3851 | 1 | 3.0 (quilt) | ||
3852 | 0 | 2 | ||
3853 | === modified file 'nc.1' | |||
3854 | --- nc.1 2008-01-30 18:24:46 +0000 | |||
3855 | +++ nc.1 2012-05-30 22:10:23 +0000 | |||
3856 | @@ -1,4 +1,4 @@ | |||
3858 | 1 | .\" $OpenBSD: nc.1,v 1.45 2007/05/31 19:20:13 jmc Exp $ | 1 | .\" $OpenBSD: nc.1,v 1.60 2012/02/07 12:11:43 lum Exp $ |
3859 | 2 | .\" | 2 | .\" |
3860 | 3 | .\" Copyright (c) 1996 David Sacerdote | 3 | .\" Copyright (c) 1996 David Sacerdote |
3861 | 4 | .\" All rights reserved. | 4 | .\" All rights reserved. |
3862 | @@ -25,7 +25,7 @@ | |||
3863 | 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
3864 | 26 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
3865 | 27 | .\" | 27 | .\" |
3867 | 28 | .Dd $Mdocdate: May 31 2007 $ | 28 | .Dd $Mdocdate: February 7 2012 $ |
3868 | 29 | .Dt NC 1 | 29 | .Dt NC 1 |
3869 | 30 | .Os | 30 | .Os |
3870 | 31 | .Sh NAME | 31 | .Sh NAME |
3871 | @@ -35,27 +35,32 @@ | |||
3872 | 35 | .Nm nc | 35 | .Nm nc |
3873 | 36 | .Bk -words | 36 | .Bk -words |
3874 | 37 | .Op Fl 46DdhklnrStUuvz | 37 | .Op Fl 46DdhklnrStUuvz |
3875 | 38 | .Op Fl I Ar length | ||
3876 | 38 | .Op Fl i Ar interval | 39 | .Op Fl i Ar interval |
3877 | 40 | .Op Fl O Ar length | ||
3878 | 39 | .Op Fl P Ar proxy_username | 41 | .Op Fl P Ar proxy_username |
3879 | 40 | .Op Fl p Ar source_port | 42 | .Op Fl p Ar source_port |
3882 | 41 | .Op Fl s Ar source_ip_address | 43 | .Op Fl s Ar source |
3883 | 42 | .Op Fl T Ar ToS | 44 | .Op Fl T Ar toskeyword |
3884 | 45 | .Op Fl V Ar rtable | ||
3885 | 43 | .Op Fl w Ar timeout | 46 | .Op Fl w Ar timeout |
3886 | 44 | .Op Fl X Ar proxy_protocol | 47 | .Op Fl X Ar proxy_protocol |
3887 | 45 | .Oo Xo | 48 | .Oo Xo |
3888 | 46 | .Fl x Ar proxy_address Ns Oo : Ns | 49 | .Fl x Ar proxy_address Ns Oo : Ns |
3893 | 47 | .Ar port Oc Oc | 50 | .Ar port Oc |
3894 | 48 | .Xc | 51 | .Xc Oc |
3895 | 49 | .Op Ar hostname | 52 | .Op Ar destination |
3896 | 50 | .Op Ar port Ns Bq Ar s | 53 | .Op Ar port |
3897 | 51 | .Ek | 54 | .Ek |
3898 | 52 | .Sh DESCRIPTION | 55 | .Sh DESCRIPTION |
3899 | 53 | The | 56 | The |
3900 | 54 | .Nm | 57 | .Nm |
3901 | 55 | (or | 58 | (or |
3902 | 56 | .Nm netcat ) | 59 | .Nm netcat ) |
3905 | 57 | utility is used for just about anything under the sun involving TCP | 60 | utility is used for just about anything under the sun involving TCP, |
3906 | 58 | or UDP. | 61 | UDP, or |
3907 | 62 | .Ux Ns -domain | ||
3908 | 63 | sockets. | ||
3909 | 59 | It can open TCP connections, send UDP packets, listen on arbitrary | 64 | It can open TCP connections, send UDP packets, listen on arbitrary |
3910 | 60 | TCP and UDP ports, do port scanning, and deal with both IPv4 and | 65 | TCP and UDP ports, do port scanning, and deal with both IPv4 and |
3911 | 61 | IPv6. | 66 | IPv6. |
3912 | @@ -101,6 +106,8 @@ | |||
3913 | 101 | Prints out | 106 | Prints out |
3914 | 102 | .Nm | 107 | .Nm |
3915 | 103 | help. | 108 | help. |
3916 | 109 | .It Fl I Ar length | ||
3917 | 110 | Specifies the size of the TCP receive buffer. | ||
3918 | 104 | .It Fl i Ar interval | 111 | .It Fl i Ar interval |
3919 | 105 | Specifies a delay time interval between lines of text sent and received. | 112 | Specifies a delay time interval between lines of text sent and received. |
3920 | 106 | Also causes a delay time between connections to multiple ports. | 113 | Also causes a delay time between connections to multiple ports. |
3921 | @@ -129,6 +136,8 @@ | |||
3922 | 129 | .It Fl n | 136 | .It Fl n |
3923 | 130 | Do not do any DNS or service lookups on any specified addresses, | 137 | Do not do any DNS or service lookups on any specified addresses, |
3924 | 131 | hostnames or ports. | 138 | hostnames or ports. |
3925 | 139 | .It Fl O Ar length | ||
3926 | 140 | Specifies the size of the TCP send buffer. | ||
3927 | 132 | .It Fl P Ar proxy_username | 141 | .It Fl P Ar proxy_username |
3928 | 133 | Specifies a username to present to a proxy server that requires authentication. | 142 | Specifies a username to present to a proxy server that requires authentication. |
3929 | 134 | If no username is specified then authentication will not be attempted. | 143 | If no username is specified then authentication will not be attempted. |
3930 | @@ -146,19 +155,30 @@ | |||
3931 | 146 | assigns them. | 155 | assigns them. |
3932 | 147 | .It Fl S | 156 | .It Fl S |
3933 | 148 | Enables the RFC 2385 TCP MD5 signature option. | 157 | Enables the RFC 2385 TCP MD5 signature option. |
3935 | 149 | .It Fl s Ar source_ip_address | 158 | .It Fl s Ar source |
3936 | 150 | Specifies the IP of the interface which is used to send the packets. | 159 | Specifies the IP of the interface which is used to send the packets. |
3937 | 160 | For | ||
3938 | 161 | .Ux Ns -domain | ||
3939 | 162 | datagram sockets, specifies the local temporary socket file | ||
3940 | 163 | to create and use so that datagrams can be received. | ||
3941 | 151 | It is an error to use this option in conjunction with the | 164 | It is an error to use this option in conjunction with the |
3942 | 152 | .Fl l | 165 | .Fl l |
3943 | 153 | option. | 166 | option. |
3952 | 154 | .It Fl T Ar ToS | 167 | .It Fl T Ar toskeyword |
3953 | 155 | Specifies IP Type of Service (ToS) for the connection. | 168 | Change IPv4 TOS value. |
3954 | 156 | Valid values are the tokens | 169 | .Ar toskeyword |
3955 | 157 | .Dq lowdelay , | 170 | may be one of |
3956 | 158 | .Dq throughput , | 171 | .Ar critical , |
3957 | 159 | .Dq reliability , | 172 | .Ar inetcontrol , |
3958 | 160 | or an 8-bit hexadecimal value preceded by | 173 | .Ar lowdelay , |
3959 | 161 | .Dq 0x . | 174 | .Ar netcontrol , |
3960 | 175 | .Ar throughput , | ||
3961 | 176 | .Ar reliability , | ||
3962 | 177 | or one of the DiffServ Code Points: | ||
3963 | 178 | .Ar ef , | ||
3964 | 179 | .Ar af11 ... af43 , | ||
3965 | 180 | .Ar cs0 ... cs7 ; | ||
3966 | 181 | or a number in either hex or decimal. | ||
3967 | 162 | .It Fl t | 182 | .It Fl t |
3968 | 163 | Causes | 183 | Causes |
3969 | 164 | .Nm | 184 | .Nm |
3970 | @@ -167,17 +187,32 @@ | |||
3971 | 167 | .Nm | 187 | .Nm |
3972 | 168 | to script telnet sessions. | 188 | to script telnet sessions. |
3973 | 169 | .It Fl U | 189 | .It Fl U |
3975 | 170 | Specifies to use Unix Domain Sockets. | 190 | Specifies to use |
3976 | 191 | .Ux Ns -domain | ||
3977 | 192 | sockets. | ||
3978 | 171 | .It Fl u | 193 | .It Fl u |
3979 | 172 | Use UDP instead of the default option of TCP. | 194 | Use UDP instead of the default option of TCP. |
3980 | 195 | For | ||
3981 | 196 | .Ux Ns -domain | ||
3982 | 197 | sockets, use a datagram socket instead of a stream socket. | ||
3983 | 198 | If a | ||
3984 | 199 | .Ux Ns -domain | ||
3985 | 200 | socket is used, a temporary receiving socket is created in | ||
3986 | 201 | .Pa /tmp | ||
3987 | 202 | unless the | ||
3988 | 203 | .Fl s | ||
3989 | 204 | flag is given. | ||
3990 | 205 | .It Fl V Ar rtable | ||
3991 | 206 | Set the routing table to be used. | ||
3992 | 207 | The default is 0. | ||
3993 | 173 | .It Fl v | 208 | .It Fl v |
3994 | 174 | Have | 209 | Have |
3995 | 175 | .Nm | 210 | .Nm |
3996 | 176 | give more verbose output. | 211 | give more verbose output. |
3997 | 177 | .It Fl w Ar timeout | 212 | .It Fl w Ar timeout |
3999 | 178 | If a connection and stdin are idle for more than | 213 | Connections which cannot be established or are idle timeout after |
4000 | 179 | .Ar timeout | 214 | .Ar timeout |
4002 | 180 | seconds, then the connection is silently closed. | 215 | seconds. |
4003 | 181 | The | 216 | The |
4004 | 182 | .Fl w | 217 | .Fl w |
4005 | 183 | flag has no effect on the | 218 | flag has no effect on the |
4006 | @@ -208,7 +243,7 @@ | |||
4007 | 208 | Requests that | 243 | Requests that |
4008 | 209 | .Nm | 244 | .Nm |
4009 | 210 | should connect to | 245 | should connect to |
4011 | 211 | .Ar hostname | 246 | .Ar destination |
4012 | 212 | using a proxy at | 247 | using a proxy at |
4013 | 213 | .Ar proxy_address | 248 | .Ar proxy_address |
4014 | 214 | and | 249 | and |
4015 | @@ -226,26 +261,31 @@ | |||
4016 | 226 | option. | 261 | option. |
4017 | 227 | .El | 262 | .El |
4018 | 228 | .Pp | 263 | .Pp |
4020 | 229 | .Ar hostname | 264 | .Ar destination |
4021 | 230 | can be a numerical IP address or a symbolic hostname | 265 | can be a numerical IP address or a symbolic hostname |
4022 | 231 | (unless the | 266 | (unless the |
4023 | 232 | .Fl n | 267 | .Fl n |
4024 | 233 | option is given). | 268 | option is given). |
4026 | 234 | In general, a hostname must be specified, | 269 | In general, a destination must be specified, |
4027 | 235 | unless the | 270 | unless the |
4028 | 236 | .Fl l | 271 | .Fl l |
4029 | 237 | option is given | 272 | option is given |
4030 | 238 | (in which case the local host is used). | 273 | (in which case the local host is used). |
4031 | 274 | For | ||
4032 | 275 | .Ux Ns -domain | ||
4033 | 276 | sockets, a destination is required and is the socket path to connect to | ||
4034 | 277 | (or listen on if the | ||
4035 | 278 | .Fl l | ||
4036 | 279 | option is given). | ||
4037 | 239 | .Pp | 280 | .Pp |
4040 | 240 | .Ar port Ns Op Ar s | 281 | .Ar port |
4041 | 241 | can be single integers or ranges. | 282 | can be a single integer or a range of ports. |
4042 | 242 | Ranges are in the form nn-mm. | 283 | Ranges are in the form nn-mm. |
4043 | 243 | In general, | 284 | In general, |
4044 | 244 | a destination port must be specified, | 285 | a destination port must be specified, |
4045 | 245 | unless the | 286 | unless the |
4046 | 246 | .Fl U | 287 | .Fl U |
4049 | 247 | option is given | 288 | option is given. |
4048 | 248 | (in which case a socket must be specified). | ||
4050 | 249 | .Sh CLIENT/SERVER MODEL | 289 | .Sh CLIENT/SERVER MODEL |
4051 | 250 | It is quite simple to build a very basic client/server model using | 290 | It is quite simple to build a very basic client/server model using |
4052 | 251 | .Nm . | 291 | .Nm . |
4053 | @@ -305,7 +345,7 @@ | |||
4054 | 305 | in response to commands issued by the client. | 345 | in response to commands issued by the client. |
4055 | 306 | For example, to retrieve the home page of a web site: | 346 | For example, to retrieve the home page of a web site: |
4056 | 307 | .Bd -literal -offset indent | 347 | .Bd -literal -offset indent |
4058 | 308 | $ echo -n "GET / HTTP/1.0\er\en\er\en" | nc host.example.com 80 | 348 | $ printf "GET / HTTP/1.0\er\en\er\en" | nc host.example.com 80 |
4059 | 309 | .Ed | 349 | .Ed |
4060 | 310 | .Pp | 350 | .Pp |
4061 | 311 | Note that this also displays the headers sent by the web server. | 351 | Note that this also displays the headers sent by the web server. |
4062 | @@ -376,7 +416,9 @@ | |||
4063 | 376 | .Pp | 416 | .Pp |
4064 | 377 | .Dl $ nc -s 10.1.2.3 host.example.com 42 | 417 | .Dl $ nc -s 10.1.2.3 host.example.com 42 |
4065 | 378 | .Pp | 418 | .Pp |
4067 | 379 | Create and listen on a Unix Domain Socket: | 419 | Create and listen on a |
4068 | 420 | .Ux Ns -domain | ||
4069 | 421 | stream socket: | ||
4070 | 380 | .Pp | 422 | .Pp |
4071 | 381 | .Dl $ nc -lU /var/tmp/dsocket | 423 | .Dl $ nc -lU /var/tmp/dsocket |
4072 | 382 | .Pp | 424 | .Pp |
4073 | @@ -407,8 +449,15 @@ | |||
4074 | 407 | Rewritten with IPv6 support by | 449 | Rewritten with IPv6 support by |
4075 | 408 | .An Eric Jackson Aq ericj@monkey.org . | 450 | .An Eric Jackson Aq ericj@monkey.org . |
4076 | 409 | .Sh CAVEATS | 451 | .Sh CAVEATS |
4082 | 410 | UDP port scans will always succeed | 452 | UDP port scans using the |
4083 | 411 | (i.e. report the port as open), | 453 | .Fl uz |
4084 | 412 | rendering the | 454 | combination of flags will always report success irrespective of |
4085 | 413 | .Fl uz | 455 | the target machine's state. |
4086 | 414 | combination of flags relatively useless. | 456 | However, |
4087 | 457 | in conjunction with a traffic sniffer either on the target machine | ||
4088 | 458 | or an intermediary device, | ||
4089 | 459 | the | ||
4090 | 460 | .Fl uz | ||
4091 | 461 | combination could be useful for communications diagnostics. | ||
4092 | 462 | Note that the amount of UDP traffic generated may be limited either | ||
4093 | 463 | due to hardware resources and/or configuration settings. | ||
4094 | 415 | 464 | ||
4095 | === modified file 'netcat.c' | |||
4096 | --- netcat.c 2008-01-30 18:24:46 +0000 | |||
4097 | +++ netcat.c 2012-05-30 22:10:23 +0000 | |||
4098 | @@ -1,4 +1,4 @@ | |||
4100 | 1 | /* $OpenBSD: netcat.c,v 1.89 2007/02/20 14:11:17 jmc Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.105 2012/02/09 06:25:35 lum Exp $ */ |
4101 | 2 | /* | 2 | /* |
4102 | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4103 | 4 | * | 4 | * |
4104 | @@ -62,6 +62,7 @@ | |||
4105 | 62 | 62 | ||
4106 | 63 | #define PORT_MAX 65535 | 63 | #define PORT_MAX 65535 |
4107 | 64 | #define PORT_MAX_LEN 6 | 64 | #define PORT_MAX_LEN 6 |
4108 | 65 | #define UNIX_DG_TMP_SOCKET_SIZE 19 | ||
4109 | 65 | 66 | ||
4110 | 66 | /* Command Line Options */ | 67 | /* Command Line Options */ |
4111 | 67 | int dflag; /* detached, no stdin */ | 68 | int dflag; /* detached, no stdin */ |
4112 | @@ -80,12 +81,16 @@ | |||
4113 | 80 | int xflag; /* Socks proxy */ | 81 | int xflag; /* Socks proxy */ |
4114 | 81 | int zflag; /* Port Scan Flag */ | 82 | int zflag; /* Port Scan Flag */ |
4115 | 82 | int Dflag; /* sodebug */ | 83 | int Dflag; /* sodebug */ |
4116 | 84 | int Iflag; /* TCP receive buffer size */ | ||
4117 | 85 | int Oflag; /* TCP send buffer size */ | ||
4118 | 83 | int Sflag; /* TCP MD5 signature option */ | 86 | int Sflag; /* TCP MD5 signature option */ |
4119 | 84 | int Tflag = -1; /* IP Type of Service */ | 87 | int Tflag = -1; /* IP Type of Service */ |
4120 | 88 | u_int rtableid; | ||
4121 | 85 | 89 | ||
4122 | 86 | int timeout = -1; | 90 | int timeout = -1; |
4123 | 87 | int family = AF_UNSPEC; | 91 | int family = AF_UNSPEC; |
4124 | 88 | char *portlist[PORT_MAX+1]; | 92 | char *portlist[PORT_MAX+1]; |
4125 | 93 | char *unix_dg_tmp_socket; | ||
4126 | 89 | 94 | ||
4127 | 90 | void atelnet(int, unsigned char *, unsigned int); | 95 | void atelnet(int, unsigned char *, unsigned int); |
4128 | 91 | void build_ports(char *); | 96 | void build_ports(char *); |
4129 | @@ -93,13 +98,15 @@ | |||
4130 | 93 | int local_listen(char *, char *, struct addrinfo); | 98 | int local_listen(char *, char *, struct addrinfo); |
4131 | 94 | void readwrite(int); | 99 | void readwrite(int); |
4132 | 95 | int remote_connect(const char *, const char *, struct addrinfo); | 100 | int remote_connect(const char *, const char *, struct addrinfo); |
4133 | 101 | int timeout_connect(int, const struct sockaddr *, socklen_t); | ||
4134 | 96 | int socks_connect(const char *, const char *, struct addrinfo, | 102 | int socks_connect(const char *, const char *, struct addrinfo, |
4135 | 97 | const char *, const char *, struct addrinfo, int, const char *); | 103 | const char *, const char *, struct addrinfo, int, const char *); |
4136 | 98 | int udptest(int); | 104 | int udptest(int); |
4137 | 105 | int unix_bind(char *); | ||
4138 | 99 | int unix_connect(char *); | 106 | int unix_connect(char *); |
4139 | 100 | int unix_listen(char *); | 107 | int unix_listen(char *); |
4140 | 101 | void set_common_sockopts(int); | 108 | void set_common_sockopts(int); |
4142 | 102 | int parse_iptos(char *); | 109 | int map_tos(char *, int *); |
4143 | 103 | void usage(int); | 110 | void usage(int); |
4144 | 104 | 111 | ||
4145 | 105 | int | 112 | int |
4146 | @@ -114,6 +121,7 @@ | |||
4147 | 114 | char *proxy; | 121 | char *proxy; |
4148 | 115 | const char *errstr, *proxyhost = "", *proxyport = NULL; | 122 | const char *errstr, *proxyhost = "", *proxyport = NULL; |
4149 | 116 | struct addrinfo proxyhints; | 123 | struct addrinfo proxyhints; |
4150 | 124 | char unix_dg_tmp_socket_buf[UNIX_DG_TMP_SOCKET_SIZE]; | ||
4151 | 117 | 125 | ||
4152 | 118 | ret = 1; | 126 | ret = 1; |
4153 | 119 | s = 0; | 127 | s = 0; |
4154 | @@ -123,7 +131,7 @@ | |||
4155 | 123 | sv = NULL; | 131 | sv = NULL; |
4156 | 124 | 132 | ||
4157 | 125 | while ((ch = getopt(argc, argv, | 133 | while ((ch = getopt(argc, argv, |
4159 | 126 | "46Ddhi:jklnP:p:rSs:tT:Uuvw:X:x:z")) != -1) { | 134 | "46DdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) { |
4160 | 127 | switch (ch) { | 135 | switch (ch) { |
4161 | 128 | case '4': | 136 | case '4': |
4162 | 129 | family = AF_INET; | 137 | family = AF_INET; |
4163 | @@ -185,6 +193,12 @@ | |||
4164 | 185 | case 'u': | 193 | case 'u': |
4165 | 186 | uflag = 1; | 194 | uflag = 1; |
4166 | 187 | break; | 195 | break; |
4167 | 196 | case 'V': | ||
4168 | 197 | rtableid = (unsigned int)strtonum(optarg, 0, | ||
4169 | 198 | RT_TABLEID_MAX, &errstr); | ||
4170 | 199 | if (errstr) | ||
4171 | 200 | errx(1, "rtable %s: %s", errstr, optarg); | ||
4172 | 201 | break; | ||
4173 | 188 | case 'v': | 202 | case 'v': |
4174 | 189 | vflag = 1; | 203 | vflag = 1; |
4175 | 190 | break; | 204 | break; |
4176 | @@ -205,11 +219,34 @@ | |||
4177 | 205 | case 'D': | 219 | case 'D': |
4178 | 206 | Dflag = 1; | 220 | Dflag = 1; |
4179 | 207 | break; | 221 | break; |
4180 | 222 | case 'I': | ||
4181 | 223 | Iflag = strtonum(optarg, 1, 65536 << 14, &errstr); | ||
4182 | 224 | if (errstr != NULL) | ||
4183 | 225 | errx(1, "TCP receive window %s: %s", | ||
4184 | 226 | errstr, optarg); | ||
4185 | 227 | break; | ||
4186 | 228 | case 'O': | ||
4187 | 229 | Oflag = strtonum(optarg, 1, 65536 << 14, &errstr); | ||
4188 | 230 | if (errstr != NULL) | ||
4189 | 231 | errx(1, "TCP send window %s: %s", | ||
4190 | 232 | errstr, optarg); | ||
4191 | 233 | break; | ||
4192 | 208 | case 'S': | 234 | case 'S': |
4193 | 209 | Sflag = 1; | 235 | Sflag = 1; |
4194 | 210 | break; | 236 | break; |
4195 | 211 | case 'T': | 237 | case 'T': |
4197 | 212 | Tflag = parse_iptos(optarg); | 238 | errstr = NULL; |
4198 | 239 | errno = 0; | ||
4199 | 240 | if (map_tos(optarg, &Tflag)) | ||
4200 | 241 | break; | ||
4201 | 242 | if (strlen(optarg) > 1 && optarg[0] == '0' && | ||
4202 | 243 | optarg[1] == 'x') | ||
4203 | 244 | Tflag = (int)strtol(optarg, NULL, 16); | ||
4204 | 245 | else | ||
4205 | 246 | Tflag = (int)strtonum(optarg, 0, 255, | ||
4206 | 247 | &errstr); | ||
4207 | 248 | if (Tflag < 0 || Tflag > 255 || errstr || errno) | ||
4208 | 249 | errx(1, "illegal tos value %s", optarg); | ||
4209 | 213 | break; | 250 | break; |
4210 | 214 | default: | 251 | default: |
4211 | 215 | usage(1); | 252 | usage(1); |
4212 | @@ -220,8 +257,6 @@ | |||
4213 | 220 | 257 | ||
4214 | 221 | /* Cruft to make sure options are clean, and used properly. */ | 258 | /* Cruft to make sure options are clean, and used properly. */ |
4215 | 222 | if (argv[0] && !argv[1] && family == AF_UNIX) { | 259 | if (argv[0] && !argv[1] && family == AF_UNIX) { |
4216 | 223 | if (uflag) | ||
4217 | 224 | errx(1, "cannot use -u and -U"); | ||
4218 | 225 | host = argv[0]; | 260 | host = argv[0]; |
4219 | 226 | uport = NULL; | 261 | uport = NULL; |
4220 | 227 | } else if (argv[0] && !argv[1]) { | 262 | } else if (argv[0] && !argv[1]) { |
4221 | @@ -244,6 +279,19 @@ | |||
4222 | 244 | if (!lflag && kflag) | 279 | if (!lflag && kflag) |
4223 | 245 | errx(1, "must use -l with -k"); | 280 | errx(1, "must use -l with -k"); |
4224 | 246 | 281 | ||
4225 | 282 | /* Get name of temporary socket for unix datagram client */ | ||
4226 | 283 | if ((family == AF_UNIX) && uflag && !lflag) { | ||
4227 | 284 | if (sflag) { | ||
4228 | 285 | unix_dg_tmp_socket = sflag; | ||
4229 | 286 | } else { | ||
4230 | 287 | strlcpy(unix_dg_tmp_socket_buf, "/tmp/nc.XXXXXXXXXX", | ||
4231 | 288 | UNIX_DG_TMP_SOCKET_SIZE); | ||
4232 | 289 | if (mktemp(unix_dg_tmp_socket_buf) == NULL) | ||
4233 | 290 | err(1, "mktemp"); | ||
4234 | 291 | unix_dg_tmp_socket = unix_dg_tmp_socket_buf; | ||
4235 | 292 | } | ||
4236 | 293 | } | ||
4237 | 294 | |||
4238 | 247 | /* Initialize addrinfo structure. */ | 295 | /* Initialize addrinfo structure. */ |
4239 | 248 | if (family != AF_UNIX) { | 296 | if (family != AF_UNIX) { |
4240 | 249 | memset(&hints, 0, sizeof(struct addrinfo)); | 297 | memset(&hints, 0, sizeof(struct addrinfo)); |
4241 | @@ -286,8 +334,12 @@ | |||
4242 | 286 | int connfd; | 334 | int connfd; |
4243 | 287 | ret = 0; | 335 | ret = 0; |
4244 | 288 | 336 | ||
4247 | 289 | if (family == AF_UNIX) | 337 | if (family == AF_UNIX) { |
4248 | 290 | s = unix_listen(host); | 338 | if (uflag) |
4249 | 339 | s = unix_bind(host); | ||
4250 | 340 | else | ||
4251 | 341 | s = unix_listen(host); | ||
4252 | 342 | } | ||
4253 | 291 | 343 | ||
4254 | 292 | /* Allow only one connection at a time, but stay alive. */ | 344 | /* Allow only one connection at a time, but stay alive. */ |
4255 | 293 | for (;;) { | 345 | for (;;) { |
4256 | @@ -302,11 +354,11 @@ | |||
4257 | 302 | */ | 354 | */ |
4258 | 303 | if (uflag) { | 355 | if (uflag) { |
4259 | 304 | int rv, plen; | 356 | int rv, plen; |
4261 | 305 | char buf[8192]; | 357 | char buf[16384]; |
4262 | 306 | struct sockaddr_storage z; | 358 | struct sockaddr_storage z; |
4263 | 307 | 359 | ||
4264 | 308 | len = sizeof(z); | 360 | len = sizeof(z); |
4266 | 309 | plen = jflag ? 8192 : 1024; | 361 | plen = jflag ? 16384 : 2048; |
4267 | 310 | rv = recvfrom(s, buf, plen, MSG_PEEK, | 362 | rv = recvfrom(s, buf, plen, MSG_PEEK, |
4268 | 311 | (struct sockaddr *)&z, &len); | 363 | (struct sockaddr *)&z, &len); |
4269 | 312 | if (rv < 0) | 364 | if (rv < 0) |
4270 | @@ -316,17 +368,21 @@ | |||
4271 | 316 | if (rv < 0) | 368 | if (rv < 0) |
4272 | 317 | err(1, "connect"); | 369 | err(1, "connect"); |
4273 | 318 | 370 | ||
4275 | 319 | connfd = s; | 371 | readwrite(s); |
4276 | 320 | } else { | 372 | } else { |
4277 | 321 | len = sizeof(cliaddr); | 373 | len = sizeof(cliaddr); |
4278 | 322 | connfd = accept(s, (struct sockaddr *)&cliaddr, | 374 | connfd = accept(s, (struct sockaddr *)&cliaddr, |
4279 | 323 | &len); | 375 | &len); |
4280 | 376 | readwrite(connfd); | ||
4281 | 377 | close(connfd); | ||
4282 | 324 | } | 378 | } |
4283 | 325 | 379 | ||
4284 | 326 | readwrite(connfd); | ||
4285 | 327 | close(connfd); | ||
4286 | 328 | if (family != AF_UNIX) | 380 | if (family != AF_UNIX) |
4287 | 329 | close(s); | 381 | close(s); |
4288 | 382 | else if (uflag) { | ||
4289 | 383 | if (connect(s, NULL, 0) < 0) | ||
4290 | 384 | err(1, "connect"); | ||
4291 | 385 | } | ||
4292 | 330 | 386 | ||
4293 | 331 | if (!kflag) | 387 | if (!kflag) |
4294 | 332 | break; | 388 | break; |
4295 | @@ -340,6 +396,8 @@ | |||
4296 | 340 | } else | 396 | } else |
4297 | 341 | ret = 1; | 397 | ret = 1; |
4298 | 342 | 398 | ||
4299 | 399 | if (uflag) | ||
4300 | 400 | unlink(unix_dg_tmp_socket); | ||
4301 | 343 | exit(ret); | 401 | exit(ret); |
4302 | 344 | 402 | ||
4303 | 345 | } else { | 403 | } else { |
4304 | @@ -382,8 +440,10 @@ | |||
4305 | 382 | uflag ? "udp" : "tcp"); | 440 | uflag ? "udp" : "tcp"); |
4306 | 383 | } | 441 | } |
4307 | 384 | 442 | ||
4310 | 385 | printf("Connection to %s %s port [%s/%s] succeeded!\n", | 443 | fprintf(stderr, |
4311 | 386 | host, portlist[i], uflag ? "udp" : "tcp", | 444 | "Connection to %s %s port [%s/%s] " |
4312 | 445 | "succeeded!\n", host, portlist[i], | ||
4313 | 446 | uflag ? "udp" : "tcp", | ||
4314 | 387 | sv ? sv->s_name : "*"); | 447 | sv ? sv->s_name : "*"); |
4315 | 388 | } | 448 | } |
4316 | 389 | if (!zflag) | 449 | if (!zflag) |
4317 | @@ -398,6 +458,38 @@ | |||
4318 | 398 | } | 458 | } |
4319 | 399 | 459 | ||
4320 | 400 | /* | 460 | /* |
4321 | 461 | * unix_bind() | ||
4322 | 462 | * Returns a unix socket bound to the given path | ||
4323 | 463 | */ | ||
4324 | 464 | int | ||
4325 | 465 | unix_bind(char *path) | ||
4326 | 466 | { | ||
4327 | 467 | struct sockaddr_un sun; | ||
4328 | 468 | int s; | ||
4329 | 469 | |||
4330 | 470 | /* Create unix domain socket. */ | ||
4331 | 471 | if ((s = socket(AF_UNIX, uflag ? SOCK_DGRAM : SOCK_STREAM, | ||
4332 | 472 | 0)) < 0) | ||
4333 | 473 | return (-1); | ||
4334 | 474 | |||
4335 | 475 | memset(&sun, 0, sizeof(struct sockaddr_un)); | ||
4336 | 476 | sun.sun_family = AF_UNIX; | ||
4337 | 477 | |||
4338 | 478 | if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= | ||
4339 | 479 | sizeof(sun.sun_path)) { | ||
4340 | 480 | close(s); | ||
4341 | 481 | errno = ENAMETOOLONG; | ||
4342 | 482 | return (-1); | ||
4343 | 483 | } | ||
4344 | 484 | |||
4345 | 485 | if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { | ||
4346 | 486 | close(s); | ||
4347 | 487 | return (-1); | ||
4348 | 488 | } | ||
4349 | 489 | return (s); | ||
4350 | 490 | } | ||
4351 | 491 | |||
4352 | 492 | /* | ||
4353 | 401 | * unix_connect() | 493 | * unix_connect() |
4354 | 402 | * Returns a socket connected to a local unix socket. Returns -1 on failure. | 494 | * Returns a socket connected to a local unix socket. Returns -1 on failure. |
4355 | 403 | */ | 495 | */ |
4356 | @@ -407,8 +499,13 @@ | |||
4357 | 407 | struct sockaddr_un sun; | 499 | struct sockaddr_un sun; |
4358 | 408 | int s; | 500 | int s; |
4359 | 409 | 501 | ||
4362 | 410 | if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) | 502 | if (uflag) { |
4363 | 411 | return (-1); | 503 | if ((s = unix_bind(unix_dg_tmp_socket)) < 0) |
4364 | 504 | return (-1); | ||
4365 | 505 | } else { | ||
4366 | 506 | if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) | ||
4367 | 507 | return (-1); | ||
4368 | 508 | } | ||
4369 | 412 | (void)fcntl(s, F_SETFD, 1); | 509 | (void)fcntl(s, F_SETFD, 1); |
4370 | 413 | 510 | ||
4371 | 414 | memset(&sun, 0, sizeof(struct sockaddr_un)); | 511 | memset(&sun, 0, sizeof(struct sockaddr_un)); |
4372 | @@ -435,27 +532,9 @@ | |||
4373 | 435 | int | 532 | int |
4374 | 436 | unix_listen(char *path) | 533 | unix_listen(char *path) |
4375 | 437 | { | 534 | { |
4376 | 438 | struct sockaddr_un sun; | ||
4377 | 439 | int s; | 535 | int s; |
4397 | 440 | 536 | if ((s = unix_bind(path)) < 0) | |
4398 | 441 | /* Create unix domain socket. */ | 537 | return (-1); |
4380 | 442 | if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) | ||
4381 | 443 | return (-1); | ||
4382 | 444 | |||
4383 | 445 | memset(&sun, 0, sizeof(struct sockaddr_un)); | ||
4384 | 446 | sun.sun_family = AF_UNIX; | ||
4385 | 447 | |||
4386 | 448 | if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= | ||
4387 | 449 | sizeof(sun.sun_path)) { | ||
4388 | 450 | close(s); | ||
4389 | 451 | errno = ENAMETOOLONG; | ||
4390 | 452 | return (-1); | ||
4391 | 453 | } | ||
4392 | 454 | |||
4393 | 455 | if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { | ||
4394 | 456 | close(s); | ||
4395 | 457 | return (-1); | ||
4396 | 458 | } | ||
4399 | 459 | 538 | ||
4400 | 460 | if (listen(s, 5) < 0) { | 539 | if (listen(s, 5) < 0) { |
4401 | 461 | close(s); | 540 | close(s); |
4402 | @@ -473,7 +552,7 @@ | |||
4403 | 473 | remote_connect(const char *host, const char *port, struct addrinfo hints) | 552 | remote_connect(const char *host, const char *port, struct addrinfo hints) |
4404 | 474 | { | 553 | { |
4405 | 475 | struct addrinfo *res, *res0; | 554 | struct addrinfo *res, *res0; |
4407 | 476 | int s, error; | 555 | int s, error, on = 1; |
4408 | 477 | 556 | ||
4409 | 478 | if ((error = getaddrinfo(host, port, &hints, &res))) | 557 | if ((error = getaddrinfo(host, port, &hints, &res))) |
4410 | 479 | errx(1, "getaddrinfo: %s", gai_strerror(error)); | 558 | errx(1, "getaddrinfo: %s", gai_strerror(error)); |
4411 | @@ -484,10 +563,18 @@ | |||
4412 | 484 | res0->ai_protocol)) < 0) | 563 | res0->ai_protocol)) < 0) |
4413 | 485 | continue; | 564 | continue; |
4414 | 486 | 565 | ||
4415 | 566 | if (rtableid) { | ||
4416 | 567 | if (setsockopt(s, SOL_SOCKET, SO_RTABLE, &rtableid, | ||
4417 | 568 | sizeof(rtableid)) == -1) | ||
4418 | 569 | err(1, "setsockopt SO_RTABLE"); | ||
4419 | 570 | } | ||
4420 | 571 | |||
4421 | 487 | /* Bind to a local port or source address if specified. */ | 572 | /* Bind to a local port or source address if specified. */ |
4422 | 488 | if (sflag || pflag) { | 573 | if (sflag || pflag) { |
4423 | 489 | struct addrinfo ahints, *ares; | 574 | struct addrinfo ahints, *ares; |
4424 | 490 | 575 | ||
4425 | 576 | /* try SO_BINDANY, but don't insist */ | ||
4426 | 577 | setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on)); | ||
4427 | 491 | memset(&ahints, 0, sizeof(struct addrinfo)); | 578 | memset(&ahints, 0, sizeof(struct addrinfo)); |
4428 | 492 | ahints.ai_family = res0->ai_family; | 579 | ahints.ai_family = res0->ai_family; |
4429 | 493 | ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM; | 580 | ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM; |
4430 | @@ -504,7 +591,7 @@ | |||
4431 | 504 | 591 | ||
4432 | 505 | set_common_sockopts(s); | 592 | set_common_sockopts(s); |
4433 | 506 | 593 | ||
4435 | 507 | if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0) | 594 | if (timeout_connect(s, res0->ai_addr, res0->ai_addrlen) == 0) |
4436 | 508 | break; | 595 | break; |
4437 | 509 | else if (vflag) | 596 | else if (vflag) |
4438 | 510 | warn("connect to %s port %s (%s) failed", host, port, | 597 | warn("connect to %s port %s (%s) failed", host, port, |
4439 | @@ -519,6 +606,43 @@ | |||
4440 | 519 | return (s); | 606 | return (s); |
4441 | 520 | } | 607 | } |
4442 | 521 | 608 | ||
4443 | 609 | int | ||
4444 | 610 | timeout_connect(int s, const struct sockaddr *name, socklen_t namelen) | ||
4445 | 611 | { | ||
4446 | 612 | struct pollfd pfd; | ||
4447 | 613 | socklen_t optlen; | ||
4448 | 614 | int flags, optval; | ||
4449 | 615 | int ret; | ||
4450 | 616 | |||
4451 | 617 | if (timeout != -1) { | ||
4452 | 618 | flags = fcntl(s, F_GETFL, 0); | ||
4453 | 619 | if (fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1) | ||
4454 | 620 | err(1, "set non-blocking mode"); | ||
4455 | 621 | } | ||
4456 | 622 | |||
4457 | 623 | if ((ret = connect(s, name, namelen)) != 0 && errno == EINPROGRESS) { | ||
4458 | 624 | pfd.fd = s; | ||
4459 | 625 | pfd.events = POLLOUT; | ||
4460 | 626 | if ((ret = poll(&pfd, 1, timeout)) == 1) { | ||
4461 | 627 | optlen = sizeof(optval); | ||
4462 | 628 | if ((ret = getsockopt(s, SOL_SOCKET, SO_ERROR, | ||
4463 | 629 | &optval, &optlen)) == 0) { | ||
4464 | 630 | errno = optval; | ||
4465 | 631 | ret = optval == 0 ? 0 : -1; | ||
4466 | 632 | } | ||
4467 | 633 | } else if (ret == 0) { | ||
4468 | 634 | errno = ETIMEDOUT; | ||
4469 | 635 | ret = -1; | ||
4470 | 636 | } else | ||
4471 | 637 | err(1, "poll failed"); | ||
4472 | 638 | } | ||
4473 | 639 | |||
4474 | 640 | if (timeout != -1 && fcntl(s, F_SETFL, flags) == -1) | ||
4475 | 641 | err(1, "restoring flags"); | ||
4476 | 642 | |||
4477 | 643 | return (ret); | ||
4478 | 644 | } | ||
4479 | 645 | |||
4480 | 522 | /* | 646 | /* |
4481 | 523 | * local_listen() | 647 | * local_listen() |
4482 | 524 | * Returns a socket listening on a local port, binds to specified source | 648 | * Returns a socket listening on a local port, binds to specified source |
4483 | @@ -550,6 +674,12 @@ | |||
4484 | 550 | res0->ai_protocol)) < 0) | 674 | res0->ai_protocol)) < 0) |
4485 | 551 | continue; | 675 | continue; |
4486 | 552 | 676 | ||
4487 | 677 | if (rtableid) { | ||
4488 | 678 | if (setsockopt(s, IPPROTO_IP, SO_RTABLE, &rtableid, | ||
4489 | 679 | sizeof(rtableid)) == -1) | ||
4490 | 680 | err(1, "setsockopt SO_RTABLE"); | ||
4491 | 681 | } | ||
4492 | 682 | |||
4493 | 553 | ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); | 683 | ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); |
4494 | 554 | if (ret == -1) | 684 | if (ret == -1) |
4495 | 555 | err(1, NULL); | 685 | err(1, NULL); |
4496 | @@ -582,12 +712,12 @@ | |||
4497 | 582 | readwrite(int nfd) | 712 | readwrite(int nfd) |
4498 | 583 | { | 713 | { |
4499 | 584 | struct pollfd pfd[2]; | 714 | struct pollfd pfd[2]; |
4501 | 585 | unsigned char buf[8192]; | 715 | unsigned char buf[16384]; |
4502 | 586 | int n, wfd = fileno(stdin); | 716 | int n, wfd = fileno(stdin); |
4503 | 587 | int lfd = fileno(stdout); | 717 | int lfd = fileno(stdout); |
4504 | 588 | int plen; | 718 | int plen; |
4505 | 589 | 719 | ||
4507 | 590 | plen = jflag ? 8192 : 1024; | 720 | plen = jflag ? 16384 : 2048; |
4508 | 591 | 721 | ||
4509 | 592 | /* Setup Network FD */ | 722 | /* Setup Network FD */ |
4510 | 593 | pfd[0].fd = nfd; | 723 | pfd[0].fd = nfd; |
4511 | @@ -646,33 +776,33 @@ | |||
4512 | 646 | unsigned char *p, *end; | 776 | unsigned char *p, *end; |
4513 | 647 | unsigned char obuf[4]; | 777 | unsigned char obuf[4]; |
4514 | 648 | 778 | ||
4517 | 649 | end = buf + size; | 779 | if (size < 3) |
4518 | 650 | obuf[0] = '\0'; | 780 | return; |
4519 | 781 | end = buf + size - 2; | ||
4520 | 651 | 782 | ||
4521 | 652 | for (p = buf; p < end; p++) { | 783 | for (p = buf; p < end; p++) { |
4522 | 653 | if (*p != IAC) | 784 | if (*p != IAC) |
4524 | 654 | break; | 785 | continue; |
4525 | 655 | 786 | ||
4526 | 656 | obuf[0] = IAC; | 787 | obuf[0] = IAC; |
4527 | 657 | p++; | 788 | p++; |
4528 | 658 | if ((*p == WILL) || (*p == WONT)) | 789 | if ((*p == WILL) || (*p == WONT)) |
4529 | 659 | obuf[1] = DONT; | 790 | obuf[1] = DONT; |
4531 | 660 | if ((*p == DO) || (*p == DONT)) | 791 | else if ((*p == DO) || (*p == DONT)) |
4532 | 661 | obuf[1] = WONT; | 792 | obuf[1] = WONT; |
4541 | 662 | if (obuf) { | 793 | else |
4542 | 663 | p++; | 794 | continue; |
4543 | 664 | obuf[2] = *p; | 795 | |
4544 | 665 | obuf[3] = '\0'; | 796 | p++; |
4545 | 666 | if (atomicio(vwrite, nfd, obuf, 3) != 3) | 797 | obuf[2] = *p; |
4546 | 667 | warn("Write Error!"); | 798 | if (atomicio(vwrite, nfd, obuf, 3) != 3) |
4547 | 668 | obuf[0] = '\0'; | 799 | warn("Write Error!"); |
4540 | 669 | } | ||
4548 | 670 | } | 800 | } |
4549 | 671 | } | 801 | } |
4550 | 672 | 802 | ||
4551 | 673 | /* | 803 | /* |
4552 | 674 | * build_ports() | 804 | * build_ports() |
4554 | 675 | * Build an array or ports in portlist[], listing each port | 805 | * Build an array of ports in portlist[], listing each port |
4555 | 676 | * that we should try to connect to. | 806 | * that we should try to connect to. |
4556 | 677 | */ | 807 | */ |
4557 | 678 | void | 808 | void |
4558 | @@ -684,9 +814,6 @@ | |||
4559 | 684 | int x = 0; | 814 | int x = 0; |
4560 | 685 | 815 | ||
4561 | 686 | if ((n = strchr(p, '-')) != NULL) { | 816 | if ((n = strchr(p, '-')) != NULL) { |
4562 | 687 | if (lflag) | ||
4563 | 688 | errx(1, "Cannot use -l with multiple ports!"); | ||
4564 | 689 | |||
4565 | 690 | *n = '\0'; | 817 | *n = '\0'; |
4566 | 691 | n++; | 818 | n++; |
4567 | 692 | 819 | ||
4568 | @@ -729,18 +856,16 @@ | |||
4569 | 729 | hi = strtonum(p, 1, PORT_MAX, &errstr); | 856 | hi = strtonum(p, 1, PORT_MAX, &errstr); |
4570 | 730 | if (errstr) | 857 | if (errstr) |
4571 | 731 | errx(1, "port number %s: %s", errstr, p); | 858 | errx(1, "port number %s: %s", errstr, p); |
4573 | 732 | portlist[0] = calloc(1, PORT_MAX_LEN); | 859 | portlist[0] = strdup(p); |
4574 | 733 | if (portlist[0] == NULL) | 860 | if (portlist[0] == NULL) |
4575 | 734 | err(1, NULL); | 861 | err(1, NULL); |
4576 | 735 | portlist[0] = p; | ||
4577 | 736 | } | 862 | } |
4578 | 737 | } | 863 | } |
4579 | 738 | 864 | ||
4580 | 739 | /* | 865 | /* |
4581 | 740 | * udptest() | 866 | * udptest() |
4582 | 741 | * Do a few writes to see if the UDP port is there. | 867 | * Do a few writes to see if the UDP port is there. |
4585 | 742 | * XXX - Better way of doing this? Doesn't work for IPv6. | 868 | * Fails once PF state table is full. |
4584 | 743 | * Also fails after around 100 ports checked. | ||
4586 | 744 | */ | 869 | */ |
4587 | 745 | int | 870 | int |
4588 | 746 | udptest(int s) | 871 | udptest(int s) |
4589 | @@ -781,23 +906,64 @@ | |||
4590 | 781 | &Tflag, sizeof(Tflag)) == -1) | 906 | &Tflag, sizeof(Tflag)) == -1) |
4591 | 782 | err(1, "set IP ToS"); | 907 | err(1, "set IP ToS"); |
4592 | 783 | } | 908 | } |
4593 | 909 | if (Iflag) { | ||
4594 | 910 | if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, | ||
4595 | 911 | &Iflag, sizeof(Iflag)) == -1) | ||
4596 | 912 | err(1, "set TCP receive buffer size"); | ||
4597 | 913 | } | ||
4598 | 914 | if (Oflag) { | ||
4599 | 915 | if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, | ||
4600 | 916 | &Oflag, sizeof(Oflag)) == -1) | ||
4601 | 917 | err(1, "set TCP send buffer size"); | ||
4602 | 918 | } | ||
4603 | 784 | } | 919 | } |
4604 | 785 | 920 | ||
4605 | 786 | int | 921 | int |
4607 | 787 | parse_iptos(char *s) | 922 | map_tos(char *s, int *val) |
4608 | 788 | { | 923 | { |
4621 | 789 | int tos = -1; | 924 | /* DiffServ Codepoints and other TOS mappings */ |
4622 | 790 | 925 | const struct toskeywords { | |
4623 | 791 | if (strcmp(s, "lowdelay") == 0) | 926 | const char *keyword; |
4624 | 792 | return (IPTOS_LOWDELAY); | 927 | int val; |
4625 | 793 | if (strcmp(s, "throughput") == 0) | 928 | } *t, toskeywords[] = { |
4626 | 794 | return (IPTOS_THROUGHPUT); | 929 | { "af11", IPTOS_DSCP_AF11 }, |
4627 | 795 | if (strcmp(s, "reliability") == 0) | 930 | { "af12", IPTOS_DSCP_AF12 }, |
4628 | 796 | return (IPTOS_RELIABILITY); | 931 | { "af13", IPTOS_DSCP_AF13 }, |
4629 | 797 | 932 | { "af21", IPTOS_DSCP_AF21 }, | |
4630 | 798 | if (sscanf(s, "0x%x", &tos) != 1 || tos < 0 || tos > 0xff) | 933 | { "af22", IPTOS_DSCP_AF22 }, |
4631 | 799 | errx(1, "invalid IP Type of Service"); | 934 | { "af23", IPTOS_DSCP_AF23 }, |
4632 | 800 | return (tos); | 935 | { "af31", IPTOS_DSCP_AF31 }, |
4633 | 936 | { "af32", IPTOS_DSCP_AF32 }, | ||
4634 | 937 | { "af33", IPTOS_DSCP_AF33 }, | ||
4635 | 938 | { "af41", IPTOS_DSCP_AF41 }, | ||
4636 | 939 | { "af42", IPTOS_DSCP_AF42 }, | ||
4637 | 940 | { "af43", IPTOS_DSCP_AF43 }, | ||
4638 | 941 | { "critical", IPTOS_PREC_CRITIC_ECP }, | ||
4639 | 942 | { "cs0", IPTOS_DSCP_CS0 }, | ||
4640 | 943 | { "cs1", IPTOS_DSCP_CS1 }, | ||
4641 | 944 | { "cs2", IPTOS_DSCP_CS2 }, | ||
4642 | 945 | { "cs3", IPTOS_DSCP_CS3 }, | ||
4643 | 946 | { "cs4", IPTOS_DSCP_CS4 }, | ||
4644 | 947 | { "cs5", IPTOS_DSCP_CS5 }, | ||
4645 | 948 | { "cs6", IPTOS_DSCP_CS6 }, | ||
4646 | 949 | { "cs7", IPTOS_DSCP_CS7 }, | ||
4647 | 950 | { "ef", IPTOS_DSCP_EF }, | ||
4648 | 951 | { "inetcontrol", IPTOS_PREC_INTERNETCONTROL }, | ||
4649 | 952 | { "lowdelay", IPTOS_LOWDELAY }, | ||
4650 | 953 | { "netcontrol", IPTOS_PREC_NETCONTROL }, | ||
4651 | 954 | { "reliability", IPTOS_RELIABILITY }, | ||
4652 | 955 | { "throughput", IPTOS_THROUGHPUT }, | ||
4653 | 956 | { NULL, -1 }, | ||
4654 | 957 | }; | ||
4655 | 958 | |||
4656 | 959 | for (t = toskeywords; t->keyword != NULL; t++) { | ||
4657 | 960 | if (strcmp(s, t->keyword) == 0) { | ||
4658 | 961 | *val = t->val; | ||
4659 | 962 | return (1); | ||
4660 | 963 | } | ||
4661 | 964 | } | ||
4662 | 965 | |||
4663 | 966 | return (0); | ||
4664 | 801 | } | 967 | } |
4665 | 802 | 968 | ||
4666 | 803 | void | 969 | void |
4667 | @@ -810,19 +976,22 @@ | |||
4668 | 810 | \t-D Enable the debug socket option\n\ | 976 | \t-D Enable the debug socket option\n\ |
4669 | 811 | \t-d Detach from stdin\n\ | 977 | \t-d Detach from stdin\n\ |
4670 | 812 | \t-h This help text\n\ | 978 | \t-h This help text\n\ |
4671 | 979 | \t-I length TCP receive buffer length\n\ | ||
4672 | 813 | \t-i secs\t Delay interval for lines sent, ports scanned\n\ | 980 | \t-i secs\t Delay interval for lines sent, ports scanned\n\ |
4673 | 814 | \t-k Keep inbound sockets open for multiple connects\n\ | 981 | \t-k Keep inbound sockets open for multiple connects\n\ |
4674 | 815 | \t-l Listen mode, for inbound connects\n\ | 982 | \t-l Listen mode, for inbound connects\n\ |
4675 | 816 | \t-n Suppress name/port resolutions\n\ | 983 | \t-n Suppress name/port resolutions\n\ |
4676 | 984 | \t-O length TCP send buffer length\n\ | ||
4677 | 817 | \t-P proxyuser\tUsername for proxy authentication\n\ | 985 | \t-P proxyuser\tUsername for proxy authentication\n\ |
4678 | 818 | \t-p port\t Specify local port for remote connects\n\ | 986 | \t-p port\t Specify local port for remote connects\n\ |
4679 | 819 | \t-r Randomize remote ports\n\ | 987 | \t-r Randomize remote ports\n\ |
4680 | 820 | \t-S Enable the TCP MD5 signature option\n\ | 988 | \t-S Enable the TCP MD5 signature option\n\ |
4681 | 821 | \t-s addr\t Local source address\n\ | 989 | \t-s addr\t Local source address\n\ |
4683 | 822 | \t-T ToS\t Set IP Type of Service\n\ | 990 | \t-T toskeyword\tSet IP Type of Service\n\ |
4684 | 823 | \t-t Answer TELNET negotiation\n\ | 991 | \t-t Answer TELNET negotiation\n\ |
4685 | 824 | \t-U Use UNIX domain socket\n\ | 992 | \t-U Use UNIX domain socket\n\ |
4686 | 825 | \t-u UDP mode\n\ | 993 | \t-u UDP mode\n\ |
4687 | 994 | \t-V rtable Specify alternate routing table\n\ | ||
4688 | 826 | \t-v Verbose\n\ | 995 | \t-v Verbose\n\ |
4689 | 827 | \t-w secs\t Timeout for connects and final net reads\n\ | 996 | \t-w secs\t Timeout for connects and final net reads\n\ |
4690 | 828 | \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\ | 997 | \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\ |
4691 | @@ -835,9 +1004,11 @@ | |||
4692 | 835 | void | 1004 | void |
4693 | 836 | usage(int ret) | 1005 | usage(int ret) |
4694 | 837 | { | 1006 | { |
4698 | 838 | fprintf(stderr, "usage: nc [-46DdhklnrStUuvz] [-i interval] [-P proxy_username] [-p source_port]\n"); | 1007 | fprintf(stderr, |
4699 | 839 | fprintf(stderr, "\t [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]\n"); | 1008 | "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n" |
4700 | 840 | fprintf(stderr, "\t [-x proxy_address[:port]] [hostname] [port[s]]\n"); | 1009 | "\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n" |
4701 | 1010 | "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n" | ||
4702 | 1011 | "\t [-x proxy_address[:port]] [destination] [port]\n"); | ||
4703 | 841 | if (ret) | 1012 | if (ret) |
4704 | 842 | exit(1); | 1013 | exit(1); |
4705 | 843 | } | 1014 | } |
4706 | 844 | 1015 | ||
4707 | === removed directory 'openbsd-compat' | |||
4708 | === removed file 'openbsd-compat/base64.c' | |||
4709 | --- openbsd-compat/base64.c 2008-01-30 18:24:46 +0000 | |||
4710 | +++ openbsd-compat/base64.c 1970-01-01 00:00:00 +0000 | |||
4711 | @@ -1,308 +0,0 @@ | |||
4712 | 1 | /* $OpenBSD: base64.c,v 1.5 2006/10/21 09:55:03 otto Exp $ */ | ||
4713 | 2 | |||
4714 | 3 | /* | ||
4715 | 4 | * Copyright (c) 1996 by Internet Software Consortium. | ||
4716 | 5 | * | ||
4717 | 6 | * Permission to use, copy, modify, and distribute this software for any | ||
4718 | 7 | * purpose with or without fee is hereby granted, provided that the above | ||
4719 | 8 | * copyright notice and this permission notice appear in all copies. | ||
4720 | 9 | * | ||
4721 | 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
4722 | 11 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
4723 | 12 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
4724 | 13 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
4725 | 14 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
4726 | 15 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
4727 | 16 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
4728 | 17 | * SOFTWARE. | ||
4729 | 18 | */ | ||
4730 | 19 | |||
4731 | 20 | /* | ||
4732 | 21 | * Portions Copyright (c) 1995 by International Business Machines, Inc. | ||
4733 | 22 | * | ||
4734 | 23 | * International Business Machines, Inc. (hereinafter called IBM) grants | ||
4735 | 24 | * permission under its copyrights to use, copy, modify, and distribute this | ||
4736 | 25 | * Software with or without fee, provided that the above copyright notice and | ||
4737 | 26 | * all paragraphs of this notice appear in all copies, and that the name of IBM | ||
4738 | 27 | * not be used in connection with the marketing of any product incorporating | ||
4739 | 28 | * the Software or modifications thereof, without specific, written prior | ||
4740 | 29 | * permission. | ||
4741 | 30 | * | ||
4742 | 31 | * To the extent it has a right to do so, IBM grants an immunity from suit | ||
4743 | 32 | * under its patents, if any, for the use, sale or manufacture of products to | ||
4744 | 33 | * the extent that such products are used for performing Domain Name System | ||
4745 | 34 | * dynamic updates in TCP/IP networks by means of the Software. No immunity is | ||
4746 | 35 | * granted for any product per se or for any other function of any product. | ||
4747 | 36 | * | ||
4748 | 37 | * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, | ||
4749 | 38 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
4750 | 39 | * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, | ||
4751 | 40 | * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING | ||
4752 | 41 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN | ||
4753 | 42 | * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. | ||
4754 | 43 | */ | ||
4755 | 44 | |||
4756 | 45 | #include <sys/types.h> | ||
4757 | 46 | #include <sys/param.h> | ||
4758 | 47 | #include <sys/socket.h> | ||
4759 | 48 | #include <netinet/in.h> | ||
4760 | 49 | #include <arpa/inet.h> | ||
4761 | 50 | #include <arpa/nameser.h> | ||
4762 | 51 | |||
4763 | 52 | #include <ctype.h> | ||
4764 | 53 | #include <resolv.h> | ||
4765 | 54 | #include <stdio.h> | ||
4766 | 55 | |||
4767 | 56 | #include <stdlib.h> | ||
4768 | 57 | #include <string.h> | ||
4769 | 58 | |||
4770 | 59 | static const char Base64[] = | ||
4771 | 60 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
4772 | 61 | static const char Pad64 = '='; | ||
4773 | 62 | |||
4774 | 63 | /* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) | ||
4775 | 64 | The following encoding technique is taken from RFC 1521 by Borenstein | ||
4776 | 65 | and Freed. It is reproduced here in a slightly edited form for | ||
4777 | 66 | convenience. | ||
4778 | 67 | |||
4779 | 68 | A 65-character subset of US-ASCII is used, enabling 6 bits to be | ||
4780 | 69 | represented per printable character. (The extra 65th character, "=", | ||
4781 | 70 | is used to signify a special processing function.) | ||
4782 | 71 | |||
4783 | 72 | The encoding process represents 24-bit groups of input bits as output | ||
4784 | 73 | strings of 4 encoded characters. Proceeding from left to right, a | ||
4785 | 74 | 24-bit input group is formed by concatenating 3 8-bit input groups. | ||
4786 | 75 | These 24 bits are then treated as 4 concatenated 6-bit groups, each | ||
4787 | 76 | of which is translated into a single digit in the base64 alphabet. | ||
4788 | 77 | |||
4789 | 78 | Each 6-bit group is used as an index into an array of 64 printable | ||
4790 | 79 | characters. The character referenced by the index is placed in the | ||
4791 | 80 | output string. | ||
4792 | 81 | |||
4793 | 82 | Table 1: The Base64 Alphabet | ||
4794 | 83 | |||
4795 | 84 | Value Encoding Value Encoding Value Encoding Value Encoding | ||
4796 | 85 | 0 A 17 R 34 i 51 z | ||
4797 | 86 | 1 B 18 S 35 j 52 0 | ||
4798 | 87 | 2 C 19 T 36 k 53 1 | ||
4799 | 88 | 3 D 20 U 37 l 54 2 | ||
4800 | 89 | 4 E 21 V 38 m 55 3 | ||
4801 | 90 | 5 F 22 W 39 n 56 4 | ||
4802 | 91 | 6 G 23 X 40 o 57 5 | ||
4803 | 92 | 7 H 24 Y 41 p 58 6 | ||
4804 | 93 | 8 I 25 Z 42 q 59 7 | ||
4805 | 94 | 9 J 26 a 43 r 60 8 | ||
4806 | 95 | 10 K 27 b 44 s 61 9 | ||
4807 | 96 | 11 L 28 c 45 t 62 + | ||
4808 | 97 | 12 M 29 d 46 u 63 / | ||
4809 | 98 | 13 N 30 e 47 v | ||
4810 | 99 | 14 O 31 f 48 w (pad) = | ||
4811 | 100 | 15 P 32 g 49 x | ||
4812 | 101 | 16 Q 33 h 50 y | ||
4813 | 102 | |||
4814 | 103 | Special processing is performed if fewer than 24 bits are available | ||
4815 | 104 | at the end of the data being encoded. A full encoding quantum is | ||
4816 | 105 | always completed at the end of a quantity. When fewer than 24 input | ||
4817 | 106 | bits are available in an input group, zero bits are added (on the | ||
4818 | 107 | right) to form an integral number of 6-bit groups. Padding at the | ||
4819 | 108 | end of the data is performed using the '=' character. | ||
4820 | 109 | |||
4821 | 110 | Since all base64 input is an integral number of octets, only the | ||
4822 | 111 | ------------------------------------------------- | ||
4823 | 112 | following cases can arise: | ||
4824 | 113 | |||
4825 | 114 | (1) the final quantum of encoding input is an integral | ||
4826 | 115 | multiple of 24 bits; here, the final unit of encoded | ||
4827 | 116 | output will be an integral multiple of 4 characters | ||
4828 | 117 | with no "=" padding, | ||
4829 | 118 | (2) the final quantum of encoding input is exactly 8 bits; | ||
4830 | 119 | here, the final unit of encoded output will be two | ||
4831 | 120 | characters followed by two "=" padding characters, or | ||
4832 | 121 | (3) the final quantum of encoding input is exactly 16 bits; | ||
4833 | 122 | here, the final unit of encoded output will be three | ||
4834 | 123 | characters followed by one "=" padding character. | ||
4835 | 124 | */ | ||
4836 | 125 | |||
4837 | 126 | int | ||
4838 | 127 | b64_ntop(src, srclength, target, targsize) | ||
4839 | 128 | u_char const *src; | ||
4840 | 129 | size_t srclength; | ||
4841 | 130 | char *target; | ||
4842 | 131 | size_t targsize; | ||
4843 | 132 | { | ||
4844 | 133 | size_t datalength = 0; | ||
4845 | 134 | u_char input[3]; | ||
4846 | 135 | u_char output[4]; | ||
4847 | 136 | int i; | ||
4848 | 137 | |||
4849 | 138 | while (2 < srclength) { | ||
4850 | 139 | input[0] = *src++; | ||
4851 | 140 | input[1] = *src++; | ||
4852 | 141 | input[2] = *src++; | ||
4853 | 142 | srclength -= 3; | ||
4854 | 143 | |||
4855 | 144 | output[0] = input[0] >> 2; | ||
4856 | 145 | output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); | ||
4857 | 146 | output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); | ||
4858 | 147 | output[3] = input[2] & 0x3f; | ||
4859 | 148 | |||
4860 | 149 | if (datalength + 4 > targsize) | ||
4861 | 150 | return (-1); | ||
4862 | 151 | target[datalength++] = Base64[output[0]]; | ||
4863 | 152 | target[datalength++] = Base64[output[1]]; | ||
4864 | 153 | target[datalength++] = Base64[output[2]]; | ||
4865 | 154 | target[datalength++] = Base64[output[3]]; | ||
4866 | 155 | } | ||
4867 | 156 | |||
4868 | 157 | /* Now we worry about padding. */ | ||
4869 | 158 | if (0 != srclength) { | ||
4870 | 159 | /* Get what's left. */ | ||
4871 | 160 | input[0] = input[1] = input[2] = '\0'; | ||
4872 | 161 | for (i = 0; i < srclength; i++) | ||
4873 | 162 | input[i] = *src++; | ||
4874 | 163 | |||
4875 | 164 | output[0] = input[0] >> 2; | ||
4876 | 165 | output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); | ||
4877 | 166 | output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); | ||
4878 | 167 | |||
4879 | 168 | if (datalength + 4 > targsize) | ||
4880 | 169 | return (-1); | ||
4881 | 170 | target[datalength++] = Base64[output[0]]; | ||
4882 | 171 | target[datalength++] = Base64[output[1]]; | ||
4883 | 172 | if (srclength == 1) | ||
4884 | 173 | target[datalength++] = Pad64; | ||
4885 | 174 | else | ||
4886 | 175 | target[datalength++] = Base64[output[2]]; | ||
4887 | 176 | target[datalength++] = Pad64; | ||
4888 | 177 | } | ||
4889 | 178 | if (datalength >= targsize) | ||
4890 | 179 | return (-1); | ||
4891 | 180 | target[datalength] = '\0'; /* Returned value doesn't count \0. */ | ||
4892 | 181 | return (datalength); | ||
4893 | 182 | } | ||
4894 | 183 | |||
4895 | 184 | /* skips all whitespace anywhere. | ||
4896 | 185 | converts characters, four at a time, starting at (or after) | ||
4897 | 186 | src from base - 64 numbers into three 8 bit bytes in the target area. | ||
4898 | 187 | it returns the number of data bytes stored at the target, or -1 on error. | ||
4899 | 188 | */ | ||
4900 | 189 | |||
4901 | 190 | int | ||
4902 | 191 | b64_pton(src, target, targsize) | ||
4903 | 192 | char const *src; | ||
4904 | 193 | u_char *target; | ||
4905 | 194 | size_t targsize; | ||
4906 | 195 | { | ||
4907 | 196 | int tarindex, state, ch; | ||
4908 | 197 | char *pos; | ||
4909 | 198 | |||
4910 | 199 | state = 0; | ||
4911 | 200 | tarindex = 0; | ||
4912 | 201 | |||
4913 | 202 | while ((ch = *src++) != '\0') { | ||
4914 | 203 | if (isspace(ch)) /* Skip whitespace anywhere. */ | ||
4915 | 204 | continue; | ||
4916 | 205 | |||
4917 | 206 | if (ch == Pad64) | ||
4918 | 207 | break; | ||
4919 | 208 | |||
4920 | 209 | pos = strchr(Base64, ch); | ||
4921 | 210 | if (pos == 0) /* A non-base64 character. */ | ||
4922 | 211 | return (-1); | ||
4923 | 212 | |||
4924 | 213 | switch (state) { | ||
4925 | 214 | case 0: | ||
4926 | 215 | if (target) { | ||
4927 | 216 | if (tarindex >= targsize) | ||
4928 | 217 | return (-1); | ||
4929 | 218 | target[tarindex] = (pos - Base64) << 2; | ||
4930 | 219 | } | ||
4931 | 220 | state = 1; | ||
4932 | 221 | break; | ||
4933 | 222 | case 1: | ||
4934 | 223 | if (target) { | ||
4935 | 224 | if (tarindex + 1 >= targsize) | ||
4936 | 225 | return (-1); | ||
4937 | 226 | target[tarindex] |= (pos - Base64) >> 4; | ||
4938 | 227 | target[tarindex+1] = ((pos - Base64) & 0x0f) | ||
4939 | 228 | << 4 ; | ||
4940 | 229 | } | ||
4941 | 230 | tarindex++; | ||
4942 | 231 | state = 2; | ||
4943 | 232 | break; | ||
4944 | 233 | case 2: | ||
4945 | 234 | if (target) { | ||
4946 | 235 | if (tarindex + 1 >= targsize) | ||
4947 | 236 | return (-1); | ||
4948 | 237 | target[tarindex] |= (pos - Base64) >> 2; | ||
4949 | 238 | target[tarindex+1] = ((pos - Base64) & 0x03) | ||
4950 | 239 | << 6; | ||
4951 | 240 | } | ||
4952 | 241 | tarindex++; | ||
4953 | 242 | state = 3; | ||
4954 | 243 | break; | ||
4955 | 244 | case 3: | ||
4956 | 245 | if (target) { | ||
4957 | 246 | if (tarindex >= targsize) | ||
4958 | 247 | return (-1); | ||
4959 | 248 | target[tarindex] |= (pos - Base64); | ||
4960 | 249 | } | ||
4961 | 250 | tarindex++; | ||
4962 | 251 | state = 0; | ||
4963 | 252 | break; | ||
4964 | 253 | } | ||
4965 | 254 | } | ||
4966 | 255 | |||
4967 | 256 | /* | ||
4968 | 257 | * We are done decoding Base-64 chars. Let's see if we ended | ||
4969 | 258 | * on a byte boundary, and/or with erroneous trailing characters. | ||
4970 | 259 | */ | ||
4971 | 260 | |||
4972 | 261 | if (ch == Pad64) { /* We got a pad char. */ | ||
4973 | 262 | ch = *src++; /* Skip it, get next. */ | ||
4974 | 263 | switch (state) { | ||
4975 | 264 | case 0: /* Invalid = in first position */ | ||
4976 | 265 | case 1: /* Invalid = in second position */ | ||
4977 | 266 | return (-1); | ||
4978 | 267 | |||
4979 | 268 | case 2: /* Valid, means one byte of info */ | ||
4980 | 269 | /* Skip any number of spaces. */ | ||
4981 | 270 | for (; ch != '\0'; ch = *src++) | ||
4982 | 271 | if (!isspace(ch)) | ||
4983 | 272 | break; | ||
4984 | 273 | /* Make sure there is another trailing = sign. */ | ||
4985 | 274 | if (ch != Pad64) | ||
4986 | 275 | return (-1); | ||
4987 | 276 | ch = *src++; /* Skip the = */ | ||
4988 | 277 | /* Fall through to "single trailing =" case. */ | ||
4989 | 278 | /* FALLTHROUGH */ | ||
4990 | 279 | |||
4991 | 280 | case 3: /* Valid, means two bytes of info */ | ||
4992 | 281 | /* | ||
4993 | 282 | * We know this char is an =. Is there anything but | ||
4994 | 283 | * whitespace after it? | ||
4995 | 284 | */ | ||
4996 | 285 | for (; ch != '\0'; ch = *src++) | ||
4997 | 286 | if (!isspace(ch)) | ||
4998 | 287 | return (-1); | ||
4999 | 288 | |||
5000 | 289 | /* |
The diff has been truncated for viewing.
looks fine, merged and uploaded