Date: Tue, 14 Apr 2015 10:20:02 +0000 (UTC) From: Garrett Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r281523 - user/ngie/more-tests/tests/sys/socket Message-ID: <201504141020.t3EAK2Yb091874@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Tue Apr 14 10:20:02 2015 New Revision: 281523 URL: https://svnweb.freebsd.org/changeset/base/281523 Log: Pick a random port if a specific one isn't provided on the command line Modified: user/ngie/more-tests/tests/sys/socket/sigpipe_test.c Modified: user/ngie/more-tests/tests/sys/socket/sigpipe_test.c ============================================================================== --- user/ngie/more-tests/tests/sys/socket/sigpipe_test.c Tue Apr 14 10:15:58 2015 (r281522) +++ user/ngie/more-tests/tests/sys/socket/sigpipe_test.c Tue Apr 14 10:20:02 2015 (r281523) @@ -26,6 +26,7 @@ * $FreeBSD$ */ +#include <sys/param.h> #include <sys/types.h> #include <sys/socket.h> @@ -54,7 +55,7 @@ static void usage(void) { - errx(-1, "usage: sigpipe tcpport"); + errx(-1, "usage: sigpipe [tcpport]"); } /* @@ -254,11 +255,16 @@ main(int argc, char *argv[]) int sock[2]; long port; - if (argc != 2) - usage(); + if (argc == 1) { + srandomdev(); - port = strtol(argv[1], &dummy, 10); - if (port < 0 || port > 65535 || *dummy != '\0') + /* Pick a random unprivileged port 1025-65535 */ + port = MAX((int)random() % 65535, 1025); + } else if (argc == 2) { + port = strtol(argv[1], &dummy, 10); + if (port < 0 || port > 65535 || *dummy != '\0') + usage(); + } else usage(); #ifndef SO_NOSIGPIPE
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201504141020.t3EAK2Yb091874>