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