if.c (53068) | if.c (54263) |
---|---|
1/* 2 * Copyright (c) 1983, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35/* 36static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95"; 37*/ 38static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35/* 36static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95"; 37*/ 38static const char rcsid[] = |
39 "$FreeBSD: head/usr.bin/netstat/if.c 53068 1999-11-09 22:22:36Z dfr $"; | 39 "$FreeBSD: head/usr.bin/netstat/if.c 54263 1999-12-07 17:39:16Z shin $"; |
40#endif /* not lint */ 41 42#include <sys/types.h> 43#include <sys/protosw.h> 44#include <sys/socket.h> 45#include <sys/sysctl.h> 46#include <sys/time.h> 47 --- 25 unchanged lines hidden (view full) --- 73#include "netstat.h" 74 75#define YES 1 76#define NO 0 77 78static void sidewaysintpr __P((u_int, u_long)); 79static void catchalarm __P((int)); 80 | 40#endif /* not lint */ 41 42#include <sys/types.h> 43#include <sys/protosw.h> 44#include <sys/socket.h> 45#include <sys/sysctl.h> 46#include <sys/time.h> 47 --- 25 unchanged lines hidden (view full) --- 73#include "netstat.h" 74 75#define YES 1 76#define NO 0 77 78static void sidewaysintpr __P((u_int, u_long)); 79static void catchalarm __P((int)); 80 |
81#ifdef INET6 82char *netname6 __P((struct sockaddr_in6 *, struct in6_addr *)); 83static char ntop_buf[INET6_ADDRSTRLEN]; /* for inet_ntop() */ 84static int bdg_done; 85#endif 86 |
|
81void 82bdg_stats(u_long dummy, char *name) /* print bridge statistics */ 83{ 84 int i; 85 size_t slen ; 86 struct bdg_stats s ; 87 int mib[4] ; 88 89 slen = sizeof(s); 90 91 mib[0] = CTL_NET ; 92 mib[1] = PF_LINK ; 93 mib[2] = IFT_ETHER ; 94 mib[3] = PF_BDG ; 95 if (sysctl(mib,4, &s,&slen,NULL,0)==-1) 96 return ; /* no bridging */ | 87void 88bdg_stats(u_long dummy, char *name) /* print bridge statistics */ 89{ 90 int i; 91 size_t slen ; 92 struct bdg_stats s ; 93 int mib[4] ; 94 95 slen = sizeof(s); 96 97 mib[0] = CTL_NET ; 98 mib[1] = PF_LINK ; 99 mib[2] = IFT_ETHER ; 100 mib[3] = PF_BDG ; 101 if (sysctl(mib,4, &s,&slen,NULL,0)==-1) 102 return ; /* no bridging */ |
103#ifdef INET6 104 if (bdg_done != 0) 105 return; 106 else 107 bdg_done = 1; 108#endif |
|
97 printf("-- Bridging statistics (%s) --\n", name) ; 98 printf( 99"Name In Out Forward Drop Bcast Mcast Local Unknown\n"); 100 for (i = 0 ; i < 16 ; i++) { 101 if (s.s[i].name[0]) 102 printf("%-6s %9ld%9ld%9ld%9ld%9ld%9ld%9ld%9ld\n", 103 s.s[i].name, 104 s.s[i].p_in[(int)BDG_IN], --- 6 unchanged lines hidden (view full) --- 111 s.s[i].p_in[(int)BDG_UNKNOWN] ); 112 } 113} 114 115/* 116 * Print a description of the network interfaces. 117 */ 118void | 109 printf("-- Bridging statistics (%s) --\n", name) ; 110 printf( 111"Name In Out Forward Drop Bcast Mcast Local Unknown\n"); 112 for (i = 0 ; i < 16 ; i++) { 113 if (s.s[i].name[0]) 114 printf("%-6s %9ld%9ld%9ld%9ld%9ld%9ld%9ld%9ld\n", 115 s.s[i].name, 116 s.s[i].p_in[(int)BDG_IN], --- 6 unchanged lines hidden (view full) --- 123 s.s[i].p_in[(int)BDG_UNKNOWN] ); 124 } 125} 126 127/* 128 * Print a description of the network interfaces. 129 */ 130void |
119intpr(interval, ifnetaddr) | 131intpr(interval, ifnetaddr, pfunc) |
120 int interval; 121 u_long ifnetaddr; | 132 int interval; 133 u_long ifnetaddr; |
134 void (*pfunc)(char *); |
|
122{ 123 struct ifnet ifnet; 124 struct ifnethead ifnethead; 125 union { 126 struct ifaddr ifa; 127 struct in_ifaddr in; | 135{ 136 struct ifnet ifnet; 137 struct ifnethead ifnethead; 138 union { 139 struct ifaddr ifa; 140 struct in_ifaddr in; |
141#ifdef INET6 142 struct in6_ifaddr in6; 143#endif |
|
128 struct ipx_ifaddr ipx; 129#ifdef NS 130 struct ns_ifaddr ns; 131#endif 132#ifdef ISO 133 struct iso_ifaddr iso; 134#endif 135 } ifaddr; --- 12 unchanged lines hidden (view full) --- 148 return; 149 } 150 if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead)) 151 return; 152 ifnetaddr = (u_long)ifnethead.tqh_first; 153 if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) 154 return; 155 | 144 struct ipx_ifaddr ipx; 145#ifdef NS 146 struct ns_ifaddr ns; 147#endif 148#ifdef ISO 149 struct iso_ifaddr iso; 150#endif 151 } ifaddr; --- 12 unchanged lines hidden (view full) --- 164 return; 165 } 166 if (kread(ifnetaddr, (char *)&ifnethead, sizeof ifnethead)) 167 return; 168 ifnetaddr = (u_long)ifnethead.tqh_first; 169 if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) 170 return; 171 |
156 printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s", 157 "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs"); 158 if (bflag) 159 printf(" %10.10s","Ibytes"); 160 printf(" %8.8s %5.5s", "Opkts", "Oerrs"); 161 if (bflag) 162 printf(" %10.10s","Obytes"); 163 printf(" %5s", "Coll"); 164 if (tflag) 165 printf(" %s", "Time"); 166 if (dflag) 167 printf(" %s", "Drop"); 168 putchar('\n'); | 172 if (!sflag && !pflag) { 173 printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s", 174 "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs"); 175 if (bflag) 176 printf(" %10.10s","Ibytes"); 177 printf(" %8.8s %5.5s", "Opkts", "Oerrs"); 178 if (bflag) 179 printf(" %10.10s","Obytes"); 180 printf(" %5s", "Coll"); 181 if (tflag) 182 printf(" %s", "Time"); 183 if (dflag) 184 printf(" %s", "Drop"); 185 putchar('\n'); 186 } |
169 ifaddraddr = 0; 170 while (ifnetaddr || ifaddraddr) { 171 struct sockaddr_in *sin; | 187 ifaddraddr = 0; 188 while (ifnetaddr || ifaddraddr) { 189 struct sockaddr_in *sin; |
190#ifdef INET6 191 struct sockaddr_in6 *sin6; 192#endif |
|
172 register char *cp; 173 int n, m; 174 175 if (ifaddraddr == 0) { 176 ifnetfound = ifnetaddr; 177 if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) || 178 kread((u_long)ifnet.if_name, tname, 16)) 179 return; 180 tname[15] = '\0'; 181 ifnetaddr = (u_long)ifnet.if_link.tqe_next; 182 snprintf(name, 32, "%s%d", tname, ifnet.if_unit); 183 if (interface != 0 && (strcmp(name, interface) != 0)) 184 continue; 185 cp = index(name, '\0'); | 193 register char *cp; 194 int n, m; 195 196 if (ifaddraddr == 0) { 197 ifnetfound = ifnetaddr; 198 if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) || 199 kread((u_long)ifnet.if_name, tname, 16)) 200 return; 201 tname[15] = '\0'; 202 ifnetaddr = (u_long)ifnet.if_link.tqe_next; 203 snprintf(name, 32, "%s%d", tname, ifnet.if_unit); 204 if (interface != 0 && (strcmp(name, interface) != 0)) 205 continue; 206 cp = index(name, '\0'); |
207 208 if (pfunc) { 209 (*pfunc)(name); 210 continue; 211 } 212 |
|
186 if ((ifnet.if_flags&IFF_UP) == 0) 187 *cp++ = '*'; 188 *cp = '\0'; 189 ifaddraddr = (u_long)ifnet.if_addrhead.tqh_first; 190 } 191 printf("%-5.5s %-5lu ", name, ifnet.if_mtu); 192 ifaddrfound = ifaddraddr; 193 if (ifaddraddr == 0) { --- 26 unchanged lines hidden (view full) --- 220#else 221 printf("%-13.13s ", 222 netname(htonl(ifaddr.in.ia_subnet), 223 ifaddr.in.ia_subnetmask)); 224#endif 225 printf("%-15.15s ", 226 routename(sin->sin_addr.s_addr)); 227 break; | 213 if ((ifnet.if_flags&IFF_UP) == 0) 214 *cp++ = '*'; 215 *cp = '\0'; 216 ifaddraddr = (u_long)ifnet.if_addrhead.tqh_first; 217 } 218 printf("%-5.5s %-5lu ", name, ifnet.if_mtu); 219 ifaddrfound = ifaddraddr; 220 if (ifaddraddr == 0) { --- 26 unchanged lines hidden (view full) --- 247#else 248 printf("%-13.13s ", 249 netname(htonl(ifaddr.in.ia_subnet), 250 ifaddr.in.ia_subnetmask)); 251#endif 252 printf("%-15.15s ", 253 routename(sin->sin_addr.s_addr)); 254 break; |
255#ifdef INET6 256 case AF_INET6: 257 sin6 = (struct sockaddr_in6 *)sa; 258 printf("%-11.11s ", 259 netname6(&ifaddr.in6.ia_addr, 260 &ifaddr.in6.ia_prefixmask.sin6_addr)); 261 printf("%-17.17s ", 262 (char *)inet_ntop(AF_INET6, 263 &sin6->sin6_addr, 264 ntop_buf, sizeof(ntop_buf))); 265 break; 266#endif /*INET6*/ |
|
228 case AF_IPX: 229 { 230 struct sockaddr_ipx *sipx = 231 (struct sockaddr_ipx *)sa; 232 u_long net; 233 char netnum[10]; 234 235 *(union ipx_net *) &net = sipx->sipx_addr.x_net; --- 25 unchanged lines hidden (view full) --- 261 ns_phost((struct sockaddr *)sns)); 262 } 263 break; 264#endif 265 case AF_LINK: 266 { 267 struct sockaddr_dl *sdl = 268 (struct sockaddr_dl *)sa; | 267 case AF_IPX: 268 { 269 struct sockaddr_ipx *sipx = 270 (struct sockaddr_ipx *)sa; 271 u_long net; 272 char netnum[10]; 273 274 *(union ipx_net *) &net = sipx->sipx_addr.x_net; --- 25 unchanged lines hidden (view full) --- 300 ns_phost((struct sockaddr *)sns)); 301 } 302 break; 303#endif 304 case AF_LINK: 305 { 306 struct sockaddr_dl *sdl = 307 (struct sockaddr_dl *)sa; |
269 cp = (char *)LLADDR(sdl); 270 n = sdl->sdl_alen; | 308 char linknum[10]; 309 cp = (char *)LLADDR(sdl); 310 n = sdl->sdl_alen; 311 sprintf(linknum, "<Link#%d>", sdl->sdl_index); 312 m = printf("%-11.11s ", linknum); |
271 } | 313 } |
272 m = printf("%-11.11s ", "<Link>"); | |
273 goto hexprint; 274 default: 275 m = printf("(%d)", sa->sa_family); 276 for (cp = sa->sa_len + (char *)sa; 277 --cp > sa->sa_data && (*cp == 0);) {} 278 n = cp - sa->sa_data + 1; 279 cp = sa->sa_data; 280 hexprint: --- 25 unchanged lines hidden (view full) --- 306 /* 307 * Print family's multicast addresses 308 */ 309 u_long multiaddr; 310 struct ifmultiaddr ifma; 311 union { 312 struct sockaddr sa; 313 struct sockaddr_in in; | 314 goto hexprint; 315 default: 316 m = printf("(%d)", sa->sa_family); 317 for (cp = sa->sa_len + (char *)sa; 318 --cp > sa->sa_data && (*cp == 0);) {} 319 n = cp - sa->sa_data + 1; 320 cp = sa->sa_data; 321 hexprint: --- 25 unchanged lines hidden (view full) --- 347 /* 348 * Print family's multicast addresses 349 */ 350 u_long multiaddr; 351 struct ifmultiaddr ifma; 352 union { 353 struct sockaddr sa; 354 struct sockaddr_in in; |
355#ifdef INET6 356 struct sockaddr_in6 in6; 357#endif /* INET6 */ |
|
314 struct sockaddr_dl dl; 315 } msa; 316 const char *fmt; 317 318 for(multiaddr = (u_long)ifnet.if_multiaddrs.lh_first; 319 multiaddr; 320 multiaddr = (u_long)ifma.ifma_link.le_next) { 321 if (kread(multiaddr, (char *)&ifma, --- 5 unchanged lines hidden (view full) --- 327 if (msa.sa.sa_family != sa->sa_family) 328 continue; 329 330 fmt = 0; 331 switch (msa.sa.sa_family) { 332 case AF_INET: 333 fmt = routename(msa.in.sin_addr.s_addr); 334 break; | 358 struct sockaddr_dl dl; 359 } msa; 360 const char *fmt; 361 362 for(multiaddr = (u_long)ifnet.if_multiaddrs.lh_first; 363 multiaddr; 364 multiaddr = (u_long)ifma.ifma_link.le_next) { 365 if (kread(multiaddr, (char *)&ifma, --- 5 unchanged lines hidden (view full) --- 371 if (msa.sa.sa_family != sa->sa_family) 372 continue; 373 374 fmt = 0; 375 switch (msa.sa.sa_family) { 376 case AF_INET: 377 fmt = routename(msa.in.sin_addr.s_addr); 378 break; |
335 | 379#ifdef INET6 380 case AF_INET6: 381 printf("%23s %-19.19s(refs: %d)\n", "", 382 inet_ntop(AF_INET6, 383 &msa.in6.sin6_addr, 384 ntop_buf, 385 sizeof(ntop_buf)), 386 ifma.ifma_refcount); 387#endif /* INET6 */ |
336 case AF_LINK: 337 switch (ifnet.if_type) { 338 case IFT_ETHER: 339 case IFT_FDDI: 340 fmt = ether_ntoa( 341 (struct ether_addr *) 342 LLADDR(&msa.dl)); 343 break; --- 195 unchanged lines hidden --- | 388 case AF_LINK: 389 switch (ifnet.if_type) { 390 case IFT_ETHER: 391 case IFT_FDDI: 392 fmt = ether_ntoa( 393 (struct ether_addr *) 394 LLADDR(&msa.dl)); 395 break; --- 195 unchanged lines hidden --- |