Deleted Added
full compact
ping.c (109733) ping.c (109734)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Mike Muuss.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 31 unchanged lines hidden (view full) ---

40 The Regents of the University of California. All rights reserved.\n";
41#endif /* not lint */
42
43#ifndef lint
44#if 0
45static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
46#endif
47static const char rcsid[] =
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Mike Muuss.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 31 unchanged lines hidden (view full) ---

40 The Regents of the University of California. All rights reserved.\n";
41#endif /* not lint */
42
43#ifndef lint
44#if 0
45static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
46#endif
47static const char rcsid[] =
48 "$FreeBSD: head/sbin/ping/ping.c 109733 2003-01-23 12:56:10Z maxim $";
48 "$FreeBSD: head/sbin/ping/ping.c 109734 2003-01-23 13:04:42Z maxim $";
49#endif /* not lint */
50
51/*
52 * P I N G . C
53 *
54 * Using the Internet Control Message Protocol (ICMP) "ECHO" facility,
55 * measure round-trip-delays and packet loss across network paths.
56 *

--- 42 unchanged lines hidden (view full) ---

99#define INADDR_LEN ((int)sizeof(in_addr_t))
100#define PHDR_LEN ((int)sizeof(struct timeval))
101#define DEFDATALEN (64 - PHDR_LEN) /* default data length */
102#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */
103 /* runs out of buffer space */
104#define MAXIPLEN (sizeof(struct ip) + MAX_IPOPTLEN)
105#define MAXICMPLEN (ICMP_ADVLENMIN + MAX_IPOPTLEN)
106#define MINICMPLEN ICMP_MINLEN
49#endif /* not lint */
50
51/*
52 * P I N G . C
53 *
54 * Using the Internet Control Message Protocol (ICMP) "ECHO" facility,
55 * measure round-trip-delays and packet loss across network paths.
56 *

--- 42 unchanged lines hidden (view full) ---

99#define INADDR_LEN ((int)sizeof(in_addr_t))
100#define PHDR_LEN ((int)sizeof(struct timeval))
101#define DEFDATALEN (64 - PHDR_LEN) /* default data length */
102#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */
103 /* runs out of buffer space */
104#define MAXIPLEN (sizeof(struct ip) + MAX_IPOPTLEN)
105#define MAXICMPLEN (ICMP_ADVLENMIN + MAX_IPOPTLEN)
106#define MINICMPLEN ICMP_MINLEN
107#define MAXPAYLOAD (IP_MAXPACKET - MAXIPLEN - MINICMPLEN)
108#define MAXWAIT 10 /* max seconds to wait for response */
109#define MAXALARM (60 * 60) /* max seconds for alarm timeout */
110#define MAXTOS 255
111
112#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
113#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
114#define SET(bit) (A(bit) |= B(bit))
115#define CLR(bit) (A(bit) &= (~B(bit)))

--- 30 unchanged lines hidden (view full) ---

146 * number of received sequence numbers we can keep track of. Change 128
147 * to 8192 for complete accuracy...
148 */
149#define MAX_DUP_CHK (8 * 128)
150int mx_dup_ck = MAX_DUP_CHK;
151char rcvd_tbl[MAX_DUP_CHK / 8];
152
153struct sockaddr_in whereto; /* who to ping */
107#define MAXWAIT 10 /* max seconds to wait for response */
108#define MAXALARM (60 * 60) /* max seconds for alarm timeout */
109#define MAXTOS 255
110
111#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
112#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
113#define SET(bit) (A(bit) |= B(bit))
114#define CLR(bit) (A(bit) &= (~B(bit)))

--- 30 unchanged lines hidden (view full) ---

145 * number of received sequence numbers we can keep track of. Change 128
146 * to 8192 for complete accuracy...
147 */
148#define MAX_DUP_CHK (8 * 128)
149int mx_dup_ck = MAX_DUP_CHK;
150char rcvd_tbl[MAX_DUP_CHK / 8];
151
152struct sockaddr_in whereto; /* who to ping */
153long maxpayload;
154int datalen = DEFDATALEN;
155int s; /* socket file descriptor */
156u_char outpackhdr[IP_MAXPACKET], *outpack;
157char BBELL = '\a'; /* characters written for MISSED and AUDIBLE */
158char BSPACE = '\b'; /* characters written for flood */
159char DOT = '.';
160char *hostname;
161char *shostname;

--- 184 unchanged lines hidden (view full) ---

346 break;
347 case 'R':
348 options |= F_RROUTE;
349 break;
350 case 'r':
351 options |= F_SO_DONTROUTE;
352 break;
353 case 's': /* size of packet to send */
154int datalen = DEFDATALEN;
155int s; /* socket file descriptor */
156u_char outpackhdr[IP_MAXPACKET], *outpack;
157char BBELL = '\a'; /* characters written for MISSED and AUDIBLE */
158char BSPACE = '\b'; /* characters written for flood */
159char DOT = '.';
160char *hostname;
161char *shostname;

