]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-icmp.c
backout 1.60
[tcpdump] / print-icmp.c
index 30f83133699e71feb2cf642cf19de9898a603d35..8b992d219ff865303a4d2852ed65515eea885f1c 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.55 2000-10-03 09:30:37 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.61 2001-07-19 19:37:31 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -39,6 +39,7 @@ struct rtentry;
 
 #include <stdio.h>
 #include <string.h>
+#include <netdb.h>             /* for MAXHOSTNAMELEN on some platforms */
 
 #include "interface.h"
 #include "addrtoname.h"
@@ -267,27 +268,21 @@ struct id_rdiscovery {
 };
 
 void
-icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2)
+icmp_print(const u_char *bp, u_int plen, const u_char *bp2)
 {
-       register char *cp;
-       register const struct icmp *dp;
-       register const struct ip *ip;
-       register const char *str, *fmt;
-       register const struct ip *oip;
-       register const struct udphdr *ouh;
-       register u_int hlen, dport, mtu;
-       char buf[256];
+       char *cp;
+       const struct icmp *dp;
+       const struct ip *ip;
+       const char *str, *fmt;
+       const struct ip *oip;
+       const struct udphdr *ouh;
+       u_int hlen, dport, mtu;
+       char buf[MAXHOSTNAMELEN + 100];
 
        dp = (struct icmp *)bp;
        ip = (struct ip *)bp2;
        str = buf;
 
-#if 0
-        (void)printf("%s > %s: ",
-               ipaddr_string(&ip->ip_src),
-               ipaddr_string(&ip->ip_dst));
-#endif
-
        TCHECK(dp->icmp_code);
        switch (dp->icmp_type) {
 
@@ -338,12 +333,12 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2)
                    {
                        register const struct mtu_discovery *mp;
                        mp = (struct mtu_discovery *)&dp->icmp_void;
-                        mtu = EXTRACT_16BITS(&mp->nexthopmtu);
-                        if (mtu) {
+                       mtu = EXTRACT_16BITS(&mp->nexthopmtu);
+                       if (mtu) {
                                (void)snprintf(buf, sizeof(buf),
                                    "%s unreachable - need to frag (mtu %d)",
                                    ipaddr_string(&dp->icmp_ip.ip_dst), mtu);
-                        } else {
+                       } else {
                                (void)snprintf(buf, sizeof(buf),
                                    "%s unreachable - need to frag",
                                    ipaddr_string(&dp->icmp_ip.ip_dst));
@@ -458,14 +453,16 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2)
 
        case ICMP_TSTAMP:
                TCHECK(dp->icmp_seq);
-               (void)sprintf(buf, "time stamp query id %u seq %u",
+               (void)snprintf(buf, sizeof(buf),
+                   "time stamp query id %u seq %u",
                    (unsigned)ntohs(dp->icmp_id),
                    (unsigned)ntohs(dp->icmp_seq));
                break;
 
        case ICMP_TSTAMPREPLY:
                TCHECK(dp->icmp_ttime);
-               (void)sprintf(buf, "time stamp reply id %u seq %u : org 0x%lx recv 0x%lx xmit 0x%lx",
+               (void)snprintf(buf, sizeof(buf),
+                   "time stamp reply id %u seq %u : org 0x%lx recv 0x%lx xmit 0x%lx",
                    (unsigned)ntohs(dp->icmp_id),
                    (unsigned)ntohs(dp->icmp_seq),
                    (unsigned long)ntohl(dp->icmp_otime),
@@ -477,7 +474,7 @@ icmp_print(register const u_char *bp, u_int plen, register const u_char *bp2)
                str = tok2str(icmp2str, "type-#%d", dp->icmp_type);
                break;
        }
-        (void)printf("icmp: %s", str);
+       (void)printf("icmp: %s", str);
        if (vflag) {
                if (TTEST2(*bp, plen)) {
                        if (in_cksum((u_short*)dp, plen, 0))