Deleted Added
sdiff udiff text old ( 38560 ) new ( 42337 )
full compact
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 "$Id: ping.c,v 1.40 1998/08/26 01:58:39 dillon Exp $";
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 *

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

136
137struct sockaddr whereto; /* who to ping */
138int datalen = DEFDATALEN;
139int s; /* socket file descriptor */
140u_char outpack[MAXPACKET];
141char BSPACE = '\b'; /* characters written for flood */
142char DOT = '.';
143char *hostname;
144int ident; /* process id to identify our packets */
145int uid; /* cached uid for micro-optimization */
146
147/* counters */
148long npackets; /* max packets to transmit */
149long nreceived; /* # of packets we got back */
150long nrepeats; /* number of duplicates */
151long ntransmitted; /* sequence # for outbound packets = #sent */

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

179
180int
181main(argc, argv)
182 int argc;
183 char *const *argv;
184{
185 struct timeval last, intvl;
186 struct hostent *hp;
187 struct sockaddr_in *to;
188 struct termios ts;
189 register int i;
190 int ch, hold, packlen, preload, sockerrno, almost_done = 0;
191 struct in_addr ifaddr;
192 unsigned char ttl, loop;
193 u_char *datap, *packet;
194 char *target, hnamebuf[MAXHOSTNAMELEN];
195 char *ep;
196 u_long ultmp;
197#ifdef IP_OPTIONS
198 char rspace[3 + 4 * NROUTES + 1]; /* record route space */
199#endif
200 struct sigaction si_sa;
201 struct iovec iov;
202 struct msghdr msg;

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

212 sockerrno = errno;
213
214 setuid(getuid());
215 uid = getuid();
216
217 preload = 0;
218
219 datap = &outpack[8 + PHDR_LEN];
220 while ((ch = getopt(argc, argv, "I:LQRT:c:adfi:l:np:qrs:v")) != -1) {
221 switch(ch) {
222 case 'a':
223 options |= F_AUDIBLE;
224 break;
225 case 'c':
226 ultmp = strtoul(optarg, &ep, 0);
227 if (*ep || ep == optarg || ultmp > LONG_MAX || !ultmp)
228 errx(EX_USAGE,

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

311 if (ultmp > MAXPACKET)
312 errx(EX_USAGE, "packet size too large: %lu",
313 ultmp);
314 if (*ep || ep == optarg || !ultmp)
315 errx(EX_USAGE, "invalid packet size: `%s'",
316 optarg);
317 datalen = ultmp;
318 break;
319 case 'T': /* multicast TTL */
320 ultmp = strtoul(optarg, &ep, 0);
321 if (*ep || ep == optarg || ultmp > 255)
322 errx(EX_USAGE, "invalid multicast TTL: `%s'",
323 optarg);
324 ttl = ultmp;
325 options |= F_MTTL;
326 break;

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

331 usage();
332 }
333 }
334
335 if (argc - optind != 1)
336 usage();
337 target = argv[optind];
338
339 bzero((char *)&whereto, sizeof(struct sockaddr));
340 to = (struct sockaddr_in *)&whereto;
341 to->sin_family = AF_INET;
342 if (inet_aton(target, &to->sin_addr) != 0) {
343 hostname = target;
344 } else {
345 hp = gethostbyname2(target, AF_INET);
346 if (!hp)

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

439 * ethernet, or just want to fill the arp cache to get some stuff for
440 * /etc/ethers. But beware: RFC 1122 allows hosts to ignore broadcast
441 * or multicast pings if they wish.
442 */
443 hold = 48 * 1024;
444 (void)setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&hold,
445 sizeof(hold));
446
447 if (to->sin_family == AF_INET)
448 (void)printf("PING %s (%s): %d data bytes\n", hostname,
449 inet_ntoa(to->sin_addr),
450 datalen);
451 else
452 (void)printf("PING %s: %d data bytes\n", hostname, datalen);
453
454 /*
455 * Use sigaction() instead of signal() to get unambiguous semantics,
456 * in particular with SA_RESTART not set.
457 */
458
459 sigemptyset(&si_sa.sa_mask);

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

1279 (void)printf("%02x", bp[jj] & 0xFF);
1280 (void)printf("\n");
1281 }
1282}
1283
1284static void
1285usage()
1286{
1287 fprintf(stderr, "%s\n%s\n",
1288"usage: ping [-QRadfnqrv] [-c count] [-i wait] [-l preload] [-p pattern]",
1289" [-s packetsize] [host | [-L] [-I iface] [-T ttl] mcast-group]");
1290 exit(EX_USAGE);
1291}