print-ripng.c revision 98524
1129198Scognet/* 2129198Scognet * Copyright (c) 1989, 1990, 1991, 1993, 1994 3139735Simp * The Regents of the University of California. All rights reserved. 4129198Scognet * 5129198Scognet * Redistribution and use in source and binary forms, with or without 6129198Scognet * modification, are permitted provided that: (1) source code distributions 7129198Scognet * retain the above copyright notice and this paragraph in its entirety, (2) 8129198Scognet * distributions including binary code include the above copyright notice and 9129198Scognet * this paragraph in its entirety in the documentation or other materials 10129198Scognet * provided with the distribution, and (3) all advertising materials mentioning 11129198Scognet * features or use of this software display the following acknowledgement: 12129198Scognet * ``This product includes software developed by the University of California, 13129198Scognet * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14129198Scognet * the University nor the names of its contributors may be used to endorse 15129198Scognet * or promote products derived from this software without specific prior 16129198Scognet * written permission. 17129198Scognet * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18129198Scognet * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19129198Scognet * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20129198Scognet */ 21129198Scognet 22129198Scognet#ifndef lint 23129198Scognetstatic const char rcsid[] = 24129198Scognet "@(#) $Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.10 2001/11/16 08:59:22 itojun Exp $"; 25129198Scognet#endif 26129198Scognet 27129198Scognet#ifdef HAVE_CONFIG_H 28129198Scognet#include "config.h" 29129198Scognet#endif 30129198Scognet 31129198Scognet#ifdef INET6 32129198Scognet 33129198Scognet#include <sys/param.h> 34129198Scognet#include <sys/time.h> 35129198Scognet#include <sys/types.h> 36129198Scognet#include <sys/socket.h> 37129198Scognet 38139735Simp#include <netinet/in.h> 39129198Scognet 40129198Scognet#include <errno.h> 41129198Scognet#include <stdio.h> 42129198Scognet 43129198Scognet#include "route6d.h" 44129198Scognet#include "interface.h" 45129198Scognet#include "addrtoname.h" 46129198Scognet 47129198Scognetstatic int 48129198Scognetrip6_entry_print(register const struct netinfo6 *ni, int metric) 49129198Scognet{ 50129198Scognet int l; 51129198Scognet l = printf("%s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen); 52129198Scognet if (ni->rip6_tag) 53129198Scognet l += printf(" [%d]", ntohs(ni->rip6_tag)); 54129198Scognet if (metric) 55129198Scognet l += printf(" (%d)", ni->rip6_metric); 56129198Scognet return l; 57129198Scognet} 58129198Scognet 59129198Scognetvoid 60129198Scognetripng_print(const u_char *dat, unsigned int length) 61129198Scognet{ 62129198Scognet register const struct rip6 *rp = (struct rip6 *)dat; 63129198Scognet register const struct netinfo6 *ni; 64129198Scognet register int amt = snapend - dat; 65129198Scognet register int i = min(length, amt) - 66129198Scognet (sizeof(struct rip6) - sizeof(struct netinfo6)); 67129198Scognet int j; 68129198Scognet int trunc; 69129198Scognet 70129198Scognet if (i < 0) 71129198Scognet return; 72129198Scognet 73129198Scognet switch (rp->rip6_cmd) { 74129198Scognet 75129198Scognet case RIP6_REQUEST: 76129198Scognet j = length / sizeof(*ni); 77129198Scognet if (j == 1 78129198Scognet && rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6 79129198Scognet && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) { 80129198Scognet printf(" ripng-req dump"); 81129198Scognet break; 82135656Scognet } 83135656Scognet if (j * sizeof(*ni) != length - 4) 84129198Scognet printf(" ripng-req %d[%u]:", j, length); 85129198Scognet else 86129198Scognet printf(" ripng-req %d:", j); 87129198Scognet trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); 88129198Scognet for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { 89129198Scognet if (vflag > 1) 90129198Scognet printf("\n\t"); 91129198Scognet else 92129198Scognet printf(" "); 93129198Scognet rip6_entry_print(ni, 0); 94129198Scognet } 95129198Scognet break; 96129198Scognet case RIP6_RESPONSE: 97138328Scognet j = length / sizeof(*ni); 98138709Scognet if (j * sizeof(*ni) != length - 4) 99135656Scognet printf(" ripng-resp %d[%u]:", j, length); 100135656Scognet else 101135656Scognet printf(" ripng-resp %d:", j); 102135656Scognet trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); 103140001Scognet for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) { 104140001Scognet if (vflag > 1) 105129198Scognet printf("\n\t"); 106129198Scognet else 107129198Scognet printf(" "); 108129198Scognet rip6_entry_print(ni, ni->rip6_metric); 109129198Scognet } 110129198Scognet if (trunc) 111129198Scognet printf("[|ripng]"); 112129198Scognet break; 113129198Scognet default: 114129198Scognet printf(" ripng-%d ?? %u", rp->rip6_cmd, length); 115129198Scognet break; 116129198Scognet } 117129198Scognet if (rp->rip6_vers != RIP6_VERSION) 118138129Sdas printf(" [vers %d]", rp->rip6_vers); 119129198Scognet} 120129198Scognet#endif /* INET6 */ 121147544Scognet