ping.c (91432) | ping.c (92806) |
---|---|
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 91432 2002-02-27 22:37:22Z fenner $"; | 48 "$FreeBSD: head/sbin/ping/ping.c 92806 2002-03-20 17:55:10Z obrien $"; |
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 * --- 139 unchanged lines hidden (view full) --- 196main(argc, argv) 197 int argc; 198 char *const *argv; 199{ 200 struct timeval last, intvl; 201 struct hostent *hp; 202 struct sockaddr_in *to, sin; 203 struct termios ts; | 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 * --- 139 unchanged lines hidden (view full) --- 196main(argc, argv) 197 int argc; 198 char *const *argv; 199{ 200 struct timeval last, intvl; 201 struct hostent *hp; 202 struct sockaddr_in *to, sin; 203 struct termios ts; |
204 register int i; | 204 int i; |
205 int ch, hold, packlen, preload, sockerrno, almost_done = 0, ttl; 206 struct in_addr ifaddr; 207 unsigned char mttl, loop; 208 u_char *datap, *packet; 209 char *source = NULL, *target, hnamebuf[MAXHOSTNAMELEN]; 210 char snamebuf[MAXHOSTNAMELEN]; 211 char *ep; 212 u_long ultmp; --- 421 unchanged lines hidden (view full) --- 634 intvl.tv_sec = 0; 635 intvl.tv_usec = 10000; 636 } else { 637 intvl.tv_sec = interval / 1000; 638 intvl.tv_usec = interval % 1000 * 1000; 639 } 640 641 while (!finish_up) { | 205 int ch, hold, packlen, preload, sockerrno, almost_done = 0, ttl; 206 struct in_addr ifaddr; 207 unsigned char mttl, loop; 208 u_char *datap, *packet; 209 char *source = NULL, *target, hnamebuf[MAXHOSTNAMELEN]; 210 char snamebuf[MAXHOSTNAMELEN]; 211 char *ep; 212 u_long ultmp; --- 421 unchanged lines hidden (view full) --- 634 intvl.tv_sec = 0; 635 intvl.tv_usec = 10000; 636 } else { 637 intvl.tv_sec = interval / 1000; 638 intvl.tv_usec = interval % 1000 * 1000; 639 } 640 641 while (!finish_up) { |
642 register int cc; | 642 int cc; |
643 int n; 644 struct timeval timeout, now; 645 fd_set rfds; 646 647 check_status(); 648 FD_ZERO(&rfds); 649 FD_SET(s, &rfds); 650 (void)gettimeofday(&now, NULL); --- 91 unchanged lines hidden (view full) --- 742 * will be added on by the kernel. The ID field is our UNIX process ID, 743 * and the sequence number is an ascending integer. The first 8 bytes 744 * of the data portion are used to hold a UNIX "timeval" struct in host 745 * byte-order, to compute the round-trip time. 746 */ 747static void 748pinger(void) 749{ | 643 int n; 644 struct timeval timeout, now; 645 fd_set rfds; 646 647 check_status(); 648 FD_ZERO(&rfds); 649 FD_SET(s, &rfds); 650 (void)gettimeofday(&now, NULL); --- 91 unchanged lines hidden (view full) --- 742 * will be added on by the kernel. The ID field is our UNIX process ID, 743 * and the sequence number is an ascending integer. The first 8 bytes 744 * of the data portion are used to hold a UNIX "timeval" struct in host 745 * byte-order, to compute the round-trip time. 746 */ 747static void 748pinger(void) 749{ |
750 register struct icmp *icp; 751 register int cc; | 750 struct icmp *icp; 751 int cc; |
752 int i; 753 754 icp = (struct icmp *)outpack; 755 icp->icmp_type = ICMP_ECHO; 756 icp->icmp_code = 0; 757 icp->icmp_cksum = 0; 758 icp->icmp_seq = htons(ntransmitted); 759 icp->icmp_id = ident; /* ID */ --- 38 unchanged lines hidden (view full) --- 798 */ 799static void 800pr_pack(buf, cc, from, tv) 801 char *buf; 802 int cc; 803 struct sockaddr_in *from; 804 struct timeval *tv; 805{ | 752 int i; 753 754 icp = (struct icmp *)outpack; 755 icp->icmp_type = ICMP_ECHO; 756 icp->icmp_code = 0; 757 icp->icmp_cksum = 0; 758 icp->icmp_seq = htons(ntransmitted); 759 icp->icmp_id = ident; /* ID */ --- 38 unchanged lines hidden (view full) --- 798 */ 799static void 800pr_pack(buf, cc, from, tv) 801 char *buf; 802 int cc; 803 struct sockaddr_in *from; 804 struct timeval *tv; 805{ |
806 register struct icmp *icp; 807 register u_long l; 808 register int i, j; 809 register u_char *cp,*dp; | 806 struct icmp *icp; 807 u_long l; 808 int i, j; 809 u_char *cp,*dp; |
810 static int old_rrlen; 811 static char old_rr[MAX_IPOPTLEN]; 812 struct ip *ip; 813 struct timeval *tp; 814 double triptime; 815 int hlen, dupflag, seq; 816 817 /* Check the IP header */ --- 218 unchanged lines hidden (view full) --- 1036 * in_cksum -- 1037 * Checksum routine for Internet Protocol family headers (C Version) 1038 */ 1039u_short 1040in_cksum(addr, len) 1041 u_short *addr; 1042 int len; 1043{ | 810 static int old_rrlen; 811 static char old_rr[MAX_IPOPTLEN]; 812 struct ip *ip; 813 struct timeval *tp; 814 double triptime; 815 int hlen, dupflag, seq; 816 817 /* Check the IP header */ --- 218 unchanged lines hidden (view full) --- 1036 * in_cksum -- 1037 * Checksum routine for Internet Protocol family headers (C Version) 1038 */ 1039u_short 1040in_cksum(addr, len) 1041 u_short *addr; 1042 int len; 1043{ |
1044 register int nleft = len; 1045 register u_short *w = addr; 1046 register int sum = 0; | 1044 int nleft = len; 1045 u_short *w = addr; 1046 int sum = 0; |
1047 union { 1048 u_short us; 1049 u_char uc[2]; 1050 } last; 1051 u_short answer; 1052 1053 /* 1054 * Our algorithm is simple, using a 32 bit accumulator (sum), we add --- 21 unchanged lines hidden (view full) --- 1076 1077/* 1078 * tvsub -- 1079 * Subtract 2 timeval structs: out = out - in. Out is assumed to 1080 * be >= in. 1081 */ 1082static void 1083tvsub(out, in) | 1047 union { 1048 u_short us; 1049 u_char uc[2]; 1050 } last; 1051 u_short answer; 1052 1053 /* 1054 * Our algorithm is simple, using a 32 bit accumulator (sum), we add --- 21 unchanged lines hidden (view full) --- 1076 1077/* 1078 * tvsub -- 1079 * Subtract 2 timeval structs: out = out - in. Out is assumed to 1080 * be >= in. 1081 */ 1082static void 1083tvsub(out, in) |
1084 register struct timeval *out, *in; | 1084 struct timeval *out, *in; |
1085{ 1086 if ((out->tv_usec -= in->tv_usec) < 0) { 1087 --out->tv_sec; 1088 out->tv_usec += 1000000; 1089 } 1090 out->tv_sec -= in->tv_sec; 1091} 1092 --- 308 unchanged lines hidden (view full) --- 1401 (void)printf("UDP: from port %u, to port %u (decimal)\n", 1402 (*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3))); 1403} 1404 1405static void 1406fill(bp, patp) 1407 char *bp, *patp; 1408{ | 1085{ 1086 if ((out->tv_usec -= in->tv_usec) < 0) { 1087 --out->tv_sec; 1088 out->tv_usec += 1000000; 1089 } 1090 out->tv_sec -= in->tv_sec; 1091} 1092 --- 308 unchanged lines hidden (view full) --- 1401 (void)printf("UDP: from port %u, to port %u (decimal)\n", 1402 (*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3))); 1403} 1404 1405static void 1406fill(bp, patp) 1407 char *bp, *patp; 1408{ |
1409 register int ii, jj, kk; | 1409 int ii, jj, kk; |
1410 int pat[16]; 1411 char *cp; 1412 1413 for (cp = patp; *cp; cp++) { 1414 if (!isxdigit(*cp)) 1415 errx(EX_USAGE, 1416 "patterns must be specified as hex digits"); 1417 --- 36 unchanged lines hidden --- | 1410 int pat[16]; 1411 char *cp; 1412 1413 for (cp = patp; *cp; cp++) { 1414 if (!isxdigit(*cp)) 1415 errx(EX_USAGE, 1416 "patterns must be specified as hex digits"); 1417 --- 36 unchanged lines hidden --- |