|
Lines 81-86
Link Here
|
| 81 |
#include <termios.h> |
81 |
#include <termios.h> |
| 82 |
#include <unistd.h> |
82 |
#include <unistd.h> |
| 83 |
|
83 |
|
|
|
84 |
#include <sys/sysctl.h> |
| 84 |
#include <sys/socket.h> |
85 |
#include <sys/socket.h> |
| 85 |
#include <sys/time.h> |
86 |
#include <sys/time.h> |
| 86 |
#include <sys/uio.h> |
87 |
#include <sys/uio.h> |
|
Lines 100-108
Link Here
|
| 100 |
#define DEFDATALEN (64 - PHDR_LEN) /* default data length */ |
101 |
#define DEFDATALEN (64 - PHDR_LEN) /* default data length */ |
| 101 |
#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */ |
102 |
#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */ |
| 102 |
/* runs out of buffer space */ |
103 |
/* runs out of buffer space */ |
| 103 |
#define MAXIPLEN 60 |
104 |
#define MAXIPLEN (sizeof(struct ip) + MAX_IPOPTLEN) |
| 104 |
#define MAXICMPLEN 76 |
105 |
#define MAXICMPLEN 76 |
| 105 |
#define MAXPACKET (65536 - 60 - 8)/* max packet size */ |
106 |
#define MAXPACKET (IP_MAXPACKET - MAXIPLEN - ICMP_MINLEN) /* max packet size */ |
| 106 |
#define MAXWAIT 10 /* max seconds to wait for response */ |
107 |
#define MAXWAIT 10 /* max seconds to wait for response */ |
| 107 |
#define MAXALARM (60 * 60) /* max seconds for alarm timeout */ |
108 |
#define MAXALARM (60 * 60) /* max seconds for alarm timeout */ |
| 108 |
#define NROUTES 9 /* number of record route slots */ |
109 |
#define NROUTES 9 /* number of record route slots */ |
|
Lines 136-141
Link Here
|
| 136 |
#endif /*IPSEC*/ |
137 |
#endif /*IPSEC*/ |
| 137 |
#define F_TTL 0x8000 |
138 |
#define F_TTL 0x8000 |
| 138 |
#define F_MISSED 0x10000 |
139 |
#define F_MISSED 0x10000 |
|
|
140 |
#define F_HDRINCL 0x20000 |
| 139 |
|
141 |
|
| 140 |
/* |
142 |
/* |
| 141 |
* MAX_DUP_CHK is the number of bits in received table, i.e. the maximum |
143 |
* MAX_DUP_CHK is the number of bits in received table, i.e. the maximum |
|
Lines 149-155
Link Here
|
| 149 |
struct sockaddr_in whereto; /* who to ping */ |
151 |
struct sockaddr_in whereto; /* who to ping */ |
| 150 |
int datalen = DEFDATALEN; |
152 |
int datalen = DEFDATALEN; |
| 151 |
int s; /* socket file descriptor */ |
153 |
int s; /* socket file descriptor */ |
| 152 |
u_char outpack[MAXPACKET]; |
154 |
u_char outpackhdr[IP_MAXPACKET]; /* Max packet size = 65535 */ |
|
|
155 |
u_char *outpack = outpackhdr + sizeof(struct ip); |
| 153 |
char BSPACE = '\b'; /* characters written for flood */ |
156 |
char BSPACE = '\b'; /* characters written for flood */ |
| 154 |
char BBELL = '\a'; /* characters written for MISSED and AUDIBLE */ |
157 |
char BBELL = '\a'; /* characters written for MISSED and AUDIBLE */ |
| 155 |
char DOT = '.'; |
158 |
char DOT = '.'; |
|
Lines 204-210
Link Here
|
| 204 |
int ch, hold, packlen, preload, sockerrno, almost_done = 0, ttl; |
207 |
int ch, hold, packlen, preload, sockerrno, almost_done = 0, ttl; |
| 205 |
struct in_addr ifaddr; |
208 |
struct in_addr ifaddr; |
| 206 |
unsigned char mttl, loop; |
209 |
unsigned char mttl, loop; |
| 207 |
u_char *datap, *packet; |
210 |
u_char *datap, *packet, df = 0; |
| 208 |
char *source = NULL, *target, hnamebuf[MAXHOSTNAMELEN]; |
211 |
char *source = NULL, *target, hnamebuf[MAXHOSTNAMELEN]; |
| 209 |
char snamebuf[MAXHOSTNAMELEN]; |
212 |
char snamebuf[MAXHOSTNAMELEN]; |
| 210 |
char *ep; |
213 |
char *ep; |
|
Lines 238-244
Link Here
|
| 238 |
|
241 |
|
| 239 |
datap = &outpack[8 + PHDR_LEN]; |
242 |
datap = &outpack[8 + PHDR_LEN]; |
| 240 |
while ((ch = getopt(argc, argv, |
243 |
while ((ch = getopt(argc, argv, |
| 241 |
"AI:LQRS:T:c:adfi:l:m:np:qrs:t:v" |
244 |
"ADI:LQRS:T:c:adfi:l:m:np:qrs:t:v" |
| 242 |
#ifdef IPSEC |
245 |
#ifdef IPSEC |
| 243 |
#ifdef IPSEC_POLICY_IPSEC |
246 |
#ifdef IPSEC_POLICY_IPSEC |
| 244 |
"P:" |
247 |
"P:" |
|
Lines 261-266
Link Here
|
| 261 |
optarg); |
264 |
optarg); |
| 262 |
npackets = ultmp; |
265 |
npackets = ultmp; |
| 263 |
break; |
266 |
break; |
|
|
267 |
case 'D': |
| 268 |
options |= F_HDRINCL; |
| 269 |
df = 1; |
| 270 |
break; |
| 264 |
case 'd': |
271 |
case 'd': |
| 265 |
options |= F_SO_DEBUG; |
272 |
options |= F_SO_DEBUG; |
| 266 |
break; |
273 |
break; |
|
Lines 315-321
Link Here
|
| 315 |
break; |
322 |
break; |
| 316 |
case 'm': /* TTL */ |
323 |
case 'm': /* TTL */ |
| 317 |
ultmp = strtoul(optarg, &ep, 0); |
324 |
ultmp = strtoul(optarg, &ep, 0); |
| 318 |
if (*ep || ep == optarg || ultmp > 255) |
325 |
if (*ep || ep == optarg || ultmp > MAXTTL) |
| 319 |
errx(EX_USAGE, "invalid TTL: `%s'", |
326 |
errx(EX_USAGE, "invalid TTL: `%s'", |
| 320 |
optarg); |
327 |
optarg); |
| 321 |
ttl = ultmp; |
328 |
ttl = ultmp; |
|
Lines 369-375
Link Here
|
| 369 |
break; |
376 |
break; |
| 370 |
case 'T': /* multicast TTL */ |
377 |
case 'T': /* multicast TTL */ |
| 371 |
ultmp = strtoul(optarg, &ep, 0); |
378 |
ultmp = strtoul(optarg, &ep, 0); |
| 372 |
if (*ep || ep == optarg || ultmp > 255) |
379 |
if (*ep || ep == optarg || ultmp > MAXTTL) |
| 373 |
errx(EX_USAGE, "invalid multicast TTL: `%s'", |
380 |
errx(EX_USAGE, "invalid multicast TTL: `%s'", |
| 374 |
optarg); |
381 |
optarg); |
| 375 |
mttl = ultmp; |
382 |
mttl = ultmp; |
|
Lines 506-511
Link Here
|
| 506 |
#endif /*IPSEC_POLICY_IPSEC*/ |
513 |
#endif /*IPSEC_POLICY_IPSEC*/ |
| 507 |
#endif /*IPSEC*/ |
514 |
#endif /*IPSEC*/ |
| 508 |
|
515 |
|
|
|
516 |
if (options & F_HDRINCL) { |
| 517 |
struct ip *ip = (struct ip*)outpackhdr; |
| 518 |
|
| 519 |
#ifdef IPCTL_DEFTTL |
| 520 |
|
| 521 |
if (!((options & F_TTL) || (options & F_MTTL))) { |
| 522 |
int mib[4] = { CTL_NET, PF_INET, IPPROTO_IP, IPCTL_DEFTTL }; |
| 523 |
size_t sz = sizeof(ttl); |
| 524 |
|
| 525 |
if (sysctl(mib, 4, &ttl, &sz, NULL, 0) == -1) |
| 526 |
err(1, "sysctl(net.inet.ip.ttl)"); |
| 527 |
} |
| 528 |
|
| 529 |
#endif |
| 530 |
|
| 531 |
setsockopt(s, IPPROTO_IP, IP_HDRINCL, &hold, sizeof(hold)); |
| 532 |
ip->ip_v = IPVERSION; |
| 533 |
ip->ip_hl = sizeof(struct ip) >> 2; |
| 534 |
ip->ip_tos = 0; |
| 535 |
ip->ip_id = 0; |
| 536 |
ip->ip_off = df ? IP_DF : 0; |
| 537 |
ip->ip_ttl = ttl; |
| 538 |
ip->ip_p = IPPROTO_ICMP; |
| 539 |
ip->ip_src.s_addr = source ? sin.sin_addr.s_addr : INADDR_ANY; |
| 540 |
ip->ip_dst = to->sin_addr; |
| 541 |
} |
| 542 |
|
| 509 |
/* record route option */ |
543 |
/* record route option */ |
| 510 |
if (options & F_RROUTE) { |
544 |
if (options & F_RROUTE) { |
| 511 |
#ifdef IP_OPTIONS |
545 |
#ifdef IP_OPTIONS |
|
Lines 560-567
Link Here
|
| 560 |
* ethernet, or just want to fill the arp cache to get some stuff for |
594 |
* ethernet, or just want to fill the arp cache to get some stuff for |
| 561 |
* /etc/ethers. But beware: RFC 1122 allows hosts to ignore broadcast |
595 |
* /etc/ethers. But beware: RFC 1122 allows hosts to ignore broadcast |
| 562 |
* or multicast pings if they wish. |
596 |
* or multicast pings if they wish. |
|
|
597 |
* |
| 598 |
* We should have our buffers are at least 64K so we can ping with |
| 599 |
* IP_MAXPACKET packet size. |
| 563 |
*/ |
600 |
*/ |
| 564 |
hold = 48 * 1024; |
601 |
hold = 64 * 1024; |
| 565 |
(void)setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&hold, |
602 |
(void)setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&hold, |
| 566 |
sizeof(hold)); |
603 |
sizeof(hold)); |
| 567 |
|
604 |
|
|
Lines 742-747
Link Here
|
| 742 |
register struct icmp *icp; |
779 |
register struct icmp *icp; |
| 743 |
register int cc; |
780 |
register int cc; |
| 744 |
int i; |
781 |
int i; |
|
|
782 |
char *packet = outpack; |
| 745 |
|
783 |
|
| 746 |
icp = (struct icmp *)outpack; |
784 |
icp = (struct icmp *)outpack; |
| 747 |
icp->icmp_type = ICMP_ECHO; |
785 |
icp->icmp_type = ICMP_ECHO; |
|
Lines 760-767
Link Here
|
| 760 |
|
798 |
|
| 761 |
/* compute ICMP checksum here */ |
799 |
/* compute ICMP checksum here */ |
| 762 |
icp->icmp_cksum = in_cksum((u_short *)icp, cc); |
800 |
icp->icmp_cksum = in_cksum((u_short *)icp, cc); |
|
|
801 |
|
| 802 |
if (options & F_HDRINCL) { |
| 803 |
struct ip *ip = (struct ip*)outpackhdr; |
| 804 |
|
| 805 |
packet = (char*)ip; |
| 806 |
cc += sizeof(struct ip); |
| 807 |
ip->ip_len = cc; |
| 808 |
ip->ip_sum = in_cksum((u_short *)outpackhdr, cc); |
| 809 |
} |
| 763 |
|
810 |
|
| 764 |
i = sendto(s, (char *)outpack, cc, 0, (struct sockaddr *)&whereto, |
811 |
i = sendto(s, (char *)packet, cc, 0, (struct sockaddr *)&whereto, |
| 765 |
sizeof(whereto)); |
812 |
sizeof(whereto)); |
| 766 |
|
813 |
|
| 767 |
if (i < 0 || i != cc) { |
814 |
if (i < 0 || i != cc) { |