From b22fc5713d7905326dc216da00e8cd15f590b1ea Mon Sep 17 00:00:00 2001 From: bms Date: Thu, 1 Mar 2007 18:36:16 +0000 Subject: Add -t to set IP TTL. --- tools/regression/netinet/ipbroadcast/ipbroadcast.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'tools/regression/netinet/ipbroadcast') diff --git a/tools/regression/netinet/ipbroadcast/ipbroadcast.c b/tools/regression/netinet/ipbroadcast/ipbroadcast.c index d0a2d05..d27ad13 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" " \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 \n"); fprintf(stderr, "-l: Set payload size to \n"); fprintf(stderr, "-p: Set source and destination port (default: %d)\n", DEFAULT_PORT); + fprintf(stderr, "-s: Set IP_SENDSRCADDR to \n"); + fprintf(stderr, "-t: Set IP_TTL to \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); -- cgit v1.1