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 #ifndef lint 23 static const char rcsid[] = 24 "@(#) $Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.2.2.1 2000/01/11 06:58:26 fenner Exp $"; 25 #endif 26 27 #ifdef HAVE_CONFIG_H 28 #include "config.h" 29 #endif 30 31 #ifdef INET6 32 33 #include <sys/param.h> 34 #include <sys/time.h> 35 #include <sys/types.h> 36 #include <sys/socket.h> 37 38 #include <netinet/in.h> 39 #include <netinet/in_systm.h> 40 #include <netinet/ip.h> 41 #include <netinet/ip_var.h> 42 #include <netinet/udp.h> 43 #include <netinet/udp_var.h> 44 45 #include <errno.h> 46 #include <stdio.h> 47 48 #include <netinet/ip6.h> 49 50 #include "route6d.h" 51 #include "interface.h" 52 #include "addrtoname.h" 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]", ntohs(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, int length) 68 { 69 register const struct rip6 *rp = (struct rip6 *)dat; 70 register const struct netinfo6 *ni; 71 register int amt = snapend - dat; 72 register int i = min(length, amt) - 73 (sizeof(struct rip6) - sizeof(struct netinfo6)); 74 int j; 75 int trunc; 76 77 if (i < 0) 78 return; 79 80 switch (rp->rip6_cmd) { 81 82 case RIP6_REQUEST: 83 j = length / sizeof(*ni); 84 if (j == 1 85 && rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6 86 && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) { 87 printf(" ripng-req dump"); 88 break; 89 } 90 if (j * sizeof(*ni) != length - 4) 91 printf(" ripng-req %d[%d]:", j, length); 92 else 93 printf(" ripng-req %d:", j); 94 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); 95 for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { 96 if (vflag) 97 printf("\n\t"); 98 else 99 printf(" "); 100 rip6_entry_print(ni, 0); 101 } 102 break; 103 case RIP6_RESPONSE: 104 j = length / sizeof(*ni); 105 if (j * sizeof(*ni) != length - 4) 106 printf(" ripng-resp %d[%d]:", j, length); 107 else 108 printf(" ripng-resp %d:", j); 109 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); 110 for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { 111 if (vflag) 112 printf("\n\t"); 113 else 114 printf(" "); 115 rip6_entry_print(ni, ni->rip6_metric); 116 } 117 if (trunc) 118 printf("[|rip]"); 119 break; 120 default: 121 printf(" ripng-%d ?? %d", rp->rip6_cmd, length); 122 break; 123 } 124 if (rp->rip6_vers != RIP6_VERSION) 125 printf(" [vers %d]", rp->rip6_vers); 126 } 127 #endif /* INET6 */ 128