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

Proposed by Adam Gandelman
Status: Merged
Merge reported by: James Page
Merged at revision: not available
Proposed branch: lp:~gandelman-a/ubuntu/quantal/netcat-openbsd/merge
Merge into: lp:ubuntu/quantal/netcat-openbsd
Diff against target: 5336 lines (+2456/-2095)
52 files modified
.pc/.version (+1/-0)
Makefile (+3/-18)
atomicio.c (+18/-13)
atomicio.h (+7/-1)
debian/changelog (+83/-0)
debian/compat (+1/-1)
debian/control (+7/-5)
debian/copyright (+46/-130)
debian/netcat-openbsd.README.Debian (+13/-0)
debian/netcat-openbsd.dirs (+0/-2)
debian/netcat-openbsd.examples (+1/-0)
debian/netcat-openbsd.install (+2/-0)
debian/netcat-openbsd.links (+1/-0)
debian/patches/0001-port-to-linux-with-libsd.patch (+466/-0)
debian/patches/0002-connect-timeout.patch (+118/-0)
debian/patches/0003-get-sev-by-name.patch (+34/-0)
debian/patches/0004-poll-hup.patch (+59/-0)
debian/patches/0005-send-crlf.patch (+103/-0)
debian/patches/0006-quit-timer.patch (+128/-0)
debian/patches/0007-udp-scan-timeout.patch (+56/-0)
debian/patches/0008-verbose-numeric-port.patch (+103/-0)
debian/patches/0009-dccp-support.patch (+299/-0)
debian/patches/0010-serialized-handling-multiple-clients.patch (+73/-0)
debian/patches/0011-misc-failures-and-features.patch (+443/-0)
debian/patches/connect-timeout.patch (+0/-120)
debian/patches/dccp.patch (+0/-191)
debian/patches/gcc-warnings.patch (+0/-157)
debian/patches/getservbyname.patch (+0/-24)
debian/patches/glib-strlcpy.patch (+0/-96)
debian/patches/help-version-exit.patch (+0/-21)
debian/patches/nc-1.84-udp_stop.patch (+0/-14)
debian/patches/netcat-info.patch (+8/-7)
debian/patches/no-strtonum.patch (+0/-107)
debian/patches/openbsd-compat.patch (+0/-54)
debian/patches/pollhup.patch (+0/-50)
debian/patches/quit-timer.patch (+0/-84)
debian/patches/reuseaddr.patch (+0/-15)
debian/patches/send-crlf.patch (+0/-109)
debian/patches/series (+11/-17)
debian/patches/silence-z.patch (+0/-13)
debian/patches/socks-b64-prototype.patch (+0/-13)
debian/patches/udp-scan-timeout.patch (+0/-50)
debian/patches/verbose-message-to-stderr.patch (+0/-17)
debian/patches/verbose-numeric-port.patch (+0/-54)
debian/rules (+12/-60)
debian/source/format (+1/-0)
nc.1 (+85/-36)
netcat.c (+249/-78)
openbsd-compat/base64.c (+0/-308)
openbsd-compat/readpassphrase.c (+0/-179)
openbsd-compat/readpassphrase.h (+0/-40)
socks.c (+25/-11)
To merge this branch: bzr merge lp:~gandelman-a/ubuntu/quantal/netcat-openbsd/merge
Reviewer Review Type Date Requested Status
Oliver Grawert Approve
Ubuntu branches 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.
Revision history for this message
Oliver Grawert (ogra) wrote :

