1 /* 2 * Copyright (c) 1989, 1990, 1991, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning 11 * features or use of this software display the following acknowledgement: 12 * ``This product includes software developed by the University of California, 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 */ 21 22 #include <sys/cdefs.h> 23 #ifndef lint 24 #if 0 25 static const char rcsid[] _U_ = 26 "@(#) Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.18 2005-01-04 00:15:54 guy Exp"; 27 #else 28 __RCSID("$NetBSD: print-ripng.c,v 1.2 2010/12/05 05:11:30 christos Exp $"); 29 #endif 30 #endif 31 32 #ifdef HAVE_CONFIG_H 33 #include "config.h" 34 #endif 35 36 #ifdef INET6 37 38 #include <tcpdump-stdinc.h> 39 #include <stdio.h> 40 41 #include "route6d.h" 42 #include "interface.h" 43 #include "addrtoname.h" 44 #include "extract.h" 45 46 #if !defined(IN6_IS_ADDR_UNSPECIFIED) && !defined(_MSC_VER) /* MSVC inline */ 47 static int IN6_IS_ADDR_UNSPECIFIED(const struct in6_addr *addr) 48 { 49 static const struct in6_addr in6addr_any; /* :: */ 50 return (memcmp(addr, &in6addr_any, sizeof(*addr)) == 0); 51 } 52 #endif 53 54 static int 55 rip6_entry_print(register const struct netinfo6 *ni, int metric) 56 { 57 int l; 58 l = printf("%s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen); 59 if (ni->rip6_tag) 60 l += printf(" [%d]", EXTRACT_16BITS(&ni->rip6_tag)); 61 if (metric) 62 l += printf(" (%d)", ni->rip6_metric); 63 return l; 64 } 65 66 void 67 ripng_print(const u_char *dat, unsigned int length) 68 { 69 register const struct rip6 *rp = (struct rip6 *)dat; 70 register const struct netinfo6 *ni; 71 register u_int amt; 72 register u_int i; 73 int j; 74 int trunc; 75 76 if (snapend < dat) 77 return; 78 amt = snapend - dat; 79 i = min(length, amt); 80 if (i < (sizeof(struct rip6) - sizeof(struct netinfo6))) 81 return; 82 i -= (sizeof(struct rip6) - sizeof(struct netinfo6)); 83 84 switch (rp->rip6_cmd) { 85 86 case RIP6_REQUEST: 87 j = length / sizeof(*ni); 88 if (j == 1 89 && rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6 90 && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) { 91 printf(" ripng-req dump"); 92 break; 93 } 94 if (j * sizeof(*ni) != length - 4) 95 printf(" ripng-req %d[%u]:", j, length); 96 else 97 printf(" ripng-req %d:", j); 98 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); 99 for (ni = rp->rip6_nets; i >= sizeof(*ni); 100 i -= sizeof(*ni), ++ni) { 101 if (vflag > 1) 102 printf("\n\t"); 103 else 104 printf(" "); 105 rip6_entry_print(ni, 0); 106 } 107 break; 108 case RIP6_RESPONSE: 109 j = length / sizeof(*ni); 110 if (j * sizeof(*ni) != length - 4) 111 printf(" ripng-resp %d[%u]:", j, length); 112 else 113 printf(" ripng-resp %d:", j); 114 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); 115 for (ni = rp->rip6_nets; i >= sizeof(*ni); 116 i -= sizeof(*ni), ++ni) { 117 if (vflag > 1) 118 printf("\n\t"); 119 else 120 printf(" "); 121 rip6_entry_print(ni, ni->rip6_metric); 122 } 123 if (trunc) 124 printf("[|ripng]"); 125 break; 126 default: 127 printf(" ripng-%d ?? %u", rp->rip6_cmd, length); 128 break; 129 } 130 if (rp->rip6_vers != RIP6_VERSION) 131 printf(" [vers %d]", rp->rip6_vers); 132 } 133 #endif /* INET6 */ 134