Ubuntu

Merge lp:~gandelman-a/ubuntu/quantal/netcat-openbsd/merge into lp:ubuntu/quantal/netcat-openbsd

Proposed by Adam Gandelman on 2012-05-30
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
To merge this branch: bzr merge lp:~gandelman-a/ubuntu/quantal/netcat-openbsd/merge
Reviewer Review Type Date Requested Status
Oliver Grawert Approve on 2012-06-14
Ubuntu branches 2012-05-30 Pending
Review via email: mp+108072@code.launchpad.net

Description of the Change

netcat-openbsd (1.105-6ubuntu1) quantal; urgency=low

  * Merge from Debian unstable (LP: #1006631).
  * debian/patches/verbose-message-to-stderr.patch: Dropped,
    applied upstream.
  * debian/patches/dccp.patch: Dropped, applied in Debian.
  * debian/control: Update XSBC-Original-Maintainer.
  * debian/patches/netcat-info.patch: Refresh.
  * Remaining changes:
    - debian/patches/netcat-info.patch: Add info about netcat-traditional
      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.
Oliver Grawert (ogra) wrote :

looks fine, merged and uploaded

review: Approve

Preview Diff

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

Subscribers

People subscribed via source and target branches