looks fine, merged and uploaded

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory '.pc'
=== added file '.pc/.version'
--- .pc/.version 1970-01-01 00:00:00 +0000
+++ .pc/.version 2012-05-30 22:10:23 +0000
@@ -0,0 +1,1 @@
12
02
=== modified file 'Makefile'
--- Makefile 2010-11-19 14:40:32 +0000
+++ Makefile 2012-05-30 22:10:23 +0000
@@ -1,21 +1,6 @@
1# $OpenBSD: Makefile,v 1.6 2001/09/02 18:45:41 jakob Exp $1# $OpenBSD: Makefile,v 1.6 2001/09/02 18:45:41 jakob Exp $
22
3PROG= nc3PROG= nc
4SRCS= netcat.c atomicio.c socks.c \4SRCS= netcat.c atomicio.c socks.c
5 openbsd-compat/base64.c openbsd-compat/readpassphrase.c5
66.include <bsd.prog.mk>
7CC = gcc
8override CFLAGS += `pkg-config --cflags glib-2.0`
9INC = -Iopenbsd-compat
10LIBS = `pkg-config --libs glib-2.0`
11OBJS = $(SRCS:.c=.o)
12
13all: nc
14nc: $(OBJS)
15 $(CC) $(OBJS) $(LIBS) -o nc
16
17$(OBJS): %.o: %.c
18 $(CC) $(CFLAGS) $(INC) -c $< -o $@
19
20clean:
21 rm -f $(OBJS) nc
227
=== modified file 'atomicio.c'
--- atomicio.c 2008-01-30 18:24:46 +0000
+++ atomicio.c 2012-05-30 22:10:23 +0000
@@ -1,7 +1,7 @@
1/* $OpenBSD: atomicio.c,v 1.8 2006/02/11 19:31:18 otto Exp $ */1/* $OpenBSD: atomicio.c,v 1.10 2011/01/08 00:47:19 jeremy Exp $ */
2
3/*2/*
4 * Copyright (c) 2005 Anil Madhavapeddy. All rights served.3 * Copyright (c) 2006 Damien Miller. All rights reserved.
4 * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
5 * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.5 * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
6 * All rights reserved.6 * All rights reserved.
7 *7 *
@@ -26,32 +26,37 @@
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */27 */
2828
29#include <sys/types.h>29#include <sys/param.h>
30#include <sys/uio.h>30
31#include <errno.h>31#include <errno.h>
32#include <poll.h>
32#include <unistd.h>33#include <unistd.h>
34
33#include "atomicio.h"35#include "atomicio.h"
3436
35/*37/*
36 * ensure all of data on socket comes through. f==read || f==vwrite38 * ensure all of data on socket comes through. f==read || f==vwrite
37 */39 */
38size_t40size_t
39atomicio(f, fd, _s, n)41atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n)
40 ssize_t (*f) (int, void *, size_t);
41 int fd;
42 void *_s;
43 size_t n;
44{42{
45 char *s = _s;43 char *s = _s;
46 size_t pos = 0;44 size_t pos = 0;
47 ssize_t res;45 ssize_t res;
46 struct pollfd pfd;
4847
48 pfd.fd = fd;
49 pfd.events = f == read ? POLLIN : POLLOUT;
49 while (n > pos) {50 while (n > pos) {
50 res = (f) (fd, s + pos, n - pos);51 res = (f) (fd, s + pos, n - pos);
51 switch (res) {52 switch (res) {
52 case -1:53 case -1:
53 if (errno == EINTR || errno == EAGAIN)54 if (errno == EINTR)
54 continue;55 continue;
56 if ((errno == EAGAIN) || (errno == ENOBUFS)) {
57 (void)poll(&pfd, 1, -1);
58 continue;
59 }
55 return 0;60 return 0;
56 case 0:61 case 0:
57 errno = EPIPE;62 errno = EPIPE;
@@ -60,5 +65,5 @@
60 pos += (size_t)res;65 pos += (size_t)res;
61 }66 }
62 }67 }
63 return pos;68 return (pos);
64}69}
6570
=== modified file 'atomicio.h'
--- atomicio.h 2008-01-30 18:24:46 +0000
+++ atomicio.h 2012-05-30 22:10:23 +0000
@@ -1,6 +1,7 @@
1/* $OpenBSD: atomicio.h,v 1.1 2005/05/24 20:13:28 avsm Exp $ */1/* $OpenBSD: atomicio.h,v 1.2 2007/09/07 14:50:44 tobias Exp $ */
22
3/*3/*
4 * Copyright (c) 2006 Damien Miller. All rights reserved.
4 * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.5 * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
5 * All rights reserved.6 * All rights reserved.
6 *7 *
@@ -25,9 +26,14 @@
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */27 */
2728
29#ifndef _ATOMICIO_H
30#define _ATOMICIO_H
31
28/*32/*
29 * Ensure all of data on socket comes through. f==read || f==vwrite33 * Ensure all of data on socket comes through. f==read || f==vwrite
30 */34 */
31size_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);35size_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);
3236
33#define vwrite (ssize_t (*)(int, void *, size_t))write37#define vwrite (ssize_t (*)(int, void *, size_t))write
38
39#endif /* _ATOMICIO_H */
3440
=== modified file 'debian/changelog'
--- debian/changelog 2011-07-01 21:39:53 +0000
+++ debian/changelog 2012-05-30 22:10:23 +0000
@@ -1,3 +1,86 @@
1netcat-openbsd (1.105-6ubuntu1) quantal; urgency=low
2
3 * Merge from Debian unstable (LP: #1006631).
4 * debian/patches/verbose-message-to-stderr.patch: Dropped,
5 applied upstream.
6 * debian/patches/dccp.patch: Dropped, applied in Debian.
7 * debian/control: Update XSBC-Original-Maintainer.
8 * debian/patches/netcat-info.patch: Refresh.
9 * Remaining changes:
10 - debian/patches/netcat-info.patch: Add info about netcat-traditional
11 if you are looking for an option when it is not available.
12 (LP: #590925)
13
14 -- Adam Gandelman <adamg@canonical.com> Wed, 30 May 2012 14:38:36 -0700
15
16netcat-openbsd (1.105-6) unstable; urgency=low
17
18 * Fix segfaults when using -Ulv (Closes: #668558).
19 * Do not continue to listen on port after accepting connection.
20
21 -- Aron Xu <aron@debian.org> Thu, 03 May 2012 07:38:59 +0800
22
23netcat-openbsd (1.105-5) unstable; urgency=low
24
25 * Add $LDFLAGS from environment (Closes: #665321).
26
27 -- Aron Xu <aron@debian.org> Mon, 26 Mar 2012 01:37:16 +0800
28
29netcat-openbsd (1.105-4) unstable; urgency=high
30
31 * High urgency for fixing RC bug.
32 * Fix readwrite() behaviour (Closes: #662741).
33
34 -- Aron Xu <aron@debian.org> Tue, 06 Mar 2012 15:18:26 +0800
35
36netcat-openbsd (1.105-3) unstable; urgency=low
37
38 * Clear up symlink of man page.
39 * Use Breaks instead of Conflicts.
40 * Fix minor warnings from man.
41
42 -- Aron Xu <aron@debian.org> Sun, 19 Feb 2012 14:28:46 +0800
43
44netcat-openbsd (1.105-2) unstable; urgency=low
45
46 * Add missing Build-Depends: pkg-config.
47
48 -- Aron Xu <aron@debian.org> Sun, 19 Feb 2012 03:59:37 +0800
49
50netcat-openbsd (1.105-1) unstable; urgency=low
51
52 * New upstream CVS snapshot, new maintainer.
53 - Verbose message to strerr (Closes: #570765).
54 - Can use packet's content > 1024 (Closes: #607003).
55 - Replace non-portable echo with printf (Closes: #510372).
56 * debian/patches:
57 - Rearrange existing patches, fix new porting issues.
58 - Option -l and -p are now compatible (Closes: #540073).
59 - Use libbsd instead of glib for strlcpy (Closes: #550611).
60 - Fix build with -Wl,--as-needed (Closes: #604781).
61 - Handling multiple clients subsquently when -k (Closes: #514792).
62 - Replace inet_ntoa with inet_ntop to support IPv6
63 (Closes: #512992).
64 - Modify -q behavior to be compatible with nc.traditional
65 (Closes: #508722, #594614, #606925, #611964).
66 - DCCP and broadcast support.
67 - Arbitrary port list to scan.
68 - Fix misc connection failures
69 (Closes: #579485, #579486, #579487, #579488, #633948).
70 - Improve verbose information and documentations.
71 * debian/rules:
72 - Link nc.openbsd.1 from nc.1 (Closes: #535951).
73 - Enable optional hardening build flags.
74 * debian/control:
75 - Replace glib with libbsd.
76 - Update to use debhelper 8, std-ver 3.9.2.
77 - Priority: important, to make it into base system.
78 - Add Vcs-*.
79 * debian/compat:
80 - Update to 8 from 4.
81
82 -- Aron Xu <aron@debian.org> Wed, 15 Feb 2012 01:39:04 +0800
83
1netcat-openbsd (1.89-4ubuntu1) oneiric; urgency=low84netcat-openbsd (1.89-4ubuntu1) oneiric; urgency=low
285
3 * Merge from Debian unstable (LP: #803856). Remaining changes:86 * Merge from Debian unstable (LP: #803856). Remaining changes:
487
=== modified file 'debian/compat'
--- debian/compat 2008-01-30 18:24:46 +0000
+++ debian/compat 2012-05-30 22:10:23 +0000
@@ -1,1 +1,1 @@
1418
22
=== modified file 'debian/control'
--- debian/control 2010-02-09 10:42:03 +0000
+++ debian/control 2012-05-30 22:10:23 +0000
@@ -2,15 +2,17 @@
2Section: net2Section: net
3Priority: optional3Priority: optional
4Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>4Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
5XSBC-Original-Maintainer: Decklin Foster <decklin@red-bean.com>5XSBC-Original-Maintainer: Aron Xu <aron@debian.org>
6Standards-Version: 3.7.36Standards-Version: 3.9.3
7Build-Depends: quilt, debhelper (>= 4.0.0), libglib2.0-dev7Build-Depends: debhelper (>= 8), quilt, libbsd-dev, pkg-config
8Vcs-Browser: http://git.debian.org/?p=collab-maint/netcat-openbsd.git
9Vcs-Git: git://anonscm.debian.org/collab-maint/netcat-openbsd.git
810
9Package: netcat-openbsd11Package: netcat-openbsd
10Architecture: any12Architecture: any
11Depends: ${shlibs:Depends}13Depends: ${shlibs:Depends}, ${misc:Depends}
12Provides: netcat14Provides: netcat
13Conflicts: netcat (<< 1.10-35)15Breaks: netcat (<< 1.10-35)
14Replaces: netcat (<< 1.10-35)16Replaces: netcat (<< 1.10-35)
15Description: TCP/IP swiss army knife17Description: TCP/IP swiss army knife
16 A simple Unix utility which reads and writes data across network18 A simple Unix utility which reads and writes data across network
1719
=== modified file 'debian/copyright'
--- debian/copyright 2008-01-30 18:24:46 +0000
+++ debian/copyright 2012-05-30 22:10:23 +0000
@@ -1,130 +1,46 @@
1The netcat-openbsd Debian package was created by Soren Hansen1Format: http://dep.debian.net/deps/dep5/
2<soren@ubuntu.com> and by Decklin Foster <decklin@red-bean.com>, based2Source: http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/nc/
3loosely on the original netcat package. The code itself was rewritten3
4by the OpenBSD project, from the original implementation by Hobbit4Files: netcat.c
5<hobbit@atstake.com>.5Copyright: 2001 Eric Jackson <ericj@monkey.org>
66License: BSD-3-Clause
7Sources can be found at:7
88Files: atomicio.*
9 http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/nc/9Copyright: 2005 Anil Madhavapeddy
1010 1995,1999 Theo de Raadt
11Copyright and license of netcat.c:11License: BSD-3-Clause
1212
13 Copyright (c) 2001 Eric Jackson <ericj@monkey.org>13Files: socks.c
1414Copyright: 1999 Niklas Hallqvist
15 Redistribution and use in source and binary forms, with or without15 2004, 2005 Damien Miller
16 modification, are permitted provided that the following conditions16License: BSD-3-Clause
17 are met:17
1818Files: debian/*
19 1. Redistributions of source code must retain the above copyright19Copyright: 2008, 2009, 2010 Decklin Foster <decklin@red-bean.com>
20 notice, this list of conditions and the following disclaimer.20 2008, 2009, 2010 Soren Hansen <soren@ubuntu.com>
21 2. Redistributions in binary form must reproduce the above copyright21 2012 Aron Xu <aron@debian.org>
22 notice, this list of conditions and the following disclaimer in the22License: BSD-3-Clause
23 documentation and/or other materials provided with the distribution.23
24 3. The name of the author may not be used to endorse or promote products24License: BSD-3-Clause
25 derived from this software without specific prior written permission.25 Redistribution and use in source and binary forms, with or without
2626 modification, are permitted provided that the following conditions
27 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR27 are met:
28 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES28 .
29 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.29 1. Redistributions of source code must retain the above copyright
30 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,30 notice, this list of conditions and the following disclaimer.
31 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT31 2. Redistributions in binary form must reproduce the above copyright
32 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,32 notice, this list of conditions and the following disclaimer in the
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY33 documentation and/or other materials provided with the distribution.
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT34 3. The name of the author may not be used to endorse or promote products
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF35 derived from this software without specific prior written permission.
36 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.36 .
3737 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
38Copyright and license of atomicio.c:38 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
3939 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
40 Copyright (c) 2005 Anil Madhavapeddy. All rights served.40 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
41 Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.41 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 All rights reserved.42 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4343 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44 Redistribution and use in source and binary forms, with or without44 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45 modification, are permitted provided that the following conditions45 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
46 are met:46 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 1. Redistributions of source code must retain the above copyright
48 notice, this list of conditions and the following disclaimer.
49 2. Redistributions in binary form must reproduce the above copyright
50 notice, this list of conditions and the following disclaimer in the
51 documentation and/or other materials provided with the distribution.
52
53 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
54 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
57 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
58 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
62 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63
64 Copyright (c) 2005 Anil Madhavapeddy. All rights served.
65 Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
66
67Copyright of socks.c (license is identical to that of atomicio.c):
68
69 Copyright (c) 1999 Niklas Hallqvist. All rights reserved.
70 Copyright (c) 2004, 2005 Damien Miller. All rights reserved.
71
72Copyright and license of readpassphrase.c:
73
74 Copyright (c) 2000-2002, 2007 Todd C. Miller <Todd.Miller@courtesan.com>
75
76 Permission to use, copy, modify, and distribute this software for any
77 purpose with or without fee is hereby granted, provided that the above
78 copyright notice and this permission notice appear in all copies.
79
80 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
81 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
82 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
83 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
84 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
85 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
86 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
87
88 Sponsored in part by the Defense Advanced Research Projects
89 Agency (DARPA) and Air Force Research Laboratory, Air Force
90 Materiel Command, USAF, under agreement number F39502-99-1-0512.
91
92Copyright and license of base64.c:
93
94 Copyright (c) 1996 by Internet Software Consortium.
95
96 Permission to use, copy, modify, and distribute this software for any
97 purpose with or without fee is hereby granted, provided that the above
98 copyright notice and this permission notice appear in all copies.
99
100 THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
101 ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
102 OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
103 CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
104 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
105 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
106 ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
107 SOFTWARE.
108
109 Portions Copyright (c) 1995 by International Business Machines, Inc.
110
111 International Business Machines, Inc. (hereinafter called IBM) grants
112 permission under its copyrights to use, copy, modify, and distribute this
113 Software with or without fee, provided that the above copyright notice and
114 all paragraphs of this notice appear in all copies, and that the name of IBM
115 not be used in connection with the marketing of any product incorporating
116 the Software or modifications thereof, without specific, written prior
117 permission.
118
119 To the extent it has a right to do so, IBM grants an immunity from suit
120 under its patents, if any, for the use, sale or manufacture of products to
121 the extent that such products are used for performing Domain Name System
122 dynamic updates in TCP/IP networks by means of the Software. No immunity is
123 granted for any product per se or for any other function of any product.
124
125 THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
126 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
127 PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
128 DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
129 OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
130 IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
13147
=== modified file 'debian/netcat-openbsd.README.Debian'
--- debian/netcat-openbsd.README.Debian 2008-01-30 18:24:46 +0000
+++ debian/netcat-openbsd.README.Debian 2012-05-30 22:10:23 +0000
@@ -1,6 +1,19 @@
1OpenBSD netcat for Debian1OpenBSD netcat for Debian
2-------------------------2-------------------------
33
4Merge with upstream again, now it links against -lresov and -lbsd. The
5former one is from libc, and the latter provides a good strlcpy(). Now
6the package has a much saner dependency to make its way into base system.
7A lot of bug fixes and some new features are also applied.
8
9For record, the reason of not implementing features like -c or -e in this
10cat is about security. These options enable anyone on the system to open
11port and execute arbitrary command on local host from remote very easily,
12which is not desired for ordinary multi-user systems. If you do need such
13function, please try nc.traditional or nc6.
14
15 -- Aron Xu <aron@debian.org> Wed, 15 Feb 2012 01:39:04 +0800
16
4This package has been rebased on OpenBSD's implementation of netcat. The17This package has been rebased on OpenBSD's implementation of netcat. The
5code has been massively cleaned up, and important functionality has been18code has been massively cleaned up, and important functionality has been
6added.19added.
720
=== removed file 'debian/netcat-openbsd.dirs'
--- debian/netcat-openbsd.dirs 2008-01-30 18:24:46 +0000
+++ debian/netcat-openbsd.dirs 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1bin
2usr/share/man/man1
30
=== added file 'debian/netcat-openbsd.examples'
--- debian/netcat-openbsd.examples 1970-01-01 00:00:00 +0000
+++ debian/netcat-openbsd.examples 2012-05-30 22:10:23 +0000
@@ -0,0 +1,1 @@
1debian/examples/*
02
=== added file 'debian/netcat-openbsd.install'
--- debian/netcat-openbsd.install 1970-01-01 00:00:00 +0000
+++ debian/netcat-openbsd.install 2012-05-30 22:10:23 +0000
@@ -0,0 +1,2 @@
1nc.openbsd bin/
2nc_openbsd.1 usr/share/man/man1/
03
=== added file 'debian/netcat-openbsd.links'
--- debian/netcat-openbsd.links 1970-01-01 00:00:00 +0000
+++ debian/netcat-openbsd.links 2012-05-30 22:10:23 +0000
@@ -0,0 +1,1 @@
1usr/share/man/man1/nc_openbsd.1 usr/share/man/man1/nc.openbsd.1
02
=== added file 'debian/patches/0001-port-to-linux-with-libsd.patch'
--- debian/patches/0001-port-to-linux-with-libsd.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0001-port-to-linux-with-libsd.patch 2012-05-30 22:10:23 +0000
@@ -0,0 +1,466 @@
1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 15:59:31 +0800
3Subject: [PATCH] port to linux with libsd
4
5---
6 Makefile | 17 +++++++++-
7 nc.1 | 2 +-
8 netcat.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------
9 socks.c | 46 +++++++++++++-------------
10 4 files changed, 130 insertions(+), 40 deletions(-)
11
12--- a/Makefile
13+++ b/Makefile
14@@ -1,6 +1,19 @@
15-# $OpenBSD: Makefile,v 1.6 2001/09/02 18:45:41 jakob Exp $
16+# $OpenBSD: Makefile,v 1.6 2001/09/02 18:45:41 jakob Exp $
17
18 PROG= nc
19 SRCS= netcat.c atomicio.c socks.c
20
21-.include <bsd.prog.mk>
22+LIBS= `pkg-config --libs libbsd` -lresolv
23+OBJS= $(SRCS:.c=.o)
24+CFLAGS= -g -O2
25+LDFLAGS= -Wl,--no-add-needed
26+
27+all: nc
28+nc: $(OBJS)
29+ $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o nc
30+
31+$(OBJS): %.o: %.c
32+ $(CC) $(CFLAGS) -c $< -o $@
33+
34+clean:
35+ rm -f $(OBJS) nc
36--- a/nc.1
37+++ b/nc.1
38@@ -146,9 +146,6 @@
39 Specifies the source port
40 .Nm
41 should use, subject to privilege restrictions and availability.
42-It is an error to use this option in conjunction with the
43-.Fl l
44-option.
45 .It Fl r
46 Specifies that source and/or destination ports should be chosen randomly
47 instead of sequentially within a range or in the order that the system
48@@ -170,6 +167,7 @@
49 may be one of
50 .Ar critical ,
51 .Ar inetcontrol ,
52+.Ar lowcost ,
53 .Ar lowdelay ,
54 .Ar netcontrol ,
55 .Ar throughput ,
56--- a/netcat.c
57+++ b/netcat.c
58@@ -42,6 +42,46 @@
59 #include <netinet/ip.h>
60 #include <arpa/telnet.h>
61
62+#ifndef IPTOS_LOWDELAY
63+# define IPTOS_LOWDELAY 0x10
64+# define IPTOS_THROUGHPUT 0x08
65+# define IPTOS_RELIABILITY 0x04
66+# define IPTOS_LOWCOST 0x02
67+# define IPTOS_MINCOST IPTOS_LOWCOST
68+#endif /* IPTOS_LOWDELAY */
69+
70+# ifndef IPTOS_DSCP_AF11
71+# define IPTOS_DSCP_AF11 0x28
72+# define IPTOS_DSCP_AF12 0x30
73+# define IPTOS_DSCP_AF13 0x38
74+# define IPTOS_DSCP_AF21 0x48
75+# define IPTOS_DSCP_AF22 0x50
76+# define IPTOS_DSCP_AF23 0x58
77+# define IPTOS_DSCP_AF31 0x68
78+# define IPTOS_DSCP_AF32 0x70
79+# define IPTOS_DSCP_AF33 0x78
80+# define IPTOS_DSCP_AF41 0x88
81+# define IPTOS_DSCP_AF42 0x90
82+# define IPTOS_DSCP_AF43 0x98
83+# define IPTOS_DSCP_EF 0xb8
84+#endif /* IPTOS_DSCP_AF11 */
85+
86+#ifndef IPTOS_DSCP_CS0
87+# define IPTOS_DSCP_CS0 0x00
88+# define IPTOS_DSCP_CS1 0x20
89+# define IPTOS_DSCP_CS2 0x40
90+# define IPTOS_DSCP_CS3 0x60
91+# define IPTOS_DSCP_CS4 0x80
92+# define IPTOS_DSCP_CS5 0xa0
93+# define IPTOS_DSCP_CS6 0xc0
94+# define IPTOS_DSCP_CS7 0xe0
95+#endif /* IPTOS_DSCP_CS0 */
96+
97+#ifndef IPTOS_DSCP_EF
98+# define IPTOS_DSCP_EF 0xb8
99+#endif /* IPTOS_DSCP_EF */
100+
101+
102 #include <err.h>
103 #include <errno.h>
104 #include <netdb.h>
105@@ -53,6 +93,8 @@
106 #include <unistd.h>
107 #include <fcntl.h>
108 #include <limits.h>
109+#include <bsd/stdlib.h>
110+#include <bsd/string.h>
111 #include "atomicio.h"
112
113 #ifndef SUN_LEN
114@@ -118,7 +160,7 @@
115 struct servent *sv;
116 socklen_t len;
117 struct sockaddr_storage cliaddr;
118- char *proxy;
119+ char *proxy = NULL;
120 const char *errstr, *proxyhost = "", *proxyport = NULL;
121 struct addrinfo proxyhints;
122 char unix_dg_tmp_socket_buf[UNIX_DG_TMP_SOCKET_SIZE];
123@@ -164,7 +206,11 @@
124 errx(1, "interval %s: %s", errstr, optarg);
125 break;
126 case 'j':
127+# if defined(SO_JUMBO)
128 jflag = 1;
129+# else
130+ errx(1, "no jumbo frame support available");
131+# endif
132 break;
133 case 'k':
134 kflag = 1;
135@@ -194,10 +240,14 @@
136 uflag = 1;
137 break;
138 case 'V':
139+# if defined(RT_TABLEID_MAX)
140 rtableid = (unsigned int)strtonum(optarg, 0,
141 RT_TABLEID_MAX, &errstr);
142 if (errstr)
143 errx(1, "rtable %s: %s", errstr, optarg);
144+# else
145+ errx(1, "no alternate routing table support available");
146+# endif
147 break;
148 case 'v':
149 vflag = 1;
150@@ -232,7 +282,11 @@
151 errstr, optarg);
152 break;
153 case 'S':
154+# if defined(TCP_MD5SIG)
155 Sflag = 1;
156+# else
157+ errx(1, "no TCP MD5 signature support available");
158+# endif
159 break;
160 case 'T':
161 errstr = NULL;
162@@ -259,6 +313,15 @@
163 if (argv[0] && !argv[1] && family == AF_UNIX) {
164 host = argv[0];
165 uport = NULL;
166+ } else if (!argv[0] && lflag) {
167+ if (sflag)
168+ errx(1, "cannot use -s and -l");
169+ if (zflag)
170+ errx(1, "cannot use -z and -l");
171+ if (pflag)
172+ uport=pflag;
173+ } else if (!lflag && kflag) {
174+ errx(1, "cannot use -k without -l");
175 } else if (argv[0] && !argv[1]) {
176 if (!lflag)
177 usage(1);
178@@ -270,14 +333,7 @@
179 } else
180 usage(1);
181
182- if (lflag && sflag)
183- errx(1, "cannot use -s and -l");
184- if (lflag && pflag)
185- errx(1, "cannot use -p and -l");
186- if (lflag && zflag)
187- errx(1, "cannot use -z and -l");
188- if (!lflag && kflag)
189- errx(1, "must use -l with -k");
190+
191
192 /* Get name of temporary socket for unix datagram client */
193 if ((family == AF_UNIX) && uflag && !lflag) {
194@@ -286,8 +342,8 @@
195 } else {
196 strlcpy(unix_dg_tmp_socket_buf, "/tmp/nc.XXXXXXXXXX",
197 UNIX_DG_TMP_SOCKET_SIZE);
198- if (mktemp(unix_dg_tmp_socket_buf) == NULL)
199- err(1, "mktemp");
200+ if (mkstemp(unix_dg_tmp_socket_buf) == -1)
201+ err(1, "mkstemp");
202 unix_dg_tmp_socket = unix_dg_tmp_socket_buf;
203 }
204 }
205@@ -563,18 +619,22 @@
206 res0->ai_protocol)) < 0)
207 continue;
208
209+# if defined(RT_TABLEID_MAX)
210 if (rtableid) {
211 if (setsockopt(s, SOL_SOCKET, SO_RTABLE, &rtableid,
212 sizeof(rtableid)) == -1)
213 err(1, "setsockopt SO_RTABLE");
214 }
215+# endif
216
217 /* Bind to a local port or source address if specified. */
218 if (sflag || pflag) {
219 struct addrinfo ahints, *ares;
220
221+# if defined (SO_BINDANY)
222 /* try SO_BINDANY, but don't insist */
223 setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on));
224+# endif
225 memset(&ahints, 0, sizeof(struct addrinfo));
226 ahints.ai_family = res0->ai_family;
227 ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
228@@ -674,15 +734,23 @@
229 res0->ai_protocol)) < 0)
230 continue;
231
232+# if defined(RT_TABLEID_MAX)
233 if (rtableid) {
234 if (setsockopt(s, IPPROTO_IP, SO_RTABLE, &rtableid,
235 sizeof(rtableid)) == -1)
236 err(1, "setsockopt SO_RTABLE");
237 }
238+# endif
239+
240+ ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
241+ if (ret == -1)
242+ err(1, NULL);
243
244+# if defined(SO_REUSEPORT)
245 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
246 if (ret == -1)
247 err(1, NULL);
248+# endif
249
250 set_common_sockopts(s);
251
252@@ -886,21 +954,25 @@
253 {
254 int x = 1;
255
256+# if defined(TCP_MD5SIG)
257 if (Sflag) {
258 if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
259 &x, sizeof(x)) == -1)
260 err(1, NULL);
261 }
262+# endif
263 if (Dflag) {
264 if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
265 &x, sizeof(x)) == -1)
266 err(1, NULL);
267 }
268+# if defined(SO_JUMBO)
269 if (jflag) {
270 if (setsockopt(s, SOL_SOCKET, SO_JUMBO,
271 &x, sizeof(x)) == -1)
272 err(1, NULL);
273 }
274+# endif
275 if (Tflag != -1) {
276 if (setsockopt(s, IPPROTO_IP, IP_TOS,
277 &Tflag, sizeof(Tflag)) == -1)
278@@ -949,6 +1021,7 @@
279 { "cs7", IPTOS_DSCP_CS7 },
280 { "ef", IPTOS_DSCP_EF },
281 { "inetcontrol", IPTOS_PREC_INTERNETCONTROL },
282+ { "lowcost", IPTOS_LOWCOST },
283 { "lowdelay", IPTOS_LOWDELAY },
284 { "netcontrol", IPTOS_PREC_NETCONTROL },
285 { "reliability", IPTOS_RELIABILITY },
286@@ -969,6 +1042,9 @@
287 void
288 help(void)
289 {
290+# if defined(DEBIAN_VERSION)
291+ fprintf(stderr, "OpenBSD netcat (Debian patchlevel " DEBIAN_VERSION ")\n");
292+# endif
293 usage(0);
294 fprintf(stderr, "\tCommand Summary:\n\
295 \t-4 Use IPv4\n\
296@@ -978,6 +1054,7 @@
297 \t-h This help text\n\
298 \t-I length TCP receive buffer length\n\
299 \t-i secs\t Delay interval for lines sent, ports scanned\n\
300+ \t-j Use jumbo frame\n\
301 \t-k Keep inbound sockets open for multiple connects\n\
302 \t-l Listen mode, for inbound connects\n\
303 \t-n Suppress name/port resolutions\n\
304@@ -998,15 +1075,15 @@
305 \t-x addr[:port]\tSpecify proxy address and port\n\
306 \t-z Zero-I/O mode [used for scanning]\n\
307 Port numbers can be individual or ranges: lo-hi [inclusive]\n");
308- exit(1);
309+ exit(0);
310 }
311
312 void
313 usage(int ret)
314 {
315 fprintf(stderr,
316- "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n"
317- "\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n"
318+ "usage: nc [-46DdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n"
319+ "\t [-P proxy_username] [-p source_port] [-s source] [-T toskeyword]\n"
320 "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
321 "\t [-x proxy_address[:port]] [destination] [port]\n");
322 if (ret)
323--- a/socks.c
324+++ b/socks.c
325@@ -38,7 +38,7 @@
326 #include <string.h>
327 #include <unistd.h>
328 #include <resolv.h>
329-#include <readpassphrase.h>
330+#include <bsd/readpassphrase.h>
331 #include "atomicio.h"
332
333 #define SOCKS_PORT "1080"
334@@ -167,11 +167,11 @@
335 buf[2] = SOCKS_NOAUTH;
336 cnt = atomicio(vwrite, proxyfd, buf, 3);
337 if (cnt != 3)
338- err(1, "write failed (%zu/3)", cnt);
339+ err(1, "write failed (%zu/3)", (size_t)cnt);
340
341 cnt = atomicio(read, proxyfd, buf, 2);
342 if (cnt != 2)
343- err(1, "read failed (%zu/3)", cnt);
344+ err(1, "read failed (%zu/3)", (size_t)cnt);
345
346 if (buf[1] == SOCKS_NOMETHOD)
347 errx(1, "authentication method negotiation failed");
348@@ -220,23 +220,23 @@
349
350 cnt = atomicio(vwrite, proxyfd, buf, wlen);
351 if (cnt != wlen)
352- err(1, "write failed (%zu/%zu)", cnt, wlen);
353+ err(1, "write failed (%zu/%zu)", (size_t)cnt, (size_t)wlen);
354
355 cnt = atomicio(read, proxyfd, buf, 4);
356 if (cnt != 4)
357- err(1, "read failed (%zu/4)", cnt);
358+ err(1, "read failed (%zu/4)", (size_t)cnt);
359 if (buf[1] != 0)
360 errx(1, "connection failed, SOCKS error %d", buf[1]);
361 switch (buf[3]) {
362 case SOCKS_IPV4:
363 cnt = atomicio(read, proxyfd, buf + 4, 6);
364 if (cnt != 6)
365- err(1, "read failed (%d/6)", cnt);
366+ err(1, "read failed (%lu/6)", (unsigned long)cnt);
367 break;
368 case SOCKS_IPV6:
369 cnt = atomicio(read, proxyfd, buf + 4, 18);
370 if (cnt != 18)
371- err(1, "read failed (%d/18)", cnt);
372+ err(1, "read failed (%lu/18)", (unsigned long)cnt);
373 break;
374 default:
375 errx(1, "connection failed, unsupported address type");
376@@ -256,11 +256,11 @@
377
378 cnt = atomicio(vwrite, proxyfd, buf, wlen);
379 if (cnt != wlen)
380- err(1, "write failed (%zu/%zu)", cnt, wlen);
381+ err(1, "write failed (%zu/%zu)", (size_t)cnt, (size_t)wlen);
382
383 cnt = atomicio(read, proxyfd, buf, 8);
384 if (cnt != 8)
385- err(1, "read failed (%zu/8)", cnt);
386+ err(1, "read failed (%zu/8)", (size_t)cnt);
387 if (buf[1] != 90)
388 errx(1, "connection failed, SOCKS error %d", buf[1]);
389 } else if (socksv == -1) {
390@@ -272,39 +272,39 @@
391
392 /* Try to be sane about numeric IPv6 addresses */
393 if (strchr(host, ':') != NULL) {
394- r = snprintf(buf, sizeof(buf),
395+ r = snprintf((char*)buf, sizeof(buf),
396 "CONNECT [%s]:%d HTTP/1.0\r\n",
397 host, ntohs(serverport));
398 } else {
399- r = snprintf(buf, sizeof(buf),
400+ r = snprintf((char*)buf, sizeof(buf),
401 "CONNECT %s:%d HTTP/1.0\r\n",
402 host, ntohs(serverport));
403 }
404 if (r == -1 || (size_t)r >= sizeof(buf))
405 errx(1, "hostname too long");
406- r = strlen(buf);
407+ r = strlen((char*)buf);
408
409 cnt = atomicio(vwrite, proxyfd, buf, r);
410 if (cnt != r)
411- err(1, "write failed (%zu/%d)", cnt, r);
412+ err(1, "write failed (%zu/%d)", (size_t)cnt, (int)r);
413
414 if (authretry > 1) {
415 char resp[1024];
416
417 proxypass = getproxypass(proxyuser, proxyhost);
418- r = snprintf(buf, sizeof(buf), "%s:%s",
419+ r = snprintf((char*)buf, sizeof(buf), "%s:%s",
420 proxyuser, proxypass);
421 if (r == -1 || (size_t)r >= sizeof(buf) ||
422- b64_ntop(buf, strlen(buf), resp,
423+ b64_ntop(buf, strlen((char*)buf), resp,
424 sizeof(resp)) == -1)
425 errx(1, "Proxy username/password too long");
426- r = snprintf(buf, sizeof(buf), "Proxy-Authorization: "
427+ r = snprintf((char*)buf, sizeof((char*)buf), "Proxy-Authorization: "
428 "Basic %s\r\n", resp);
429 if (r == -1 || (size_t)r >= sizeof(buf))
430 errx(1, "Proxy auth response too long");
431- r = strlen(buf);
432+ r = strlen((char*)buf);
433 if ((cnt = atomicio(vwrite, proxyfd, buf, r)) != r)
434- err(1, "write failed (%zu/%d)", cnt, r);
435+ err(1, "write failed (%zu/%d)", (size_t)cnt, r);
436 }
437
438 /* Terminate headers */
439@@ -312,22 +312,22 @@
440 err(1, "write failed (2/%d)", r);
441
442 /* Read status reply */
443- proxy_read_line(proxyfd, buf, sizeof(buf));
444+ proxy_read_line(proxyfd, (char*)buf, sizeof(buf));
445 if (proxyuser != NULL &&
446- strncmp(buf, "HTTP/1.0 407 ", 12) == 0) {
447+ strncmp((char*)buf, "HTTP/1.0 407 ", 12) == 0) {
448 if (authretry > 1) {
449 fprintf(stderr, "Proxy authentication "
450 "failed\n");
451 }
452 close(proxyfd);
453 goto again;
454- } else if (strncmp(buf, "HTTP/1.0 200 ", 12) != 0 &&
455- strncmp(buf, "HTTP/1.1 200 ", 12) != 0)
456+ } else if (strncmp((char*)buf, "HTTP/1.0 200 ", 12) != 0 &&
457+ strncmp((char*)buf, "HTTP/1.1 200 ", 12) != 0)
458 errx(1, "Proxy error: \"%s\"", buf);
459
460 /* Headers continue until we hit an empty line */
461 for (r = 0; r < HTTP_MAXHDRS; r++) {
462- proxy_read_line(proxyfd, buf, sizeof(buf));
463+ proxy_read_line(proxyfd, (char*)buf, sizeof(buf));
464 if (*buf == '\0')
465 break;
466 }
0467
=== added file 'debian/patches/0002-connect-timeout.patch'
--- debian/patches/0002-connect-timeout.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0002-connect-timeout.patch 2012-05-30 22:10:23 +0000
@@ -0,0 +1,118 @@
1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 14:43:56 +0800
3Subject: [PATCH] connect timeout
4
5---
6 netcat.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
7 1 files changed, 75 insertions(+), 2 deletions(-)
8
9--- a/netcat.c
10+++ b/netcat.c
11@@ -106,6 +106,10 @@
12 #define PORT_MAX_LEN 6
13 #define UNIX_DG_TMP_SOCKET_SIZE 19
14
15+#define CONNECTION_SUCCESS 0
16+#define CONNECTION_FAILED 1
17+#define CONNECTION_TIMEOUT 2
18+
19 /* Command Line Options */
20 int dflag; /* detached, no stdin */
21 unsigned int iflag; /* Interval Flag */
22@@ -151,6 +155,9 @@
23 int map_tos(char *, int *);
24 void usage(int);
25
26+static int connect_with_timeout(int fd, const struct sockaddr *sa,
27+ socklen_t salen, int ctimeout);
28+
29 int
30 main(int argc, char *argv[])
31 {
32@@ -651,11 +658,14 @@
33
34 set_common_sockopts(s);
35
36- if (timeout_connect(s, res0->ai_addr, res0->ai_addrlen) == 0)
37+ if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout))== CONNECTION_SUCCESS)
38 break;
39- else if (vflag)
40+ else if (vflag && error == CONNECTION_FAILED)
41 warn("connect to %s port %s (%s) failed", host, port,
42 uflag ? "udp" : "tcp");
43+ else if (vflag && error == CONNECTION_TIMEOUT)
44+ warn("connect to %s port %s (%s) timed out", host, port,
45+ uflag ? "udp" : "tcp");
46
47 close(s);
48 s = -1;
49@@ -703,6 +713,69 @@
50 return (ret);
51 }
52
53+static int connect_with_timeout(int fd, const struct sockaddr *sa,
54+ socklen_t salen, int ctimeout)
55+{
56+ int err;
57+ struct timeval tv, *tvp = NULL;
58+ fd_set connect_fdset;
59+ socklen_t len;
60+ int orig_flags;
61+
62+ orig_flags = fcntl(fd, F_GETFL, 0);
63+ if (fcntl(fd, F_SETFL, orig_flags | O_NONBLOCK) < 0 ) {
64+ warn("can't set O_NONBLOCK - timeout not available");
65+ if (connect(fd, sa, salen) == 0)
66+ return CONNECTION_SUCCESS;
67+ else
68+ return CONNECTION_FAILED;
69+ }
70+
71+ /* set connect timeout */
72+ if (ctimeout > 0) {
73+ tv.tv_sec = (time_t)ctimeout/1000;
74+ tv.tv_usec = 0;
75+ tvp = &tv;
76+ }
77+
78+ /* attempt the connection */
79+ err = connect(fd, sa, salen);
80+ if (err != 0 && errno == EINPROGRESS) {
81+ /* connection is proceeding
82+ * it is complete (or failed) when select returns */
83+
84+ /* initialize connect_fdset */
85+ FD_ZERO(&connect_fdset);
86+ FD_SET(fd, &connect_fdset);
87+
88+ /* call select */
89+ do {
90+ err = select(fd + 1, NULL, &connect_fdset,
91+ NULL, tvp);
92+ } while (err < 0 && errno == EINTR);
93+
94+ /* select error */
95+ if (err < 0)
96+ errx(1,"select error: %s", strerror(errno));
97+ /* we have reached a timeout */
98+ if (err == 0)
99+ return CONNECTION_TIMEOUT;
100+ /* select returned successfully, but we must test socket
101+ * error for result */
102+ len = sizeof(err);
103+ if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len) < 0)
104+ errx(1, "getsockopt error: %s", strerror(errno));
105+ /* setup errno according to the result returned by
106+ * getsockopt */
107+ if (err != 0)
108+ errno = err;
109+ }
110+
111+ /* return aborted if an error occured, and valid otherwise */
112+ fcntl(fd, F_SETFL, orig_flags);
113+ return (err != 0)? CONNECTION_FAILED : CONNECTION_SUCCESS;
114+}
115+
116 /*
117 * local_listen()
118 * Returns a socket listening on a local port, binds to specified source
0119
=== added file 'debian/patches/0003-get-sev-by-name.patch'
--- debian/patches/0003-get-sev-by-name.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0003-get-sev-by-name.patch 2012-05-30 22:10:23 +0000
@@ -0,0 +1,34 @@
1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 14:45:08 +0800
3Subject: [PATCH] get sev by name
4
5---
6 netcat.c | 9 ++++++++-
7 1 files changed, 8 insertions(+), 1 deletions(-)
8
9diff --git a/netcat.c b/netcat.c
10index 51a5729..28e871e 100644
11--- a/netcat.c
12+++ b/netcat.c
13@@ -949,12 +949,19 @@ atelnet(int nfd, unsigned char *buf, unsigned int size)
14 void
15 build_ports(char *p)
16 {
17+ struct servent *sv;
18 const char *errstr;
19 char *n;
20 int hi, lo, cp;
21 int x = 0;
22
23- if ((n = strchr(p, '-')) != NULL) {
24+ sv = getservbyname(p, uflag ? "udp" : "tcp");
25+ if (sv) {
26+ portlist[0] = calloc(1, PORT_MAX_LEN);
27+ if (portlist[0] == NULL)
28+ err(1, NULL);
29+ snprintf(portlist[0], PORT_MAX_LEN, "%d", ntohs(sv->s_port));
30+ } else if ((n = strchr(p, '-')) != NULL) {
31 *n = '\0';
32 n++;
33
34--
035
=== added file 'debian/patches/0004-poll-hup.patch'
--- debian/patches/0004-poll-hup.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0004-poll-hup.patch 2012-05-30 22:10:23 +0000
@@ -0,0 +1,59 @@
1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 15:08:33 +0800
3Subject: [PATCH] poll hup
4
5---
6 netcat.c | 24 +++++++++++++++++-------
7 1 files changed, 17 insertions(+), 7 deletions(-)
8
9diff --git a/netcat.c b/netcat.c
10index 28e871e..b36583f 100644
11--- a/netcat.c
12+++ b/netcat.c
13@@ -884,9 +884,7 @@ readwrite(int nfd)
14 if ((n = read(nfd, buf, plen)) < 0)
15 return;
16 else if (n == 0) {
17- shutdown(nfd, SHUT_RD);
18- pfd[0].fd = -1;
19- pfd[0].events = 0;
20+ goto shutdown_rd;
21 } else {
22 if (tflag)
23 atelnet(nfd, buf, n);
24@@ -894,18 +892,30 @@ readwrite(int nfd)
25 return;
26 }
27 }
28+ else if (pfd[0].revents & POLLHUP) {
29+ shutdown_rd:
30+ shutdown(nfd, SHUT_RD);
31+ pfd[0].fd = -1;
32+ pfd[0].events = 0;
33+ }
34
35- if (!dflag && pfd[1].revents & POLLIN) {
36+ if (!dflag) {
37+ if(pfd[1].revents & POLLIN) {
38 if ((n = read(wfd, buf, plen)) < 0)
39 return;
40 else if (n == 0) {
41- shutdown(nfd, SHUT_WR);
42- pfd[1].fd = -1;
43- pfd[1].events = 0;
44+ goto shutdown_wr;
45 } else {
46 if (atomicio(vwrite, nfd, buf, n) != n)
47 return;
48 }
49+ }
50+ else if (pfd[1].revents & POLLHUP) {
51+ shutdown_wr:
52+ shutdown(nfd, SHUT_WR);
53+ pfd[1].fd = -1;
54+ pfd[1].events = 0;
55+ }
56 }
57 }
58 }
59--
060
=== added file 'debian/patches/0005-send-crlf.patch'
--- debian/patches/0005-send-crlf.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0005-send-crlf.patch 2012-05-30 22:10:23 +0000
@@ -0,0 +1,103 @@
1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 14:57:45 +0800
3Subject: [PATCH] send crlf
4
5---
6 nc.1 | 6 ++++--
7 netcat.c | 21 +++++++++++++++++----
8 2 files changed, 21 insertions(+), 6 deletions(-)
9
10--- a/nc.1
11+++ b/nc.1
12@@ -34,7 +34,7 @@
13 .Sh SYNOPSIS
14 .Nm nc
15 .Bk -words
16-.Op Fl 46DdhklnrStUuvz
17+.Op Fl 46CDdhklnrStUuvz
18 .Op Fl I Ar length
19 .Op Fl i Ar interval
20 .Op Fl O Ar length
21@@ -98,6 +98,8 @@
22 Forces
23 .Nm
24 to use IPv6 addresses only.
25+.It Fl C
26+Send CRLF as line-ending.
27 .It Fl D
28 Enable debugging on the socket.
29 .It Fl d
30@@ -355,7 +357,7 @@
31 of requests required by the server.
32 As another example, an email may be submitted to an SMTP server using:
33 .Bd -literal -offset indent
34-$ nc localhost 25 \*(Lt\*(Lt EOF
35+$ nc [\-C] localhost 25 \*(Lt\*(Lt EOF
36 HELO host.example.com
37 MAIL FROM:\*(Ltuser@host.example.com\*(Gt
38 RCPT TO:\*(Ltuser2@host.example.com\*(Gt
39--- a/netcat.c
40+++ b/netcat.c
41@@ -111,6 +111,7 @@
42 #define CONNECTION_TIMEOUT 2
43
44 /* Command Line Options */
45+int Cflag = 0; /* CRLF line-ending */
46 int dflag; /* detached, no stdin */
47 unsigned int iflag; /* Interval Flag */
48 int jflag; /* use jumbo frames if we can */
49@@ -180,7 +181,7 @@
50 sv = NULL;
51
52 while ((ch = getopt(argc, argv,
53- "46DdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) {
54+ "46CDdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) {
55 switch (ch) {
56 case '4':
57 family = AF_INET;
58@@ -309,6 +310,9 @@
59 if (Tflag < 0 || Tflag > 255 || errstr || errno)
60 errx(1, "illegal tos value %s", optarg);
61 break;
62+ case 'C':
63+ Cflag = 1;
64+ break;
65 default:
66 usage(1);
67 }
68@@ -906,8 +910,16 @@
69 else if (n == 0) {
70 goto shutdown_wr;
71 } else {
72- if (atomicio(vwrite, nfd, buf, n) != n)
73- return;
74+ if ((Cflag) && (buf[n-1]=='\n')) {
75+ if (atomicio(vwrite, nfd, buf, n-1) != (n-1))
76+ return;
77+ if (atomicio(vwrite, nfd, "\r\n", 2) != 2)
78+ return;
79+ }
80+ else {
81+ if (atomicio(vwrite, nfd, buf, n) != n)
82+ return;
83+ }
84 }
85 }
86 else if (pfd[1].revents & POLLHUP) {
87@@ -1139,6 +1151,7 @@
88 fprintf(stderr, "\tCommand Summary:\n\
89 \t-4 Use IPv4\n\
90 \t-6 Use IPv6\n\
91+ \t-C Send CRLF as line-ending\n\
92 \t-D Enable the debug socket option\n\
93 \t-d Detach from stdin\n\
94 \t-h This help text\n\
95@@ -1172,7 +1185,7 @@
96 usage(int ret)
97 {
98 fprintf(stderr,
99- "usage: nc [-46DdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n"
100+ "usage: nc [-46CDdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n"
101 "\t [-P proxy_username] [-p source_port] [-s source] [-T toskeyword]\n"
102 "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
103 "\t [-x proxy_address[:port]] [destination] [port]\n");
0104
=== added file 'debian/patches/0006-quit-timer.patch'
--- debian/patches/0006-quit-timer.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0006-quit-timer.patch 2012-05-30 22:10:23 +0000
@@ -0,0 +1,128 @@
1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 15:16:04 +0800
3Subject: [PATCH] quit timer
4
5---
6 nc.1 | 5 +++++
7 netcat.c | 39 ++++++++++++++++++++++++++++++++++-----
8 2 files changed, 39 insertions(+), 5 deletions(-)
9
10--- a/nc.1
11+++ b/nc.1
12@@ -40,6 +40,7 @@
13 .Op Fl O Ar length
14 .Op Fl P Ar proxy_username
15 .Op Fl p Ar source_port
16+.Op Fl q Ar seconds
17 .Op Fl s Ar source
18 .Op Fl T Ar toskeyword
19 .Op Fl V Ar rtable
20@@ -148,6 +149,10 @@
21 Specifies the source port
22 .Nm
23 should use, subject to privilege restrictions and availability.
24+.It Fl q Ar seconds
25+after EOF on stdin, wait the specified number of seconds and then quit. If
26+.Ar seconds
27+is negative, wait forever.
28 .It Fl r
29 Specifies that source and/or destination ports should be chosen randomly
30 instead of sequentially within a range or in the order that the system
31--- a/netcat.c
32+++ b/netcat.c
33@@ -86,6 +86,7 @@
34 #include <errno.h>
35 #include <netdb.h>
36 #include <poll.h>
37+#include <signal.h>
38 #include <stdarg.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41@@ -120,6 +121,7 @@
42 int nflag; /* Don't do name look up */
43 char *Pflag; /* Proxy username */
44 char *pflag; /* Localport flag */
45+int qflag = 0; /* Quit after some secs */
46 int rflag; /* Random ports flag */
47 char *sflag; /* Source Address */
48 int tflag; /* Telnet Emulation */
49@@ -158,6 +160,7 @@
50
51 static int connect_with_timeout(int fd, const struct sockaddr *sa,
52 socklen_t salen, int ctimeout);
53+static void quit();
54
55 int
56 main(int argc, char *argv[])
57@@ -181,7 +184,7 @@
58 sv = NULL;
59
60 while ((ch = getopt(argc, argv,
61- "46CDdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) {
62+ "46CDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:z")) != -1) {
63 switch (ch) {
64 case '4':
65 family = AF_INET;
66@@ -235,6 +238,11 @@
67 case 'p':
68 pflag = optarg;
69 break;
70+ case 'q':
71+ qflag = strtonum(optarg, INT_MIN, INT_MAX, &errstr);
72+ if (errstr)
73+ errx(1, "quit timer %s: %s", errstr, optarg);
74+ break;
75 case 'r':
76 rflag = 1;
77 break;
78@@ -924,9 +932,18 @@
79 }
80 else if (pfd[1].revents & POLLHUP) {
81 shutdown_wr:
82+ /* if the user asked to exit on EOF, do it */
83+ if (qflag == 0) {
84 shutdown(nfd, SHUT_WR);
85- pfd[1].fd = -1;
86- pfd[1].events = 0;
87+ close(wfd);
88+ }
89+ /* if user asked to die after a while, arrange for it */
90+ if (qflag > 0) {
91+ signal(SIGALRM, quit);
92+ alarm(qflag);
93+ }
94+ pfd[1].fd = -1;
95+ pfd[1].events = 0;
96 }
97 }
98 }
99@@ -1164,6 +1181,7 @@
100 \t-O length TCP send buffer length\n\
101 \t-P proxyuser\tUsername for proxy authentication\n\
102 \t-p port\t Specify local port for remote connects\n\
103+ \t-q secs\t quit after EOF on stdin and delay of secs\n\
104 \t-r Randomize remote ports\n\
105 \t-S Enable the TCP MD5 signature option\n\
106 \t-s addr\t Local source address\n\
107@@ -1186,9 +1204,19 @@
108 {
109 fprintf(stderr,
110 "usage: nc [-46CDdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n"
111- "\t [-P proxy_username] [-p source_port] [-s source] [-T toskeyword]\n"
112- "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
113+ "\t [-P proxy_username] [-p source_port] [-q seconds] [-s source]\n"
114+ "\t [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]\n"
115 "\t [-x proxy_address[:port]] [destination] [port]\n");
116 if (ret)
117 exit(1);
118 }
119+
120+/*
121+ * quit()
122+ * handler for a "-q" timeout (exit 0 instead of 1)
123+ */
124+static void quit()
125+{
126+ /* XXX: should explicitly close fds here */
127+ exit(0);
128+}
0129
=== added file 'debian/patches/0007-udp-scan-timeout.patch'
--- debian/patches/0007-udp-scan-timeout.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0007-udp-scan-timeout.patch 2012-05-30 22:10:23 +0000
@@ -0,0 +1,56 @@
1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 15:29:37 +0800
3Subject: [PATCH] udp scan timeout
4
5---
6 netcat.c | 25 ++++++++++++++++---------
7 1 files changed, 16 insertions(+), 9 deletions(-)
8
9--- a/netcat.c
10+++ b/netcat.c
11@@ -111,6 +111,8 @@
12 #define CONNECTION_FAILED 1
13 #define CONNECTION_TIMEOUT 2
14
15+#define UDP_SCAN_TIMEOUT 3 /* Seconds */
16+
17 /* Command Line Options */
18 int Cflag = 0; /* CRLF line-ending */
19 int dflag; /* detached, no stdin */
20@@ -497,7 +499,7 @@
21 continue;
22
23 ret = 0;
24- if (vflag || zflag) {
25+ if (vflag) {
26 /* For UDP, make sure we are connected. */
27 if (uflag) {
28 if (udptest(s) == -1) {
29@@ -1057,15 +1059,20 @@
30 int
31 udptest(int s)
32 {
33- int i, ret;
34+ int i, t;
35
36- for (i = 0; i <= 3; i++) {
37- if (write(s, "X", 1) == 1)
38- ret = 1;
39- else
40- ret = -1;
41+ if ((write(s, "X", 1) != 1) ||
42+ ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED)))
43+ return -1;
44+
45+ /* Give the remote host some time to reply. */
46+ for (i = 0, t = (timeout == -1) ? UDP_SCAN_TIMEOUT : (timeout / 1000);
47+ i < t; i++) {
48+ sleep(1);
49+ if ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED))
50+ return -1;
51 }
52- return (ret);
53+ return 1;
54 }
55
56 void
057
=== added file 'debian/patches/0008-verbose-numeric-port.patch'
--- debian/patches/0008-verbose-numeric-port.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0008-verbose-numeric-port.patch 2012-05-30 22:10:23 +0000
@@ -0,0 +1,103 @@
1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 15:38:15 +0800
3Subject: [PATCH] verbose numeric port
4
5---
6 netcat.c | 44 ++++++++++++++++++++++++++++++++++++++++----
7 1 files changed, 40 insertions(+), 4 deletions(-)
8
9--- a/netcat.c
10+++ b/netcat.c
11@@ -41,6 +41,7 @@
12 #include <netinet/tcp.h>
13 #include <netinet/ip.h>
14 #include <arpa/telnet.h>
15+#include <arpa/inet.h>
16
17 #ifndef IPTOS_LOWDELAY
18 # define IPTOS_LOWDELAY 0x10
19@@ -424,6 +425,18 @@
20 s = local_listen(host, uport, hints);
21 if (s < 0)
22 err(1, NULL);
23+
24+ char* local;
25+ if (family == AF_INET6
26+ local = "0.0.0.0";
27+ else if (family == AF_INET)
28+ local = ":::";
29+ else
30+ local = "unknown"
31+ fprintf(stderr, "Listening on [%s] (family %d, port %d)\n",
32+ host ?: local,
33+ family,
34+ *uport);
35 /*
36 * For UDP, we will use recvfrom() initially
37 * to wait for a caller, then use the regular
38@@ -432,16 +445,15 @@
39 if (uflag) {
40 int rv, plen;
41 char buf[16384];
42- struct sockaddr_storage z;
43
44- len = sizeof(z);
45+ len = sizeof(cliaddr);
46 plen = jflag ? 16384 : 2048;
47 rv = recvfrom(s, buf, plen, MSG_PEEK,
48- (struct sockaddr *)&z, &len);
49+ (struct sockaddr *)&cliaddr, &len);
50 if (rv < 0)
51 err(1, "recvfrom");
52
53- rv = connect(s, (struct sockaddr *)&z, len);
54+ rv = connect(s, (struct sockaddr *)&cliaddr, len);
55 if (rv < 0)
56 err(1, "connect");
57
58@@ -450,6 +462,45 @@
59 len = sizeof(cliaddr);
60 connfd = accept(s, (struct sockaddr *)&cliaddr,
61 &len);
62+ if(vflag) {
63+ /* Don't look up port if -n. */
64+ if (nflag)
65+ sv = NULL;
66+ else
67+ sv = getservbyport(ntohs(atoi(uport)),
68+ uflag ? "udp" : "tcp");
69+
70+ if (((struct sockaddr *)&cliaddr)->sa_family == AF_INET) {
71+ char dst[INET_ADDRSTRLEN];
72+ inet_ntop(((struct sockaddr *)&cliaddr)->sa_family,&(((struct sockaddr_in *)&cliaddr)->sin_addr),dst,INET_ADDRSTRLEN);
73+ fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n",
74+ dst,
75+ uport,
76+ uflag ? "udp" : "tcp",
77+ sv ? sv->s_name : "*",
78+ ((struct sockaddr *)(&cliaddr))->sa_family,
79+ ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
80+ }
81+ else if(((struct sockaddr *)&cliaddr)->sa_family == AF_INET6) {
82+ char dst[INET6_ADDRSTRLEN];
83+ inet_ntop(((struct sockaddr *)&cliaddr)->sa_family,&(((struct sockaddr_in6 *)&cliaddr)->sin6_addr),dst,INET6_ADDRSTRLEN);
84+ fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n",
85+ dst,
86+ uport,
87+ uflag ? "udp" : "tcp",
88+ sv ? sv->s_name : "*",
89+ ((struct sockaddr *)&cliaddr)->sa_family,
90+ ntohs(((struct sockaddr_in6 *)&cliaddr)->sin6_port));
91+ }
92+ else {
93+ fprintf(stderr, "Connection from unknown port %s [%s/%s] accepted (family %d, sport %d)\n",
94+ uport,
95+ uflag ? "udp" : "tcp",
96+ sv ? sv->s_name : "*",
97+ ((struct sockaddr *)(&cliaddr))->sa_family,
98+ ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
99+ }
100+ }
101 readwrite(connfd);
102 close(connfd);
103 }
0104
=== added file 'debian/patches/0009-dccp-support.patch'
--- debian/patches/0009-dccp-support.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0009-dccp-support.patch 2012-05-30 22:10:23 +0000
@@ -0,0 +1,299 @@
1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 15:56:51 +0800
3Subject: [PATCH] dccp support
4
5---
6 nc.1 | 4 ++-
7 netcat.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++----------
8 2 files changed, 88 insertions(+), 18 deletions(-)
9
10--- a/nc.1
11+++ b/nc.1
12@@ -34,7 +34,7 @@
13 .Sh SYNOPSIS
14 .Nm nc
15 .Bk -words
16-.Op Fl 46CDdhklnrStUuvz
17+.Op Fl 46CDdhklnrStUuvZz
18 .Op Fl I Ar length
19 .Op Fl i Ar interval
20 .Op Fl O Ar length
21@@ -257,6 +257,8 @@
22 .Ar port
23 is not specified, the well-known port for the proxy protocol is used (1080
24 for SOCKS, 3128 for HTTPS).
25+.It Fl Z
26+DCCP mode.
27 .It Fl z
28 Specifies that
29 .Nm
30--- a/netcat.c
31+++ b/netcat.c
32@@ -129,6 +129,7 @@
33 char *sflag; /* Source Address */
34 int tflag; /* Telnet Emulation */
35 int uflag; /* UDP - Default to TCP */
36+int dccpflag; /* DCCP - Default to TCP */
37 int vflag; /* Verbosity */
38 int xflag; /* Socks proxy */
39 int zflag; /* Port Scan Flag */
40@@ -160,6 +161,7 @@
41 void set_common_sockopts(int);
42 int map_tos(char *, int *);
43 void usage(int);
44+char *proto_name(int uflag, int dccpflag);
45
46 static int connect_with_timeout(int fd, const struct sockaddr *sa,
47 socklen_t salen, int ctimeout);
48@@ -187,7 +189,7 @@
49 sv = NULL;
50
51 while ((ch = getopt(argc, argv,
52- "46CDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:z")) != -1) {
53+ "46CDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:Zz")) != -1) {
54 switch (ch) {
55 case '4':
56 family = AF_INET;
57@@ -258,6 +260,13 @@
58 case 'u':
59 uflag = 1;
60 break;
61+ case 'Z':
62+# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP)
63+ dccpflag = 1;
64+# else
65+ errx(1, "no DCCP support available");
66+# endif
67+ break;
68 case 'V':
69 # if defined(RT_TABLEID_MAX)
70 rtableid = (unsigned int)strtonum(optarg, 0,
71@@ -333,6 +342,12 @@
72
73 /* Cruft to make sure options are clean, and used properly. */
74 if (argv[0] && !argv[1] && family == AF_UNIX) {
75+ if (uflag)
76+ errx(1, "cannot use -u and -U");
77+# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP)
78+ if (dccpflag)
79+ errx(1, "cannot use -Z and -U");
80+# endif
81 host = argv[0];
82 uport = NULL;
83 } else if (!argv[0] && lflag) {
84@@ -374,8 +389,20 @@
85 if (family != AF_UNIX) {
86 memset(&hints, 0, sizeof(struct addrinfo));
87 hints.ai_family = family;
88- hints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
89- hints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
90+ if (uflag) {
91+ hints.ai_socktype = SOCK_DGRAM;
92+ hints.ai_protocol = IPPROTO_UDP;
93+ }
94+# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP)
95+ else if (dccpflag) {
96+ hints.ai_socktype = SOCK_DCCP;
97+ hints.ai_protocol = IPPROTO_DCCP;
98+ }
99+# endif
100+ else {
101+ hints.ai_socktype = SOCK_STREAM;
102+ hints.ai_protocol = IPPROTO_TCP;
103+ }
104 if (nflag)
105 hints.ai_flags |= AI_NUMERICHOST;
106 }
107@@ -383,7 +410,10 @@
108 if (xflag) {
109 if (uflag)
110 errx(1, "no proxy support for UDP mode");
111-
112+# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP)
113+ if (dccpflag)
114+ errx(1, "no proxy support for DCCP mode");
115+# endif
116 if (lflag)
117 errx(1, "no proxy support for listen");
118
119@@ -427,12 +457,12 @@
120 err(1, NULL);
121
122 char* local;
123- if (family == AF_INET6
124+ if (family == AF_INET6 )
125 local = "0.0.0.0";
126 else if (family == AF_INET)
127 local = ":::";
128 else
129- local = "unknown"
130+ local = "unknown";
131 fprintf(stderr, "Listening on [%s] (family %d, port %d)\n",
132 host ?: local,
133 family,
134@@ -463,12 +493,13 @@
135 connfd = accept(s, (struct sockaddr *)&cliaddr,
136 &len);
137 if(vflag) {
138+ char *proto = proto_name(uflag, dccpflag);
139 /* Don't look up port if -n. */
140 if (nflag)
141 sv = NULL;
142 else
143 sv = getservbyport(ntohs(atoi(uport)),
144- uflag ? "udp" : "tcp");
145+ proto);
146
147 if (((struct sockaddr *)&cliaddr)->sa_family == AF_INET) {
148 char dst[INET_ADDRSTRLEN];
149@@ -476,7 +507,7 @@
150 fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n",
151 dst,
152 uport,
153- uflag ? "udp" : "tcp",
154+ proto,
155 sv ? sv->s_name : "*",
156 ((struct sockaddr *)(&cliaddr))->sa_family,
157 ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
158@@ -487,7 +518,7 @@
159 fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n",
160 dst,
161 uport,
162- uflag ? "udp" : "tcp",
163+ proto,
164 sv ? sv->s_name : "*",
165 ((struct sockaddr *)&cliaddr)->sa_family,
166 ntohs(((struct sockaddr_in6 *)&cliaddr)->sin6_port));
167@@ -495,7 +526,7 @@
168 else {
169 fprintf(stderr, "Connection from unknown port %s [%s/%s] accepted (family %d, sport %d)\n",
170 uport,
171- uflag ? "udp" : "tcp",
172+ proto,
173 sv ? sv->s_name : "*",
174 ((struct sockaddr *)(&cliaddr))->sa_family,
175 ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
176@@ -559,19 +590,20 @@
177 }
178 }
179
180+ char *proto = proto_name(uflag, dccpflag);
181 /* Don't look up port if -n. */
182 if (nflag)
183 sv = NULL;
184 else {
185 sv = getservbyport(
186 ntohs(atoi(portlist[i])),
187- uflag ? "udp" : "tcp");
188+ proto);
189 }
190
191 fprintf(stderr,
192 "Connection to %s %s port [%s/%s] "
193 "succeeded!\n", host, portlist[i],
194- uflag ? "udp" : "tcp",
195+ proto,
196 sv ? sv->s_name : "*");
197 }
198 if (!zflag)
199@@ -671,6 +703,24 @@
200 return (s);
201 }
202
203+char *proto_name(uflag, dccpflag) {
204+
205+ char *proto = NULL;
206+ if (uflag) {
207+ proto = "udp";
208+ }
209+# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP)
210+ else if (dccpflag) {
211+ proto = "dccp";
212+ }
213+# endif
214+ else {
215+ proto = "tcp";
216+ }
217+
218+ return proto;
219+}
220+
221 /*
222 * remote_connect()
223 * Returns a socket connected to a remote host. Properly binds to a local
224@@ -709,8 +759,21 @@
225 # endif
226 memset(&ahints, 0, sizeof(struct addrinfo));
227 ahints.ai_family = res0->ai_family;
228- ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
229- ahints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
230+ if (uflag) {
231+ ahints.ai_socktype = SOCK_DGRAM;
232+ ahints.ai_protocol = IPPROTO_UDP;
233+
234+ }
235+# if defined(IPPROTO_DCCP) && defined(SOCK_DCCP)
236+ else if (dccpflag) {
237+ hints.ai_socktype = SOCK_DCCP;
238+ hints.ai_protocol = IPPROTO_DCCP;
239+ }
240+# endif
241+ else {
242+ ahints.ai_socktype = SOCK_STREAM;
243+ ahints.ai_protocol = IPPROTO_TCP;
244+ }
245 ahints.ai_flags = AI_PASSIVE;
246 if ((error = getaddrinfo(sflag, pflag, &ahints, &ares)))
247 errx(1, "getaddrinfo: %s", gai_strerror(error));
248@@ -722,15 +785,19 @@
249 }
250
251 set_common_sockopts(s);
252+ char *proto = proto_name(uflag, dccpflag);
253
254- if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout))== CONNECTION_SUCCESS)
255+ if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout))== CONNECTION_SUCCESS) {
256 break;
257- else if (vflag && error == CONNECTION_FAILED)
258+ }
259+ else if (vflag && error == CONNECTION_FAILED) {
260 warn("connect to %s port %s (%s) failed", host, port,
261- uflag ? "udp" : "tcp");
262- else if (vflag && error == CONNECTION_TIMEOUT)
263+ proto);
264+ }
265+ else if (vflag && error == CONNECTION_TIMEOUT) {
266 warn("connect to %s port %s (%s) timed out", host, port,
267- uflag ? "udp" : "tcp");
268+ proto);
269+ }
270
271 close(s);
272 s = -1;
273@@ -1047,7 +1114,8 @@
274 int hi, lo, cp;
275 int x = 0;
276
277- sv = getservbyname(p, uflag ? "udp" : "tcp");
278+ char *proto = proto_name(uflag, dccpflag);
279+ sv = getservbyname(p, proto);
280 if (sv) {
281 portlist[0] = calloc(1, PORT_MAX_LEN);
282 if (portlist[0] == NULL)
283@@ -1252,6 +1320,7 @@
284 \t-w secs\t Timeout for connects and final net reads\n\
285 \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\
286 \t-x addr[:port]\tSpecify proxy address and port\n\
287+ \t-Z DCCP mode\n\
288 \t-z Zero-I/O mode [used for scanning]\n\
289 Port numbers can be individual or ranges: lo-hi [inclusive]\n");
290 exit(0);
291@@ -1261,7 +1330,7 @@
292 usage(int ret)
293 {
294 fprintf(stderr,
295- "usage: nc [-46CDdhjklnrStUuvz] [-I length] [-i interval] [-O length]\n"
296+ "usage: nc [-46CDdhjklnrStUuvZz] [-I length] [-i interval] [-O length]\n"
297 "\t [-P proxy_username] [-p source_port] [-q seconds] [-s source]\n"
298 "\t [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]\n"
299 "\t [-x proxy_address[:port]] [destination] [port]\n");
0300
=== added file 'debian/patches/0010-serialized-handling-multiple-clients.patch'
--- debian/patches/0010-serialized-handling-multiple-clients.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0010-serialized-handling-multiple-clients.patch 2012-05-30 22:10:23 +0000
@@ -0,0 +1,73 @@
1From: Aron Xu <aron@debian.org>
2Date: Tue, 14 Feb 2012 23:02:00 +0800
3Subject: [PATCH] serialized handling multiple clients
4
5---
6 netcat.c | 18 +++++++++---------
7 1 files changed, 9 insertions(+), 9 deletions(-)
8
9--- a/netcat.c
10+++ b/netcat.c
11@@ -447,26 +447,24 @@
12 s = unix_bind(host);
13 else
14 s = unix_listen(host);
15- }
16+ } else
17+ s = local_listen(host, uport, hints);
18+ if (s < 0)
19+ err(1, NULL);
20+
21+ char* local;
22+ if (family == AF_INET6)
23+ local = ":::";
24+ else
25+ local = "0.0.0.0";
26+ fprintf(stderr, "Listening on [%s] (family %d, port %d)\n",
27+ host ?: local,
28+ family,
29+ *uport);
30
31 /* Allow only one connection at a time, but stay alive. */
32 for (;;) {
33- if (family != AF_UNIX)
34- s = local_listen(host, uport, hints);
35- if (s < 0)
36- err(1, NULL);
37-
38- char* local;
39- if (family == AF_INET6 )
40- local = "0.0.0.0";
41- else if (family == AF_INET)
42- local = ":::";
43- else
44- local = "unknown";
45- fprintf(stderr, "Listening on [%s] (family %d, port %d)\n",
46- host ?: local,
47- family,
48- *uport);
49+
50 /*
51 * For UDP, we will use recvfrom() initially
52 * to wait for a caller, then use the regular
53@@ -536,15 +534,16 @@
54 close(connfd);
55 }
56
57- if (family != AF_UNIX)
58+ if (kflag)
59+ continue;
60+ if (family != AF_UNIX) {
61 close(s);
62+ }
63 else if (uflag) {
64 if (connect(s, NULL, 0) < 0)
65 err(1, "connect");
66 }
67-
68- if (!kflag)
69- break;
70+ break;
71 }
72 } else if (family == AF_UNIX) {
73 ret = 0;
074
=== added file 'debian/patches/0011-misc-failures-and-features.patch'
--- debian/patches/0011-misc-failures-and-features.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0011-misc-failures-and-features.patch 2012-05-30 22:10:23 +0000
@@ -0,0 +1,443 @@
1From: Aron Xu <aron@debian.org>
2Date: Mon, 13 Feb 2012 19:06:52 +0800
3Subject: [PATCH] misc connection failures
4
5---
6 netcat.c | 22 +++++++++++++++++++---
7 1 files changed, 19 insertions(+), 3 deletions(-)
8
9--- a/netcat.c
10+++ b/netcat.c
11@@ -88,6 +88,7 @@
12 #include <netdb.h>
13 #include <poll.h>
14 #include <signal.h>
15+#include <stddef.h>
16 #include <stdarg.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19@@ -115,6 +116,7 @@
20 #define UDP_SCAN_TIMEOUT 3 /* Seconds */
21
22 /* Command Line Options */
23+int bflag; /* Allow Broadcast */
24 int Cflag = 0; /* CRLF line-ending */
25 int dflag; /* detached, no stdin */
26 unsigned int iflag; /* Interval Flag */
27@@ -146,7 +148,7 @@
28 char *unix_dg_tmp_socket;
29
30 void atelnet(int, unsigned char *, unsigned int);
31-void build_ports(char *);
32+void build_ports(char **);
33 void help(void);
34 int local_listen(char *, char *, struct addrinfo);
35 void readwrite(int);
36@@ -171,11 +173,14 @@
37 main(int argc, char *argv[])
38 {
39 int ch, s, ret, socksv;
40- char *host, *uport;
41+ char *host, **uport;
42 struct addrinfo hints;
43 struct servent *sv;
44 socklen_t len;
45- struct sockaddr_storage cliaddr;
46+ union {
47+ struct sockaddr_storage storage;
48+ struct sockaddr_un forunix;
49+ } cliaddr;
50 char *proxy = NULL;
51 const char *errstr, *proxyhost = "", *proxyport = NULL;
52 struct addrinfo proxyhints;
53@@ -189,7 +194,7 @@
54 sv = NULL;
55
56 while ((ch = getopt(argc, argv,
57- "46CDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:Zz")) != -1) {
58+ "46bCDdhI:i:jklnO:P:p:q:rSs:tT:UuV:vw:X:x:Zz")) != -1) {
59 switch (ch) {
60 case '4':
61 family = AF_INET;
62@@ -197,6 +202,13 @@
63 case '6':
64 family = AF_INET6;
65 break;
66+ case 'b':
67+# if defined(SO_BROADCAST)
68+ bflag = 1;
69+# else
70+ errx(1, "no broadcast frame support available");
71+# endif
72+ break;
73 case 'U':
74 family = AF_UNIX;
75 break;
76@@ -350,27 +362,34 @@
77 # endif
78 host = argv[0];
79 uport = NULL;
80- } else if (!argv[0] && lflag) {
81- if (sflag)
82- errx(1, "cannot use -s and -l");
83- if (zflag)
84- errx(1, "cannot use -z and -l");
85- if (pflag)
86- uport=pflag;
87- } else if (!lflag && kflag) {
88- errx(1, "cannot use -k without -l");
89- } else if (argv[0] && !argv[1]) {
90- if (!lflag)
91- usage(1);
92- uport = argv[0];
93+ } else if (argv[0] && !argv[1] && lflag) {
94+ if (pflag) {
95+ uport = &pflag;
96+ host = argv[0];
97+ } else {
98+ uport = argv;
99+ host = NULL;
100+ }
101+ } else if (!argv[0] && lflag && pflag) {
102+ uport = &pflag;
103 host = NULL;
104 } else if (argv[0] && argv[1]) {
105 host = argv[0];
106- uport = argv[1];
107+ uport = &argv[1];
108 } else
109 usage(1);
110
111-
112+ if (lflag) {
113+ if (sflag)
114+ errx(1, "cannot use -s and -l");
115+ if (zflag)
116+ errx(1, "cannot use -z and -l");
117+ if (pflag)
118+ /* This still does not work well because of getopt mess
119+ errx(1, "cannot use -p and -l"); */
120+ uport = &pflag;
121+ } else if (!lflag && kflag)
122+ errx(1, "cannot use -k without -l");
123
124 /* Get name of temporary socket for unix datagram client */
125 if ((family == AF_UNIX) && uflag && !lflag) {
126@@ -448,7 +467,7 @@
127 else
128 s = unix_listen(host);
129 } else
130- s = local_listen(host, uport, hints);
131+ s = local_listen(host, *uport, hints);
132 if (s < 0)
133 err(1, NULL);
134
135@@ -457,7 +476,8 @@
136 local = ":::";
137 else
138 local = "0.0.0.0";
139- fprintf(stderr, "Listening on [%s] (family %d, port %d)\n",
140+ if (vflag && (family != AF_UNIX))
141+ fprintf(stderr, "Listening on [%s] (family %d, port %s)\n",
142 host ?: local,
143 family,
144 *uport);
145@@ -490,13 +510,17 @@
146 len = sizeof(cliaddr);
147 connfd = accept(s, (struct sockaddr *)&cliaddr,
148 &len);
149- if(vflag) {
150+ if(vflag && family == AF_UNIX) {
151+ fprintf(stderr, "Connection from \"%.*s\" accepted\n",
152+ (len - (int)offsetof(struct sockaddr_un, sun_path)),
153+ ((struct sockaddr_un*)&cliaddr)->sun_path);
154+ } else if(vflag) {
155 char *proto = proto_name(uflag, dccpflag);
156 /* Don't look up port if -n. */
157 if (nflag)
158 sv = NULL;
159 else
160- sv = getservbyport(ntohs(atoi(uport)),
161+ sv = getservbyport(ntohs(atoi(*uport)),
162 proto);
163
164 if (((struct sockaddr *)&cliaddr)->sa_family == AF_INET) {
165@@ -504,7 +528,7 @@
166 inet_ntop(((struct sockaddr *)&cliaddr)->sa_family,&(((struct sockaddr_in *)&cliaddr)->sin_addr),dst,INET_ADDRSTRLEN);
167 fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n",
168 dst,
169- uport,
170+ *uport,
171 proto,
172 sv ? sv->s_name : "*",
173 ((struct sockaddr *)(&cliaddr))->sa_family,
174@@ -515,7 +539,7 @@
175 inet_ntop(((struct sockaddr *)&cliaddr)->sa_family,&(((struct sockaddr_in6 *)&cliaddr)->sin6_addr),dst,INET6_ADDRSTRLEN);
176 fprintf(stderr, "Connection from [%s] port %s [%s/%s] accepted (family %d, sport %d)\n",
177 dst,
178- uport,
179+ *uport,
180 proto,
181 sv ? sv->s_name : "*",
182 ((struct sockaddr *)&cliaddr)->sa_family,
183@@ -523,17 +547,21 @@
184 }
185 else {
186 fprintf(stderr, "Connection from unknown port %s [%s/%s] accepted (family %d, sport %d)\n",
187- uport,
188+ *uport,
189 proto,
190 sv ? sv->s_name : "*",
191 ((struct sockaddr *)(&cliaddr))->sa_family,
192 ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
193 }
194 }
195+ if(!kflag)
196+ close(s);
197 readwrite(connfd);
198 close(connfd);
199 }
200
201+ if (vflag && kflag)
202+ fprintf(stderr, "Connection closed, listening again.\n");
203 if (kflag)
204 continue;
205 if (family != AF_UNIX) {
206@@ -641,6 +669,8 @@
207 return (-1);
208 }
209
210+ unlink(path);
211+
212 if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
213 close(s);
214 return (-1);
215@@ -662,8 +692,10 @@
216 if ((s = unix_bind(unix_dg_tmp_socket)) < 0)
217 return (-1);
218 } else {
219- if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
220+ if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
221+ errx(1,"create unix socket failed");
222 return (-1);
223+ }
224 }
225 (void)fcntl(s, F_SETFD, 1);
226
227@@ -674,9 +706,11 @@
228 sizeof(sun.sun_path)) {
229 close(s);
230 errno = ENAMETOOLONG;
231+ warn("unix connect abandoned");
232 return (-1);
233 }
234 if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
235+ warn("unix connect failed");
236 close(s);
237 return (-1);
238 }
239@@ -1105,22 +1139,23 @@
240 * that we should try to connect to.
241 */
242 void
243-build_ports(char *p)
244+build_ports(char **p)
245 {
246 struct servent *sv;
247 const char *errstr;
248 char *n;
249 int hi, lo, cp;
250 int x = 0;
251+ int i;
252
253 char *proto = proto_name(uflag, dccpflag);
254- sv = getservbyname(p, proto);
255+ sv = getservbyname(*p, proto);
256 if (sv) {
257 portlist[0] = calloc(1, PORT_MAX_LEN);
258 if (portlist[0] == NULL)
259 err(1, NULL);
260 snprintf(portlist[0], PORT_MAX_LEN, "%d", ntohs(sv->s_port));
261- } else if ((n = strchr(p, '-')) != NULL) {
262+ } else if ((n = strchr(*p, '-')) != NULL) {
263 *n = '\0';
264 n++;
265
266@@ -1128,9 +1163,9 @@
267 hi = strtonum(n, 1, PORT_MAX, &errstr);
268 if (errstr)
269 errx(1, "port number %s: %s", errstr, n);
270- lo = strtonum(p, 1, PORT_MAX, &errstr);
271+ lo = strtonum(*p, 1, PORT_MAX, &errstr);
272 if (errstr)
273- errx(1, "port number %s: %s", errstr, p);
274+ errx(1, "port number %s: %s", errstr, *p);
275
276 if (lo > hi) {
277 cp = hi;
278@@ -1160,10 +1195,12 @@
279 }
280 }
281 } else {
282- hi = strtonum(p, 1, PORT_MAX, &errstr);
283+ hi = strtonum(*p, 1, PORT_MAX, &errstr);
284 if (errstr)
285- errx(1, "port number %s: %s", errstr, p);
286- portlist[0] = strdup(p);
287+ errx(1, "port number %s: %s", errstr, *p);
288+ for (i=0;p[i];i++) {
289+ portlist[i] = strdup(p[i]);
290+ }
291 if (portlist[0] == NULL)
292 err(1, NULL);
293 }
294@@ -1198,6 +1235,13 @@
295 {
296 int x = 1;
297
298+# if defined(SO_BROADCAST)
299+ if (bflag) {
300+ if (setsockopt(s, IPPROTO_TCP, SO_BROADCAST,
301+ &x, sizeof(x)) == -1)
302+ err(1, NULL);
303+ }
304+# endif
305 # if defined(TCP_MD5SIG)
306 if (Sflag) {
307 if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
308@@ -1293,6 +1337,7 @@
309 fprintf(stderr, "\tCommand Summary:\n\
310 \t-4 Use IPv4\n\
311 \t-6 Use IPv6\n\
312+ \t-b Allow broadcast\n\
313 \t-C Send CRLF as line-ending\n\
314 \t-D Enable the debug socket option\n\
315 \t-d Detach from stdin\n\
316@@ -1329,7 +1374,7 @@
317 usage(int ret)
318 {
319 fprintf(stderr,
320- "usage: nc [-46CDdhjklnrStUuvZz] [-I length] [-i interval] [-O length]\n"
321+ "usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length]\n"
322 "\t [-P proxy_username] [-p source_port] [-q seconds] [-s source]\n"
323 "\t [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]\n"
324 "\t [-x proxy_address[:port]] [destination] [port]\n");
325--- a/nc.1
326+++ b/nc.1
327@@ -34,7 +34,7 @@
328 .Sh SYNOPSIS
329 .Nm nc
330 .Bk -words
331-.Op Fl 46CDdhklnrStUuvZz
332+.Op Fl 46bCDdhklnrStUuvZz
333 .Op Fl I Ar length
334 .Op Fl i Ar interval
335 .Op Fl O Ar length
336@@ -99,6 +99,8 @@
337 Forces
338 .Nm
339 to use IPv6 addresses only.
340+.It Fl b
341+Allow broadcast.
342 .It Fl C
343 Send CRLF as line-ending.
344 .It Fl D
345@@ -323,6 +325,54 @@
346 The connection may be terminated using an
347 .Dv EOF
348 .Pq Sq ^D .
349+.Pp
350+There is no
351+.Fl c
352+or
353+.Fl e
354+option in this netcat, but you still can execute a command after connection
355+being established by redirecting file descriptors. Be cautious here because
356+opening a port and let anyone connected execute arbitrary command on your
357+site is DANGEROUS. If you really need to do this, here is an example:
358+.Pp
359+On
360+.Sq server
361+side:
362+.Pp
363+.Dl $ rm -f /tmp/f; mkfifo /tmp/f
364+.Dl $ cat /tmp/f | /bin/sh -i 2>&1 | nc -l 127.0.0.1 1234 > /tmp/f
365+.Pp
366+On
367+.Sq client
368+side:
369+.Pp
370+.Dl $ nc host.example.com 1234
371+.Dl $ (shell prompt from host.example.com)
372+.Pp
373+By doing this, you create a fifo at /tmp/f and make nc listen at port 1234
374+of address 127.0.0.1 on
375+.Sq server
376+side, when a
377+.Sq client
378+establishes a connection successfully to that port, /bin/sh gets executed
379+on
380+.Sq server
381+side and the shell prompt is given to
382+.Sq client
383+side.
384+.Pp
385+When connection is terminated,
386+.Nm
387+quits as well. Use
388+.Fl k
389+if you want it keep listening, but if the command quits this option won't
390+restart it or keep
391+.Nm
392+running. Also don't forget to remove the file descriptor once you don't need
393+it anymore:
394+.Pp
395+.Dl $ rm -f /tmp/f
396+.Pp
397 .Sh DATA TRANSFER
398 The example in the previous section can be expanded to build a
399 basic data transfer model.
400@@ -382,15 +432,30 @@
401 flag can be used to tell
402 .Nm
403 to report open ports,
404-rather than initiate a connection.
405+rather than initiate a connection. Usually it's useful to turn on verbose
406+output to stderr by use this option in conjunction with
407+.Fl v
408+option.
409+.Pp
410 For example:
411 .Bd -literal -offset indent
412-$ nc -z host.example.com 20-30
413+$ nc \-zv host.example.com 20-30
414 Connection to host.example.com 22 port [tcp/ssh] succeeded!
415 Connection to host.example.com 25 port [tcp/smtp] succeeded!
416 .Ed
417 .Pp
418-The port range was specified to limit the search to ports 20 \- 30.
419+The port range was specified to limit the search to ports 20 \- 30, and is
420+scanned by increasing order.
421+.Pp
422+You can also specify a list of ports to scan, for example:
423+.Bd -literal -offset indent
424+$ nc \-zv host.example.com 80 20 22
425+nc: connect to host.example.com 80 (tcp) failed: Connection refused
426+nc: connect to host.example.com 20 (tcp) failed: Connection refused
427+Connection to host.example.com port [tcp/ssh] succeeded!
428+.Ed
429+.Pp
430+The ports are scanned by the order you given.
431 .Pp
432 Alternatively, it might be useful to know which server software
433 is running, and which versions.
434@@ -455,6 +520,9 @@
435 .br
436 Rewritten with IPv6 support by
437 .An Eric Jackson Aq ericj@monkey.org .
438+.br
439+Modified for Debian port by Aron Xu
440+.Aq aron@debian.org .
441 .Sh CAVEATS
442 UDP port scans using the
443 .Fl uz
0444
=== removed file 'debian/patches/connect-timeout.patch'
--- debian/patches/connect-timeout.patch 2008-01-30 18:24:46 +0000
+++ debian/patches/connect-timeout.patch 1970-01-01 00:00:00 +0000
@@ -1,120 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:27.000000000 -0500
4+++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:30.000000000 -0500
5@@ -65,6 +65,10 @@
6 #define PORT_MAX 65535
7 #define PORT_MAX_LEN 6
8
9+#define CONNECTION_SUCCESS 0
10+#define CONNECTION_FAILED 1
11+#define CONNECTION_TIMEOUT 2
12+
13 /* Command Line Options */
14 int dflag; /* detached, no stdin */
15 int iflag; /* Interval Flag */
16@@ -104,6 +108,9 @@
17 int parse_iptos(char *);
18 void usage(int);
19
20+static int connect_with_timeout(int fd, const struct sockaddr *sa,
21+ socklen_t salen, int ctimeout);
22+
23 int
24 main(int argc, char *argv[])
25 {
26@@ -508,13 +515,15 @@
27 }
28
29 set_common_sockopts(s);
30-
31- if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0)
32+ if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout)) == CONNECTION_SUCCESS)
33 break;
34- else if (vflag)
35+ else if (vflag && error == CONNECTION_FAILED)
36 warn("connect to %s port %s (%s) failed", host, port,
37 uflag ? "udp" : "tcp");
38-
39+ else if (vflag && error == CONNECTION_TIMEOUT)
40+ warn("connect to %s port %s (%s) timed out", host, port,
41+ uflag ? "udp" : "tcp");
42+
43 close(s);
44 s = -1;
45 } while ((res0 = res0->ai_next) != NULL);
46@@ -524,6 +533,74 @@
47 return (s);
48 }
49
50+static int connect_with_timeout(int fd, const struct sockaddr *sa,
51+ socklen_t salen, int ctimeout)
52+{
53+ int err;
54+ struct timeval tv, *tvp = NULL;
55+ fd_set connect_fdset;
56+ socklen_t len;
57+ int orig_flags;
58+
59+ orig_flags = fcntl(fd, F_GETFL, 0);
60+ if (fcntl(fd, F_SETFL, orig_flags | O_NONBLOCK) < 0 ) {
61+ warn("can't set O_NONBLOCK - timeout not avaliable");
62+ if (connect(fd, sa, salen) == 0)
63+ return CONNECTION_SUCCESS;
64+ else
65+ return CONNECTION_FAILED;
66+ }
67+
68+ /* set connect timeout */
69+ if (ctimeout > 0) {
70+ tv.tv_sec = (time_t)ctimeout/1000;
71+ tv.tv_usec = 0;
72+ tvp = &tv;
73+ }
74+
75+ /* attempt the connection */
76+ err = connect(fd, sa, salen);
77+
78+ if (err != 0 && errno == EINPROGRESS) {
79+ /* connection is proceeding
80+ * it is complete (or failed) when select returns */
81+
82+ /* initialize connect_fdset */
83+ FD_ZERO(&connect_fdset);
84+ FD_SET(fd, &connect_fdset);
85+
86+ /* call select */
87+ do {
88+ err = select(fd + 1, NULL, &connect_fdset,
89+ NULL, tvp);
90+ } while (err < 0 && errno == EINTR);
91+
92+ /* select error */
93+ if (err < 0)
94+ errx(1,"select error: %s", strerror(errno));
95+
96+ /* we have reached a timeout */
97+ if (err == 0)
98+ return CONNECTION_TIMEOUT;
99+
100+ /* select returned successfully, but we must test socket
101+ * error for result */
102+ len = sizeof(err);
103+ if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len) < 0)
104+ errx(1, "getsockopt error: %s", strerror(errno));
105+
106+ /* setup errno according to the result returned by
107+ * getsockopt */
108+ if (err != 0)
109+ errno = err;
110+ }
111+
112+ /* return aborted if an error occured, and valid otherwise */
113+ fcntl(fd, F_SETFL, orig_flags);
114+ return (err != 0)? CONNECTION_FAILED : CONNECTION_SUCCESS;
115+}
116+
117+
118 /*
119 * local_listen()
120 * Returns a socket listening on a local port, binds to specified source
1210
=== removed file 'debian/patches/dccp.patch'
--- debian/patches/dccp.patch 2011-06-11 14:31:06 +0000
+++ debian/patches/dccp.patch 1970-01-01 00:00:00 +0000
@@ -1,191 +0,0 @@
1Index: netcat-openbsd-oneiric/netcat.c
2===================================================================
3--- netcat-openbsd-oneiric.orig/netcat.c 2011-06-10 22:29:16.371916860 +0300
4+++ netcat-openbsd-oneiric/netcat.c 2011-06-10 22:29:16.371916860 +0300
5@@ -88,6 +88,7 @@
6 char *sflag; /* Source Address */
7 int tflag; /* Telnet Emulation */
8 int uflag; /* UDP - Default to TCP */
9+int dccpflag; /* DCCP - Default to TCP */
10 int vflag; /* Verbosity */
11 int xflag; /* Socks proxy */
12 int zflag; /* Port Scan Flag */
13@@ -113,6 +114,7 @@
14 void set_common_sockopts(int);
15 int parse_iptos(char *);
16 void usage(int);
17+char *proto_name(int uflag, int dccpflag);
18
19 static int connect_with_timeout(int fd, const struct sockaddr *sa,
20 socklen_t salen, int ctimeout);
21@@ -140,7 +142,7 @@
22 sv = NULL;
23
24 while ((ch = getopt(argc, argv,
25- "46Ddhi:jklnP:p:q:rSs:tT:Uuvw:X:x:zC")) != -1) {
26+ "46Ddhi:jklnP:p:q:rSs:tT:UuZvw:X:x:zC")) != -1) {
27 switch (ch) {
28 case '4':
29 family = AF_INET;
30@@ -205,6 +207,9 @@
31 case 'u':
32 uflag = 1;
33 break;
34+ case 'Z':
35+ dccpflag = 1;
36+ break;
37 case 'v':
38 vflag = 1;
39 break;
40@@ -247,6 +252,9 @@
41 if (argv[0] && !argv[1] && family == AF_UNIX) {
42 if (uflag)
43 errx(1, "cannot use -u and -U");
44+ if (dccpflag)
45+ errx(1, "cannot use -C and -U");
46+
47 host = argv[0];
48 uport = NULL;
49 } else if (argv[0] && !argv[1]) {
50@@ -273,8 +281,18 @@
51 if (family != AF_UNIX) {
52 memset(&hints, 0, sizeof(struct addrinfo));
53 hints.ai_family = family;
54- hints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
55- hints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
56+ if (uflag) {
57+ hints.ai_socktype = SOCK_DGRAM;
58+ hints.ai_protocol = IPPROTO_UDP;
59+ }
60+ else if (dccpflag) {
61+ hints.ai_socktype = SOCK_DCCP;
62+ hints.ai_protocol = IPPROTO_DCCP;
63+ }
64+ else {
65+ hints.ai_socktype = SOCK_STREAM;
66+ hints.ai_protocol = IPPROTO_TCP;
67+ }
68 if (nflag)
69 hints.ai_flags |= AI_NUMERICHOST;
70 }
71@@ -283,6 +301,9 @@
72 if (uflag)
73 errx(1, "no proxy support for UDP mode");
74
75+ if (dccpflag)
76+ errx(1, "no proxy support for DCCP mode");
77+
78 if (lflag)
79 errx(1, "no proxy support for listen");
80
81@@ -348,17 +369,19 @@
82 }
83
84 if(vflag) {
85+ char *proto = proto_name(uflag, dccpflag);
86+
87 /* Don't look up port if -n. */
88 if (nflag)
89 sv = NULL;
90 else
91 sv = getservbyport(ntohs(atoi(uport)),
92- uflag ? "udp" : "tcp");
93+ proto);
94
95 fprintf(stderr, "Connection from %s port %s [%s/%s] accepted\n",
96 inet_ntoa(((struct sockaddr_in *)(&cliaddr))->sin_addr),
97 uport,
98- uflag ? "udp" : "tcp",
99+ proto,
100 sv ? sv->s_name : "*");
101 }
102
103@@ -503,6 +526,22 @@
104 return (s);
105 }
106
107+char *proto_name(uflag, dccpflag) {
108+
109+ char *proto = NULL;
110+ if (uflag) {
111+ proto = "udp";
112+ }
113+ else if (dccpflag) {
114+ proto = "dccp";
115+ }
116+ else {
117+ proto = "tcp";
118+ }
119+
120+ return proto;
121+}
122+
123 /*
124 * remote_connect()
125 * Returns a socket connected to a remote host. Properly binds to a local
126@@ -529,8 +568,19 @@
127
128 memset(&ahints, 0, sizeof(struct addrinfo));
129 ahints.ai_family = res0->ai_family;
130- ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
131- ahints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
132+ if (uflag) {
133+ ahints.ai_socktype = SOCK_DGRAM;
134+ ahints.ai_protocol = IPPROTO_UDP;
135+
136+ }
137+ else if (dccpflag) {
138+ ahints.ai_socktype = SOCK_DCCP;
139+ ahints.ai_protocol = IPPROTO_DCCP;
140+ }
141+ else {
142+ ahints.ai_socktype = SOCK_STREAM;
143+ ahints.ai_protocol = IPPROTO_TCP;
144+ }
145 ahints.ai_flags = AI_PASSIVE;
146 if ((error = getaddrinfo(sflag, pflag, &ahints, &ares)))
147 errx(1, "getaddrinfo: %s", gai_strerror(error));
148@@ -542,14 +592,19 @@
149 }
150
151 set_common_sockopts(s);
152- if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout)) == CONNECTION_SUCCESS)
153+ char *proto = proto_name(uflag, dccpflag);
154+
155+ if ((error = connect_with_timeout(s, res0->ai_addr, res0->ai_addrlen, timeout)) == CONNECTION_SUCCESS) {
156 break;
157- else if (vflag && error == CONNECTION_FAILED)
158+ }
159+ else if (vflag && error == CONNECTION_FAILED) {
160 warn("connect to %s port %s (%s) failed", host, port,
161- uflag ? "udp" : "tcp");
162- else if (vflag && error == CONNECTION_TIMEOUT)
163+ proto);
164+ }
165+ else if (vflag && error == CONNECTION_TIMEOUT) {
166 warn("connect to %s port %s (%s) timed out", host, port,
167- uflag ? "udp" : "tcp");
168+ proto);
169+ }
170
171 close(s);
172 s = -1;
173@@ -817,8 +872,8 @@
174 char *n, *endp;
175 int hi, lo, cp;
176 int x = 0;
177-
178- sv = getservbyname(p, uflag ? "udp" : "tcp");
179+ char *proto = proto_name(uflag, dccpflag);
180+ sv = getservbyname(p, proto);
181 if (sv) {
182 portlist[0] = calloc(1, PORT_MAX_LEN);
183 if (portlist[0] == NULL)
184@@ -979,6 +1034,7 @@
185 \t-t Answer TELNET negotiation\n\
186 \t-U Use UNIX domain socket\n\
187 \t-u UDP mode\n\
188+ \t-Z DCCP mode\n\
189 \t-v Verbose\n\
190 \t-w secs\t Timeout for connects and final net reads\n\
191 \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\
1920
=== removed file 'debian/patches/gcc-warnings.patch'
--- debian/patches/gcc-warnings.patch 2008-01-30 18:24:46 +0000
+++ debian/patches/gcc-warnings.patch 1970-01-01 00:00:00 +0000
@@ -1,157 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 20:39:46.000000000 -0500
4+++ netcat-openbsd-1.89/netcat.c 2008-01-22 20:42:35.000000000 -0500
5@@ -127,7 +127,7 @@
6 struct servent *sv;
7 socklen_t len;
8 struct sockaddr_storage cliaddr;
9- char *proxy;
10+ char *proxy = NULL;
11 const char *proxyhost = "", *proxyport = NULL;
12 struct addrinfo proxyhints;
13
14@@ -800,14 +800,12 @@
15 obuf[1] = DONT;
16 if ((*p == DO) || (*p == DONT))
17 obuf[1] = WONT;
18- if (obuf) {
19- p++;
20- obuf[2] = *p;
21- obuf[3] = '\0';
22- if (atomicio(vwrite, nfd, obuf, 3) != 3)
23- warn("Write Error!");
24- obuf[0] = '\0';
25- }
26+ p++;
27+ obuf[2] = *p;
28+ obuf[3] = '\0';
29+ if (atomicio(vwrite, nfd, obuf, 3) != 3)
30+ warn("Write Error!");
31+ obuf[0] = '\0';
32 }
33 }
34
35Index: netcat-openbsd-1.89/socks.c
36===================================================================
37--- netcat-openbsd-1.89.orig/socks.c 2008-01-22 20:36:26.000000000 -0500
38+++ netcat-openbsd-1.89/socks.c 2008-01-22 20:39:46.000000000 -0500
39@@ -169,11 +169,11 @@
40 buf[2] = SOCKS_NOAUTH;
41 cnt = atomicio(vwrite, proxyfd, buf, 3);
42 if (cnt != 3)
43- err(1, "write failed (%d/3)", cnt);
44+ err(1, "write failed (%d/3)", (int)cnt);
45
46 cnt = atomicio(read, proxyfd, buf, 2);
47 if (cnt != 2)
48- err(1, "read failed (%d/3)", cnt);
49+ err(1, "read failed (%d/3)", (int)cnt);
50
51 if (buf[1] == SOCKS_NOMETHOD)
52 errx(1, "authentication method negotiation failed");
53@@ -222,11 +222,11 @@
54
55 cnt = atomicio(vwrite, proxyfd, buf, wlen);
56 if (cnt != wlen)
57- err(1, "write failed (%d/%d)", cnt, wlen);
58+ err(1, "write failed (%d/%d)", (int)cnt, (int)wlen);
59
60 cnt = atomicio(read, proxyfd, buf, 10);
61 if (cnt != 10)
62- err(1, "read failed (%d/10)", cnt);
63+ err(1, "read failed (%d/10)", (int)cnt);
64 if (buf[1] != 0)
65 errx(1, "connection failed, SOCKS error %d", buf[1]);
66 } else if (socksv == 4) {
67@@ -244,11 +244,11 @@
68
69 cnt = atomicio(vwrite, proxyfd, buf, wlen);
70 if (cnt != wlen)
71- err(1, "write failed (%d/%d)", cnt, wlen);
72+ err(1, "write failed (%d/%d)", (int)cnt, (int)wlen);
73
74 cnt = atomicio(read, proxyfd, buf, 8);
75 if (cnt != 8)
76- err(1, "read failed (%d/8)", cnt);
77+ err(1, "read failed (%d/8)", (int)cnt);
78 if (buf[1] != 90)
79 errx(1, "connection failed, SOCKS error %d", buf[1]);
80 } else if (socksv == -1) {
81@@ -260,39 +260,39 @@
82
83 /* Try to be sane about numeric IPv6 addresses */
84 if (strchr(host, ':') != NULL) {
85- r = snprintf(buf, sizeof(buf),
86+ r = snprintf((char*)buf, sizeof(buf),
87 "CONNECT [%s]:%d HTTP/1.0\r\n",
88 host, ntohs(serverport));
89 } else {
90- r = snprintf(buf, sizeof(buf),
91+ r = snprintf((char*)buf, sizeof(buf),
92 "CONNECT %s:%d HTTP/1.0\r\n",
93 host, ntohs(serverport));
94 }
95 if (r == -1 || (size_t)r >= sizeof(buf))
96 errx(1, "hostname too long");
97- r = strlen(buf);
98+ r = strlen((char*)buf);
99
100 cnt = atomicio(vwrite, proxyfd, buf, r);
101 if (cnt != r)
102- err(1, "write failed (%d/%d)", cnt, r);
103+ err(1, "write failed (%d/%d)", (int)cnt, (int)r);
104
105 if (authretry > 1) {
106 char resp[1024];
107
108 proxypass = getproxypass(proxyuser, proxyhost);
109- r = snprintf(buf, sizeof(buf), "%s:%s",
110+ r = snprintf((char*)buf, sizeof(buf), "%s:%s",
111 proxyuser, proxypass);
112 if (r == -1 || (size_t)r >= sizeof(buf) ||
113- b64_ntop(buf, strlen(buf), resp,
114+ b64_ntop(buf, strlen((char*)buf), resp,
115 sizeof(resp)) == -1)
116 errx(1, "Proxy username/password too long");
117- r = snprintf(buf, sizeof(buf), "Proxy-Authorization: "
118+ r = snprintf((char*)buf, sizeof((char*)buf), "Proxy-Authorization: "
119 "Basic %s\r\n", resp);
120 if (r == -1 || (size_t)r >= sizeof(buf))
121 errx(1, "Proxy auth response too long");
122- r = strlen(buf);
123+ r = strlen((char*)buf);
124 if ((cnt = atomicio(vwrite, proxyfd, buf, r)) != r)
125- err(1, "write failed (%d/%d)", cnt, r);
126+ err(1, "write failed (%d/%d)", (int)cnt, r);
127 }
128
129 /* Terminate headers */
130@@ -300,22 +300,22 @@
131 err(1, "write failed (2/%d)", r);
132
133 /* Read status reply */
134- proxy_read_line(proxyfd, buf, sizeof(buf));
135+ proxy_read_line(proxyfd, (char*)buf, sizeof(buf));
136 if (proxyuser != NULL &&
137- strncmp(buf, "HTTP/1.0 407 ", 12) == 0) {
138+ strncmp((char*)buf, "HTTP/1.0 407 ", 12) == 0) {
139 if (authretry > 1) {
140 fprintf(stderr, "Proxy authentication "
141 "failed\n");
142 }
143 close(proxyfd);
144 goto again;
145- } else if (strncmp(buf, "HTTP/1.0 200 ", 12) != 0 &&
146- strncmp(buf, "HTTP/1.1 200 ", 12) != 0)
147+ } else if (strncmp((char*)buf, "HTTP/1.0 200 ", 12) != 0 &&
148+ strncmp((char*)buf, "HTTP/1.1 200 ", 12) != 0)
149 errx(1, "Proxy error: \"%s\"", buf);
150
151 /* Headers continue until we hit an empty line */
152 for (r = 0; r < HTTP_MAXHDRS; r++) {
153- proxy_read_line(proxyfd, buf, sizeof(buf));
154+ proxy_read_line(proxyfd, (char*)buf, sizeof(buf));
155 if (*buf == '\0')
156 break;
157 }
1580
=== removed file 'debian/patches/getservbyname.patch'
--- debian/patches/getservbyname.patch 2008-01-30 18:24:46 +0000
+++ debian/patches/getservbyname.patch 1970-01-01 00:00:00 +0000
@@ -1,24 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 20:39:46.000000000 -0500
4+++ netcat-openbsd-1.89/netcat.c 2008-01-22 20:43:36.000000000 -0500
5@@ -819,11 +819,18 @@
6 void
7 build_ports(char *p)
8 {
9+ struct servent *sv;
10 char *n, *endp;
11 int hi, lo, cp;
12 int x = 0;
13
14- if ((n = strchr(p, '-')) != NULL) {
15+ sv = getservbyname(p, uflag ? "udp" : "tcp");
16+ if (sv) {
17+ portlist[0] = calloc(1, PORT_MAX_LEN);
18+ if (portlist[0] == NULL)
19+ err(1, NULL);
20+ snprintf(portlist[0], PORT_MAX_LEN, "%d", ntohs(sv->s_port));
21+ } else if ((n = strchr(p, '-')) != NULL) {
22 if (lflag)
23 errx(1, "Cannot use -l with multiple ports!");
24
250
=== removed file 'debian/patches/glib-strlcpy.patch'
--- debian/patches/glib-strlcpy.patch 2008-01-30 18:24:46 +0000
+++ debian/patches/glib-strlcpy.patch 1970-01-01 00:00:00 +0000
@@ -1,96 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2007-02-20 09:11:17.000000000 -0500
4+++ netcat-openbsd-1.89/netcat.c 2008-01-21 18:48:23.000000000 -0500
5@@ -55,6 +55,8 @@
6 #include <limits.h>
7 #include "atomicio.h"
8
9+#include <glib.h>
10+
11 #ifndef SUN_LEN
12 #define SUN_LEN(su) \
13 (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
14@@ -414,7 +416,7 @@
15 memset(&sun, 0, sizeof(struct sockaddr_un));
16 sun.sun_family = AF_UNIX;
17
18- if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
19+ if (g_strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
20 sizeof(sun.sun_path)) {
21 close(s);
22 errno = ENAMETOOLONG;
23@@ -445,7 +447,7 @@
24 memset(&sun, 0, sizeof(struct sockaddr_un));
25 sun.sun_family = AF_UNIX;
26
27- if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
28+ if (g_strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
29 sizeof(sun.sun_path)) {
30 close(s);
31 errno = ENAMETOOLONG;
32@@ -549,11 +551,11 @@
33 if ((s = socket(res0->ai_family, res0->ai_socktype,
34 res0->ai_protocol)) < 0)
35 continue;
36-
37+ #ifdef SO_REUSEPORT
38 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
39 if (ret == -1)
40 err(1, NULL);
41-
42+ #endif
43 set_common_sockopts(s);
44
45 if (bind(s, (struct sockaddr *)res0->ai_addr,
46@@ -719,7 +721,8 @@
47 char *c;
48
49 for (x = 0; x <= (hi - lo); x++) {
50- y = (arc4random() & 0xFFFF) % (hi - lo);
51+ /* use random instead of arc4random */
52+ y = (random() & 0xFFFF) % (hi - lo);
53 c = portlist[x];
54 portlist[x] = portlist[y];
55 portlist[y] = c;
56@@ -761,21 +764,25 @@
57 {
58 int x = 1;
59
60+#ifdef TCP_MD5SIG
61 if (Sflag) {
62 if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
63 &x, sizeof(x)) == -1)
64 err(1, NULL);
65 }
66+#endif
67 if (Dflag) {
68 if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
69 &x, sizeof(x)) == -1)
70 err(1, NULL);
71 }
72+#ifdef SO_JUMBO
73 if (jflag) {
74 if (setsockopt(s, SOL_SOCKET, SO_JUMBO,
75 &x, sizeof(x)) == -1)
76 err(1, NULL);
77 }
78+#endif
79 if (Tflag != -1) {
80 if (setsockopt(s, IPPROTO_IP, IP_TOS,
81 &Tflag, sizeof(Tflag)) == -1)
82@@ -816,9 +823,11 @@
83 \t-n Suppress name/port resolutions\n\
84 \t-P proxyuser\tUsername for proxy authentication\n\
85 \t-p port\t Specify local port for remote connects\n\
86- \t-r Randomize remote ports\n\
87- \t-S Enable the TCP MD5 signature option\n\
88- \t-s addr\t Local source address\n\
89+ \t-r Randomize remote ports\n "
90+#ifdef TCP_MD5SIG
91+" \t-S Enable the TCP MD5 signature option\n"
92+#endif
93+" \t-s addr\t Local source address\n\
94 \t-T ToS\t Set IP Type of Service\n\
95 \t-t Answer TELNET negotiation\n\
96 \t-U Use UNIX domain socket\n\
970
=== removed file 'debian/patches/help-version-exit.patch'
--- debian/patches/help-version-exit.patch 2008-01-30 18:24:46 +0000
+++ debian/patches/help-version-exit.patch 1970-01-01 00:00:00 +0000
@@ -1,21 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2008-01-25 13:14:34.000000000 -0500
4+++ netcat-openbsd-1.89/netcat.c 2008-01-25 13:15:49.000000000 -0500
5@@ -937,6 +937,7 @@
6 void
7 help(void)
8 {
9+ fprintf(stderr, "OpenBSD netcat (Debian patchlevel " DEBIAN_VERSION ")\n");
10 usage(0);
11 fprintf(stderr, "\tCommand Summary:\n\
12 \t-4 Use IPv4\n\
13@@ -966,7 +967,7 @@
14 \t-x addr[:port]\tSpecify proxy address and port\n\
15 \t-z Zero-I/O mode [used for scanning]\n\
16 Port numbers can be individual or ranges: lo-hi [inclusive]\n");
17- exit(1);
18+ exit(0);
19 }
20
21 void
220
=== removed file 'debian/patches/nc-1.84-udp_stop.patch'
--- debian/patches/nc-1.84-udp_stop.patch 2008-01-30 18:24:46 +0000
+++ debian/patches/nc-1.84-udp_stop.patch 1970-01-01 00:00:00 +0000
@@ -1,14 +0,0 @@
1Index: netcat-1.84/netcat.c
2===================================================================
3--- netcat-1.84.orig/netcat.c 2008-01-15 10:10:22.373351813 +0100
4+++ netcat-1.84/netcat.c 2008-01-15 10:10:24.840730278 +0100
5@@ -799,6 +799,9 @@
6 hi = lo;
7 lo = cp;
8 }
9+ else if (pfd[0].revents & POLLERR)
10+ if (write(nfd, "", 1) == -1)
11+ warn("Write error");
12
13 /* Load ports sequentially. */
14 for (cp = lo; cp <= hi; cp++) {
150
=== modified file 'debian/patches/netcat-info.patch'
--- debian/patches/netcat-info.patch 2011-01-04 14:31:12 +0000
+++ debian/patches/netcat-info.patch 2012-05-30 22:10:23 +0000
@@ -1,12 +1,13 @@
1diff -Naurp netcat-openbsd-1.89.orig//netcat.c netcat-openbsd-1.89/netcat.c1Index: netcat-openbsd/netcat.c
2--- netcat-openbsd-1.89.orig//netcat.c 2011-01-04 13:54:23.707910134 -05002===================================================================
3+++ netcat-openbsd-1.89/netcat.c 2011-01-04 14:12:50.499950473 -05003--- netcat-openbsd.orig/netcat.c 2012-05-30 14:44:13.000000000 -0700
4@@ -995,6 +995,8 @@ help(void)4+++ netcat-openbsd/netcat.c 2012-05-30 14:46:35.810792514 -0700
5@@ -1373,6 +1373,8 @@
5 void6 void
6 usage(int ret)7 usage(int ret)
7 {8 {
8+ fprintf(stderr, "This is nc from the netcat-openbsd package. An alternative nc is available\n");9+ fprintf(stderr, "This is nc from the netcat-openbsd package. An alternative nc is available\n");
9+ fprintf(stderr, "in the netcat-traditional package.\n");10+ fprintf(stderr, "in the netcat-traditional package.\n");
10 fprintf(stderr, "usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]\n");11 fprintf(stderr,
11 fprintf(stderr, "\t [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]\n");12 "usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length]\n"
12 fprintf(stderr, "\t [-x proxy_address[:port]] [hostname] [port[s]]\n");13 "\t [-P proxy_username] [-p source_port] [-q seconds] [-s source]\n"
1314
=== removed file 'debian/patches/no-strtonum.patch'
--- debian/patches/no-strtonum.patch 2008-01-30 18:24:46 +0000
+++ debian/patches/no-strtonum.patch 1970-01-01 00:00:00 +0000
@@ -1,107 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:17.000000000 -0500
4+++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:18.000000000 -0500
5@@ -67,7 +67,7 @@
6
7 /* Command Line Options */
8 int dflag; /* detached, no stdin */
9-unsigned int iflag; /* Interval Flag */
10+int iflag; /* Interval Flag */
11 int jflag; /* use jumbo frames if we can */
12 int kflag; /* More than one connect */
13 int lflag; /* Bind to local port */
14@@ -108,13 +108,13 @@
15 main(int argc, char *argv[])
16 {
17 int ch, s, ret, socksv;
18- char *host, *uport;
19+ char *host, *uport, *endp;
20 struct addrinfo hints;
21 struct servent *sv;
22 socklen_t len;
23 struct sockaddr_storage cliaddr;
24 char *proxy;
25- const char *errstr, *proxyhost = "", *proxyport = NULL;
26+ const char *proxyhost = "", *proxyport = NULL;
27 struct addrinfo proxyhints;
28
29 ret = 1;
30@@ -122,6 +122,7 @@
31 socksv = 5;
32 host = NULL;
33 uport = NULL;
34+ endp = NULL;
35 sv = NULL;
36
37 while ((ch = getopt(argc, argv,
38@@ -153,9 +154,9 @@
39 help();
40 break;
41 case 'i':
42- iflag = strtonum(optarg, 0, UINT_MAX, &errstr);
43- if (errstr)
44- errx(1, "interval %s: %s", errstr, optarg);
45+ iflag = (int)strtoul(optarg, &endp, 10);
46+ if (iflag < 0 || *endp != '\0')
47+ errx(1, "interval cannot be negative");
48 break;
49 case 'j':
50 jflag = 1;
51@@ -191,9 +192,11 @@
52 vflag = 1;
53 break;
54 case 'w':
55- timeout = strtonum(optarg, 0, INT_MAX / 1000, &errstr);
56- if (errstr)
57- errx(1, "timeout %s: %s", errstr, optarg);
58+ timeout = (int)strtoul(optarg, &endp, 10);
59+ if (timeout < 0 || *endp != '\0')
60+ errx(1, "timeout cannot be negative");
61+ if (timeout >= (INT_MAX / 1000))
62+ errx(1, "timeout too large");
63 timeout *= 1000;
64 break;
65 case 'x':
66@@ -680,8 +683,7 @@
67 void
68 build_ports(char *p)
69 {
70- const char *errstr;
71- char *n;
72+ char *n, *endp;
73 int hi, lo, cp;
74 int x = 0;
75
76@@ -693,12 +695,12 @@
77 n++;
78
79 /* Make sure the ports are in order: lowest->highest. */
80- hi = strtonum(n, 1, PORT_MAX, &errstr);
81- if (errstr)
82- errx(1, "port number %s: %s", errstr, n);
83- lo = strtonum(p, 1, PORT_MAX, &errstr);
84- if (errstr)
85- errx(1, "port number %s: %s", errstr, p);
86+ hi = (int)strtoul(n, &endp, 10);
87+ if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
88+ errx(1, "port range not valid");
89+ lo = (int)strtoul(p, &endp, 10);
90+ if (lo <= 0 || lo > PORT_MAX || *endp != '\0')
91+ errx(1, "port range not valid");
92
93 if (lo > hi) {
94 cp = hi;
95@@ -729,9 +731,9 @@
96 }
97 }
98 } else {
99- hi = strtonum(p, 1, PORT_MAX, &errstr);
100- if (errstr)
101- errx(1, "port number %s: %s", errstr, p);
102+ hi = (int)strtoul(p, &endp, 10);
103+ if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
104+ errx(1, "port range not valid");
105 portlist[0] = calloc(1, PORT_MAX_LEN);
106 if (portlist[0] == NULL)
107 err(1, NULL);
1080
=== removed file 'debian/patches/openbsd-compat.patch'
--- debian/patches/openbsd-compat.patch 2008-01-30 18:24:46 +0000
+++ debian/patches/openbsd-compat.patch 1970-01-01 00:00:00 +0000
@@ -1,54 +0,0 @@
1Index: netcat-openbsd-1.89/openbsd-compat/readpassphrase.c
2===================================================================
3--- netcat-openbsd-1.89.orig/openbsd-compat/readpassphrase.c 2008-01-22 18:21:56.000000000 -0500
4+++ netcat-openbsd-1.89/openbsd-compat/readpassphrase.c 2008-01-22 18:22:58.000000000 -0500
5@@ -31,6 +31,12 @@
6 #include <unistd.h>
7 #include <readpassphrase.h>
8
9+#ifdef TCSASOFT
10+# define _T_FLUSH (TCSAFLUSH|TCSASOFT)
11+#else
12+# define _T_FLUSH (TCSAFLUSH)
13+#endif
14+
15 static volatile sig_atomic_t signo;
16
17 static void handler(int);
18@@ -92,9 +98,11 @@
19 memcpy(&term, &oterm, sizeof(term));
20 if (!(flags & RPP_ECHO_ON))
21 term.c_lflag &= ~(ECHO | ECHONL);
22+#ifdef VSTATUS
23 if (term.c_cc[VSTATUS] != _POSIX_VDISABLE)
24 term.c_cc[VSTATUS] = _POSIX_VDISABLE;
25- (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term);
26+#endif
27+ (void)tcsetattr(input, _T_FLUSH, &term);
28 } else {
29 memset(&term, 0, sizeof(term));
30 term.c_lflag |= ECHO;
31@@ -129,7 +137,7 @@
32
33 /* Restore old terminal settings and signals. */
34 if (memcmp(&term, &oterm, sizeof(term)) != 0) {
35- while (tcsetattr(input, TCSAFLUSH|TCSASOFT, &oterm) == -1 &&
36+ while (tcsetattr(input, _T_FLUSH, &oterm) == -1 &&
37 errno == EINTR)
38 continue;
39 }
40@@ -164,14 +172,6 @@
41 return(nr == -1 ? NULL : buf);
42 }
43
44-char *
45-getpass(const char *prompt)
46-{
47- static char buf[_PASSWORD_LEN + 1];
48-
49- return(readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF));
50-}
51-
52 static void handler(int s)
53 {
54
550
=== removed file 'debian/patches/pollhup.patch'
--- debian/patches/pollhup.patch 2008-01-30 18:24:46 +0000
+++ debian/patches/pollhup.patch 1970-01-01 00:00:00 +0000
@@ -1,50 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:18.000000000 -0500
4+++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:25.000000000 -0500
5@@ -618,9 +618,7 @@
6 if ((n = read(nfd, buf, plen)) < 0)
7 return;
8 else if (n == 0) {
9- shutdown(nfd, SHUT_RD);
10- pfd[0].fd = -1;
11- pfd[0].events = 0;
12+ goto shutdown_rd;
13 } else {
14 if (tflag)
15 atelnet(nfd, buf, n);
16@@ -628,18 +626,30 @@
17 return;
18 }
19 }
20+ else if (pfd[0].revents & POLLHUP) {
21+ shutdown_rd:
22+ shutdown(nfd, SHUT_RD);
23+ pfd[0].fd = -1;
24+ pfd[0].events = 0;
25+ }
26
27- if (!dflag && pfd[1].revents & POLLIN) {
28+ if (!dflag) {
29+ if(pfd[1].revents & POLLIN) {
30 if ((n = read(wfd, buf, plen)) < 0)
31 return;
32 else if (n == 0) {
33- shutdown(nfd, SHUT_WR);
34- pfd[1].fd = -1;
35- pfd[1].events = 0;
36+ goto shutdown_wr;
37 } else {
38 if (atomicio(vwrite, nfd, buf, n) != n)
39 return;
40 }
41+ }
42+ else if (pfd[1].revents & POLLHUP) {
43+ shutdown_wr:
44+ shutdown(nfd, SHUT_WR);
45+ pfd[1].fd = -1;
46+ pfd[1].events = 0;
47+ }
48 }
49 }
50 }
510
=== removed file 'debian/patches/quit-timer.patch'
--- debian/patches/quit-timer.patch 2011-06-30 11:55:43 +0000
+++ debian/patches/quit-timer.patch 1970-01-01 00:00:00 +0000
@@ -1,84 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2010-04-18 20:02:55.240980186 -0400
4+++ netcat-openbsd-1.89/netcat.c 2010-04-18 20:04:41.987984568 -0400
5@@ -47,6 +47,7 @@
6 #include <errno.h>
7 #include <netdb.h>
8 #include <poll.h>
9+#include <signal.h>
10 #include <stdarg.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13@@ -82,6 +83,7 @@
14 int nflag; /* Don't do name look up */
15 char *Pflag; /* Proxy username */
16 char *pflag; /* Localport flag */
17+int qflag = -1; /* Quit after some secs */
18 int rflag; /* Random ports flag */
19 char *sflag; /* Source Address */
20 int tflag; /* Telnet Emulation */
21@@ -114,6 +116,7 @@
22
23 static int connect_with_timeout(int fd, const struct sockaddr *sa,
24 socklen_t salen, int ctimeout);
25+static void quit();
26
27 int
28 main(int argc, char *argv[])
29@@ -137,7 +140,7 @@
30 sv = NULL;
31
32 while ((ch = getopt(argc, argv,
33- "46Ddhi:jklnP:p:rSs:tT:Uuvw:X:x:zC")) != -1) {
34+ "46Ddhi:jklnP:p:q:rSs:tT:Uuvw:X:x:zC")) != -1) {
35 switch (ch) {
36 case '4':
37 family = AF_INET;
38@@ -187,6 +190,9 @@
39 case 'p':
40 pflag = optarg;
41 break;
42+ case 'q':
43+ qflag = (int)strtoul(optarg, &endp, 10);
44+ break;
45 case 'r':
46 rflag = 1;
47 break;
48@@ -756,7 +762,13 @@
49 }
50 else if (pfd[1].revents & POLLHUP) {
51 shutdown_wr:
52- shutdown(nfd, SHUT_WR);
53+ /* if user asked to die after a while, arrange for it */
54+ if (qflag > 0) {
55+ signal(SIGALRM, quit);
56+ alarm(qflag);
57+ } else {
58+ shutdown(nfd, SHUT_WR);
59+ }
60 pfd[1].fd = -1;
61 pfd[1].events = 0;
62 }
63@@ -951,6 +963,7 @@
64 \t-n Suppress name/port resolutions\n\
65 \t-P proxyuser\tUsername for proxy authentication\n\
66 \t-p port\t Specify local port for remote connects\n\
67+ \t-q secs\t quit after EOF on stdin and delay of secs\n\
68 \t-r Randomize remote ports\n "
69 #ifdef TCP_MD5SIG
70 " \t-S Enable the TCP MD5 signature option\n"
71@@ -979,3 +992,13 @@
72 if (ret)
73 exit(1);
74 }
75+
76+/*
77+ * quit()
78+ * handler for a "-q" timeout (exit 0 instead of 1)
79+ */
80+static void quit()
81+{
82+ /* XXX: should explicitly close fds here */
83+ exit(0);
84+}
850
=== removed file 'debian/patches/reuseaddr.patch'
--- debian/patches/reuseaddr.patch 2008-01-30 18:24:46 +0000
+++ debian/patches/reuseaddr.patch 1970-01-01 00:00:00 +0000
@@ -1,15 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:25.000000000 -0500
4+++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:27.000000000 -0500
5@@ -554,6 +554,10 @@
6 if ((s = socket(res0->ai_family, res0->ai_socktype,
7 res0->ai_protocol)) < 0)
8 continue;
9+
10+ ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
11+ if (ret == -1)
12+ err(1, NULL);
13 #ifdef SO_REUSEPORT
14 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
15 if (ret == -1)
160
=== removed file 'debian/patches/send-crlf.patch'
--- debian/patches/send-crlf.patch 2008-06-19 16:20:01 +0000
+++ debian/patches/send-crlf.patch 1970-01-01 00:00:00 +0000
@@ -1,109 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2008-06-19 16:49:57.000000000 -0400
4+++ netcat-openbsd-1.89/netcat.c 2008-06-19 17:04:22.000000000 -0400
5@@ -73,6 +73,7 @@
6 #define UDP_SCAN_TIMEOUT 3 /* Seconds */
7
8 /* Command Line Options */
9+int Cflag = 0; /* CRLF line-ending */
10 int dflag; /* detached, no stdin */
11 int iflag; /* Interval Flag */
12 int jflag; /* use jumbo frames if we can */
13@@ -136,7 +137,7 @@
14 sv = NULL;
15
16 while ((ch = getopt(argc, argv,
17- "46Ddhi:jklnP:p:rSs:tT:Uuvw:X:x:z")) != -1) {
18+ "46Ddhi:jklnP:p:rSs:tT:Uuvw:X:x:zC")) != -1) {
19 switch (ch) {
20 case '4':
21 family = AF_INET;
22@@ -226,6 +227,9 @@
23 case 'T':
24 Tflag = parse_iptos(optarg);
25 break;
26+ case 'C':
27+ Cflag = 1;
28+ break;
29 default:
30 usage(1);
31 }
32@@ -738,8 +742,16 @@
33 else if (n == 0) {
34 goto shutdown_wr;
35 } else {
36- if (atomicio(vwrite, nfd, buf, n) != n)
37- return;
38+ if ((Cflag) && (buf[n-1]=='\n')) {
39+ if (atomicio(vwrite, nfd, buf, n-1) != (n-1))
40+ return;
41+ if (atomicio(vwrite, nfd, "\r\n", 2) != 2)
42+ return;
43+ }
44+ else {
45+ if (atomicio(vwrite, nfd, buf, n) != n)
46+ return;
47+ }
48 }
49 }
50 else if (pfd[1].revents & POLLHUP) {
51@@ -944,6 +956,7 @@
52 #endif
53 " \t-s addr\t Local source address\n\
54 \t-T ToS\t Set IP Type of Service\n\
55+ \t-C Send CRLF as line-ending\n\
56 \t-t Answer TELNET negotiation\n\
57 \t-U Use UNIX domain socket\n\
58 \t-u UDP mode\n\
59@@ -959,7 +972,7 @@
60 void
61 usage(int ret)
62 {
63- fprintf(stderr, "usage: nc [-46DdhklnrStUuvz] [-i interval] [-P proxy_username] [-p source_port]\n");
64+ fprintf(stderr, "usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]\n");
65 fprintf(stderr, "\t [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]\n");
66 fprintf(stderr, "\t [-x proxy_address[:port]] [hostname] [port[s]]\n");
67 if (ret)
68Index: netcat-openbsd-1.89/nc.1
69===================================================================
70--- netcat-openbsd-1.89.orig/nc.1 2008-06-19 16:49:39.000000000 -0400
71+++ netcat-openbsd-1.89/nc.1 2008-06-19 16:54:36.000000000 -0400
72@@ -34,7 +34,7 @@
73 .Sh SYNOPSIS
74 .Nm nc
75 .Bk -words
76-.Op Fl 46DdhklnrStUuvz
77+.Op Fl 46DdhklnrStUuvzC
78 .Op Fl i Ar interval
79 .Op Fl P Ar proxy_username
80 .Op Fl p Ar source_port
81@@ -140,6 +140,10 @@
82 It is an error to use this option in conjunction with the
83 .Fl l
84 option.
85+.It Fl q
86+after EOF on stdin, wait the specified number of seconds and then quit. If
87+.Ar seconds
88+is negative, wait forever.
89 .It Fl r
90 Specifies that source and/or destination ports should be chosen randomly
91 instead of sequentially within a range or in the order that the system
92@@ -159,6 +163,8 @@
93 .Dq reliability ,
94 or an 8-bit hexadecimal value preceded by
95 .Dq 0x .
96+.It Fl C
97+Send CRLF as line-ending
98 .It Fl t
99 Causes
100 .Nm
101@@ -317,7 +323,7 @@
102 of requests required by the server.
103 As another example, an email may be submitted to an SMTP server using:
104 .Bd -literal -offset indent
105-$ nc localhost 25 \*(Lt\*(Lt EOF
106+$ nc [-C] localhost 25 \*(Lt\*(Lt EOF
107 HELO host.example.com
108 MAIL FROM:\*(Ltuser@host.example.com\*(Gt
109 RCPT TO:\*(Ltuser2@host.example.com\*(Gt
1100
=== modified file 'debian/patches/series'
--- debian/patches/series 2011-06-11 14:31:06 +0000
+++ debian/patches/series 2012-05-30 22:10:23 +0000
@@ -1,18 +1,12 @@
1openbsd-compat.patch10001-port-to-linux-with-libsd.patch
2socks-b64-prototype.patch20002-connect-timeout.patch
3silence-z.patch30003-get-sev-by-name.patch
4glib-strlcpy.patch40004-poll-hup.patch
5no-strtonum.patch50005-send-crlf.patch
6pollhup.patch60006-quit-timer.patch
7reuseaddr.patch70007-udp-scan-timeout.patch
8connect-timeout.patch80008-verbose-numeric-port.patch
9udp-scan-timeout.patch90009-dccp-support.patch
10verbose-numeric-port.patch100010-serialized-handling-multiple-clients.patch
11send-crlf.patch110011-misc-failures-and-features.patch
12help-version-exit.patch
13quit-timer.patch
14getservbyname.patch
15gcc-warnings.patch
16verbose-message-to-stderr.patch
17netcat-info.patch12netcat-info.patch
18dccp.patch
1913
=== removed file 'debian/patches/silence-z.patch'
--- debian/patches/silence-z.patch 2008-06-19 16:20:01 +0000
+++ debian/patches/silence-z.patch 1970-01-01 00:00:00 +0000
@@ -1,13 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2008-06-19 16:33:52.000000000 -0400
4+++ netcat-openbsd-1.89/netcat.c 2008-06-19 16:34:58.000000000 -0400
5@@ -364,7 +364,7 @@
6 continue;
7
8 ret = 0;
9- if (vflag || zflag) {
10+ if (vflag) {
11 /* For UDP, make sure we are connected. */
12 if (uflag) {
13 if (udptest(s) == -1) {
140
=== removed file 'debian/patches/socks-b64-prototype.patch'
--- debian/patches/socks-b64-prototype.patch 2008-06-19 16:20:01 +0000
+++ debian/patches/socks-b64-prototype.patch 1970-01-01 00:00:00 +0000
@@ -1,13 +0,0 @@
1Index: netcat-openbsd-1.89/socks.c
2===================================================================
3--- netcat-openbsd-1.89.orig/socks.c 2008-06-19 16:30:45.000000000 -0400
4+++ netcat-openbsd-1.89/socks.c 2008-06-19 16:30:36.000000000 -0400
5@@ -53,6 +53,8 @@
6 #define SOCKS_DOMAIN 3
7 #define SOCKS_IPV6 4
8
9+extern int b64_ntop(unsigned char const *, size_t, char *, size_t);
10+
11 int remote_connect(const char *, const char *, struct addrinfo);
12 int socks_connect(const char *, const char *, struct addrinfo,
13 const char *, const char *, struct addrinfo, int,
140
=== removed file 'debian/patches/udp-scan-timeout.patch'
--- debian/patches/udp-scan-timeout.patch 2008-06-19 16:20:01 +0000
+++ debian/patches/udp-scan-timeout.patch 1970-01-01 00:00:00 +0000
@@ -1,50 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:30.000000000 -0500
4+++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:34.000000000 -0500
5@@ -69,6 +69,8 @@
6 #define CONNECTION_FAILED 1
7 #define CONNECTION_TIMEOUT 2
8
9+#define UDP_SCAN_TIMEOUT 3 /* Seconds */
10+
11 /* Command Line Options */
12 int dflag; /* detached, no stdin */
13 int iflag; /* Interval Flag */
14@@ -376,7 +378,7 @@
15 continue;
16
17 ret = 0;
18- if (vflag) {
19+ if (vflag && !uflag) {
20 /* For UDP, make sure we are connected. */
21 if (uflag) {
22 if (udptest(s) == -1) {
23@@ -841,15 +843,20 @@
24 int
25 udptest(int s)
26 {
27- int i, ret;
28+ int i, t;
29
30- for (i = 0; i <= 3; i++) {
31- if (write(s, "X", 1) == 1)
32- ret = 1;
33- else
34- ret = -1;
35+ if ((write(s, "X", 1) != 1) ||
36+ ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED)))
37+ return -1;
38+
39+ /* Give the remote host some time to reply. */
40+ for (i = 0, t = (timeout == -1) ? UDP_SCAN_TIMEOUT : (timeout / 1000);
41+ i < t; i++) {
42+ sleep(1);
43+ if ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED))
44+ return -1;
45 }
46- return (ret);
47+ return 1;
48 }
49
50 void
510
=== removed file 'debian/patches/verbose-message-to-stderr.patch'
--- debian/patches/verbose-message-to-stderr.patch 2010-02-09 10:42:03 +0000
+++ debian/patches/verbose-message-to-stderr.patch 1970-01-01 00:00:00 +0000
@@ -1,17 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2010-02-09 10:29:21.000000000 +0100
4+++ netcat-openbsd-1.89/netcat.c 2010-02-09 10:29:45.000000000 +0100
5@@ -421,9 +421,9 @@ main(int argc, char *argv[])
6 uflag ? "udp" : "tcp");
7 }
8
9- printf("Connection to %s %s port [%s/%s] succeeded!\n",
10- host, portlist[i], uflag ? "udp" : "tcp",
11- sv ? sv->s_name : "*");
12+ fprintf(stderr, "Connection to %s %s port [%s/%s] "
13+ "succeeded!\n", host, portlist[i],
14+ uflag ? "udp" : "tcp", sv ? sv->s_name : "*");
15 }
16 if (!zflag)
17 readwrite(s);
180
=== removed file 'debian/patches/verbose-numeric-port.patch'
--- debian/patches/verbose-numeric-port.patch 2008-01-30 18:24:46 +0000
+++ debian/patches/verbose-numeric-port.patch 1970-01-01 00:00:00 +0000
@@ -1,54 +0,0 @@
1Index: netcat-openbsd-1.89/netcat.c
2===================================================================
3--- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:34.000000000 -0500
4+++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:44.000000000 -0500
5@@ -41,6 +41,7 @@
6 #include <netinet/tcp.h>
7 #include <netinet/ip.h>
8 #include <arpa/telnet.h>
9+#include <arpa/inet.h>
10
11 #include <err.h>
12 #include <errno.h>
13@@ -317,16 +318,15 @@
14 if (uflag) {
15 int rv, plen;
16 char buf[8192];
17- struct sockaddr_storage z;
18
19- len = sizeof(z);
20+ len = sizeof(cliaddr);
21 plen = jflag ? 8192 : 1024;
22 rv = recvfrom(s, buf, plen, MSG_PEEK,
23- (struct sockaddr *)&z, &len);
24+ (struct sockaddr *)&cliaddr, &len);
25 if (rv < 0)
26 err(1, "recvfrom");
27
28- rv = connect(s, (struct sockaddr *)&z, len);
29+ rv = connect(s, (struct sockaddr *)&cliaddr, len);
30 if (rv < 0)
31 err(1, "connect");
32
33@@ -337,6 +337,21 @@
34 &len);
35 }
36
37+ if(vflag) {
38+ /* Don't look up port if -n. */
39+ if (nflag)
40+ sv = NULL;
41+ else
42+ sv = getservbyport(ntohs(atoi(uport)),
43+ uflag ? "udp" : "tcp");
44+
45+ fprintf(stderr, "Connection from %s port %s [%s/%s] accepted\n",
46+ inet_ntoa(((struct sockaddr_in *)(&cliaddr))->sin_addr),
47+ uport,
48+ uflag ? "udp" : "tcp",
49+ sv ? sv->s_name : "*");
50+ }
51+
52 readwrite(connfd);
53 close(connfd);
54 if (family != AF_UNIX)
550
=== modified file 'debian/rules'
--- debian/rules 2008-01-30 18:24:46 +0000
+++ debian/rules 2012-05-30 22:10:23 +0000
@@ -1,64 +1,16 @@
1#!/usr/bin/make -f1#!/usr/bin/make -f
2#export DH_VERBOSE=12DPKG_EXPORT_BUILDFLAGS = 1
3-include /usr/share/dpkg/buildflags.mk
34
4DEB_CFLAGS = -g -Wall5DEB_CFLAGS = $(CPPFLAGS) $(CFLAGS)
5ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))6DEB_LDFLAGS = $(LDFLAGS) -Wl,--no-add-needed,--as-needed
6DEB_CFLAGS += -O0
7else
8DEB_CFLAGS += -O2
9endif
10ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
11INSTALL_PROG = install -m 0755
12else
13INSTALL_PROG = install -s -m 0755
14endif
15DEB_VER = $(shell dpkg-parsechangelog | sed -n 's/^Version: //p')7DEB_VER = $(shell dpkg-parsechangelog | sed -n 's/^Version: //p')
168
17patch: patch-stamp9%:
18patch-stamp:10 dh $@
19 QUILT_PATCHES=debian/patches quilt push -a || test $$? = 211override_dh_auto_build:
20 touch patch-stamp12 $(MAKE) CFLAGS='$(DEB_CFLAGS) -DDEBIAN_VERSION=\"$(DEB_VER)\"' LDFLAGS="$(DEB_LDFLAGS)"
2113override_dh_auto_install:
22unpatch:14 mv nc nc.openbsd
23 QUILT_PATCHES=debian/patches quilt pop -a -R || test $$? = 215 mv nc.1 nc_openbsd.1
24 rm -rf .pc patch-stamp16 dh_auto_install
25
26build: build-stamp
27build-stamp: patch-stamp
28
29 $(MAKE) CFLAGS='$(DEB_CFLAGS) -DDEBIAN_VERSION=\"$(DEB_VER)\"'
30 touch build-stamp
31
32clean: unpatch
33 dh_testdir
34 dh_clean patch-stamp build-stamp
35 $(MAKE) clean
36
37install:
38 dh_testdir
39 dh_testroot
40 dh_clean -k
41 dh_installdirs
42
43 $(INSTALL_PROG) nc $(CURDIR)/debian/netcat-openbsd/bin/nc.openbsd
44 cp nc.1 $(CURDIR)/debian/netcat-openbsd/usr/share/man/man1/nc_openbsd.1
45
46binary-indep: build install
47
48binary-arch: build install
49 dh_testdir
50 dh_testroot
51 dh_installchangelogs
52 dh_installdocs
53 dh_installexamples debian/examples/*
54 dh_link
55 dh_strip
56 dh_compress -Xexamples
57 dh_fixperms
58 dh_installdeb
59 dh_shlibdeps
60 dh_gencontrol
61 dh_md5sums
62 dh_builddeb
63
64binary: binary-indep binary-arch
6517
=== added directory 'debian/source'
=== added file 'debian/source/format'
--- debian/source/format 1970-01-01 00:00:00 +0000
+++ debian/source/format 2012-05-30 22:10:23 +0000
@@ -0,0 +1,1 @@
13.0 (quilt)
02
=== modified file 'nc.1'
--- nc.1 2008-01-30 18:24:46 +0000
+++ nc.1 2012-05-30 22:10:23 +0000
@@ -1,4 +1,4 @@
1.\" $OpenBSD: nc.1,v 1.45 2007/05/31 19:20:13 jmc Exp $1.\" $OpenBSD: nc.1,v 1.60 2012/02/07 12:11:43 lum Exp $
2.\"2.\"
3.\" Copyright (c) 1996 David Sacerdote3.\" Copyright (c) 1996 David Sacerdote
4.\" All rights reserved.4.\" All rights reserved.
@@ -25,7 +25,7 @@
25.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF25.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27.\"27.\"
28.Dd $Mdocdate: May 31 2007 $28.Dd $Mdocdate: February 7 2012 $
29.Dt NC 129.Dt NC 1
30.Os30.Os
31.Sh NAME31.Sh NAME
@@ -35,27 +35,32 @@
35.Nm nc35.Nm nc
36.Bk -words36.Bk -words
37.Op Fl 46DdhklnrStUuvz37.Op Fl 46DdhklnrStUuvz
38.Op Fl I Ar length
38.Op Fl i Ar interval39.Op Fl i Ar interval
40.Op Fl O Ar length
39.Op Fl P Ar proxy_username41.Op Fl P Ar proxy_username
40.Op Fl p Ar source_port42.Op Fl p Ar source_port
41.Op Fl s Ar source_ip_address43.Op Fl s Ar source
42.Op Fl T Ar ToS44.Op Fl T Ar toskeyword
45.Op Fl V Ar rtable
43.Op Fl w Ar timeout46.Op Fl w Ar timeout
44.Op Fl X Ar proxy_protocol47.Op Fl X Ar proxy_protocol
45.Oo Xo48.Oo Xo
46.Fl x Ar proxy_address Ns Oo : Ns49.Fl x Ar proxy_address Ns Oo : Ns
47.Ar port Oc Oc50.Ar port Oc
48.Xc51.Xc Oc
49.Op Ar hostname52.Op Ar destination
50.Op Ar port Ns Bq Ar s53.Op Ar port
51.Ek54.Ek
52.Sh DESCRIPTION55.Sh DESCRIPTION
53The56The
54.Nm57.Nm
55(or58(or
56.Nm netcat )59.Nm netcat )
57utility is used for just about anything under the sun involving TCP60utility is used for just about anything under the sun involving TCP,
58or UDP.61UDP, or
62.Ux Ns -domain
63sockets.
59It can open TCP connections, send UDP packets, listen on arbitrary64It can open TCP connections, send UDP packets, listen on arbitrary
60TCP and UDP ports, do port scanning, and deal with both IPv4 and65TCP and UDP ports, do port scanning, and deal with both IPv4 and
61IPv6.66IPv6.
@@ -101,6 +106,8 @@
101Prints out106Prints out
102.Nm107.Nm
103help.108help.
109.It Fl I Ar length
110Specifies the size of the TCP receive buffer.
104.It Fl i Ar interval111.It Fl i Ar interval
105Specifies a delay time interval between lines of text sent and received.112Specifies a delay time interval between lines of text sent and received.
106Also causes a delay time between connections to multiple ports.113Also causes a delay time between connections to multiple ports.
@@ -129,6 +136,8 @@
129.It Fl n136.It Fl n
130Do not do any DNS or service lookups on any specified addresses,137Do not do any DNS or service lookups on any specified addresses,
131hostnames or ports.138hostnames or ports.
139.It Fl O Ar length
140Specifies the size of the TCP send buffer.
132.It Fl P Ar proxy_username141.It Fl P Ar proxy_username
133Specifies a username to present to a proxy server that requires authentication.142Specifies a username to present to a proxy server that requires authentication.
134If no username is specified then authentication will not be attempted.143If no username is specified then authentication will not be attempted.
@@ -146,19 +155,30 @@
146assigns them.155assigns them.
147.It Fl S156.It Fl S
148Enables the RFC 2385 TCP MD5 signature option.157Enables the RFC 2385 TCP MD5 signature option.
149.It Fl s Ar source_ip_address158.It Fl s Ar source
150Specifies the IP of the interface which is used to send the packets.159Specifies the IP of the interface which is used to send the packets.
160For
161.Ux Ns -domain
162datagram sockets, specifies the local temporary socket file
163to create and use so that datagrams can be received.
151It is an error to use this option in conjunction with the164It is an error to use this option in conjunction with the
152.Fl l165.Fl l
153option.166option.
154.It Fl T Ar ToS167.It Fl T Ar toskeyword
155Specifies IP Type of Service (ToS) for the connection.168Change IPv4 TOS value.
156Valid values are the tokens169.Ar toskeyword
157.Dq lowdelay ,170may be one of
158.Dq throughput ,171.Ar critical ,
159.Dq reliability ,172.Ar inetcontrol ,
160or an 8-bit hexadecimal value preceded by173.Ar lowdelay ,
161.Dq 0x .174.Ar netcontrol ,
175.Ar throughput ,
176.Ar reliability ,
177or one of the DiffServ Code Points:
178.Ar ef ,
179.Ar af11 ... af43 ,
180.Ar cs0 ... cs7 ;
181or a number in either hex or decimal.
162.It Fl t182.It Fl t
163Causes183Causes
164.Nm184.Nm
@@ -167,17 +187,32 @@
167.Nm187.Nm
168to script telnet sessions.188to script telnet sessions.
169.It Fl U189.It Fl U
170Specifies to use Unix Domain Sockets.190Specifies to use
191.Ux Ns -domain
192sockets.
171.It Fl u193.It Fl u
172Use UDP instead of the default option of TCP.194Use UDP instead of the default option of TCP.
195For
196.Ux Ns -domain
197sockets, use a datagram socket instead of a stream socket.
198If a
199.Ux Ns -domain
200socket is used, a temporary receiving socket is created in
201.Pa /tmp
202unless the
203.Fl s
204flag is given.
205.It Fl V Ar rtable
206Set the routing table to be used.
207The default is 0.
173.It Fl v208.It Fl v
174Have209Have
175.Nm210.Nm
176give more verbose output.211give more verbose output.
177.It Fl w Ar timeout212.It Fl w Ar timeout
178If a connection and stdin are idle for more than213Connections which cannot be established or are idle timeout after
179.Ar timeout214.Ar timeout
180seconds, then the connection is silently closed.215seconds.
181The216The
182.Fl w217.Fl w
183flag has no effect on the218flag has no effect on the
@@ -208,7 +243,7 @@
208Requests that243Requests that
209.Nm244.Nm
210should connect to245should connect to
211.Ar hostname246.Ar destination
212using a proxy at247using a proxy at
213.Ar proxy_address248.Ar proxy_address
214and249and
@@ -226,26 +261,31 @@
226option.261option.
227.El262.El
228.Pp263.Pp
229.Ar hostname264.Ar destination
230can be a numerical IP address or a symbolic hostname265can be a numerical IP address or a symbolic hostname
231(unless the266(unless the
232.Fl n267.Fl n
233option is given).268option is given).
234In general, a hostname must be specified,269In general, a destination must be specified,
235unless the270unless the
236.Fl l271.Fl l
237option is given272option is given
238(in which case the local host is used).273(in which case the local host is used).
274For
275.Ux Ns -domain
276sockets, a destination is required and is the socket path to connect to
277(or listen on if the
278.Fl l
279option is given).
239.Pp280.Pp
240.Ar port Ns Op Ar s281.Ar port
241can be single integers or ranges.282can be a single integer or a range of ports.
242Ranges are in the form nn-mm.283Ranges are in the form nn-mm.
243In general,284In general,
244a destination port must be specified,285a destination port must be specified,
245unless the286unless the
246.Fl U287.Fl U
247option is given288option is given.
248(in which case a socket must be specified).
249.Sh CLIENT/SERVER MODEL289.Sh CLIENT/SERVER MODEL
250It is quite simple to build a very basic client/server model using290It is quite simple to build a very basic client/server model using
251.Nm .291.Nm .
@@ -305,7 +345,7 @@
305in response to commands issued by the client.345in response to commands issued by the client.
306For example, to retrieve the home page of a web site:346For example, to retrieve the home page of a web site:
307.Bd -literal -offset indent347.Bd -literal -offset indent
308$ echo -n "GET / HTTP/1.0\er\en\er\en" | nc host.example.com 80348$ printf "GET / HTTP/1.0\er\en\er\en" | nc host.example.com 80
309.Ed349.Ed
310.Pp350.Pp
311Note that this also displays the headers sent by the web server.351Note that this also displays the headers sent by the web server.
@@ -376,7 +416,9 @@
376.Pp416.Pp
377.Dl $ nc -s 10.1.2.3 host.example.com 42417.Dl $ nc -s 10.1.2.3 host.example.com 42
378.Pp418.Pp
379Create and listen on a Unix Domain Socket:419Create and listen on a
420.Ux Ns -domain
421stream socket:
380.Pp422.Pp
381.Dl $ nc -lU /var/tmp/dsocket423.Dl $ nc -lU /var/tmp/dsocket
382.Pp424.Pp
@@ -407,8 +449,15 @@
407Rewritten with IPv6 support by449Rewritten with IPv6 support by
408.An Eric Jackson Aq ericj@monkey.org .450.An Eric Jackson Aq ericj@monkey.org .
409.Sh CAVEATS451.Sh CAVEATS
410UDP port scans will always succeed452UDP port scans using the
411(i.e. report the port as open),453.Fl uz
412rendering the454combination of flags will always report success irrespective of
413.Fl uz455the target machine's state.
414combination of flags relatively useless.456However,
457in conjunction with a traffic sniffer either on the target machine
458or an intermediary device,
459the
460.Fl uz
461combination could be useful for communications diagnostics.
462Note that the amount of UDP traffic generated may be limited either
463due to hardware resources and/or configuration settings.
415464
=== modified file 'netcat.c'
--- netcat.c 2008-01-30 18:24:46 +0000
+++ netcat.c 2012-05-30 22:10:23 +0000
@@ -1,4 +1,4 @@
1/* $OpenBSD: netcat.c,v 1.89 2007/02/20 14:11:17 jmc Exp $ */1/* $OpenBSD: netcat.c,v 1.105 2012/02/09 06:25:35 lum Exp $ */
2/*2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 *4 *
@@ -62,6 +62,7 @@
6262
63#define PORT_MAX 6553563#define PORT_MAX 65535
64#define PORT_MAX_LEN 664#define PORT_MAX_LEN 6
65#define UNIX_DG_TMP_SOCKET_SIZE 19
6566
66/* Command Line Options */67/* Command Line Options */
67int dflag; /* detached, no stdin */68int dflag; /* detached, no stdin */
@@ -80,12 +81,16 @@
80int xflag; /* Socks proxy */81int xflag; /* Socks proxy */
81int zflag; /* Port Scan Flag */82int zflag; /* Port Scan Flag */
82int Dflag; /* sodebug */83int Dflag; /* sodebug */
84int Iflag; /* TCP receive buffer size */
85int Oflag; /* TCP send buffer size */
83int Sflag; /* TCP MD5 signature option */86int Sflag; /* TCP MD5 signature option */
84int Tflag = -1; /* IP Type of Service */87int Tflag = -1; /* IP Type of Service */
88u_int rtableid;
8589
86int timeout = -1;90int timeout = -1;
87int family = AF_UNSPEC;91int family = AF_UNSPEC;
88char *portlist[PORT_MAX+1];92char *portlist[PORT_MAX+1];
93char *unix_dg_tmp_socket;
8994
90void atelnet(int, unsigned char *, unsigned int);95void atelnet(int, unsigned char *, unsigned int);
91void build_ports(char *);96void build_ports(char *);
@@ -93,13 +98,15 @@
93int local_listen(char *, char *, struct addrinfo);98int local_listen(char *, char *, struct addrinfo);
94void readwrite(int);99void readwrite(int);
95int remote_connect(const char *, const char *, struct addrinfo);100int remote_connect(const char *, const char *, struct addrinfo);
101int timeout_connect(int, const struct sockaddr *, socklen_t);
96int socks_connect(const char *, const char *, struct addrinfo,102int socks_connect(const char *, const char *, struct addrinfo,
97 const char *, const char *, struct addrinfo, int, const char *);103 const char *, const char *, struct addrinfo, int, const char *);
98int udptest(int);104int udptest(int);
105int unix_bind(char *);
99int unix_connect(char *);106int unix_connect(char *);
100int unix_listen(char *);107int unix_listen(char *);
101void set_common_sockopts(int);108void set_common_sockopts(int);
102int parse_iptos(char *);109int map_tos(char *, int *);
103void usage(int);110void usage(int);
104111
105int112int
@@ -114,6 +121,7 @@
114 char *proxy;121 char *proxy;
115 const char *errstr, *proxyhost = "", *proxyport = NULL;122 const char *errstr, *proxyhost = "", *proxyport = NULL;
116 struct addrinfo proxyhints;123 struct addrinfo proxyhints;
124 char unix_dg_tmp_socket_buf[UNIX_DG_TMP_SOCKET_SIZE];
117125
118 ret = 1;126 ret = 1;
119 s = 0;127 s = 0;
@@ -123,7 +131,7 @@
123 sv = NULL;131 sv = NULL;
124132
125 while ((ch = getopt(argc, argv,133 while ((ch = getopt(argc, argv,
126 "46Ddhi:jklnP:p:rSs:tT:Uuvw:X:x:z")) != -1) {134 "46DdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) {
127 switch (ch) {135 switch (ch) {
128 case '4':136 case '4':
129 family = AF_INET;137 family = AF_INET;
@@ -185,6 +193,12 @@
185 case 'u':193 case 'u':
186 uflag = 1;194 uflag = 1;
187 break;195 break;
196 case 'V':
197 rtableid = (unsigned int)strtonum(optarg, 0,
198 RT_TABLEID_MAX, &errstr);
199 if (errstr)
200 errx(1, "rtable %s: %s", errstr, optarg);
201 break;
188 case 'v':202 case 'v':
189 vflag = 1;203 vflag = 1;
190 break;204 break;
@@ -205,11 +219,34 @@
205 case 'D':219 case 'D':
206 Dflag = 1;220 Dflag = 1;
207 break;221 break;
222 case 'I':
223 Iflag = strtonum(optarg, 1, 65536 << 14, &errstr);
224 if (errstr != NULL)
225 errx(1, "TCP receive window %s: %s",
226 errstr, optarg);
227 break;
228 case 'O':
229 Oflag = strtonum(optarg, 1, 65536 << 14, &errstr);
230 if (errstr != NULL)
231 errx(1, "TCP send window %s: %s",
232 errstr, optarg);
233 break;
208 case 'S':234 case 'S':
209 Sflag = 1;235 Sflag = 1;
210 break;236 break;
211 case 'T':237 case 'T':
212 Tflag = parse_iptos(optarg);238 errstr = NULL;
239 errno = 0;
240 if (map_tos(optarg, &Tflag))
241 break;
242 if (strlen(optarg) > 1 && optarg[0] == '0' &&
243 optarg[1] == 'x')
244 Tflag = (int)strtol(optarg, NULL, 16);
245 else
246 Tflag = (int)strtonum(optarg, 0, 255,
247 &errstr);
248 if (Tflag < 0 || Tflag > 255 || errstr || errno)
249 errx(1, "illegal tos value %s", optarg);
213 break;250 break;
214 default:251 default:
215 usage(1);252 usage(1);
@@ -220,8 +257,6 @@
220257
221 /* Cruft to make sure options are clean, and used properly. */258 /* Cruft to make sure options are clean, and used properly. */
222 if (argv[0] && !argv[1] && family == AF_UNIX) {259 if (argv[0] && !argv[1] && family == AF_UNIX) {
223 if (uflag)
224 errx(1, "cannot use -u and -U");
225 host = argv[0];260 host = argv[0];
226 uport = NULL;261 uport = NULL;
227 } else if (argv[0] && !argv[1]) {262 } else if (argv[0] && !argv[1]) {
@@ -244,6 +279,19 @@
244 if (!lflag && kflag)279 if (!lflag && kflag)
245 errx(1, "must use -l with -k");280 errx(1, "must use -l with -k");
246281
282 /* Get name of temporary socket for unix datagram client */
283 if ((family == AF_UNIX) && uflag && !lflag) {
284 if (sflag) {
285 unix_dg_tmp_socket = sflag;
286 } else {
287 strlcpy(unix_dg_tmp_socket_buf, "/tmp/nc.XXXXXXXXXX",
288 UNIX_DG_TMP_SOCKET_SIZE);
289 if (mktemp(unix_dg_tmp_socket_buf) == NULL)
290 err(1, "mktemp");
291 unix_dg_tmp_socket = unix_dg_tmp_socket_buf;
292 }
293 }
294
247 /* Initialize addrinfo structure. */295 /* Initialize addrinfo structure. */
248 if (family != AF_UNIX) {296 if (family != AF_UNIX) {
249 memset(&hints, 0, sizeof(struct addrinfo));297 memset(&hints, 0, sizeof(struct addrinfo));
@@ -286,8 +334,12 @@
286 int connfd;334 int connfd;
287 ret = 0;335 ret = 0;
288336
289 if (family == AF_UNIX)337 if (family == AF_UNIX) {
290 s = unix_listen(host);338 if (uflag)
339 s = unix_bind(host);
340 else
341 s = unix_listen(host);
342 }
291343
292 /* Allow only one connection at a time, but stay alive. */344 /* Allow only one connection at a time, but stay alive. */
293 for (;;) {345 for (;;) {
@@ -302,11 +354,11 @@
302 */354 */
303 if (uflag) {355 if (uflag) {
304 int rv, plen;356 int rv, plen;
305 char buf[8192];357 char buf[16384];
306 struct sockaddr_storage z;358 struct sockaddr_storage z;
307359
308 len = sizeof(z);360 len = sizeof(z);
309 plen = jflag ? 8192 : 1024;361 plen = jflag ? 16384 : 2048;
310 rv = recvfrom(s, buf, plen, MSG_PEEK,362 rv = recvfrom(s, buf, plen, MSG_PEEK,
311 (struct sockaddr *)&z, &len);363 (struct sockaddr *)&z, &len);
312 if (rv < 0)364 if (rv < 0)
@@ -316,17 +368,21 @@
316 if (rv < 0)368 if (rv < 0)
317 err(1, "connect");369 err(1, "connect");
318370
319 connfd = s;371 readwrite(s);
320 } else {372 } else {
321 len = sizeof(cliaddr);373 len = sizeof(cliaddr);
322 connfd = accept(s, (struct sockaddr *)&cliaddr,374 connfd = accept(s, (struct sockaddr *)&cliaddr,
323 &len);375 &len);
376 readwrite(connfd);
377 close(connfd);
324 }378 }
325379
326 readwrite(connfd);
327 close(connfd);
328 if (family != AF_UNIX)380 if (family != AF_UNIX)
329 close(s);381 close(s);
382 else if (uflag) {
383 if (connect(s, NULL, 0) < 0)
384 err(1, "connect");
385 }
330386
331 if (!kflag)387 if (!kflag)
332 break;388 break;
@@ -340,6 +396,8 @@
340 } else396 } else
341 ret = 1;397 ret = 1;
342398
399 if (uflag)
400 unlink(unix_dg_tmp_socket);
343 exit(ret);401 exit(ret);
344402
345 } else {403 } else {
@@ -382,8 +440,10 @@
382 uflag ? "udp" : "tcp");440 uflag ? "udp" : "tcp");
383 }441 }
384442
385 printf("Connection to %s %s port [%s/%s] succeeded!\n",443 fprintf(stderr,
386 host, portlist[i], uflag ? "udp" : "tcp",444 "Connection to %s %s port [%s/%s] "
445 "succeeded!\n", host, portlist[i],
446 uflag ? "udp" : "tcp",
387 sv ? sv->s_name : "*");447 sv ? sv->s_name : "*");
388 }448 }
389 if (!zflag)449 if (!zflag)
@@ -398,6 +458,38 @@
398}458}
399459
400/*460/*
461 * unix_bind()
462 * Returns a unix socket bound to the given path
463 */
464int
465unix_bind(char *path)
466{
467 struct sockaddr_un sun;
468 int s;
469
470 /* Create unix domain socket. */
471 if ((s = socket(AF_UNIX, uflag ? SOCK_DGRAM : SOCK_STREAM,
472 0)) < 0)
473 return (-1);
474
475 memset(&sun, 0, sizeof(struct sockaddr_un));
476 sun.sun_family = AF_UNIX;
477
478 if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
479 sizeof(sun.sun_path)) {
480 close(s);
481 errno = ENAMETOOLONG;
482 return (-1);
483 }
484
485 if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
486 close(s);
487 return (-1);
488 }
489 return (s);
490}
491
492/*
401 * unix_connect()493 * unix_connect()
402 * Returns a socket connected to a local unix socket. Returns -1 on failure.494 * Returns a socket connected to a local unix socket. Returns -1 on failure.
403 */495 */
@@ -407,8 +499,13 @@
407 struct sockaddr_un sun;499 struct sockaddr_un sun;
408 int s;500 int s;
409501
410 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)502 if (uflag) {
411 return (-1);503 if ((s = unix_bind(unix_dg_tmp_socket)) < 0)
504 return (-1);
505 } else {
506 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
507 return (-1);
508 }
412 (void)fcntl(s, F_SETFD, 1);509 (void)fcntl(s, F_SETFD, 1);
413510
414 memset(&sun, 0, sizeof(struct sockaddr_un));511 memset(&sun, 0, sizeof(struct sockaddr_un));
@@ -435,27 +532,9 @@
435int532int
436unix_listen(char *path)533unix_listen(char *path)
437{534{
438 struct sockaddr_un sun;
439 int s;535 int s;
440536 if ((s = unix_bind(path)) < 0)
441 /* Create unix domain socket. */537 return (-1);
442 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
443 return (-1);
444
445 memset(&sun, 0, sizeof(struct sockaddr_un));
446 sun.sun_family = AF_UNIX;
447
448 if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
449 sizeof(sun.sun_path)) {
450 close(s);
451 errno = ENAMETOOLONG;
452 return (-1);
453 }
454
455 if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
456 close(s);
457 return (-1);
458 }
459538
460 if (listen(s, 5) < 0) {539 if (listen(s, 5) < 0) {
461 close(s);540 close(s);
@@ -473,7 +552,7 @@
473remote_connect(const char *host, const char *port, struct addrinfo hints)552remote_connect(const char *host, const char *port, struct addrinfo hints)
474{553{
475 struct addrinfo *res, *res0;554 struct addrinfo *res, *res0;
476 int s, error;555 int s, error, on = 1;
477556
478 if ((error = getaddrinfo(host, port, &hints, &res)))557 if ((error = getaddrinfo(host, port, &hints, &res)))
479 errx(1, "getaddrinfo: %s", gai_strerror(error));558 errx(1, "getaddrinfo: %s", gai_strerror(error));
@@ -484,10 +563,18 @@
484 res0->ai_protocol)) < 0)563 res0->ai_protocol)) < 0)
485 continue;564 continue;
486565
566 if (rtableid) {
567 if (setsockopt(s, SOL_SOCKET, SO_RTABLE, &rtableid,
568 sizeof(rtableid)) == -1)
569 err(1, "setsockopt SO_RTABLE");
570 }
571
487 /* Bind to a local port or source address if specified. */572 /* Bind to a local port or source address if specified. */
488 if (sflag || pflag) {573 if (sflag || pflag) {
489 struct addrinfo ahints, *ares;574 struct addrinfo ahints, *ares;
490575
576 /* try SO_BINDANY, but don't insist */
577 setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on));
491 memset(&ahints, 0, sizeof(struct addrinfo));578 memset(&ahints, 0, sizeof(struct addrinfo));
492 ahints.ai_family = res0->ai_family;579 ahints.ai_family = res0->ai_family;
493 ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;580 ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
@@ -504,7 +591,7 @@
504591
505 set_common_sockopts(s);592 set_common_sockopts(s);
506593
507 if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0)594 if (timeout_connect(s, res0->ai_addr, res0->ai_addrlen) == 0)
508 break;595 break;
509 else if (vflag)596 else if (vflag)
510 warn("connect to %s port %s (%s) failed", host, port,597 warn("connect to %s port %s (%s) failed", host, port,
@@ -519,6 +606,43 @@
519 return (s);606 return (s);
520}607}
521608
609int
610timeout_connect(int s, const struct sockaddr *name, socklen_t namelen)
611{
612 struct pollfd pfd;
613 socklen_t optlen;
614 int flags, optval;
615 int ret;
616
617 if (timeout != -1) {
618 flags = fcntl(s, F_GETFL, 0);
619 if (fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1)
620 err(1, "set non-blocking mode");
621 }
622
623 if ((ret = connect(s, name, namelen)) != 0 && errno == EINPROGRESS) {
624 pfd.fd = s;
625 pfd.events = POLLOUT;
626 if ((ret = poll(&pfd, 1, timeout)) == 1) {
627 optlen = sizeof(optval);
628 if ((ret = getsockopt(s, SOL_SOCKET, SO_ERROR,
629 &optval, &optlen)) == 0) {
630 errno = optval;
631 ret = optval == 0 ? 0 : -1;
632 }
633 } else if (ret == 0) {
634 errno = ETIMEDOUT;
635 ret = -1;
636 } else
637 err(1, "poll failed");
638 }
639
640 if (timeout != -1 && fcntl(s, F_SETFL, flags) == -1)
641 err(1, "restoring flags");
642
643 return (ret);
644}
645
522/*646/*
523 * local_listen()647 * local_listen()
524 * Returns a socket listening on a local port, binds to specified source648 * Returns a socket listening on a local port, binds to specified source
@@ -550,6 +674,12 @@
550 res0->ai_protocol)) < 0)674 res0->ai_protocol)) < 0)
551 continue;675 continue;
552676
677 if (rtableid) {
678 if (setsockopt(s, IPPROTO_IP, SO_RTABLE, &rtableid,
679 sizeof(rtableid)) == -1)
680 err(1, "setsockopt SO_RTABLE");
681 }
682
553 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));683 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
554 if (ret == -1)684 if (ret == -1)
555 err(1, NULL);685 err(1, NULL);
@@ -582,12 +712,12 @@
582readwrite(int nfd)712readwrite(int nfd)
583{713{
584 struct pollfd pfd[2];714 struct pollfd pfd[2];
585 unsigned char buf[8192];715 unsigned char buf[16384];
586 int n, wfd = fileno(stdin);716 int n, wfd = fileno(stdin);
587 int lfd = fileno(stdout);717 int lfd = fileno(stdout);
588 int plen;718 int plen;
589719
590 plen = jflag ? 8192 : 1024;720 plen = jflag ? 16384 : 2048;
591721
592 /* Setup Network FD */722 /* Setup Network FD */
593 pfd[0].fd = nfd;723 pfd[0].fd = nfd;
@@ -646,33 +776,33 @@
646 unsigned char *p, *end;776 unsigned char *p, *end;
647 unsigned char obuf[4];777 unsigned char obuf[4];
648778
649 end = buf + size;779 if (size < 3)
650 obuf[0] = '\0';780 return;
781 end = buf + size - 2;
651782
652 for (p = buf; p < end; p++) {783 for (p = buf; p < end; p++) {
653 if (*p != IAC)784 if (*p != IAC)
654 break;785 continue;
655786
656 obuf[0] = IAC;787 obuf[0] = IAC;
657 p++;788 p++;
658 if ((*p == WILL) || (*p == WONT))789 if ((*p == WILL) || (*p == WONT))
659 obuf[1] = DONT;790 obuf[1] = DONT;
660 if ((*p == DO) || (*p == DONT))791 else if ((*p == DO) || (*p == DONT))
661 obuf[1] = WONT;792 obuf[1] = WONT;
662 if (obuf) {793 else
663 p++;794 continue;
664 obuf[2] = *p;795
665 obuf[3] = '\0';796 p++;
666 if (atomicio(vwrite, nfd, obuf, 3) != 3)797 obuf[2] = *p;
667 warn("Write Error!");798 if (atomicio(vwrite, nfd, obuf, 3) != 3)
668 obuf[0] = '\0';799 warn("Write Error!");
669 }
670 }800 }
671}801}
672802
673/*803/*
674 * build_ports()804 * build_ports()
675 * Build an array or ports in portlist[], listing each port805 * Build an array of ports in portlist[], listing each port
676 * that we should try to connect to.806 * that we should try to connect to.
677 */807 */
678void808void
@@ -684,9 +814,6 @@
684 int x = 0;814 int x = 0;
685815
686 if ((n = strchr(p, '-')) != NULL) {816 if ((n = strchr(p, '-')) != NULL) {
687 if (lflag)
688 errx(1, "Cannot use -l with multiple ports!");
689
690 *n = '\0';817 *n = '\0';
691 n++;818 n++;
692819
@@ -729,18 +856,16 @@
729 hi = strtonum(p, 1, PORT_MAX, &errstr);856 hi = strtonum(p, 1, PORT_MAX, &errstr);
730 if (errstr)857 if (errstr)
731 errx(1, "port number %s: %s", errstr, p);858 errx(1, "port number %s: %s", errstr, p);
732 portlist[0] = calloc(1, PORT_MAX_LEN);859 portlist[0] = strdup(p);
733 if (portlist[0] == NULL)860 if (portlist[0] == NULL)
734 err(1, NULL);861 err(1, NULL);
735 portlist[0] = p;
736 }862 }
737}863}
738864
739/*865/*
740 * udptest()866 * udptest()
741 * Do a few writes to see if the UDP port is there.867 * Do a few writes to see if the UDP port is there.
742 * XXX - Better way of doing this? Doesn't work for IPv6.868 * Fails once PF state table is full.
743 * Also fails after around 100 ports checked.
744 */869 */
745int870int
746udptest(int s)871udptest(int s)
@@ -781,23 +906,64 @@
781 &Tflag, sizeof(Tflag)) == -1)906 &Tflag, sizeof(Tflag)) == -1)
782 err(1, "set IP ToS");907 err(1, "set IP ToS");
783 }908 }
909 if (Iflag) {
910 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
911 &Iflag, sizeof(Iflag)) == -1)
912 err(1, "set TCP receive buffer size");
913 }
914 if (Oflag) {
915 if (setsockopt(s, SOL_SOCKET, SO_SNDBUF,
916 &Oflag, sizeof(Oflag)) == -1)
917 err(1, "set TCP send buffer size");
918 }
784}919}
785920
786int921int
787parse_iptos(char *s)922map_tos(char *s, int *val)
788{923{
789 int tos = -1;924 /* DiffServ Codepoints and other TOS mappings */
790925 const struct toskeywords {
791 if (strcmp(s, "lowdelay") == 0)926 const char *keyword;
792 return (IPTOS_LOWDELAY);927 int val;
793 if (strcmp(s, "throughput") == 0)928 } *t, toskeywords[] = {
794 return (IPTOS_THROUGHPUT);929 { "af11", IPTOS_DSCP_AF11 },
795 if (strcmp(s, "reliability") == 0)930 { "af12", IPTOS_DSCP_AF12 },
796 return (IPTOS_RELIABILITY);931 { "af13", IPTOS_DSCP_AF13 },
797932 { "af21", IPTOS_DSCP_AF21 },
798 if (sscanf(s, "0x%x", &tos) != 1 || tos < 0 || tos > 0xff)933 { "af22", IPTOS_DSCP_AF22 },
799 errx(1, "invalid IP Type of Service");934 { "af23", IPTOS_DSCP_AF23 },
800 return (tos);935 { "af31", IPTOS_DSCP_AF31 },
936 { "af32", IPTOS_DSCP_AF32 },
937 { "af33", IPTOS_DSCP_AF33 },
938 { "af41", IPTOS_DSCP_AF41 },
939 { "af42", IPTOS_DSCP_AF42 },
940 { "af43", IPTOS_DSCP_AF43 },
941 { "critical", IPTOS_PREC_CRITIC_ECP },
942 { "cs0", IPTOS_DSCP_CS0 },
943 { "cs1", IPTOS_DSCP_CS1 },
944 { "cs2", IPTOS_DSCP_CS2 },
945 { "cs3", IPTOS_DSCP_CS3 },
946 { "cs4", IPTOS_DSCP_CS4 },
947 { "cs5", IPTOS_DSCP_CS5 },
948 { "cs6", IPTOS_DSCP_CS6 },
949 { "cs7", IPTOS_DSCP_CS7 },
950 { "ef", IPTOS_DSCP_EF },
951 { "inetcontrol", IPTOS_PREC_INTERNETCONTROL },
952 { "lowdelay", IPTOS_LOWDELAY },
953 { "netcontrol", IPTOS_PREC_NETCONTROL },
954 { "reliability", IPTOS_RELIABILITY },
955 { "throughput", IPTOS_THROUGHPUT },
956 { NULL, -1 },
957 };
958
959 for (t = toskeywords; t->keyword != NULL; t++) {
960 if (strcmp(s, t->keyword) == 0) {
961 *val = t->val;
962 return (1);
963 }
964 }
965
966 return (0);
801}967}
802968
803void969void
@@ -810,19 +976,22 @@
810 \t-D Enable the debug socket option\n\976 \t-D Enable the debug socket option\n\
811 \t-d Detach from stdin\n\977 \t-d Detach from stdin\n\
812 \t-h This help text\n\978 \t-h This help text\n\
979 \t-I length TCP receive buffer length\n\
813 \t-i secs\t Delay interval for lines sent, ports scanned\n\980 \t-i secs\t Delay interval for lines sent, ports scanned\n\
814 \t-k Keep inbound sockets open for multiple connects\n\981 \t-k Keep inbound sockets open for multiple connects\n\
815 \t-l Listen mode, for inbound connects\n\982 \t-l Listen mode, for inbound connects\n\
816 \t-n Suppress name/port resolutions\n\983 \t-n Suppress name/port resolutions\n\
984 \t-O length TCP send buffer length\n\
817 \t-P proxyuser\tUsername for proxy authentication\n\985 \t-P proxyuser\tUsername for proxy authentication\n\
818 \t-p port\t Specify local port for remote connects\n\986 \t-p port\t Specify local port for remote connects\n\
819 \t-r Randomize remote ports\n\987 \t-r Randomize remote ports\n\
820 \t-S Enable the TCP MD5 signature option\n\988 \t-S Enable the TCP MD5 signature option\n\
821 \t-s addr\t Local source address\n\989 \t-s addr\t Local source address\n\
822 \t-T ToS\t Set IP Type of Service\n\990 \t-T toskeyword\tSet IP Type of Service\n\
823 \t-t Answer TELNET negotiation\n\991 \t-t Answer TELNET negotiation\n\
824 \t-U Use UNIX domain socket\n\992 \t-U Use UNIX domain socket\n\
825 \t-u UDP mode\n\993 \t-u UDP mode\n\
994 \t-V rtable Specify alternate routing table\n\
826 \t-v Verbose\n\995 \t-v Verbose\n\
827 \t-w secs\t Timeout for connects and final net reads\n\996 \t-w secs\t Timeout for connects and final net reads\n\
828 \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\997 \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\
@@ -835,9 +1004,11 @@
835void1004void
836usage(int ret)1005usage(int ret)
837{1006{
838 fprintf(stderr, "usage: nc [-46DdhklnrStUuvz] [-i interval] [-P proxy_username] [-p source_port]\n");1007 fprintf(stderr,
839 fprintf(stderr, "\t [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]\n");1008 "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n"
840 fprintf(stderr, "\t [-x proxy_address[:port]] [hostname] [port[s]]\n");1009 "\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n"
1010 "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
1011 "\t [-x proxy_address[:port]] [destination] [port]\n");
841 if (ret)1012 if (ret)
842 exit(1);1013 exit(1);
843}1014}
8441015
=== removed directory 'openbsd-compat'
=== removed file 'openbsd-compat/base64.c'
--- openbsd-compat/base64.c 2008-01-30 18:24:46 +0000
+++ openbsd-compat/base64.c 1970-01-01 00:00:00 +0000
@@ -1,308 +0,0 @@
1/* $OpenBSD: base64.c,v 1.5 2006/10/21 09:55:03 otto Exp $ */
2
3/*
4 * Copyright (c) 1996 by Internet Software Consortium.
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
11 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
12 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
13 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
16 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
17 * SOFTWARE.
18 */
19
20/*
21 * Portions Copyright (c) 1995 by International Business Machines, Inc.
22 *
23 * International Business Machines, Inc. (hereinafter called IBM) grants
24 * permission under its copyrights to use, copy, modify, and distribute this
25 * Software with or without fee, provided that the above copyright notice and
26 * all paragraphs of this notice appear in all copies, and that the name of IBM
27 * not be used in connection with the marketing of any product incorporating
28 * the Software or modifications thereof, without specific, written prior
29 * permission.
30 *
31 * To the extent it has a right to do so, IBM grants an immunity from suit
32 * under its patents, if any, for the use, sale or manufacture of products to
33 * the extent that such products are used for performing Domain Name System
34 * dynamic updates in TCP/IP networks by means of the Software. No immunity is
35 * granted for any product per se or for any other function of any product.
36 *
37 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
38 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
39 * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
40 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
41 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
42 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <sys/types.h>
46#include <sys/param.h>
47#include <sys/socket.h>
48#include <netinet/in.h>
49#include <arpa/inet.h>
50#include <arpa/nameser.h>
51
52#include <ctype.h>
53#include <resolv.h>
54#include <stdio.h>
55
56#include <stdlib.h>
57#include <string.h>
58
59static const char Base64[] =
60 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
61static const char Pad64 = '=';
62
63/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
64 The following encoding technique is taken from RFC 1521 by Borenstein
65 and Freed. It is reproduced here in a slightly edited form for
66 convenience.
67
68 A 65-character subset of US-ASCII is used, enabling 6 bits to be
69 represented per printable character. (The extra 65th character, "=",
70 is used to signify a special processing function.)
71
72 The encoding process represents 24-bit groups of input bits as output
73 strings of 4 encoded characters. Proceeding from left to right, a
74 24-bit input group is formed by concatenating 3 8-bit input groups.
75 These 24 bits are then treated as 4 concatenated 6-bit groups, each
76 of which is translated into a single digit in the base64 alphabet.
77
78 Each 6-bit group is used as an index into an array of 64 printable
79 characters. The character referenced by the index is placed in the
80 output string.
81
82 Table 1: The Base64 Alphabet
83
84 Value Encoding Value Encoding Value Encoding Value Encoding
85 0 A 17 R 34 i 51 z
86 1 B 18 S 35 j 52 0
87 2 C 19 T 36 k 53 1
88 3 D 20 U 37 l 54 2
89 4 E 21 V 38 m 55 3
90 5 F 22 W 39 n 56 4
91 6 G 23 X 40 o 57 5
92 7 H 24 Y 41 p 58 6
93 8 I 25 Z 42 q 59 7
94 9 J 26 a 43 r 60 8
95 10 K 27 b 44 s 61 9
96 11 L 28 c 45 t 62 +
97 12 M 29 d 46 u 63 /
98 13 N 30 e 47 v
99 14 O 31 f 48 w (pad) =
100 15 P 32 g 49 x
101 16 Q 33 h 50 y
102
103 Special processing is performed if fewer than 24 bits are available
104 at the end of the data being encoded. A full encoding quantum is
105 always completed at the end of a quantity. When fewer than 24 input
106 bits are available in an input group, zero bits are added (on the
107 right) to form an integral number of 6-bit groups. Padding at the
108 end of the data is performed using the '=' character.
109
110 Since all base64 input is an integral number of octets, only the
111 -------------------------------------------------
112 following cases can arise:
113
114 (1) the final quantum of encoding input is an integral
115 multiple of 24 bits; here, the final unit of encoded
116 output will be an integral multiple of 4 characters
117 with no "=" padding,
118 (2) the final quantum of encoding input is exactly 8 bits;
119 here, the final unit of encoded output will be two
120 characters followed by two "=" padding characters, or
121 (3) the final quantum of encoding input is exactly 16 bits;
122 here, the final unit of encoded output will be three
123 characters followed by one "=" padding character.
124 */
125
126int
127b64_ntop(src, srclength, target, targsize)
128 u_char const *src;
129 size_t srclength;
130 char *target;
131 size_t targsize;
132{
133 size_t datalength = 0;
134 u_char input[3];
135 u_char output[4];
136 int i;
137
138 while (2 < srclength) {
139 input[0] = *src++;
140 input[1] = *src++;
141 input[2] = *src++;
142 srclength -= 3;
143
144 output[0] = input[0] >> 2;
145 output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
146 output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
147 output[3] = input[2] & 0x3f;
148
149 if (datalength + 4 > targsize)
150 return (-1);
151 target[datalength++] = Base64[output[0]];
152 target[datalength++] = Base64[output[1]];
153 target[datalength++] = Base64[output[2]];
154 target[datalength++] = Base64[output[3]];
155 }
156
157 /* Now we worry about padding. */
158 if (0 != srclength) {
159 /* Get what's left. */
160 input[0] = input[1] = input[2] = '\0';
161 for (i = 0; i < srclength; i++)
162 input[i] = *src++;
163
164 output[0] = input[0] >> 2;
165 output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
166 output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
167
168 if (datalength + 4 > targsize)
169 return (-1);
170 target[datalength++] = Base64[output[0]];
171 target[datalength++] = Base64[output[1]];
172 if (srclength == 1)
173 target[datalength++] = Pad64;
174 else
175 target[datalength++] = Base64[output[2]];
176 target[datalength++] = Pad64;
177 }
178 if (datalength >= targsize)
179 return (-1);
180 target[datalength] = '\0'; /* Returned value doesn't count \0. */
181 return (datalength);
182}
183
184/* skips all whitespace anywhere.
185 converts characters, four at a time, starting at (or after)
186 src from base - 64 numbers into three 8 bit bytes in the target area.
187 it returns the number of data bytes stored at the target, or -1 on error.
188 */
189
190int
191b64_pton(src, target, targsize)
192 char const *src;
193 u_char *target;
194 size_t targsize;
195{
196 int tarindex, state, ch;
197 char *pos;
198
199 state = 0;
200 tarindex = 0;
201
202 while ((ch = *src++) != '\0') {
203 if (isspace(ch)) /* Skip whitespace anywhere. */
204 continue;
205
206 if (ch == Pad64)
207 break;
208
209 pos = strchr(Base64, ch);
210 if (pos == 0) /* A non-base64 character. */
211 return (-1);
212
213 switch (state) {
214 case 0:
215 if (target) {
216 if (tarindex >= targsize)
217 return (-1);
218 target[tarindex] = (pos - Base64) << 2;
219 }
220 state = 1;
221 break;
222 case 1:
223 if (target) {
224 if (tarindex + 1 >= targsize)
225 return (-1);
226 target[tarindex] |= (pos - Base64) >> 4;
227 target[tarindex+1] = ((pos - Base64) & 0x0f)
228 << 4 ;
229 }
230 tarindex++;
231 state = 2;
232 break;
233 case 2:
234 if (target) {
235 if (tarindex + 1 >= targsize)
236 return (-1);
237 target[tarindex] |= (pos - Base64) >> 2;
238 target[tarindex+1] = ((pos - Base64) & 0x03)
239 << 6;
240 }
241 tarindex++;
242 state = 3;
243 break;
244 case 3:
245 if (target) {
246 if (tarindex >= targsize)
247 return (-1);
248 target[tarindex] |= (pos - Base64);
249 }
250 tarindex++;
251 state = 0;
252 break;
253 }
254 }
255
256 /*
257 * We are done decoding Base-64 chars. Let's see if we ended
258 * on a byte boundary, and/or with erroneous trailing characters.
259 */
260
261 if (ch == Pad64) { /* We got a pad char. */
262 ch = *src++; /* Skip it, get next. */
263 switch (state) {
264 case 0: /* Invalid = in first position */
265 case 1: /* Invalid = in second position */
266 return (-1);
267
268 case 2: /* Valid, means one byte of info */
269 /* Skip any number of spaces. */
270 for (; ch != '\0'; ch = *src++)
271 if (!isspace(ch))
272 break;
273 /* Make sure there is another trailing = sign. */
274 if (ch != Pad64)
275 return (-1);
276 ch = *src++; /* Skip the = */
277 /* Fall through to "single trailing =" case. */
278 /* FALLTHROUGH */
279
280 case 3: /* Valid, means two bytes of info */
281 /*
282 * We know this char is an =. Is there anything but
283 * whitespace after it?
284 */
285 for (; ch != '\0'; ch = *src++)
286 if (!isspace(ch))
287 return (-1);
288
289 /*
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches