MFC: netcat 4.7.

This commit is contained in:
Xin LI 2010-04-22 00:28:49 +00:00
parent b6a02e249f
commit b36b15fd88
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/stable/8/; revision=207040
4 changed files with 36 additions and 71 deletions

View File

@ -1,19 +0,0 @@
$FreeBSD$
1. Export from OpenBSD's nc(1) into an empty directory (say "v-nc").
2. while read pattern; do rm ${pattern} ; done < FREEBSD-Xlist
3. Checkout our contrib/netcat to another directory (say "f-nc"),
with -rOPENBSD, and usr.bin/nc to its ../../
4. copy the files from v-nc to f-nc
5. do cvs up -A in f-nc
6. If there is conflicits, try to resolve them.
7. do build in f-nc/../../usr.bin/nc
8. If everything seems ok, do the actual import in v-nc:
cvs -n import src/contrib/netcat OPENBSD OPENBSD_<release>
Everything appears be Ok? Do:
cvs import src/contrib/netcat OPENBSD OPENBSD_<release>
(note: recently we import from OpenBSD's release branches
rather than importing -HEAD snapshots)
9. Resolve the conflicits with the patchset obtained in step 6.
delphij@FreeBSD.org - 21 Apr 2008

View File

@ -1,5 +0,0 @@
# $FreeBSD$
Project: netcat (aka src/usr.bin/nc in OpenBSD)
ProjectURL: http://www.openbsd.org/
Version: 4.6
License: BSD

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: nc.1,v 1.50 2009/06/05 06:47:12 jmc Exp $
.\" $OpenBSD: nc.1,v 1.53 2010/02/23 23:00:52 schwarze Exp $
.\"
.\" Copyright (c) 1996 David Sacerdote
.\" All rights reserved.
@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd June 5 2009
.Dd April 15, 2010
.Dt NC 1
.Os
.Sh NAME
@ -36,7 +36,7 @@
.Sh SYNOPSIS
.Nm nc
.Bk -words
.Op Fl 46DdEhklnorStUuvz
.Op Fl 46DdEhklnrStUuvz
.Op Fl e Ar IPsec_policy
.Op Fl I Ar length
.Op Fl i Ar interval
@ -51,8 +51,8 @@
.Op Fl X Ar proxy_protocol
.Oo Xo
.Fl x Ar proxy_address Ns Oo : Ns
.Ar port Oc Oc
.Xc
.Ar port Oc
.Xc Oc
.Op Ar hostname
.Op Ar port
.Ek
@ -159,15 +159,6 @@ socket option.
.It Fl O Ar length
Specifies the size of the TCP send buffer.
When
.It Fl o
.Dq Once-only mode .
By default,
.Nm
does not terminate on EOF condition on input,
but continues until the network side has been closed down.
Specifying
.Fl o
will make it terminate on EOF as well.
.It Fl P Ar proxy_username
Specifies a username to present to a proxy server that requires authentication.
If no username is specified then authentication will not be attempted.
@ -206,7 +197,9 @@ This makes it possible to use
.Nm
to script telnet sessions.
.It Fl U
Specifies to use Unix Domain Sockets.
Specifies to use
.Ux Ns -domain
sockets.
.It Fl u
Use UDP instead of the default option of TCP.
.It Fl V Ar fib
@ -428,7 +421,9 @@ outgoing traffic only.
.Pp
.Dl $ nc -e 'out ipsec esp/transport//require' host.example.com 42
.Pp
Create and listen on a Unix Domain Socket:
Create and listen on a
.Ux Ns -domain
socket:
.Pp
.Dl $ nc -lU /var/tmp/dsocket
.Pp

View File

