print-ripng.c revision 98524
1214503Srpaulo/* 2214503Srpaulo * Copyright (c) 1989, 1990, 1991, 1993, 1994 3214503Srpaulo * The Regents of the University of California. All rights reserved. 4214503Srpaulo * 5281806Srpaulo * Redistribution and use in source and binary forms, with or without 6214503Srpaulo * modification, are permitted provided that: (1) source code distributions 7214503Srpaulo * retain the above copyright notice and this paragraph in its entirety, (2) 8252726Srpaulo * distributions including binary code include the above copyright notice and 9252726Srpaulo * this paragraph in its entirety in the documentation or other materials 10214503Srpaulo * provided with the distribution, and (3) all advertising materials mentioning 11252726Srpaulo * features or use of this software display the following acknowledgement: 12252726Srpaulo * ``This product includes software developed by the University of California, 13214503Srpaulo * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14214503Srpaulo * the University nor the names of its contributors may be used to endorse 15252726Srpaulo * or promote products derived from this software without specific prior 16214503Srpaulo * written permission. 17214503Srpaulo * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18214503Srpaulo * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19252726Srpaulo * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20252726Srpaulo */ 21214503Srpaulo 22214503Srpaulo#ifndef lint 23214503Srpaulostatic const char rcsid[] = 24214503Srpaulo "@(#) $Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.10 2001/11/16 08:59:22 itojun Exp $"; 25214503Srpaulo#endif 26214503Srpaulo 27214503Srpaulo#ifdef HAVE_CONFIG_H 28214503Srpaulo#include "config.h" 29214503Srpaulo#endif 30214503Srpaulo 31214503Srpaulo#ifdef INET6 32214503Srpaulo 33214503Srpaulo#include <sys/param.h> 34214503Srpaulo#include <sys/time.h> 35214503Srpaulo#include <sys/types.h> 36214503Srpaulo#include <sys/socket.h> 37214503Srpaulo 38214503Srpaulo#include <netinet/in.h> 39214503Srpaulo 40214503Srpaulo#include <errno.h> 41214503Srpaulo#include <stdio.h> 42214503Srpaulo 43214503Srpaulo#include "route6d.h" 44214503Srpaulo#include "interface.h" 45214503Srpaulo#include "addrtoname.h" 46214503Srpaulo 47214503Srpaulostatic int 48214503Srpaulorip6_entry_print(register const struct netinfo6 *ni, int metric) 49214503Srpaulo{ 50214503Srpaulo int l; 51214503Srpaulo l = printf("%s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen); 52214503Srpaulo if (ni->rip6_tag) 53214503Srpaulo l += printf(" [%d]", ntohs(ni->rip6_tag)); 54214503Srpaulo if (metric) 55214503Srpaulo l += printf(" (%d)", ni->rip6_metric); 56214503Srpaulo return l; 57214503Srpaulo} 58214503Srpaulo 59214503Srpaulovoid 60214503Srpauloripng_print(const u_char *dat, unsigned int length) 61214503Srpaulo{ 62214503Srpaulo register const struct rip6 *rp = (struct rip6 *)dat; 63214503Srpaulo register const struct netinfo6 *ni; 64214503Srpaulo register int amt = snapend - dat; 65214503Srpaulo register int i = min(length, amt) - 66214503Srpaulo (sizeof(struct rip6) - sizeof(struct netinfo6)); 67214503Srpaulo int j; 68214503Srpaulo int trunc; 69214503Srpaulo 70214503Srpaulo if (i < 0) 71214503Srpaulo return; 72214503Srpaulo 73214503Srpaulo switch (rp->rip6_cmd) { 74214503Srpaulo 75214503Srpaulo case RIP6_REQUEST: 76214503Srpaulo j = length / sizeof(*ni); 77214503Srpaulo if (j == 1 78214503Srpaulo && rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6 79214503Srpaulo && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) { 80214503Srpaulo printf(" ripng-req dump"); 81214503Srpaulo break; 82214503Srpaulo } 83214503Srpaulo if (j * sizeof(*ni) != length - 4) 84214503Srpaulo printf(" ripng-req %d[%u]:", j, length); 85214503Srpaulo else 86214503Srpaulo printf(" ripng-req %d:", j); 87214503Srpaulo trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); 88214503Srpaulo for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { 89214503Srpaulo if (vflag > 1) 90214503Srpaulo printf("\n\t"); 91214503Srpaulo else 92214503Srpaulo printf(" "); 93214503Srpaulo rip6_entry_print(ni, 0); 94214503Srpaulo } 95214503Srpaulo break; 96214503Srpaulo case RIP6_RESPONSE: 97214503Srpaulo j = length / sizeof(*ni); 98214503Srpaulo if (j * sizeof(*ni) != length - 4) 99214503Srpaulo printf(" ripng-resp %d[%u]:", j, length); 100214503Srpaulo else 101214503Srpaulo printf(" ripng-resp %d:", j); 102214503Srpaulo trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); 103214503Srpaulo for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { 104214503Srpaulo if (vflag > 1) 105214503Srpaulo printf("\n\t"); 106214503Srpaulo else 107214503Srpaulo printf(" "); 108214503Srpaulo rip6_entry_print(ni, ni->rip6_metric); 109214503Srpaulo } 110214503Srpaulo if (trunc) 111214503Srpaulo printf("[|ripng]"); 112214503Srpaulo break; 113214503Srpaulo default: 114214503Srpaulo printf(" ripng-%d ?? %u", rp->rip6_cmd, length); 115214503Srpaulo break; 116214503Srpaulo } 117214503Srpaulo if (rp->rip6_vers != RIP6_VERSION) 118214503Srpaulo printf(" [vers %d]", rp->rip6_vers); 119214503Srpaulo} 120214503Srpaulo#endif /* INET6 */ 121214503Srpaulo