]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ripng.c
Remove the -a flag. It's nonsensical to apply the local netmask to all
[tcpdump] / print-ripng.c
index 69864b3acd059e6b86357461fdcca6af5dd15bb1..b1f7ec273d90dac17c6134cc36f3fa5f59d855af 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) /master/usr.sbin/tcpdump/tcpdump/print-rip.c,v 2.1 1995/02/03 18:15:05 polk Exp (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.15 2002-12-11 22:29:22 guy Exp $";
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
 #endif
 
 #ifdef INET6
 
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <tcpdump-stdinc.h>
 
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_var.h>
-#include <netinet/udp.h>
-#include <netinet/udp_var.h>
+#ifdef WIN32
+const struct in6_addr in6addr_any;        /* :: */
+#endif /* WIN32 */
 
-#include <errno.h>
-#include <stdio.h>
+#ifdef __MINGW32__
+int
+IN6_ADDR_EQUAL(const struct in6_addr *a, const struct in6_addr *b)
+{
+    return (memcmp(a, b, sizeof(struct in6_addr)) == 0);
+}
 
-#include <netinet/ip6.h>
+#define IN6_IS_ADDR_UNSPECIFIED(a) IN6_ADDR_EQUAL((a), &in6addr_any)
+
+#endif /* __MINGW32__ */
+
+#include <stdio.h>
 
 #include "route6d.h"
 #include "interface.h"
 #include "addrtoname.h"
+#include "extract.h"
 
 static int
 rip6_entry_print(register const struct netinfo6 *ni, int metric)
@@ -53,25 +60,29 @@ rip6_entry_print(register const struct netinfo6 *ni, int metric)
        int l;
        l = printf("%s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen);
        if (ni->rip6_tag)
-               l += printf(" [%d]", ntohs(ni->rip6_tag));
+               l += printf(" [%d]", EXTRACT_16BITS(&ni->rip6_tag));
        if (metric)
                l += printf(" (%d)", ni->rip6_metric);
        return l;
 }
 
 void
-ripng_print(const u_char *dat, int length)
+ripng_print(const u_char *dat, unsigned int length)
 {
        register const struct rip6 *rp = (struct rip6 *)dat;
        register const struct netinfo6 *ni;
-       register int amt = snapend - dat;
-       register int i = min(length, amt) -
-                        (sizeof(struct rip6) - sizeof(struct netinfo6));
+       register u_int amt;
+       register u_int i;
        int j;
        int trunc;
 
-       if (i < 0)
+       if (snapend < dat)
+               return;
+       amt = snapend - dat;
+       i = min(length, amt);
+       if (i < (sizeof(struct rip6) - sizeof(struct netinfo6)))
                return;
+       i -= (sizeof(struct rip6) - sizeof(struct netinfo6));
 
        switch (rp->rip6_cmd) {
 
@@ -84,12 +95,13 @@ ripng_print(const u_char *dat, int length)
                        break;
                }
                if (j * sizeof(*ni) != length - 4)
-                       printf(" ripng-req %d[%d]:", j, length);
+                       printf(" ripng-req %d[%u]:", j, length);
                else
                        printf(" ripng-req %d:", j);
                trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
-               for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) {
-                       if (vflag)
+               for (ni = rp->rip6_nets; i >= sizeof(*ni);
+                   i -= sizeof(*ni), ++ni) {
+                       if (vflag > 1)
                                printf("\n\t");
                        else
                                printf(" ");
@@ -99,22 +111,23 @@ ripng_print(const u_char *dat, int length)
        case RIP6_RESPONSE:
                j = length / sizeof(*ni);
                if (j * sizeof(*ni) != length - 4)
-                       printf(" ripng-resp %d[%d]:", j, length);
+                       printf(" ripng-resp %d[%u]:", j, length);
                else
                        printf(" ripng-resp %d:", j);
                trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
-               for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) {
-                       if (vflag)
+               for (ni = rp->rip6_nets; i >= sizeof(*ni);
+                   i -= sizeof(*ni), ++ni) {
+                       if (vflag > 1)
                                printf("\n\t");
                        else
                                printf(" ");
                        rip6_entry_print(ni, ni->rip6_metric);
                }
                if (trunc)
-                       printf("[|rip]");
+                       printf("[|ripng]");
                break;
        default:
-               printf(" ripng-%d ?? %d", rp->rip6_cmd, length);
+               printf(" ripng-%d ?? %u", rp->rip6_cmd, length);
                break;
        }
        if (rp->rip6_vers != RIP6_VERSION)