@ -1,4 +1,4 @@
/* $OpenBSD: netcat.c,v 1.93 2009/06/05 00:18:10 claudio Exp $ */
/* $OpenBSD: netcat.c,v 1.95 2010/02/27 00:58:56 nicm Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
*
@ -72,14 +72,12 @@
#define PORT_MAX_LEN 6
/* Command Line Options */
int Eflag; /* Use IPsec ESP */
int dflag; /* detached, no stdin */
unsigned int iflag; /* Interval Flag */
int jflag; /* use jumbo frames if we can */
int kflag; /* More than one connect */
int lflag; /* Bind to local port */
int nflag; /* Don't do name look up */
int oflag; /* Once only: stop on EOF */
int FreeBSD_Oflag; /* Do not use TCP options */
char *Pflag; /* Proxy username */
char *pflag; /* Localport flag */
@ -151,7 +149,7 @@ main(int argc, char *argv[])
sv = NULL;
while ((ch = getopt_long(argc, argv,
"46DdEe:hI:i:jklnO:oP:p:rSs:tT:UuV:vw:X:x:z",
"46DdEe:hI:i:jklnoO:P:p:rSs:tT:UuV:vw:X:x:z",
longopts, NULL)) != -1) {
switch (ch) {
case '4':
@ -214,7 +212,7 @@ main(int argc, char *argv[])
nflag = 1;
break;
case 'o':
oflag = 1;
fprintf(stderr, "option -o is deprecated.\n");
break;
case 'P':
Pflag = optarg;
@ -282,8 +280,6 @@ main(int argc, char *argv[])
case 'T':
Tflag = parse_iptos(optarg);
break;
case 0:
break;
default:
usage(1);
}
@ -455,8 +451,10 @@ main(int argc, char *argv[])
uflag ? "udp" : "tcp");
}
printf("Connection to %s %s port [%s/%s] succeeded!\n",
host, portlist[i], uflag ? "udp" : "tcp",
fprintf(stderr,
"Connection to %s %s port [%s/%s] "
"succeeded!\n", host, portlist[i],
uflag ? "udp" : "tcp",
sv ? sv->s_name : "*");
}
if (!zflag)
@ -572,10 +570,8 @@ remote_connect(const char *host, const char *port, struct addrinfo hints)
if (sflag || pflag) {
struct addrinfo ahints, *ares;
#ifdef SO_BINDANY
/* try SO_BINDANY, but don't insist */
setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on));
#endif
/* try IP_BINDANY, but don't insist */
setsockopt(s, IPPROTO_IP, IP_BINDANY, &on, sizeof(on));
memset(&ahints, 0, sizeof(struct addrinfo));
ahints.ai_family = res0->ai_family;
ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
@ -727,10 +723,9 @@ readwrite(int nfd)
}
if (!dflag && pfd[1].revents & POLLIN) {
if ((n = read(wfd, buf, plen)) < 0 ||
(oflag && n == 0)) {
if ((n = read(wfd, buf, plen)) < 0)
return;
} else if (n == 0) {
else if (n == 0) {
shutdown(nfd, SHUT_WR);
pfd[1].fd = -1;
pfd[1].events = 0;
@ -749,27 +744,27 @@ atelnet(int nfd, unsigned char *buf, unsigned int size)
unsigned char *p, *end;
unsigned char obuf[4];
end = buf + size;
obuf[0] = '\0';
if (size < 3)
return;
end = buf + size - 2;
for (p = buf; p < end; p++) {
if (*p != IAC)
break;
continue;
obuf[0] = IAC;
p++;
if ((*p == WILL) || (*p == WONT))
obuf[1] = DONT;
if ((*p == DO) || (*p == DONT))
else if ((*p == DO) || (*p == DONT))
obuf[1] = WONT;
if (obuf) {
p++;
obuf[2] = *p;
obuf[3] = '\0';
if (atomicio(vwrite, nfd, obuf, 3) != 3)
warn("Write Error!");
obuf[0] = '\0';
}
else
continue;
p++;
obuf[2] = *p;
if (atomicio(vwrite, nfd, obuf, 3) != 3)
warn("Write Error!");
}
}
@ -943,7 +938,6 @@ help(void)
\t-n Suppress name/port resolutions\n\
\t--no-tcpopt Disable TCP options\n\
\t-O length TCP send buffer length\n\
\t-o Terminate on EOF on input\n\
\t-P proxyuser\tUsername for proxy authentication\n\
\t-p port\t Specify local port for remote connects\n\
\t-r Randomize remote ports\n\
@ -993,9 +987,9 @@ usage(int ret)
{
fprintf(stderr,
#ifdef IPSEC
"usage: nc [-46DdEhklnorStUuvz] [-e policy] [-I length] [-i interval] [-O length]\n"
"usage: nc [-46DdEhklnrStUuvz] [-e policy] [-I length] [-i interval] [-O length]\n"
#else
"usage: nc [-46DdhklnorStUuvz] [-I length] [-i interval] [-O length]\n"
"usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n"
#endif
"\t [-P proxy_username] [-p source_port] [-s source_ip_address] [-T ToS]\n"
"\t [-V fib] [-w timeout] [-X proxy_protocol]\n"