Vendor import from OpenBSD 5.1.

This commit is contained in:
Xin LI 2012-10-22 18:47:59 +00:00
parent 4e1e6f2641
commit 0537a01239
3 changed files with 59 additions and 22 deletions

8
nc.1
View File

@ -1,4 +1,4 @@
.\" $OpenBSD: nc.1,v 1.60 2012/02/07 12:11:43 lum Exp $ .\" $OpenBSD: nc.1,v 1.61 2012/07/07 15:33:02 haesbaert Exp $
.\" .\"
.\" Copyright (c) 1996 David Sacerdote .\" Copyright (c) 1996 David Sacerdote
.\" All rights reserved. .\" All rights reserved.
@ -25,7 +25,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd $Mdocdate: October 4 2011 $ .Dd $Mdocdate: February 7 2012 $
.Dt NC 1 .Dt NC 1
.Os .Os
.Sh NAME .Sh NAME
@ -119,6 +119,10 @@ is completed.
It is an error to use this option without the It is an error to use this option without the
.Fl l .Fl l
option. option.
When used together with the
.Fl u
option, the server socket is not connected and it can receive UDP datagrams from
multiple hosts.
.It Fl l .It Fl l
Used to specify that Used to specify that
.Nm .Nm

View File

@ -1,4 +1,4 @@
/* $OpenBSD: netcat.c,v 1.105 2012/02/09 06:25:35 lum Exp $ */ /* $OpenBSD: netcat.c,v 1.109 2012/07/07 15:33:02 haesbaert Exp $ */
/* /*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org> * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
* *
@ -67,7 +67,6 @@
/* Command Line Options */ /* Command Line Options */
int dflag; /* detached, no stdin */ int dflag; /* detached, no stdin */
unsigned int iflag; /* Interval Flag */ unsigned int iflag; /* Interval Flag */
int jflag; /* use jumbo frames if we can */
int kflag; /* More than one connect */ int kflag; /* More than one connect */
int lflag; /* Bind to local port */ int lflag; /* Bind to local port */
int nflag; /* Don't do name look up */ int nflag; /* Don't do name look up */
@ -107,6 +106,7 @@ int unix_connect(char *);
int unix_listen(char *); int unix_listen(char *);
void set_common_sockopts(int); void set_common_sockopts(int);
int map_tos(char *, int *); int map_tos(char *, int *);
void report_connect(const struct sockaddr *, socklen_t);
void usage(int); void usage(int);
int int
@ -131,7 +131,7 @@ main(int argc, char *argv[])
sv = NULL; sv = NULL;
while ((ch = getopt(argc, argv, while ((ch = getopt(argc, argv,
"46DdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) { "46DdhI:i:klnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) {
switch (ch) { switch (ch) {
case '4': case '4':
family = AF_INET; family = AF_INET;
@ -163,9 +163,6 @@ main(int argc, char *argv[])
if (errstr) if (errstr)
errx(1, "interval %s: %s", errstr, optarg); errx(1, "interval %s: %s", errstr, optarg);
break; break;
case 'j':
jflag = 1;
break;
case 'k': case 'k':
kflag = 1; kflag = 1;
break; break;
@ -348,17 +345,23 @@ main(int argc, char *argv[])
if (s < 0) if (s < 0)
err(1, NULL); err(1, NULL);
/* /*
* For UDP, we will use recvfrom() initially * For UDP and -k, don't connect the socket, let it
* to wait for a caller, then use the regular * receive datagrams from multiple socket pairs.
* functions to talk to the caller.
*/ */
if (uflag) { if (uflag && kflag)
readwrite(s);
/*
* For UDP and not -k, we will use recvfrom() initially
* to wait for a caller, then use the regular functions
* to talk to the caller.
*/
else if (uflag && !kflag) {
int rv, plen; int rv, plen;
char buf[16384]; char buf[16384];
struct sockaddr_storage z; struct sockaddr_storage z;
len = sizeof(z); len = sizeof(z);
plen = jflag ? 16384 : 2048; plen = 2048;
rv = recvfrom(s, buf, plen, MSG_PEEK, rv = recvfrom(s, buf, plen, MSG_PEEK,
(struct sockaddr *)&z, &len); (struct sockaddr *)&z, &len);
if (rv < 0) if (rv < 0)
@ -368,11 +371,20 @@ main(int argc, char *argv[])
if (rv < 0) if (rv < 0)
err(1, "connect"); err(1, "connect");
if (vflag)
report_connect((struct sockaddr *)&z, len);
readwrite(s); readwrite(s);
} else { } else {
len = sizeof(cliaddr); len = sizeof(cliaddr);
connfd = accept(s, (struct sockaddr *)&cliaddr, connfd = accept(s, (struct sockaddr *)&cliaddr,
&len); &len);
if (connfd == -1)
err(1, "accept");
if (vflag)
report_connect((struct sockaddr *)&cliaddr, len);
readwrite(connfd); readwrite(connfd);
close(connfd); close(connfd);
} }
@ -717,7 +729,7 @@ readwrite(int nfd)
int lfd = fileno(stdout); int lfd = fileno(stdout);
int plen; int plen;
plen = jflag ? 16384 : 2048; plen = 2048;
/* Setup Network FD */ /* Setup Network FD */
pfd[0].fd = nfd; pfd[0].fd = nfd;
@ -896,11 +908,6 @@ set_common_sockopts(int s)
&x, sizeof(x)) == -1) &x, sizeof(x)) == -1)
err(1, NULL); err(1, NULL);
} }
if (jflag) {
if (setsockopt(s, SOL_SOCKET, SO_JUMBO,
&x, sizeof(x)) == -1)
err(1, NULL);
}
if (Tflag != -1) { if (Tflag != -1) {
if (setsockopt(s, IPPROTO_IP, IP_TOS, if (setsockopt(s, IPPROTO_IP, IP_TOS,
&Tflag, sizeof(Tflag)) == -1) &Tflag, sizeof(Tflag)) == -1)
@ -966,6 +973,32 @@ map_tos(char *s, int *val)
return (0); return (0);
} }
void
report_connect(const struct sockaddr *sa, socklen_t salen)
{
char remote_host[NI_MAXHOST];
char remote_port[NI_MAXSERV];
int herr;
int flags = NI_NUMERICSERV;
if (nflag)
flags |= NI_NUMERICHOST;
if ((herr = getnameinfo(sa, salen,
remote_host, sizeof(remote_host),
remote_port, sizeof(remote_port),
flags)) != 0) {
if (herr == EAI_SYSTEM)
err(1, "getnameinfo");
else
errx(1, "getnameinfo: %s", gai_strerror(herr));
}
fprintf(stderr,
"Connection from %s %s "
"received!\n", remote_host, remote_port);
}
void void
help(void) help(void)
{ {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: socks.c,v 1.19 2011/02/12 15:54:18 okan Exp $ */ /* $OpenBSD: socks.c,v 1.20 2012/03/08 09:56:28 espie Exp $ */
/* /*
* Copyright (c) 1999 Niklas Hallqvist. All rights reserved. * Copyright (c) 1999 Niklas Hallqvist. All rights reserved.
@ -231,12 +231,12 @@ socks_connect(const char *host, const char *port,
case SOCKS_IPV4: case SOCKS_IPV4:
cnt = atomicio(read, proxyfd, buf + 4, 6); cnt = atomicio(read, proxyfd, buf + 4, 6);
if (cnt != 6) if (cnt != 6)
err(1, "read failed (%d/6)", cnt); err(1, "read failed (%zu/6)", cnt);
break; break;
case SOCKS_IPV6: case SOCKS_IPV6:
cnt = atomicio(read, proxyfd, buf + 4, 18); cnt = atomicio(read, proxyfd, buf + 4, 18);
if (cnt != 18) if (cnt != 18)
err(1, "read failed (%d/18)", cnt); err(1, "read failed (%zu/18)", cnt);
break; break;
default: default:
errx(1, "connection failed, unsupported address type"); errx(1, "connection failed, unsupported address type");