1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1991-1999 by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" /* SunOS */ 28 29 #include <ctype.h> 30 #include <fcntl.h> 31 #include <sys/socket.h> 32 #include <sys/types.h> 33 #include <net/if.h> 34 #include <netinet/in_systm.h> 35 #include <netinet/in.h> 36 #include <netinet/ip.h> 37 #include <inet/led.h> 38 #include <inet/ip6.h> 39 #include <arpa/inet.h> 40 #include <protocols/routed.h> 41 #include <protocols/ripngd.h> 42 #include "snoop.h" 43 44 extern char *dlc_header; 45 static char *show_cmd6(); 46 47 static struct in6_addr all_zeroes_addr = { { 0x0, 0x0, 0x0, 0x0, 48 0x0, 0x0, 0x0, 0x0, 49 0x0, 0x0, 0x0, 0x0, 50 0x0, 0x0, 0x0, 0x0 } }; 51 52 interpret_rip6(flags, rip6, fraglen) 53 int flags; 54 struct rip6 *rip6; 55 int fraglen; 56 { 57 char *p; 58 struct netinfo6 *n; 59 int len, count; 60 struct in6_addr *dst; 61 int notdefault = 0; 62 char dststr[INET6_ADDRSTRLEN]; 63 64 if (flags & F_SUM) { 65 switch (rip6->rip6_cmd) { 66 case RIPCMD6_REQUEST: p = "C"; break; 67 case RIPCMD6_RESPONSE: p = "R"; break; 68 default: p = "?"; break; 69 } 70 71 switch (rip6->rip6_cmd) { 72 case RIPCMD6_REQUEST: 73 case RIPCMD6_RESPONSE: 74 len = fraglen - 4; 75 count = 0; 76 for (n = rip6->rip6_nets; 77 len >= sizeof (struct netinfo6); n++) { 78 count++; 79 len -= sizeof (struct netinfo6); 80 } 81 (void) sprintf(get_sum_line(), 82 "RIPng %s (%d destinations)", p, count); 83 break; 84 default: 85 (void) sprintf(get_sum_line(), "RIPng %s", p); 86 break; 87 } 88 } 89 90 if (flags & F_DTAIL) { 91 92 show_header("RIPng: ", "Routing Information Protocol for IPv6", 93 fraglen); 94 show_space(); 95 (void) sprintf(get_line((char *)rip6->rip6_cmd - dlc_header, 1), 96 "Opcode = %d (%s)", 97 rip6->rip6_cmd, 98 show_cmd6(rip6->rip6_cmd)); 99 (void) sprintf(get_line((char *)rip6->rip6_vers - 100 dlc_header, 1), "Version = %d", 101 rip6->rip6_vers); 102 103 switch (rip6->rip6_cmd) { 104 case RIPCMD6_REQUEST: 105 case RIPCMD6_RESPONSE: 106 show_space(); 107 (void) sprintf(get_line(0, 0), "Address" 108 " Prefix Metric"); 109 len = fraglen - 4; 110 for (n = rip6->rip6_nets; 111 len >= sizeof (struct netinfo6); n++) { 112 if (rip6->rip6_vers > 0) { 113 n->rip6_metric = n->rip6_metric; 114 } 115 dst = &n->rip6_prefix; 116 notdefault = bcmp((caddr_t *)dst, 117 (caddr_t *)&all_zeroes_addr, sizeof (*dst)); 118 (void) inet_ntop(AF_INET6, (char *)dst, dststr, 119 INET6_ADDRSTRLEN); 120 (void) sprintf(get_line((char *)n - dlc_header, 121 sizeof (struct netinfo6)), 122 "%-30s %-10d %-5d %s", 123 notdefault ? dststr : 124 " (default)", n->rip6_prefix_length, 125 n->rip6_metric, n->rip6_metric == 16 ? 126 " (not reachable)":""); 127 len -= sizeof (struct netinfo); 128 } 129 break; 130 } 131 } 132 return (fraglen); 133 } 134 135 static char * 136 show_cmd6(c) 137 int c; 138 { 139 switch (c) { 140 case RIPCMD6_REQUEST: return ("route request"); 141 case RIPCMD6_RESPONSE: return ("route response"); 142 } 143 return ("?"); 144 } 145