Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Mar 2012 11:25:54 +0000 (UTC)
From:      Gavin Atkinson <gavin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r232779 - head/contrib/tnftp/src
Message-ID:  <201203101125.q2ABPsX4054317@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gavin
Date: Sat Mar 10 11:25:53 2012
New Revision: 232779
URL: http://svn.freebsd.org/changeset/base/232779

Log:
  Move determination of socket buffer sizes from startup to the first time a
  socket is used.  The previous code structure assumed that AF_INET sockets
  were always available, which is an invalid assumption on IPv6-only systems.
  
  This merges the fololowing revisions from NetBSD:
  src/usr.bin/ftp/main.c 1.120
  src/usr.bin/ftp/util.c 1.156
  
  PR:		bin/162661
  Tested by:	bz
  Obtained from:	NetBSD
  MFC after:	1 week

Modified:
  head/contrib/tnftp/src/main.c
  head/contrib/tnftp/src/util.c

Modified: head/contrib/tnftp/src/main.c
==============================================================================
--- head/contrib/tnftp/src/main.c	Sat Mar 10 10:54:52 2012	(r232778)
+++ head/contrib/tnftp/src/main.c	Sat Mar 10 11:25:53 2012	(r232779)
@@ -146,9 +146,8 @@ main(int volatile argc, char **volatile 
 	struct passwd *pw;
 	char *cp, *ep, *anonpass, *upload_path, *src_addr;
 	const char *anonuser;
-	int dumbterm, s, isupload;
+	int dumbterm, isupload;
 	size_t len;
-	socklen_t slen;
 
 	tzset();
 #if 0	/* tnftp */	/* XXX */
@@ -213,35 +212,6 @@ main(int volatile argc, char **volatile 
 	if (cp != NULL && strlcpy(netrc, cp, sizeof(netrc)) >= sizeof(netrc))
 		errx(1, "$NETRC `%s': %s", cp, strerror(ENAMETOOLONG));
 
-	/*
-	 * Get the default socket buffer sizes if we don't already have them.
-	 * It doesn't matter which socket we do this to, because on the first
-	 * call no socket buffer sizes will have been modified, so we are
-	 * guaranteed to get the system defaults.
-	 */
-	s = socket(AF_INET, SOCK_STREAM, 0);
-	if (s == -1)
-		err(1, "Can't create socket to determine default socket sizes");
-	slen = sizeof(rcvbuf_size);
-	if (getsockopt(s, SOL_SOCKET, SO_RCVBUF,
-	    (void *)&rcvbuf_size, &slen) == -1)
-		err(1, "Unable to get default rcvbuf size");
-	slen = sizeof(sndbuf_size);
-	if (getsockopt(s, SOL_SOCKET, SO_SNDBUF,
-	    (void *)&sndbuf_size, &slen) == -1)
-		err(1, "Unable to get default sndbuf size");
-	(void)close(s);
-					/* sanity check returned buffer sizes */
-	if (rcvbuf_size <= 0)
-		rcvbuf_size = 8 * 1024;
-	if (sndbuf_size <= 0)
-		sndbuf_size = 8 * 1024;
-
-	if (sndbuf_size > 8 * 1024 * 1024)
-		sndbuf_size = 8 * 1024 * 1024;
-	if (rcvbuf_size > 8 * 1024 * 1024)
-		rcvbuf_size = 8 * 1024 * 1024;
-
 	marg_sl = ftp_sl_init();
 	if ((tmpdir = getenv("TMPDIR")) == NULL)
 		tmpdir = _PATH_TMP;

Modified: head/contrib/tnftp/src/util.c
==============================================================================
--- head/contrib/tnftp/src/util.c	Sat Mar 10 10:54:52 2012	(r232778)
+++ head/contrib/tnftp/src/util.c	Sat Mar 10 11:25:53 2012	(r232779)
@@ -1060,6 +1060,32 @@ strsuftoi(const char *arg)
 void
 setupsockbufsize(int sock)
 {
+	socklen_t slen;
+
+	if (0 == rcvbuf_size) {
+		slen = sizeof(rcvbuf_size);
+		if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF,
+		    (void *)&rcvbuf_size, &slen) == -1)
+			err(1, "Unable to determine rcvbuf size");
+		if (rcvbuf_size <= 0)
+			rcvbuf_size = 8 * 1024;
+		if (rcvbuf_size > 8 * 1024 * 1024)
+			rcvbuf_size = 8 * 1024 * 1024;
+		DPRINTF("setupsockbufsize: rcvbuf_size determined as %d\n",
+		    rcvbuf_size);
+	}
+	if (0 == sndbuf_size) {
+		slen = sizeof(sndbuf_size);
+		if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF,
+		    (void *)&sndbuf_size, &slen) == -1)
+			err(1, "Unable to determine sndbuf size");
+		if (sndbuf_size <= 0)
+			sndbuf_size = 8 * 1024;
+		if (sndbuf_size > 8 * 1024 * 1024)
+			sndbuf_size = 8 * 1024 * 1024;
+		DPRINTF("setupsockbufsize: sndbuf_size determined as %d\n",
+		    sndbuf_size);
+	}
 
 	if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
 	    (void *)&sndbuf_size, sizeof(sndbuf_size)) == -1)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203101125.q2ABPsX4054317>