From 02af88335e19f307ad39131753559142a14ad3d3 Mon Sep 17 00:00:00 2001 From: bms Date: Tue, 13 Mar 2007 23:36:48 +0000 Subject: [PATCH] Add raw IP support (protocol 114) to ipbroadcast regression test. --- .../netinet/ipbroadcast/ipbroadcast.c | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/regression/netinet/ipbroadcast/ipbroadcast.c b/tools/regression/netinet/ipbroadcast/ipbroadcast.c index 2cfa36f1df63..8d6f2479aabf 100644 --- a/tools/regression/netinet/ipbroadcast/ipbroadcast.c +++ b/tools/regression/netinet/ipbroadcast/ipbroadcast.c @@ -60,6 +60,10 @@ __FBSDID("$FreeBSD$"); #define IP_SENDIF 24 /* XXX */ #endif +#ifndef IPPROTO_ZEROHOP +#define IPPROTO_ZEROHOP 114 /* any 0-hop protocol */ +#endif + #define DEFAULT_PORT 6698 #define DEFAULT_PAYLOAD_SIZE 24 #define DEFAULT_TTL 1 @@ -78,7 +82,7 @@ usage(void) "datagram to :.\n\n", DEFAULT_PAYLOAD_SIZE); fprintf(stderr, "usage: %s [-1] [-A laddr] [-b] [-B] [-d] [-i iface] [-l len]\n" -" [-p port] [-r] [-s srcaddr] [-t ttl] \n", +" [-p port] [-R] [-s srcaddr] [-t ttl] \n", progname); fprintf(stderr, "-1: Set IP_ONESBCAST\n"); fprintf(stderr, "-A: specify laddr (default: INADDR_ANY)\n"); @@ -89,6 +93,7 @@ usage(void) fprintf(stderr, "-l: Set payload size to \n"); fprintf(stderr, "-p: Set local and remote port (default: %d)\n", DEFAULT_PORT); + fprintf(stderr, "-R: Use raw IP (protocol %d)\n", IPPROTO_ZEROHOP); #if 0 fprintf(stderr, "-r: Fill datagram with random bytes\n"); #endif @@ -120,6 +125,7 @@ main(int argc, char *argv[]) int dontroute; int doonesbcast; int dorandom; + int dorawip; size_t buflen; ssize_t nbytes; int portno; @@ -134,6 +140,7 @@ main(int argc, char *argv[]) dontroute = 0; doonesbcast = 0; dorandom = 0; + dorawip = 0; ifname = NULL; dstaddr.s_addr = INADDR_ANY; @@ -146,7 +153,7 @@ main(int argc, char *argv[]) buflen = DEFAULT_PAYLOAD_SIZE; progname = basename(argv[0]); - while ((ch = getopt(argc, argv, "1A:bBdi:l:p:rs:t:")) != -1) { + while ((ch = getopt(argc, argv, "1A:bBdi:l:p:Rrs:t:")) != -1) { switch (ch) { case '1': doonesbcast = 1; @@ -172,6 +179,9 @@ main(int argc, char *argv[]) case 'p': portno = atoi(optarg); break; + case 'R': + dorawip = 1; + break; case 'r': dorandom = 1; break; @@ -196,7 +206,13 @@ main(int argc, char *argv[]) /* IP_SENDSRCADDR and IP_SENDIF are mutually exclusive just now. */ if (srcaddr_s != NULL && ifname != NULL) usage(); - s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (dorawip) { + if (geteuid() != 0) + fprintf(stderr, "WARNING: not running as root.\n"); + s = socket(PF_INET, SOCK_RAW, IPPROTO_ZEROHOP); + } else { + s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); + } if (s == -1) { perror("socket"); exit(EXIT_FAILURE);