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