]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-gre.c
Default to first interface from pcap_findalldevs()
[tcpdump] / print-gre.c
index a8584f485c523a843f60d1b1b201b86ad338b97f..187a5b9f48297a9b260ea4d1e4a3328d01ccc871 100644 (file)
  */
 
 /*
- * tcpdump filter for GRE - Generic Routing Encapsulation
+ * netdissect printer for GRE - Generic Routing Encapsulation
  * RFC1701 (GRE), RFC1702 (GRE IPv4), and RFC2637 (Enhanced GRE)
  */
 
-#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include <tcpdump-stdinc.h>
+#include <netdissect-stdinc.h>
 
 #include <string.h>
 
-#include "interface.h"
+#include "netdissect.h"
+#include "addrtostr.h"
 #include "extract.h"
 #include "ethertype.h"
 
@@ -78,9 +78,9 @@ static const struct tok gre_flag_values[] = {
 
 static void gre_print_0(netdissect_options *, const u_char *, u_int);
 static void gre_print_1(netdissect_options *, const u_char *, u_int);
-static void gre_sre_print(netdissect_options *, u_int16_t, u_int8_t, u_int8_t, const u_char *, u_int);
-static void gre_sre_ip_print(netdissect_options *, u_int8_t, u_int8_t, const u_char *, u_int);
-static void gre_sre_asn_print(netdissect_options *, u_int8_t, u_int8_t, const u_char *, u_int);
+static void gre_sre_print(netdissect_options *, uint16_t, uint8_t, uint8_t, const u_char *, u_int);
+static void gre_sre_ip_print(netdissect_options *, uint8_t, uint8_t, const u_char *, u_int);
+static void gre_sre_asn_print(netdissect_options *, uint8_t, uint8_t, const u_char *, u_int);
 
 void
 gre_print(netdissect_options *ndo, const u_char *bp, u_int length)
@@ -111,7 +111,7 @@ static void
 gre_print_0(netdissect_options *ndo, const u_char *bp, u_int length)
 {
        u_int len = length;
-       u_int16_t flags, prot;
+       uint16_t flags, prot;
 
        flags = EXTRACT_16BITS(bp);
         if (ndo->ndo_vflag)
@@ -160,9 +160,9 @@ gre_print_0(netdissect_options *ndo, const u_char *bp, u_int length)
 
        if (flags & GRE_RP) {
                for (;;) {
-                       u_int16_t af;
-                       u_int8_t sreoff;
-                       u_int8_t srelen;
+                       uint16_t af;
+                       uint8_t sreoff;
+                       uint8_t srelen;
 
                        if (len < 4)
                                goto trunc;
@@ -200,11 +200,9 @@ gre_print_0(netdissect_options *ndo, const u_char *bp, u_int length)
        case ETHERTYPE_IP:
                ip_print(ndo, bp, len);
                break;
-#ifdef INET6
        case ETHERTYPE_IPV6:
                ip6_print(ndo, bp, len);
                break;
-#endif
        case ETHERTYPE_MPLS:
                mpls_print(ndo, bp, len);
                break;
@@ -233,7 +231,7 @@ static void
 gre_print_1(netdissect_options *ndo, const u_char *bp, u_int length)
 {
        u_int len = length;
-       u_int16_t flags, prot;
+       uint16_t flags, prot;
 
        flags = EXTRACT_16BITS(bp);
        len -= 2;
@@ -251,7 +249,7 @@ gre_print_1(netdissect_options *ndo, const u_char *bp, u_int length)
 
 
        if (flags & GRE_KP) {
-               u_int32_t k;
+               uint32_t k;
 
                if (len < 4)
                        goto trunc;
@@ -297,7 +295,7 @@ gre_print_1(netdissect_options *ndo, const u_char *bp, u_int length)
 
        switch (prot) {
        case ETHERTYPE_PPP:
-                ppp_print(bp, len);
+               ppp_print(ndo, bp, len);
                break;
        default:
                ND_PRINT((ndo, "gre-proto-0x%x", prot));
@@ -310,31 +308,31 @@ trunc:
 }
 
 static void
-gre_sre_print(netdissect_options *ndo, u_int16_t af, u_int8_t sreoff,
-    u_int8_t srelen, const u_char *bp, u_int len)
+gre_sre_print(netdissect_options *ndo, uint16_t af, uint8_t sreoff,
+    uint8_t srelen, const u_char *bp, u_int len)
 {
        switch (af) {
        case GRESRE_IP:
                ND_PRINT((ndo, ", (rtaf=ip"));
                gre_sre_ip_print(ndo, sreoff, srelen, bp, len);
-               ND_PRINT((ndo, ") "));
+               ND_PRINT((ndo, ")"));
                break;
        case GRESRE_ASN:
                ND_PRINT((ndo, ", (rtaf=asn"));
                gre_sre_asn_print(ndo, sreoff, srelen, bp, len);
-               ND_PRINT((ndo, ") "));
+               ND_PRINT((ndo, ")"));
                break;
        default:
-               ND_PRINT((ndo, ", (rtaf=0x%x) ", af));
+               ND_PRINT((ndo, ", (rtaf=0x%x)", af));
        }
 }
 
 static void
-gre_sre_ip_print(netdissect_options *ndo, u_int8_t sreoff, u_int8_t srelen,
+gre_sre_ip_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen,
                  const u_char *bp, u_int len)
 {
-       struct in_addr a;
        const u_char *up = bp;
+       char buf[INET_ADDRSTRLEN];
 
        if (sreoff & 3) {
                ND_PRINT((ndo, ", badoffset=%u", sreoff));
@@ -353,10 +351,9 @@ gre_sre_ip_print(netdissect_options *ndo, u_int8_t sreoff, u_int8_t srelen,
                if (len < 4 || srelen == 0)
                        return;
 
-               memcpy(&a, bp, sizeof(a));
+               addrtostr(bp, buf, sizeof(buf));
                ND_PRINT((ndo, " %s%s",
-                   ((bp - up) == sreoff) ? "*" : "",
-                   inet_ntoa(a)));
+                   ((bp - up) == sreoff) ? "*" : "", buf));
 
                bp += 4;
                len -= 4;
@@ -365,7 +362,7 @@ gre_sre_ip_print(netdissect_options *ndo, u_int8_t sreoff, u_int8_t srelen,
 }
 
 static void
-gre_sre_asn_print(netdissect_options *ndo, u_int8_t sreoff, u_int8_t srelen,
+gre_sre_asn_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen,
                   const u_char *bp, u_int len)
 {
        const u_char *up = bp;