svn commit: r281523 - user/ngie/more-tests/tests/sys/socket
Garrett Cooper
ngie at FreeBSD.org
Tue Apr 14 10:20:03 UTC 2015
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
More information about the svn-src-user
mailing list