FreeBSD Bugzilla – Attachment 54612 Details for
Bug 82625
[PATCH] Enhancement to ping to ping through
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
ping.c.diff
ping.c.diff (text/plain; charset=us-ascii), 6.81 KB, created by
Chris Hellberg
on 2005-06-25 00:06:17 UTC
(
hide
)
Description:
ping.c.diff
Filename:
MIME Type:
Creator:
Chris Hellberg
Created:
2005-06-25 00:06:17 UTC
Size:
6.81 KB
patch
obsolete
>--- src/sbin/ping/ping.c 2004-09-30 03:35:56.000000000 -0400 >+++ ping.c 2005-06-24 18:13:31.000000000 -0400 >@@ -42,7 +42,7 @@ > #endif /* not lint */ > #endif > #include <sys/cdefs.h> >-__FBSDID("$FreeBSD: src/sbin/ping/ping.c,v 1.106 2004/09/30 07:35:56 maxim Exp $"); >+__FBSDID("$FreeBSD: src/sbin/ping/ping.c,v 1.105 2004/08/14 17:46:10 stefanf Exp $"); > > /* > * P I N G . C >@@ -111,8 +111,8 @@ > #define TST(bit) (A(bit) & B(bit)) > > struct tv32 { >- int32_t tv32_sec; >- int32_t tv32_usec; >+ int32_t tv32_sec; >+ int32_t tv32_usec; > }; > > /* various options */ >@@ -142,6 +142,7 @@ > #define F_HDRINCL 0x40000 > #define F_MASK 0x80000 > #define F_TIME 0x100000 >+#define F_SWEEP 0x200000 > > /* > * MAX_DUP_CHK is the number of bits in received table, i.e. the maximum >@@ -175,8 +176,12 @@ > long nreceived; /* # of packets we got back */ > long nrepeats; /* number of duplicates */ > long ntransmitted; /* sequence # for outbound packets = #sent */ >+int sweepmax; >+int sweepmin = 0; >+int sweepincr = 1; > int interval = 1000; /* interval between packets, ms */ > >+ > /* timing */ > int timing; /* flag to do timing */ > double tmin = 999999999.0; /* minimum round trip time */ >@@ -226,7 +231,7 @@ > double t; > u_long alarmtimeout, ultmp; > int almost_done, ch, df, hold, i, icmp_len, mib[4], preload, sockerrno, >- tos, ttl; >+ tos, ttl, ninsweep=0, totpackets; > char ctrl[CMSG_SPACE(sizeof(struct timeval))]; > char hnamebuf[MAXHOSTNAMELEN], snamebuf[MAXHOSTNAMELEN]; > #ifdef IP_OPTIONS >@@ -254,7 +259,7 @@ > > outpack = outpackhdr + sizeof(struct ip); > while ((ch = getopt(argc, argv, >- "Aac:DdfI:i:Ll:M:m:nop:QqRrS:s:T:t:vz:" >+ "Aac:DdfI:i:g:G:h:Ll:M:m:nop:QqRrS:s:T:t:vz:" > #ifdef IPSEC > #ifdef IPSEC_POLICY_IPSEC > "P:" >@@ -292,6 +297,48 @@ > options |= F_FLOOD; > setbuf(stdout, (char *)NULL); > break; >+ case 'g': /* Minimum packet size for ping sweep */ >+ ultmp = strtoul(optarg, &ep, 0); >+ if (*ep || ep == optarg) >+ errx(EX_USAGE, "invalid packet size: `%s'", >+ optarg); >+ if (uid != 0 && ultmp > DEFDATALEN) { >+ errno = EPERM; >+ err(EX_NOPERM, >+ "packet size too large: %lu > %u", >+ ultmp, DEFDATALEN); >+ } >+ options |= F_SWEEP; >+ sweepmin = ultmp; >+ break; >+ case 'G': /* Maximum packet size for ping sweep */ >+ ultmp = strtoul(optarg, &ep, 0); >+ if (*ep || ep == optarg) >+ errx(EX_USAGE, "invalid packet size: `%s'", >+ optarg); >+ if (uid != 0 && ultmp > DEFDATALEN) { >+ errno = EPERM; >+ err(EX_NOPERM, >+ "packet size too large: %lu > %u", >+ ultmp, DEFDATALEN); >+ } >+ options |= F_SWEEP; >+ sweepmax = ultmp; >+ break; >+ case 'h': /* Packet size increment for ping sweep */ >+ ultmp = strtoul(optarg, &ep, 0); >+ if (*ep || ep == optarg) >+ errx(EX_USAGE, "invalid packet size: `%s'", >+ optarg); >+ if (uid != 0 && ultmp > DEFDATALEN) { >+ errno = EPERM; >+ err(EX_NOPERM, >+ "packet size too large: %lu > %u", >+ ultmp, DEFDATALEN); >+ } >+ options |= F_SWEEP; >+ sweepincr = ultmp; >+ break; > case 'I': /* multicast interface */ > if (inet_aton(optarg, &ifaddr) == 0) > errx(EX_USAGE, >@@ -643,6 +690,21 @@ > err(EX_OSERR, "setsockopt SO_TIMESTAMP"); > } > #endif >+ if (sweepmax) { >+ if (sweepmin >= sweepmax) >+ errx(EX_USAGE,"Maximum packet size must be greater than the minimum packet size"); >+ >+ if (datalen != DEFDATALEN) >+ errx(EX_USAGE,"Packet size and ping sweep are mutually exclusive"); >+ >+ if (!npackets) >+ npackets = 1; >+ totpackets = npackets * (1+(sweepmax-sweepmin)/sweepincr); >+ datalen = sweepmin; >+ send_len = icmp_len + sweepmin; >+ } >+ if (options & F_SWEEP && !sweepmax) >+ errx(EX_USAGE, "Maximum sweep size must be specified"); > > /* > * When pinging the broadcast address, you can get a lot of answers. >@@ -668,9 +730,19 @@ > inet_ntoa(to->sin_addr)); > if (source) > (void)printf(" from %s", shostname); >- (void)printf(": %d data bytes\n", datalen); >- } else >- (void)printf("PING %s: %d data bytes\n", hostname, datalen); >+ if (sweepmax) { >+ (void)printf(": (%d...%d) data bytes\n", sweepmin,sweepmax); >+ } else >+ (void)printf(": %d data bytes\n", datalen); >+ >+ } else { >+ if (sweepmax) { >+ (void)printf("PING %s: (%d...%d) data bytes\n", hostname, sweepmin,sweepmax); >+ >+ } else { >+ (void)printf("PING %s: %d data bytes\n", hostname, datalen); >+ } >+ } > > /* > * Use sigaction() instead of signal() to get unambiguous semantics, >@@ -706,9 +778,10 @@ > iov.iov_base = packet; > iov.iov_len = IP_MAXPACKET; > >- if (preload == 0) >+ if (preload == 0) { > pinger(); /* send the first ping */ >- else { >+ ninsweep++; >+ } else { > if (npackets != 0 && preload > npackets) > preload = npackets; > while (preload--) /* fire off them quickies */ >@@ -729,7 +802,6 @@ > struct timeval now, timeout; > fd_set rfds; > int cc, n; >- > check_status(); > if ((unsigned)s >= FD_SETSIZE) > errx(EX_OSERR, "descriptor too large"); >@@ -779,14 +851,24 @@ > tv = &now; > } > pr_pack((char *)packet, cc, &from, tv); >- if ((options & F_ONCE && nreceived) || >- (npackets && nreceived >= npackets)) >- break; >+ if ((options & F_ONCE && nreceived) || >+ (totpackets && ntransmitted >= totpackets)) >+ break; >+ > } >+ > if (n == 0 || options & F_FLOOD) { >- if (!npackets || ntransmitted < npackets) >+ if (totpackets && ninsweep == npackets) { >+ for (i = 0; i < sweepincr ; ++i) >+ *datap++ = i; >+ datalen = datalen+sweepincr; >+ send_len = icmp_len + datalen; >+ ninsweep = 0; >+ } >+ if (!npackets || ntransmitted < totpackets) { > pinger(); >- else { >+ ninsweep++; >+ } else { > if (almost_done) > break; > almost_done = 1; >@@ -805,7 +887,7 @@ > (void)write(STDOUT_FILENO, &BBELL, 1); > } > } >- } >+ } > finish(); > /* NOTREACHED */ > exit(0); /* Make the compiler happy */ >@@ -1600,12 +1682,14 @@ > usage() > { > >- (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", >+ (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", > "usage: ping [-AaDdfnoQqRrv] [-c count] [-i wait] [-l preload] [-M mask | time]", > " [-m ttl]" SECOPT " [-p pattern] [-S src_addr] [-s packetsize]", >-" [-t timeout] [-z tos] host", >-" ping [-AaDdfLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]", >-" [-M mask | time] [-m ttl]" SECOPT " [-p pattern] [-S src_addr]", >-" [-s packetsize] [-T ttl] [-t timeout] [-z tos] mcast-group"); >+" [-t timeout] [-z tos] host [ -G sweepmaxsize ] [ -g sweepminsize ]", >+" [ -h sweepincrsize ] ", >+" ping [-AaDdfLnoQqRrv] [-c count] [-i wait] [-I iface] [-l preload]", >+" [-M mask | time] [-m ttl]" SECOPT " [-p pattern] ", >+" [-S src_addr] [-s packetsize] [-T ttl] [-t timeout] ", >+" [-z tos] mcast-group "); > exit(EX_USAGE); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 82625
:
54611
| 54612
Working