debian/0000755000000000000000000000000011432030716007163 5ustar debian/TODO0000644000000000000000000000012011273644440007654 0ustar * licencecheck reports some mistakes about FSF address (upstream contacted) debian/compat0000644000000000000000000000000211273643640010372 0ustar 7 debian/dirs0000644000000000000000000000000411273643640010052 0ustar bin debian/rules0000755000000000000000000000023211365415670010253 0ustar #!/usr/bin/make -f include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/autotools.mk DEB_CONFIGURE_EXTRA_FLAGS := --bindir=/bin debian/source/0000755000000000000000000000000011432030716010463 5ustar debian/source/format0000644000000000000000000000001411365415670011704 0ustar 3.0 (quilt) debian/netcat6.postinst0000644000000000000000000000060511273644440012345 0ustar #!/bin/sh set -e if [ "$1" = "configure" ]; then update-alternatives \ --install /bin/nc nc /bin/nc6 50 \ --slave /bin/netcat netcat /bin/nc6 \ --slave /usr/share/man/man1/nc.1.gz nc.1.gz \ /usr/share/man/man1/nc6.1.gz \ --slave /usr/share/man/man1/netcat.1.gz netcat.1.gz \ /usr/share/man/man1/nc6.1.gz fi #DEBHELPER# debian/copyright0000644000000000000000000000272311273643177011140 0ustar This package was debianized by: Peter Makholm on Thu, 9 May 2002 21:14:30 +0200. Guillaume Delacour on Mon, 10 Mar 2009 22:02:21 +200. It was downloaded from: http://www.deepspace6.net/projects/netcat6.html Upstream Authors: Mauro Tortonesi Chris Leishman Simone Piunno Filippo Natali Copyright: Copyright (C) 2001 Mauro Tortonesi Copyright (C) 2002 Chris Leishman License: This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this package; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA On Debian systems, the complete text of the GNU General Public License can be found in `/usr/share/common-licenses/GPL-2'. The Debian packaging is: Copyright C) 2002, Peter Makholm and is licensed under the GPL, see above. debian/control0000644000000000000000000000141411432030412010557 0ustar Source: nc6 Section: net Priority: optional Maintainer: Guillaume Delacour Build-Depends: debhelper (>= 7), cdbs, autotools-dev Standards-Version: 3.9.1.0 Homepage: http://www.deepspace6.net/projects/netcat6.html Package: netcat6 Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: TCP/IP swiss army knife with IPv6 support A simple Unix utility which reads and writes data across network connections using TCP or UDP protocol. It is designed to be a reliable "back-end" tool that can be used directly or easily driven by other programs and scripts. At the same time it is a feature-rich network debugging and exploration tool. . Netcat6 is a rewrite of the original netcat with support for IPv6 and an enhanced support for UDP. debian/netcat6.prerm0000644000000000000000000000015411273644440011606 0ustar #!/bin/sh set -e if [ "$1" = "remove" ]; then update-alternatives --remove nc /bin/nc6 fi #DEBHELPER# debian/watch0000644000000000000000000000011211365415670010221 0ustar version=3 http://ftp.deepspace6.net/pub/ds6/sources/nc6/nc6-(\d.*).tar.gz debian/docs0000644000000000000000000000004611273642366010053 0ustar AUTHORS BUGS CREDITS NEWS README TODO debian/changelog0000644000000000000000000000700111432030530011025 0ustar nc6 (1.0-8) unstable; urgency=low * Fix parsing of -e argument, refresh impacted patches: - 02_multicast.patch (error in this patch) - 03_send_crlf.diff - 06_idle_timeout_parsing.diff - 07_z_argument.diff (Closes: #591988) * Bump to Standards-Version 3.9.1.0 (no changes needed) -- Guillaume Delacour Sun, 15 Aug 2010 16:17:57 +0200 nc6 (1.0-7) unstable; urgency=low * debian/patches/07_z_argument.diff: Fix to always set zflag boolean (Closes: #586999) * Bump to Standards-Version 3.9.0.0 (no changes needed) -- Guillaume Delacour Mon, 28 Jun 2010 21:15:58 +0200 nc6 (1.0-6) unstable; urgency=low * debian/watch: delete unnecessary comment lines * Switch to dpkg-source 3.0 (quilt) format + debian/rules: Remove simple-patchsys + debian/control: Remove patchutils Build-Dep + debian/patches/* rename to .diff and add patch header * Bump to Standards-Version 3.8.4 (no changes needed) * debian/patches/01_quiet_socket_announce.diff: Refresh patch to include parser.h to avoid implicit declaration * debian/patches/05_source_service_and_source_address.diff: Don't overwrite ai_flags when using -s or -p (Closes: #578706) * debian/patches/06_idle_timeout_parsing.diff: Fix parsing of -t argument * debian/patches/07_z_argument.diff: Add -z argument support like other netcat alternatives (Closes: #581894) -- Guillaume Delacour Mon, 26 Apr 2010 21:25:45 +0000 nc6 (1.0-5) unstable; urgency=low * debian/patches/02_multicast.patch: Fix for multicast addresses in UDP mode (Closes: #236635), thanks to Alexander Clouter. * debian/patches/03_send_crlf.patch: Add CRLF support for common services (Closes: #545570), thanks to Róbert Koszorús. * debian/patches/04_minus_to_hyphen.patch: Escape "-" in man page (lintian hyphen-used-as-minus-sign check). * debian/control: + Add Homepage field. + Bump to Standards-Version 3.8.3. + Bump debhelper minimum version to 7 (also in debian/compat). * Provide alternative like netcat and netcat-openbsd (Closes: #513601). (Change binary location from /usr/bin to /bin, like other alternatives). -- Guillaume Delacour Tue, 22 Sep 2009 22:39:11 +0000 nc6 (1.0-4) unstable; urgency=low * New maintainer (Closes: #516881) * debian/copyright: + Adapt copyright file to new standards * debian/control + Add ${misc:Depends} + Bump to Standards-Version 3.8.1 -- Guillaume Delacour Fri, 13 May 2009 21:17:03 +0100 nc6 (1.0-3) unstable; urgency=low * Remember to add the build-dependency on cdbs. Ooops... -- Peter Makholm Wed, 26 Sep 2007 07:44:07 +0000 nc6 (1.0-2) unstable; urgency=low * Converted to cdbs * Added patch to only announce socket type in verbose mode (Closes: #432116) -- Peter Makholm Fri, 31 Aug 2007 17:29:57 +0000 nc6 (1.0-1) unstable; urgency=low * New upstream version (at last...) (Closes: #356999) -- Peter Makholm Fri, 20 Oct 2006 16:38:12 +0000 nc6 (0.5-1) unstable; urgency=low * New upstream release (Closes: #216585) -- Peter Makholm Tue, 21 Oct 2003 18:41:03 +0200 nc6 (0.4-1) unstable; urgency=low * New upstream release (Closes: #185348) -- Peter Makholm Wed, 9 Apr 2003 20:05:01 +0200 nc6 (0.2pre2-1) unstable; urgency=low * Initial Release. (Closes: #145880) -- Peter Makholm Thu, 9 May 2002 21:14:30 +0200 debian/patches/0000755000000000000000000000000011432030716010612 5ustar debian/patches/04_minus_to_hyphen.diff0000644000000000000000000001625111365415670015177 0ustar Change hyphen to minus in manpage --- a/docs/nc6.1.in +++ b/docs/nc6.1.in @@ -69,19 +69,19 @@ .TP 13 .I \-b, --bluetooth With this option set, netcat6 will use bluetooth to establish connections. -By default the L2CAP protocol will be used (also see '--sco'). +By default the L2CAP protocol will be used (also see '\-\-sco'). .TP 13 .I \--buffer-size=BYTES Set the buffer size for the local and remote endpoints. netcat6 does all reads into these buffers, so they should be large enough to minimize excessive reads from the socket and in UDP mode it should be large -enough to receive an entire datagram (also see '--nru'). By default, the +enough to receive an entire datagram (also see '\-\-nru'). By default, the buffer size is 8 kilobytes for TCP connections and 128 kilobytes for UDP. .TP 13 .I \--continuous Enable continuous accepting of connections in listen mode, like inetd. Must -be used with --exec to specify the command to run locally (try 'nc6 ---continuous --exec cat -l -p ' to make a simple echo server). +be used with \-\-exec to specify the command to run locally (try 'nc6 +\-\-continuous \-\-exec cat \-l \-p ' to make a simple echo server). .TP 13 .I \--disable-nagle Disable the use of the Nagle algorithm for TCP connections (see "NAGLE @@ -153,7 +153,7 @@ .TP 13 .I \--sco With this option set, netcat6 with use SCO over bluetooth -(note that '-b' or '--bluetooth' must also be specified). +(note that '\-b' or '\-\-bluetooth' must also be specified). .TP 13 .I \--send-only Only send data, don't receive. This also disables any hold timeouts. @@ -180,13 +180,13 @@ .TP 13 .I \-x, --transfer File transfer mode (see "FILE TRANSFER"). If listen mode is -specified, this is equivalent to "--recv-only --buffer-size=65536" otherwise -it is equivalent to "--send-only --buffer-size=65536". +specified, this is equivalent to "\-\-recv-only \-\-buffer-size=65536" otherwise +it is equivalent to "\-\-send-only \-\-buffer-size=65536". .I \-X, --rev-transfer Reverse file transfer mode (see "FILE TRANSFER"). This transfers in the opposite direction to normal transfer. If listen mode is specified, this is -equivalent to "--send-only --buffer-size=65536" otherwise it is equivalent to -"--recv-only --buffer-size=65536". +equivalent to "\-\-send-only \-\-buffer-size=65536" otherwise it is equivalent to +"\-\-recv-only \-\-buffer-size=65536". .SH UDP UDP support in netcat6 works very well in both connect and in listen mode. When using UDP in listen mode netcat6 accepts UDP packets from any source that @@ -205,13 +205,13 @@ .P netcat6 allows for fine control over the buffer sizes, MTU's and NRU's for the connection, which is especially useful for UDP connections. See the ---buffer-size, --mtu and --nru options. +\-\-buffer-size, \-\-mtu and \-\-nru options. .SH TIMEOUTS netcat6 currently implements a connect/accept timeout, and idle timeout, and hold timeouts on both the remote and local endpoints. .IP \(bu 4 -The connect/accept timeout is optional and is specified with the -w or ---timeout option. If a connection cannot be established within the specified +The connect/accept timeout is optional and is specified with the \-w or +\-\-timeout option. If a connection cannot be established within the specified time, nc6 will exit with a non-zero exit status. If the option is not specified, nc6 will wait forever when listening for new connections (in listen mode), and will use the standard operating system timeout when @@ -219,7 +219,7 @@ essentially ignored when creating UDP connections to a remote server, as UDP is a connectionless protocol. .IP \(bu 4 -The idle timeout is optional and is specified with the -t or --idle-timeout +The idle timeout is optional and is specified with the \-t or \-\-idle-timeout option. If no data is sent or received from the remote host in the specified time, nc6 will exit with a non-zero exit status. The default is to not timeout idle connections. @@ -244,7 +244,7 @@ default. .SH FILE TRANSFER netcat6 can be used to transfer files and data streams efficiently, using the -\'-x' or '--transfer' command line option (or the '-X' and '--rev-transfer' +\'\-x' or '\-\-transfer' command line option (or the '\-X' and '\-\-rev-transfer' equivalents for transfer in the opposite direction). .P For example, to transfer a file from machine 'foo.example.com' to machine @@ -253,32 +253,32 @@ On 'bar', set up a listening nc6 on any local port: .RS -bar$ nc6 -x -l -p 7676 > targetfile +bar$ nc6 \-x \-l \-p 7676 > targetfile .RE Then on 'foo', use nc6 to send the file to the listening nc6: .RS -foo$ nc6 -x bar.example.com 7676 < sourcefile +foo$ nc6 \-x bar.example.com 7676 < sourcefile .RE You can also use file transfer mode to pipe the output of programs over networks. For example, you can use tar with nc6 to copy entire directories: .RS -bar$ nc6 -x -l -p 7676 | tar xpzf - +bar$ nc6 \-x \-l \-p 7676 | tar xpzf \- -foo$ tar cpzf - /home | nc6 -x bar.example.com 7676 +foo$ tar cpzf \- /home | nc6 \-x bar.example.com 7676 .RE -The '-x' or '--transfer' option is just an alias for various other options +The '\-x' or '\-\-transfer' option is just an alias for various other options which set the direction of transfer and increase the buffer sizes used. In -listen mode, it is equivalent to "--recv-only --buffer-size=65536" otherwise -it is equivalent to "--send-only --buffer-size=65536". +listen mode, it is equivalent to "\-\-recv-only \-\-buffer-size=65536" otherwise +it is equivalent to "\-\-send-only \-\-buffer-size=65536". .P The normal file transfer mode options assume the file will be sent TO the netcat6 process that is in listen mode, FROM the netcat6 process that is -connecting to it. To transfer the other way use the -X or --rev-transfer +connecting to it. To transfer the other way use the \-X or \-\-rev-transfer options. .SH HALF CLOSE Stream based data transfers, such as TCP, have 2 separate streams - the @@ -299,7 +299,7 @@ transmit stream after they send their request. In default mode, netcat6 will close the entire connection before sending the response back to the client. .P -However, by specifying the "--half-close" option, netcat6 will keep trying to +However, by specifying the "\-\-half-close" option, netcat6 will keep trying to send data to the remote server after the receive stream has closed. It will also close the remote transmit stream when there is no more data to send (EOF has been received on stdin). @@ -324,7 +324,7 @@ algorithm on most systems, using the TCP_NODELAY socket option. .P .B netcat6 -provides the '--disable-nagle' command line option to disable the Nagle +provides the '\-\-disable-nagle' command line option to disable the Nagle algorithm for the connection. .SH ERRORS .B netcat6 @@ -337,7 +337,7 @@ to the stdout without any errors. It DOES NOT indicate whether all data read from stdin has been successfully sent to the remote machine. .P -In --half-close mode, nc6 exists successfully when an EOF has been received +In \-\-half-close mode, nc6 exists successfully when an EOF has been received from both the remote machine AND from stdin, and all data has been successfully sent. Thus the exit status indicates that all data was transfered successfully. debian/patches/06_idle_timeout_parsing.diff0000644000000000000000000000057311431773330016171 0ustar Fix parsing of -t argument (from upstream cvs) --- a/src/parser.c +++ b/src/parser.c @@ -164,7 +164,7 @@ _verbosity_level = 0; /* option recognition loop */ - while ((c = getopt_long(argc, argv, "46be:T:hlnp:q:s:uvw:xXC", + while ((c = getopt_long(argc, argv, "46be:T:hlnp:q:s:uvw:xXCt:", long_options, &option_index)) >= 0) { switch (c) { debian/patches/02_multicast.diff0000644000000000000000000001631611431773062013770 0ustar Fix for multicast addresses in UDP mode --- a/docs/nc6.1.in +++ b/docs/nc6.1.in @@ -117,6 +117,11 @@ .I \--no-reuseaddr Disables the SO_REUSEADDR socket option (this is only useful in listen mode). .TP 13 +.I \-T, \--ttl=TTL +Set's the IP TTL of the packets leaving (this is only useful in connect mode). +This is mainly useful for multicast, otherwise packets will often leave with +the OS default of 1, making it rarely useful. +.TP 13 .I \--nru=BYTES Set the miNimum Receive Unit for the remote endpoint (network receives). Note that this does not mean that every network read will get the specified number --- a/src/afindep.c +++ b/src/afindep.c @@ -64,6 +64,9 @@ struct addrinfo *res = NULL, *ptr; bool connect_attempted = false; char name_buf[AI_STR_SIZE]; + const connection_attributes_t *attrs = + *((const connection_attributes_t **)hdata); + int on; /* make sure arguments are valid and preconditions are respected */ assert(hints != NULL); @@ -90,6 +93,23 @@ /* only accept results we can handle */ if (skip_address(ptr) == true) continue; + if (ptr->ai_socktype == SOCK_STREAM) { + if (ptr->ai_family == PF_INET) { + if (IN_MULTICAST(ntohl(((struct sockaddr_in *)(ptr->ai_addr))->sin_addr.s_addr))) { + warning("socket type STREAM and multicast bad, udp only!"); + return -1; + } + } +#ifdef ENABLE_IPV6 + else if (ptr->ai_family == PF_INET6) { + if (IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)(ptr->ai_addr))->sin6_addr)) { + warning("socket type STREAM and multicast bad, udp only!"); + return -1; + } + } +#endif + } + /* we are going to try to connect to this address */ connect_attempted = true; @@ -182,6 +202,28 @@ freeaddrinfo(src_res); } + /* setup the ttl */ + if ((on = ca_ttl(attrs)) > -1) { + if ( ptr->ai_family == PF_INET ) { + if (IN_MULTICAST(ntohl(((struct sockaddr_in *)(ptr->ai_addr))->sin_addr.s_addr))) { + setsockopt(fd, SOL_IP, IP_MULTICAST_TTL, &on, sizeof(on)); + } + else { + setsockopt(fd, SOL_IP, IP_TTL, &on, sizeof(on)); + } + } +#ifdef ENABLE_IPV6 + else if ( ptr->ai_family == PF_INET6 ) { + if (IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)(ptr->ai_addr))->sin6_addr)) { + setsockopt(fd, SOL_IPV6, IPV6_MULTICAST_HOPS, &on, sizeof(on)); + } + else { + setsockopt(fd, SOL_IPV6, IPV6_UNICAST_HOPS, &on, sizeof(on)); + } + } +#endif + } + /* attempt the connection */ err = connect_with_timeout(fd, ptr->ai_addr, ptr->ai_addrlen, timeout); @@ -250,7 +292,10 @@ { int nfd, i, fd, err, maxfd = -1; struct addrinfo *res = NULL, *ptr; + int off = 0; + struct ip_mreq mreq; #ifdef ENABLE_IPV6 + struct ipv6_mreq mreq6; bool set_ipv6_only = false; bool bound_ipv6_any = false; #endif @@ -327,7 +372,24 @@ /* only accept results we can handle */ if (skip_address(ptr) == true) continue; - + + if (ptr->ai_socktype == SOCK_STREAM) { + if (ptr->ai_family == PF_INET) { + if (IN_MULTICAST(ntohl(((struct sockaddr_in *)(ptr->ai_addr))->sin_addr.s_addr))) { + warning("socket type STREAM and multicast bad, udp only!"); + return -1; + } + } +#ifdef ENABLE_IPV6 + else if (ptr->ai_family == PF_INET6) { + if (IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)(ptr->ai_addr))->sin6_addr)) { + warning("socket type STREAM and multicast bad, udp only!"); + return -1; + } + } +#endif + } + /* create the socket */ fd = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); if (fd < 0) { @@ -414,6 +476,27 @@ FD_SET(fd, &accept_fdset); maxfd = MAX(maxfd, fd); nfd++; + + if (ptr->ai_family == PF_INET) { + if (IN_MULTICAST(ntohl(((struct sockaddr_in *)(ptr->ai_addr))->sin_addr.s_addr))) { + memset(&mreq, 0, sizeof(mreq)); + mreq.imr_multiaddr = ((struct sockaddr_in *)(ptr->ai_addr))->sin_addr; + mreq.imr_interface.s_addr = INADDR_ANY; + setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); + setsockopt(fd, SOL_IP, IP_MULTICAST_LOOP, &off, sizeof(off)); + } + } +#ifdef ENABLE_IPV6 + else if (ptr->ai_family == PF_INET6) { + if (IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)(ptr->ai_addr))->sin6_addr)) { + memset(&mreq6, 0, sizeof(mreq6)); + mreq6.ipv6mr_multiaddr = ((struct sockaddr_in6 *)(ptr->ai_addr))->sin6_addr; + mreq6.ipv6mr_interface = 0; + setsockopt(fd, SOL_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof(mreq)); + setsockopt(fd, SOL_IPV6, IPV6_MULTICAST_LOOP, &off, sizeof(off)); + } + } +#endif } freeaddrinfo(res); --- a/src/connection.h +++ b/src/connection.h @@ -56,6 +56,7 @@ sock_protocol_t protocol; address_t remote_address; address_t local_address; + int ttl; int flags; size_t buffer_size; size_t remote_mtu; @@ -104,6 +105,9 @@ #define ca_set_flag(CA, FLG) ((CA)->flags |= (FLG)) #define ca_clear_flag(CA, FLG) ((CA)->flags &= ~(FLG)) +#define ca_ttl(CA) ((CA)->ttl) +#define ca_set_ttl(CA, SZ) ((CA)->ttl = (SZ)) + #define ca_buffer_size(CA) ((CA)->buffer_size) #define ca_set_buffer_size(CA, SZ) ((CA)->buffer_size = (SZ)) --- a/src/parser.c +++ b/src/parser.c @@ -109,7 +109,9 @@ {"bluetooth", no_argument, NULL, 'b'}, #define OPT_SCO 24 {"sco", no_argument, NULL, 0 }, -#define OPT_MAX 25 +#define OPT_TTL 25 + {"ttl", required_argument, NULL, 'T'}, +#define OPT_MAX 26 {0, 0, 0, 0} }; @@ -142,6 +144,7 @@ int remote_hold_timeout = 0; int remote_mtu = 0; int remote_nru = 0; + int ttl = -1; int buffer_size = 0; int sndbuf_size = 0; int rcvbuf_size = 0; @@ -160,7 +163,7 @@ _verbosity_level = 0; /* option recognition loop */ - while ((c = getopt_long(argc, argv, "46be:hlnp:q:s:uvw:xX", + while ((c = getopt_long(argc, argv, "46be:T:hlnp:q:s:uvw:xX", long_options, &option_index)) >= 0) { switch (c) { @@ -296,6 +299,14 @@ case 'X': rev_file_transfer = true; break; + case 'T': + assert(optarg != NULL); + if (safe_atoi(optarg, &ttl)) + fatal(_("invalid argument to " + "--ttl")); + if (ttl < -1 || ttl > 255 ) + fatal(_("ttl can only be set between 0 to 255")); + break; case '?': print_usage(stderr); exit(EXIT_FAILURE); @@ -446,6 +457,11 @@ fatal(_("--continuous option " "must be used with --exec")); } + + if (ttl != -1) { + warning(_("setting ttl in listen mode " + "is meaningless, ignoring")); + } } else { /* check port has been specified (except with sco) */ if (remote_address.address == NULL || @@ -508,11 +524,12 @@ if (set_local_hold_timeout == true) ca_set_local_hold_timeout(attrs, local_hold_timeout); - /* setup mtu, nru, and buffer sizes if they were specified */ + /* setup mtu, nru, ttl, and buffer sizes if they were specified */ if (remote_mtu > 0) ca_set_remote_MTU(attrs, remote_mtu); if (remote_nru > 0) ca_set_remote_NRU(attrs, remote_nru); + ca_set_ttl(attrs, ttl); if (buffer_size > 0) ca_set_buffer_size(attrs, buffer_size); if (sndbuf_size > 0) @@ -603,6 +620,7 @@ fprintf(fp, " -x, --transfer %s\n", _("File transfer mode")); fprintf(fp, " -X, --rev-transfer %s\n", _("File transfer mode (reverse direction)")); + fprintf(fp, " -T, --ttl=TTL %s\n", _("TTL of outgoing IP packet")); fprintf(fp, "\n"); } debian/patches/01_quiet_socket_announce.diff0000644000000000000000000000145411365415670016350 0ustar Very verbose mode --- a/src/network.c +++ b/src/network.c @@ -23,6 +23,7 @@ #include "network.h" #include "connection.h" #include "afindep.h" +#include "parser.h" #ifdef ENABLE_BLUEZ #include "bluez.h" #endif/*ENABLE_BLUEZ*/ @@ -292,13 +293,16 @@ /* announce the socket in very verbose mode */ switch (socktype) { case SOCK_STREAM: - warning(_("using stream socket")); + if (very_verbose_mode()) + warning(_("using stream socket")); break; case SOCK_DGRAM: - warning(_("using datagram socket")); + if (very_verbose_mode()) + warning(_("using datagram socket")); break; case SOCK_SEQPACKET: - warning(_("using seqpacket socket")); + if (very_verbose_mode()) + warning(_("using seqpacket socket")); break; default: fatal_internal("unsupported socket type %d", socktype); debian/patches/07_z_argument.diff0000644000000000000000000000662211431773347014150 0ustar Add -z arugment like other netcat alternatives --- a/docs/nc6.1.in +++ b/docs/nc6.1.in @@ -187,6 +187,9 @@ opposite direction to normal transfer. If listen mode is specified, this is equivalent to "\-\-send-only \-\-buffer-size=65536" otherwise it is equivalent to "\-\-recv-only \-\-buffer-size=65536". +.TP 13 +.I \-z +Don't send any data (scanning mode). .SH UDP UDP support in netcat6 works very well in both connect and in listen mode. When using UDP in listen mode netcat6 accepts UDP packets from any source that --- a/src/parser.c +++ b/src/parser.c @@ -149,6 +149,7 @@ int buffer_size = 0; int sndbuf_size = 0; int rcvbuf_size = 0; + bool zflag = false; /* check arguments */ assert(argc > 0); @@ -164,7 +165,7 @@ _verbosity_level = 0; /* option recognition loop */ - while ((c = getopt_long(argc, argv, "46be:T:hlnp:q:s:uvw:xXCt:", + while ((c = getopt_long(argc, argv, "46be:T:hlnp:q:s:uvw:xXCt:z", long_options, &option_index)) >= 0) { switch (c) { @@ -316,6 +317,9 @@ if (ttl < -1 || ttl > 255 ) fatal(_("ttl can only be set between 0 to 255")); break; + case 'z': + zflag = true; + break; case '?': print_usage(stderr); exit(EXIT_FAILURE); @@ -404,6 +408,11 @@ fatal_internal("invalid protocol family %d", family); } + /* don't set -l and -z both */ + if (listen_mode == true && zflag == true) { + fatal(_("cannot set both -l and -z")); + } + /* set mode flags */ if (listen_mode == true) { ca_set_flag(attrs, CA_LISTEN_MODE); @@ -545,6 +554,9 @@ ca_set_sndbuf_size(attrs, sndbuf_size); if (rcvbuf_size > 0) ca_set_rcvbuf_size(attrs, rcvbuf_size); + + /* setup zflag */ + ca_set_zflag(attrs, zflag); } @@ -640,6 +652,7 @@ fprintf(fp, " -X, --rev-transfer %s\n", _("File transfer mode (reverse direction)")); fprintf(fp, " -T, --ttl=TTL %s\n", _("TTL of outgoing IP packet")); + fprintf(fp, " -z %s\n", _("Don't send any data (scan mode)")); fprintf(fp, "\n"); } --- a/src/connection.h +++ b/src/connection.h @@ -70,6 +70,7 @@ bool remote_half_close_suppress; bool local_half_close_suppress; char *local_exec; + bool zflag; } connection_attributes_t; /* CA flags */ @@ -136,6 +137,9 @@ #define ca_set_local_hold_timeout(CA, T) \ ((CA)->local_hold_timeout = (T)) +#define ca_zflag(CA) ((CA)->zflag) +#define ca_set_zflag(CA, Z) ((CA)->zflag = (Z)) + #define ca_remote_half_close_suppress(CA) \ ((CA)->remote_half_close_suppress) #define ca_set_remote_half_close_suppress(CA, B) \ --- a/src/main.c +++ b/src/main.c @@ -174,7 +174,7 @@ { circ_buf_t remote_buffer, local_buffer; io_stream_t remote_stream, local_stream; - int retval; + int retval=0; assert(attrs != NULL); assert(fd >= 0); @@ -219,14 +219,17 @@ remote_stream.mtu); } - /* transfer data between endpoints */ - retval = run_transfer(attrs, &remote_stream, &local_stream); - - /* cleanup */ - io_stream_destroy(&local_stream); - io_stream_destroy(&remote_stream); - cb_destroy(&local_buffer); - cb_destroy(&remote_buffer); + /* if not in scan mode, send data */ + if (attrs->zflag == false) { + /* transfer data between endpoints */ + retval = run_transfer(attrs, &remote_stream, &local_stream); + + /* cleanup */ + io_stream_destroy(&local_stream); + io_stream_destroy(&remote_stream); + cb_destroy(&local_buffer); + cb_destroy(&remote_buffer); + } return retval; } debian/patches/series0000644000000000000000000000026411401563340012031 0ustar 01_quiet_socket_announce.diff 02_multicast.diff 03_send_crlf.diff 04_minus_to_hyphen.diff 05_source_service_and_source_address.diff 06_idle_timeout_parsing.diff 07_z_argument.diff debian/patches/05_source_service_and_source_address.diff0000644000000000000000000000073611367310041020704 0ustar Don't override ai_flags with hints.ai_flags --- a/src/afindep.c +++ b/src/afindep.c @@ -154,7 +154,8 @@ src_hints.ai_flags = AI_PASSIVE; src_hints.ai_socktype = ptr->ai_socktype; src_hints.ai_protocol = ptr->ai_protocol; - src_hints.ai_flags = hints->ai_flags; + /* Don't override previous ai_flags */ + src_hints.ai_flags |= hints->ai_flags; /* get the local IP address of the connection */ err = getaddrinfo(local_address, local_service, debian/patches/03_send_crlf.diff0000644000000000000000000001515411431773313013721 0ustar Add CRLF support for common services --- nc6-1.0.orig/configure.ac 2009-09-07 07:41:40.000000000 +0200 +++ nc6-1.0/configure.ac 2009-09-07 08:22:46.000000000 +0200 @@ -161,6 +161,18 @@ LIBS="${INET6_LIBS} ${LIBS}" fi +# CRLF option +crlfoption="yes" +AC_ARG_ENABLE(crlfoption, AC_HELP_STRING([--disable-crlfoption], + [compile without crlfoption support]), + [ if test x$enable_crlfoption = xno; then crlfoption="no"; fi ], + [ crlfoption="yes" ] +) + +if test $crlfoption = "yes"; then + AC_DEFINE([CRLFOPTION],1,[compile with CRLF option]) +fi + dnl Check for libraries AC_CHECK_LIB(socket, socket) --- nc6-1.0.orig/docs/nc6.1.in 2009-09-07 07:41:40.000000000 +0200 +++ nc6-1.0/docs/nc6.1.in 2009-09-07 16:15:41.000000000 +0200 @@ -170,6 +170,9 @@ .I \-w, --timeout=SECONDS Timeout for network connects and accepts (see "TIMEOUTS"). .TP 13 +.I \-C +Send CRLF as line-ending +.TP 13 .I \-x, --transfer File transfer mode (see "FILE TRANSFER"). If listen mode is specified, this is equivalent to "--recv-only --buffer-size=65536" otherwise --- nc6-1.0.orig/src/circ_buf.c 2009-09-07 07:41:40.000000000 +0200 +++ nc6-1.0/src/circ_buf.c 2009-09-07 15:41:59.000000000 +0200 @@ -382,6 +382,28 @@ +ssize_t cb_write_crlf(circ_buf_t *cb, int fd, size_t nbytes) +{ + circ_buf_t cb2; + ssize_t cb2ptr; + ssize_t rr; + + cb_init(&cb2, (cb->data_size * 2)); + + for ( cb2ptr = 0; cb2ptr < cb->data_size; cb2ptr++, rr++ ) { + if ( cb->buf[cb2ptr] == '\n' ) /* LF? */ + cb_append(&cb2, (const uint8_t *)"\r\n", 2); /* replace with CRLF */ + else + cb_append(&cb2, &(cb->buf[cb2ptr]), 1); + } + + cb->data_size -= rr; + + return cb_write(&cb2, fd, nbytes); +} + + + ssize_t cb_send(circ_buf_t *cb, int fd, size_t nbytes, struct sockaddr *dest, size_t destlen) { --- nc6-1.0.orig/src/circ_buf.h 2009-09-07 07:41:40.000000000 +0200 +++ nc6-1.0/src/circ_buf.h 2009-09-07 14:41:17.000000000 +0200 @@ -55,6 +55,7 @@ struct sockaddr *from, size_t *fromlen); ssize_t cb_write(circ_buf_t *cb, int fd, size_t nbytes); +ssize_t cb_write_crlf(circ_buf_t *cb, int fd, size_t nbytes); ssize_t cb_send(circ_buf_t *cb, int fd, size_t nbytes, struct sockaddr *dest, size_t destlen); --- nc6-1.0.orig/src/io_stream.c 2009-09-07 07:41:40.000000000 +0200 +++ nc6-1.0/src/io_stream.c 2009-09-07 14:40:50.000000000 +0200 @@ -359,6 +359,57 @@ +ssize_t ios_write_crlf(io_stream_t *ios) +{ + ssize_t rr; + + /* check argument */ + ios_assert(ios); + + /* should only be called if ios_schedule_write returned a true result */ + assert(ios->fd_out >= 0); + assert(!cb_is_empty(ios->buf_out)); + + /* write as much as the mtu allows */ + if (ios->socktype == SOCK_DGRAM) + rr = cb_send(ios->buf_out, ios->fd_out, ios->mtu, NULL, 0); + else + rr = cb_write_crlf(ios->buf_out, ios->fd_out, ios->mtu); + + if (rr > 0) { + ios->sent += rr; +#ifndef NDEBUG + if (very_verbose_mode()) + warning("wrote %d bytes to %s", rr, ios->name); +#endif + /* record that the ios was active */ + gettimeofday(&(ios->last_active), NULL); + + /* shutdown the write if buf_out is empty and out eof is set */ + if ((ios->flags & IOS_OUTPUT_EOF) && cb_is_empty(ios->buf_out)) + ios_shutdown(ios, SHUT_WR); + + return rr; + } else if (rr == 0) { + /* shouldn't happen? */ + return 0; + } else if (errno == EAGAIN) { + /* not ready? */ + return 0; + } else { + if (very_verbose_mode()) { + if (errno == EPIPE) + warning(_("received SIGPIPE on %s"), ios->name); + else + warning(_("error writing to %s: %s"), + ios->name, strerror(errno)); + } + return IOS_FAILED; + } +} + + + void ios_write_eof(io_stream_t *ios) { /* check argument */ --- nc6-1.0.orig/src/io_stream.h 2009-09-07 07:41:40.000000000 +0200 +++ nc6-1.0/src/io_stream.h 2009-09-07 14:39:16.000000000 +0200 @@ -110,6 +110,10 @@ * should only be called if ios_schedule_write returned a true value * returns the total bytes read, or a negative error code */ ssize_t ios_write(io_stream_t *ios); +/* write from the output buffer in CDRL mode. + * should only be called if ios_schedule_write returned a true value + * returns the total bytes read, or a negative error code */ +ssize_t ios_write_crlf(io_stream_t *ios); /* error return values from ios_read/ios_write */ #define IOS_FAILED -1 --- nc6-1.0.orig/src/parser.c 2009-09-07 07:41:40.000000000 +0200 +++ nc6-1.0/src/parser.c 2009-09-07 14:32:08.000000000 +0200 @@ -56,6 +56,7 @@ /* storage for the global flags */ static int _verbosity_level = 0; +static int opt_crlf = 0x00; /* CRLF line-ending default false */ /* long options */ static const struct option long_options[] = { @@ -160,7 +161,7 @@ _verbosity_level = 0; /* option recognition loop */ - while ((c = getopt_long(argc, argv, "46be:T:hlnp:q:s:uvw:xX", + while ((c = getopt_long(argc, argv, "46be:T:hlnp:q:s:uvw:xXC", long_options, &option_index)) >= 0) { switch (c) { @@ -285,6 +286,14 @@ case 'v': ++_verbosity_level; break; + case 'C': /* CRLF line-ending */ +#ifdef CRLFOPTION + opt_crlf = 0x01; /* CRLF true */ +#else + fatal_internal( + "invalid option -- %c (netcat was compiled with --disable-crlfoption)\n", c); +#endif /* CRLFOPTION */ + break; case 'w': assert(optarg != NULL); if (safe_atoi(optarg, &connect_timeout)) @@ -537,6 +546,13 @@ +bool crlf_mode() +{ + return ((opt_crlf == 0x00) ? false : true); +} + + + static void print_usage(FILE *fp) { const char *program_name = get_program_name(); @@ -596,6 +612,9 @@ fprintf(fp, " -v %s\n", _("Increase program verbosity\n" " (call twice for max verbosity)")); +#ifdef CRLFOPTION + fprintf(fp, " -C %s\n", _("Send CRLF as line ending")); +#endif /* CRLFOPTION */ fprintf(fp, " --version %s\n", _("Display nc6 version information")); fprintf(fp, " -w, --timeout=SECONDS %s\n", --- nc6-1.0.orig/src/parser.h 2009-09-07 07:41:40.000000000 +0200 +++ nc6-1.0/src/parser.h 2009-09-07 14:32:26.000000000 +0200 @@ -26,6 +26,7 @@ bool verbose_mode(void); bool very_verbose_mode(void); +bool crlf_mode(void); void parse_arguments(int argc, char **argv, connection_attributes_t *attrs); --- nc6-1.0.orig/src/readwrite.c 2009-09-07 07:41:40.000000000 +0200 +++ nc6-1.0/src/readwrite.c 2009-09-07 14:36:18.000000000 +0200 @@ -199,7 +199,10 @@ if (ios1_write_fd >= 0 && FD_ISSET(ios1_write_fd, &write_fdset)) { /* ios1 is ready to write */ - rr = ios_write(ios1); + if ( crlf_mode() ) + rr = ios_write_crlf(ios1); /* CRLF mode */ + else + rr = ios_write(ios1); if (rr < 0) { /* write failed -