From owner-p4-projects@FreeBSD.ORG Fri Aug 5 23:02:02 2011 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 88F3F1065672; Fri, 5 Aug 2011 23:02:02 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 33528106564A for ; Fri, 5 Aug 2011 23:02:02 +0000 (UTC) (envelope-from cnicutar@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 203268FC0C for ; Fri, 5 Aug 2011 23:02:02 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id p75N22Y0059135 for ; Fri, 5 Aug 2011 23:02:02 GMT (envelope-from cnicutar@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id p75N214J059132 for perforce@freebsd.org; Fri, 5 Aug 2011 23:02:02 GMT (envelope-from cnicutar@freebsd.org) Date: Fri, 5 Aug 2011 23:02:02 GMT Message-Id: <201108052302.p75N214J059132@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to cnicutar@freebsd.org using -f From: Catalin Nicutar To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 197243 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Aug 2011 23:02:02 -0000 http://p4web.freebsd.org/@@197243?ac=10 Change 197243 by cnicutar@cnicutar_cronos on 2011/08/05 23:01:13 Forward-port netcat UTO support to HEAD. Affected files ... .. //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/netcat/nc.1#2 edit .. //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/netcat/netcat.c#2 edit Differences ... ==== //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/netcat/nc.1#2 (text+ko) ==== @@ -27,7 +27,7 @@ .\" .\" $FreeBSD: src/contrib/netcat/nc.1,v 1.21 2011/05/11 21:52:26 delphij Exp $ .\" -.Dd January 8, 2011 +.Dd July 19, 2011 .Dt NC 1 .Os .Sh NAME @@ -175,6 +175,9 @@ Specifies that source and/or destination ports should be chosen randomly instead of sequentially within a range or in the order that the system assigns them. +.It Fl -rcv-uto +Specifies that the UTO value sent by the peer should be accepted when TCP +computes the local User Timeout. .It Fl S Enables the RFC 2385 TCP MD5 signature option. .It Fl s Ar source @@ -240,6 +243,9 @@ .Fl w flag. The default is no timeout. +.Tf +This timeout also controls the User Timeout advertised to the peer by +TCP. .It Fl X Ar proxy_protocol Requests that .Nm ==== //depot/projects/soc2011/cnicutar_tcputo_9/src/contrib/netcat/netcat.c#2 (text+ko) ==== @@ -83,6 +83,7 @@ char *Pflag; /* Proxy username */ char *pflag; /* Localport flag */ int rflag; /* Random ports flag */ +int utoflag; /* Accept peer UTO. */ char *sflag; /* Source Address */ int tflag; /* Telnet Emulation */ int uflag; /* UDP - Default to TCP */ @@ -140,6 +141,7 @@ char unix_dg_tmp_socket_buf[UNIX_DG_TMP_SOCKET_SIZE]; struct option longopts[] = { { "no-tcpopt", no_argument, &FreeBSD_Oflag, 1 }, + { "rcv-uto", no_argument, &utoflag, 1 }, { NULL, 0, NULL, 0 } }; @@ -250,7 +252,6 @@ timeout = strtonum(optarg, 0, INT_MAX / 1000, &errstr); if (errstr) errx(1, "timeout %s: %s", errstr, optarg); - timeout *= 1000; break; case 'x': xflag = 1; @@ -283,6 +284,9 @@ case 'T': Tflag = parse_iptos(optarg); break; + case 0: + /* getopt_long returns 0 for --long-options. */ + break; default: usage(1); } @@ -742,7 +746,7 @@ if (iflag) sleep(iflag); - if ((n = poll(pfd, 2 - dflag, timeout)) < 0) { + if ((n = poll(pfd, 2 - dflag, timeout * 1000)) < 0) { close(nfd); err(1, "Polling Error"); } @@ -938,6 +942,19 @@ &FreeBSD_Oflag, sizeof(FreeBSD_Oflag)) == -1) err(1, "disable TCP options"); } + /* + * Try to set the sent timeout but don't die on error. The timeout + * option was here before UTO so this would break existing + * applications on systems where UTO is disabled. + */ + if (timeout > 0 && setsockopt(s, IPPROTO_TCP, TCP_SNDUTO_TIMEOUT, + &timeout, sizeof(timeout))) + perror("setsokopt send TCP UTO"); + + /* Set the disposition to accept the timeout of the peer. */ + if (utoflag && setsockopt(s, IPPROTO_TCP, TCP_RCVUTO_TIMEOUT, + &utoflag, sizeof(utoflag))) + err(1, "setsokopt receive TCP UTO"); } int @@ -983,6 +1000,7 @@ \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\ + \t--rcv-uto Accept peer User Timeout\n\ \t-S Enable the TCP MD5 signature option\n\ \t-s addr\t Local source address\n\ \t-T ToS\t Set IP Type of Service\n\