--- 184 unchanged lines hidden (view full) ---

346 break;
347 case 'R':
348 options |= F_RROUTE;
349 break;
350 case 'r':
351 options |= F_SO_DONTROUTE;
352 break;
353 case 's': /* size of packet to send */
354 if (uid) {
355 errno = EPERM;
356 err(EX_NOPERM, "-s flag");
357 }
358 ultmp = strtoul(optarg, &ep, 0);
354 ultmp = strtoul(optarg, &ep, 0);
359 if (ultmp > MAXPAYLOAD)
360 errx(EX_USAGE,
361 "packet size too large: %lu > %u",
362 ultmp, MAXPAYLOAD);
363 if (*ep || ep == optarg)
364 errx(EX_USAGE, "invalid packet size: `%s'",
365 optarg);
355 if (*ep || ep == optarg)
356 errx(EX_USAGE, "invalid packet size: `%s'",
357 optarg);
358 if (uid != 0 && ultmp > DEFDATALEN) {
359 errno = EPERM;
360 err(EX_NOPERM,
361 "packet size too large: %lu > %u",
362 ultmp, DEFDATALEN);
363 }
366 datalen = ultmp;
367 break;
368 case 'S':
369 source = optarg;
370 break;
371 case 't':
372 alarmtimeout = strtoul(optarg, &ep, 0);
373 if ((alarmtimeout < 1) || (alarmtimeout == ULONG_MAX))

--- 39 unchanged lines hidden (view full) ---

413 usage();
414 }
415 }
416
417 if (argc - optind != 1)
418 usage();
419 target = argv[optind];
420
364 datalen = ultmp;
365 break;
366 case 'S':
367 source = optarg;
368 break;
369 case 't':
370 alarmtimeout = strtoul(optarg, &ep, 0);
371 if ((alarmtimeout < 1) || (alarmtimeout == ULONG_MAX))

--- 39 unchanged lines hidden (view full) ---

411 usage();
412 }
413 }
414
415 if (argc - optind != 1)
416 usage();
417 target = argv[optind];
418
419 maxpayload = IP_MAXPACKET - sizeof(struct ip) - MINICMPLEN;
420 if (options & F_RROUTE)
421 maxpayload -= MAX_IPOPTLEN;
422 if (datalen > maxpayload)
423 errx(EX_USAGE, "packet size too large: %lu > %u", datalen,
424 maxpayload);
421 if (source) {
422 bzero((char *)&sin, sizeof(sin));
423 sin.sin_family = AF_INET;
424 if (inet_aton(source, &sin.sin_addr) != 0) {
425 shostname = source;
426 } else {
427 hp = gethostbyname2(source, AF_INET);
428 if (!hp)

--- 1043 unchanged lines hidden (view full) ---

1472 }
1473 ii = sscanf(patp,
1474 "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
1475 &pat[0], &pat[1], &pat[2], &pat[3], &pat[4], &pat[5], &pat[6],
1476 &pat[7], &pat[8], &pat[9], &pat[10], &pat[11], &pat[12],
1477 &pat[13], &pat[14], &pat[15]);
1478
1479 if (ii > 0)
425 if (source) {
426 bzero((char *)&sin, sizeof(sin));
427 sin.sin_family = AF_INET;
428 if (inet_aton(source, &sin.sin_addr) != 0) {
429 shostname = source;
430 } else {
431 hp = gethostbyname2(source, AF_INET);
432 if (!hp)

--- 1043 unchanged lines hidden (view full) ---

1476 }
1477 ii = sscanf(patp,
1478 "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
1479 &pat[0], &pat[1], &pat[2], &pat[3], &pat[4], &pat[5], &pat[6],
1480 &pat[7], &pat[8], &pat[9], &pat[10], &pat[11], &pat[12],
1481 &pat[13], &pat[14], &pat[15]);
1482
1483 if (ii > 0)
1480 for (kk = 0; kk <= MAXPAYLOAD - (PHDR_LEN + ii); kk += ii)
1484 for (kk = 0; kk <= maxpayload - (PHDR_LEN + ii); kk += ii)
1481 for (jj = 0; jj < ii; ++jj)
1482 bp[jj + kk] = pat[jj];
1483 if (!(options & F_QUIET)) {
1484 (void)printf("PATTERN: 0x");
1485 for (jj = 0; jj < ii; ++jj)
1486 (void)printf("%02x", bp[jj] & 0xFF);
1487 (void)printf("\n");
1488 }

--- 17 unchanged lines hidden ---
1485 for (jj = 0; jj < ii; ++jj)
1486 bp[jj + kk] = pat[jj];
1487 if (!(options & F_QUIET)) {
1488 (void)printf("PATTERN: 0x");
1489 for (jj = 0; jj < ii; ++jj)
1490 (void)printf("%02x", bp[jj] & 0xFF);
1491 (void)printf("\n");
1492 }

--- 17 unchanged lines hidden ---