summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2012-10-22 18:56:31 +0000
committerdelphij <delphij@FreeBSD.org>2012-10-22 18:56:31 +0000
commit79f289a888cc90ade3ab05d0211600ba13c0eab4 (patch)
treeee4d0ac497cf034719d5d70d7afef7125393f925 /contrib
parent708d8e446e991358da23bb52ec5320440221f12f (diff)
downloadFreeBSD-src-79f289a888cc90ade3ab05d0211600ba13c0eab4.zip
FreeBSD-src-79f289a888cc90ade3ab05d0211600ba13c0eab4.tar.gz
MFV: netcat from OpenBSD 5.2.
MFC after: 1 month
Diffstat (limited to 'contrib')
-rw-r--r--contrib/netcat/FREEBSD-vendor2
-rw-r--r--contrib/netcat/nc.18
-rw-r--r--contrib/netcat/netcat.c71
-rw-r--r--contrib/netcat/socks.c6
4 files changed, 60 insertions, 27 deletions
diff --git a/contrib/netcat/FREEBSD-vendor b/contrib/netcat/FREEBSD-vendor
index 3f3aaed..8d112fd 100644
--- a/contrib/netcat/FREEBSD-vendor
+++ b/contrib/netcat/FREEBSD-vendor
@@ -1,5 +1,5 @@
# $FreeBSD$
Project: netcat (aka src/usr.bin/nc in OpenBSD)
ProjectURL: http://www.openbsd.org/
-Version: 5.1
+Version: 5.2
License: BSD
diff --git a/contrib/netcat/nc.1 b/contrib/netcat/nc.1
index eb8cd9f..62eca47 100644
--- a/contrib/netcat/nc.1
+++ b/contrib/netcat/nc.1
@@ -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
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd October 4, 2011
+.Dd February 7, 2012
.Dt NC 1
.Os
.Sh NAME
@@ -137,6 +137,10 @@ is completed.
It is an error to use this option without the
.Fl l
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
Used to specify that
.Nm
diff --git a/contrib/netcat/netcat.c b/contrib/netcat/netcat.c
index d6d507c..a062162 100644
--- a/contrib/netcat/netcat.c
+++ b/contrib/netcat/netcat.c
@@ -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>
*
@@ -75,7 +75,6 @@
/* Command Line Options */
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 */
@@ -116,6 +115,7 @@ int unix_connect(char *);
int unix_listen(char *);
void set_common_sockopts(int);
int map_tos(char *, int *);
+void report_connect(const struct sockaddr *, socklen_t);
void usage(int);
#ifdef IPSEC
@@ -153,7 +153,7 @@ main(int argc, char *argv[])
sv = NULL;
while ((ch = getopt_long(argc, argv,
- "46DdEe:hI:i:jklnoO:P:p:rSs:tT:UuV:vw:X:x:z",
+ "46DdEe:hI:i:klnoO:P:p:rSs:tT:UuV:vw:X:x:z",
longopts, NULL)) != -1) {
switch (ch) {
case '4':
@@ -201,11 +201,6 @@ main(int argc, char *argv[])
if (errstr)
errx(1, "interval %s: %s", errstr, optarg);
break;
-#ifdef SO_JUMBO
- case 'j':
- jflag = 1;
- break;
-#endif
case 'k':
kflag = 1;
break;
@@ -395,17 +390,23 @@ main(int argc, char *argv[])
if (s < 0)
err(1, NULL);
/*
- * For UDP, we will use recvfrom() initially
- * to wait for a caller, then use the regular
- * functions to talk to the caller.
+ * For UDP and -k, don't connect the socket, let it
+ * receive datagrams from multiple socket pairs.
+ */
+ 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.
*/
- if (uflag) {
+ else if (uflag && !kflag) {
int rv, plen;
char buf[16384];
struct sockaddr_storage z;
len = sizeof(z);
- plen = jflag ? 16384 : 2048;
+ plen = 2048;
rv = recvfrom(s, buf, plen, MSG_PEEK,
(struct sockaddr *)&z, &len);
if (rv < 0)
@@ -415,11 +416,20 @@ main(int argc, char *argv[])
if (rv < 0)
err(1, "connect");
+ if (vflag)
+ report_connect((struct sockaddr *)&z, len);
+
readwrite(s);
} else {
len = sizeof(cliaddr);
connfd = accept(s, (struct sockaddr *)&cliaddr,
&len);
+ if (connfd == -1)
+ err(1, "accept");
+
+ if (vflag)
+ report_connect((struct sockaddr *)&cliaddr, len);
+
readwrite(connfd);
close(connfd);
}
@@ -782,7 +792,7 @@ readwrite(int nfd)
int lfd = fileno(stdout);
int plen;
- plen = jflag ? 16384 : 2048;
+ plen = 2048;
/* Setup Network FD */
pfd[0].fd = nfd;
@@ -961,13 +971,6 @@ set_common_sockopts(int s)
&x, sizeof(x)) == -1)
err(1, NULL);
}
-#ifdef SO_JUMBO
- if (jflag) {
- if (setsockopt(s, SOL_SOCKET, SO_JUMBO,
- &x, sizeof(x)) == -1)
- err(1, NULL);
- }
-#endif
if (Tflag != -1) {
if (setsockopt(s, IPPROTO_IP, IP_TOS,
&Tflag, sizeof(Tflag)) == -1)
@@ -1039,6 +1042,32 @@ map_tos(char *s, int *val)
}
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
help(void)
{
usage(0);
diff --git a/contrib/netcat/socks.c b/contrib/netcat/socks.c
index cb31a3c..f8adda4 100644
--- a/contrib/netcat/socks.c
+++ b/contrib/netcat/socks.c
@@ -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.
@@ -231,12 +231,12 @@ socks_connect(const char *host, const char *port,
case SOCKS_IPV4:
cnt = atomicio(read, proxyfd, buf + 4, 6);
if (cnt != 6)
- err(1, "read failed (%zd/6)", cnt);
+ err(1, "read failed (%zu/6)", cnt);
break;
case SOCKS_IPV6:
cnt = atomicio(read, proxyfd, buf + 4, 18);
if (cnt != 18)
- err(1, "read failed (%zd/18)", cnt);
+ err(1, "read failed (%zu/18)", cnt);
break;
default:
errx(1, "connection failed, unsupported address type");
OpenPOWER on IntegriCloud