diff options
author | Bruce M Simpson <bms@FreeBSD.org> | 2007-03-01 18:36:16 +0000 |
---|---|---|
committer | Bruce M Simpson <bms@FreeBSD.org> | 2007-03-01 18:36:16 +0000 |
commit | df7babd68930c6d8c0855fb20234e7714f286526 (patch) | |
tree | 21812a0b6bc916ad68c6e54f944635e5f0bd423c /tools/regression/netinet/ipbroadcast/ipbroadcast.c | |
parent | a404ab168ebf90e65af1e0b6311f2b4ea8019ca2 (diff) |
Add -t to set IP TTL.
Notes
Notes:
svn path=/head/; revision=167149
Diffstat (limited to 'tools/regression/netinet/ipbroadcast/ipbroadcast.c')
-rw-r--r-- | tools/regression/netinet/ipbroadcast/ipbroadcast.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/tools/regression/netinet/ipbroadcast/ipbroadcast.c b/tools/regression/netinet/ipbroadcast/ipbroadcast.c index d0a2d05bfc4b..d27ad13f5440 100644 --- a/tools/regression/netinet/ipbroadcast/ipbroadcast.c +++ b/tools/regression/netinet/ipbroadcast/ipbroadcast.c @@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$"); #define DEFAULT_PORT 6698 #define DEFAULT_PAYLOAD_SIZE 24 +#define DEFAULT_TTL 1 #define MY_CMSG_SIZE CMSG_SPACE(sizeof(struct in_addr)) static char *progname = NULL; @@ -65,7 +66,7 @@ usage(void) { fprintf(stderr, -"usage: %s [-1] [-b] [-B] [-d] [-l len] [-p port] [-r] [-s srcaddr] \n" +"usage: %s [-1] [-b] [-B] [-d] [-l len] [-p port] [-r] [-s srcaddr] [-t ttl]\n" " <dest>\n", progname); fprintf(stderr, "IPv4 broadcast test program. Sends a %d byte UDP " @@ -77,10 +78,11 @@ usage(void) #if 0 fprintf(stderr, "-r: Fill datagram with random bytes\n"); #endif - fprintf(stderr, "-s: Set IP_SENDSRCADDR to <srcaddr>\n"); fprintf(stderr, "-l: Set payload size to <len>\n"); fprintf(stderr, "-p: Set source and destination port (default: %d)\n", DEFAULT_PORT); + fprintf(stderr, "-s: Set IP_SENDSRCADDR to <srcaddr>\n"); + fprintf(stderr, "-t: Set IP_TTL to <ttl>\n"); exit(EXIT_FAILURE); } @@ -110,6 +112,7 @@ main(int argc, char *argv[]) int s; socklen_t soptlen; int soptval; + int ttl; dobind = 0; dobroadcast = 0; @@ -120,12 +123,13 @@ main(int argc, char *argv[]) dstaddr.s_addr = INADDR_ANY; srcaddr_s = NULL; portno = DEFAULT_PORT; + ttl = DEFAULT_TTL; buf = NULL; buflen = DEFAULT_PAYLOAD_SIZE; progname = basename(argv[0]); - while ((ch = getopt(argc, argv, "1bBdl:p:rs:")) != -1) { + while ((ch = getopt(argc, argv, "1bBdl:p:rs:t:")) != -1) { switch (ch) { case '1': doonesbcast = 1; @@ -151,6 +155,9 @@ main(int argc, char *argv[]) case 's': srcaddr_s = optarg; break; + case 't': + ttl = atoi(optarg); + break; default: usage(); break; @@ -193,6 +200,15 @@ main(int argc, char *argv[]) } } + soptval = ttl; + soptlen = sizeof(soptval); + ret = setsockopt(s, IPPROTO_IP, IP_TTL, &soptval, soptlen); + if (ret == -1) { + perror("setsockopt IPPROTO_IP IP_TTL"); + close(s); + exit(EXIT_FAILURE); + } + if (doonesbcast) { soptval = 1; soptlen = sizeof(soptval); |