per-interface statistics.
bring in and enable KAME scopeid hack. lots of cleanups. (sync with latest KAME)
This commit is contained in:
parent
ea861f0183
commit
033763d6c9
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.18 1999/07/12 18:17:56 thorpej Exp $
|
||||
# $NetBSD: Makefile,v 1.19 1999/12/13 15:22:55 itojun Exp $
|
||||
# from: @(#)Makefile 8.1 (Berkeley) 6/12/93
|
||||
|
||||
PROG= netstat
|
||||
@ -11,4 +11,7 @@ LDADD= -lkvm
|
||||
DPADD= ${LIBKVM}
|
||||
CPPFLAGS+= -DINET6 -DIPSEC
|
||||
|
||||
# KAME scope id hack
|
||||
CPPFLAGS+=-DKAME_SCOPEID
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if.c,v 1.33 1999/11/19 10:44:33 bouyer Exp $ */
|
||||
/* $NetBSD: if.c,v 1.34 1999/12/13 15:22:55 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1988, 1993
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: if.c,v 1.33 1999/11/19 10:44:33 bouyer Exp $");
|
||||
__RCSID("$NetBSD: if.c,v 1.34 1999/12/13 15:22:55 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -61,6 +61,7 @@ __RCSID("$NetBSD: if.c,v 1.33 1999/11/19 10:44:33 bouyer Exp $");
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "netstat.h"
|
||||
|
||||
@ -71,8 +72,7 @@ static void sidewaysintpr __P((u_int, u_long));
|
||||
static void catchalarm __P((int));
|
||||
|
||||
#ifdef INET6
|
||||
char *netname6 __P((struct in6_addr *, struct in6_addr *));
|
||||
static char ntop_buf[INET6_ADDRSTRLEN]; /* for inet_ntop() */
|
||||
char *netname6 __P((struct sockaddr_in6 *, struct in6_addr *));
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -81,9 +81,10 @@ static char ntop_buf[INET6_ADDRSTRLEN]; /* for inet_ntop() */
|
||||
* which is a TAILQ_HEAD.
|
||||
*/
|
||||
void
|
||||
intpr(interval, ifnetaddr)
|
||||
intpr(interval, ifnetaddr, pfunc)
|
||||
int interval;
|
||||
u_long ifnetaddr;
|
||||
void (*pfunc)(char *);
|
||||
{
|
||||
struct ifnet ifnet;
|
||||
union {
|
||||
@ -99,6 +100,14 @@ intpr(interval, ifnetaddr)
|
||||
struct sockaddr *sa;
|
||||
struct ifnet_head ifhead; /* TAILQ_HEAD */
|
||||
char name[IFNAMSIZ];
|
||||
#ifdef INET6
|
||||
char hbuf[NI_MAXHOST]; /* for getnameinfo() */
|
||||
#ifdef KAME_SCOPEID
|
||||
const int niflag = NI_NUMERICHOST | NI_WITHSCOPEID;
|
||||
#else
|
||||
const int niflag = NI_NUMERICHOST;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (ifnetaddr == 0) {
|
||||
printf("ifnet: symbol not defined\n");
|
||||
@ -118,22 +127,24 @@ intpr(interval, ifnetaddr)
|
||||
return;
|
||||
ifnetaddr = (u_long)ifhead.tqh_first;
|
||||
|
||||
if (bflag) {
|
||||
printf("%-5.5s %-5.5s %-13.13s %-17.17s "
|
||||
"%10.10s %10.10s",
|
||||
"Name", "Mtu", "Network", "Address",
|
||||
"Ibytes", "Obytes");
|
||||
} else {
|
||||
printf("%-5.5s %-5.5s %-13.13s %-17.17s "
|
||||
"%8.8s %5.5s %8.8s %5.5s %5.5s",
|
||||
"Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
|
||||
"Opkts", "Oerrs", "Colls");
|
||||
if (!sflag & !pflag) {
|
||||
if (bflag) {
|
||||
printf("%-5.5s %-5.5s %-13.13s %-17.17s "
|
||||
"%10.10s %10.10s",
|
||||
"Name", "Mtu", "Network", "Address",
|
||||
"Ibytes", "Obytes");
|
||||
} else {
|
||||
printf("%-5.5s %-5.5s %-13.13s %-17.17s "
|
||||
"%8.8s %5.5s %8.8s %5.5s %5.5s",
|
||||
"Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
|
||||
"Opkts", "Oerrs", "Colls");
|
||||
}
|
||||
if (tflag)
|
||||
printf(" %4.4s", "Time");
|
||||
if (dflag)
|
||||
printf(" %5.5s", "Drops");
|
||||
putchar('\n');
|
||||
}
|
||||
if (tflag)
|
||||
printf(" %4.4s", "Time");
|
||||
if (dflag)
|
||||
printf(" %5.5s", "Drops");
|
||||
putchar('\n');
|
||||
ifaddraddr = 0;
|
||||
while (ifnetaddr || ifaddraddr) {
|
||||
struct sockaddr_in *sin;
|
||||
@ -152,6 +163,12 @@ intpr(interval, ifnetaddr)
|
||||
if (interface != 0 && strcmp(name, interface) != 0)
|
||||
continue;
|
||||
cp = strchr(name, '\0');
|
||||
|
||||
if (pfunc) {
|
||||
(*pfunc)(name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((ifnet.if_flags & IFF_UP) == 0)
|
||||
*cp++ = '*';
|
||||
*cp = '\0';
|
||||
@ -216,13 +233,34 @@ intpr(interval, ifnetaddr)
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
sin6 = (struct sockaddr_in6 *)sa;
|
||||
printf("%-13.13s ",
|
||||
netname6(&ifaddr.in6.ia_addr.sin6_addr,
|
||||
&ifaddr.in6.ia_prefixmask.sin6_addr));
|
||||
printf("%-17.17s ",
|
||||
(char *)inet_ntop(AF_INET6,
|
||||
&sin6->sin6_addr,
|
||||
ntop_buf, sizeof(ntop_buf)));
|
||||
cp = netname6(&ifaddr.in6.ia_addr,
|
||||
&ifaddr.in6.ia_prefixmask.sin6_addr);
|
||||
if (vflag)
|
||||
n = strlen(cp) < 13 ? 13 : strlen(cp);
|
||||
else
|
||||
n = 13;
|
||||
printf("%-*.*s ", n, n, cp);
|
||||
#if 0 /* KAME_SCOPEID: don't do it twice */
|
||||
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
||||
sin6->sin6_scope_id =
|
||||
ntohs(*(u_int16_t *)
|
||||
&sin6->sin6_addr.s6_addr[2]);
|
||||
sin6->sin6_addr.s6_addr[2] = 0;
|
||||
sin6->sin6_addr.s6_addr[3] = 0;
|
||||
}
|
||||
#endif
|
||||
if (getnameinfo((struct sockaddr *)sin6,
|
||||
sin6->sin6_len,
|
||||
hbuf, sizeof(hbuf), NULL, 0,
|
||||
niflag) != 0) {
|
||||
cp = "?";
|
||||
} else
|
||||
cp = hbuf;
|
||||
if (vflag)
|
||||
n = strlen(cp) < 17 ? 17 : strlen(cp);
|
||||
else
|
||||
n = 17;
|
||||
printf("%-*.*s ", n, n, cp);
|
||||
break;
|
||||
#endif /*INET6*/
|
||||
#ifndef SMALL
|
||||
@ -300,14 +338,14 @@ intpr(interval, ifnetaddr)
|
||||
#define MAXIF 100
|
||||
struct iftot {
|
||||
char ift_name[IFNAMSIZ]; /* interface name */
|
||||
u_quad_t ift_ip; /* input packets */
|
||||
u_quad_t ift_ib; /* input bytes */
|
||||
u_quad_t ift_ie; /* input errors */
|
||||
u_quad_t ift_op; /* output packets */
|
||||
u_quad_t ift_ob; /* output bytes */
|
||||
u_quad_t ift_oe; /* output errors */
|
||||
u_quad_t ift_co; /* collisions */
|
||||
u_quad_t ift_dr; /* drops */
|
||||
u_long ift_ip; /* input packets */
|
||||
u_long ift_ib; /* input bytes */
|
||||
u_long ift_ie; /* input errors */
|
||||
u_long ift_op; /* output packets */
|
||||
u_long ift_ob; /* output bytes */
|
||||
u_long ift_oe; /* output errors */
|
||||
u_long ift_co; /* collisions */
|
||||
int ift_dr; /* drops */
|
||||
} iftot[MAXIF];
|
||||
|
||||
u_char signalled; /* set if alarm goes off "early" */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: inet6.c,v 1.4 1999/11/19 10:44:33 bouyer Exp $ */
|
||||
/* $NetBSD: inet6.c,v 1.5 1999/12/13 15:22:55 itojun Exp $ */
|
||||
|
||||
/* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */
|
||||
/*
|
||||
@ -39,13 +39,14 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: inet6.c,v 1.4 1999/11/19 10:44:33 bouyer Exp $");
|
||||
__RCSID("$NetBSD: inet6.c,v 1.5 1999/12/13 15:22:55 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/protosw.h>
|
||||
|
||||
@ -60,6 +61,7 @@ __RCSID("$NetBSD: inet6.c,v 1.4 1999/11/19 10:44:33 bouyer Exp $");
|
||||
#include <netinet/ip_var.h>
|
||||
#endif
|
||||
#include <netinet6/in6_pcb.h>
|
||||
#include <netinet6/in6_var.h>
|
||||
#include <netinet6/ip6_var.h>
|
||||
#ifdef TCP6
|
||||
#include <netinet6/tcp6.h>
|
||||
@ -110,8 +112,6 @@ struct socket sockb;
|
||||
char *inet6name __P((struct in6_addr *));
|
||||
void inet6print __P((struct in6_addr *, int, char *));
|
||||
|
||||
static char ntop_buf[INET6_ADDRSTRLEN];
|
||||
|
||||
/*
|
||||
* Print a summary of connections related to an Internet
|
||||
* protocol. For TCP, also give state of connection.
|
||||
@ -143,7 +143,7 @@ ip6protopr(off, name)
|
||||
printf("???\n");
|
||||
break;
|
||||
}
|
||||
if (!aflag && IN6_IS_ADDR_ANY(&in6pcb.in6p_laddr)) {
|
||||
if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_laddr)) {
|
||||
prev = next;
|
||||
continue;
|
||||
}
|
||||
@ -657,10 +657,75 @@ ip6_stats(off, name)
|
||||
p(ip6s_exthdrtoolong,
|
||||
"\t%llu packet%s whose headers are not continuous\n");
|
||||
p(ip6s_nogif, "\t%llu tunneling packet%s that can't find gif\n");
|
||||
p(ip6s_toomanyhdr, "\t%qu packet%s discarded due to too many headers\n");
|
||||
p(ip6s_pulldown, "\t%qu call%s to m_pulldown\n");
|
||||
p(ip6s_pulldown_alloc, "\t%qu mbuf allocation%s in m_pulldown\n");
|
||||
if (ip6stat.ip6s_pulldown_copy != 1) {
|
||||
p1(ip6s_pulldown_copy, "\t%qu mbuf copies in m_pulldown\n");
|
||||
} else {
|
||||
p1(ip6s_pulldown_copy, "\t%qu mbuf copy in m_pulldown\n");
|
||||
}
|
||||
#undef p
|
||||
#undef p1
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump IPv6 per-interface statistics based on RFC 2465.
|
||||
*/
|
||||
void
|
||||
ip6_ifstats(ifname)
|
||||
char *ifname;
|
||||
{
|
||||
struct in6_ifreq ifr;
|
||||
int s;
|
||||
#define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
|
||||
printf(m, ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f))
|
||||
#define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
|
||||
printf(m, ip6stat.f)
|
||||
|
||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("Warning: socket(AF_INET6)");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(ifr.ifr_name, ifname);
|
||||
printf("ip6 on %s:\n", ifr.ifr_name);
|
||||
|
||||
if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
|
||||
perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
|
||||
goto end;
|
||||
}
|
||||
|
||||
p(ifs6_in_receive, "\t%llu total input datagram%s\n");
|
||||
p(ifs6_in_hdrerr, "\t%llu datagram%s with invalid header received\n");
|
||||
p(ifs6_in_toobig, "\t%llu datagram%s exceeded MTU received\n");
|
||||
p(ifs6_in_noroute, "\t%llu datagram%s with no route received\n");
|
||||
p(ifs6_in_addrerr, "\t%llu datagram%s with invalid dst received\n");
|
||||
p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n");
|
||||
p(ifs6_in_protounknown, "\t%llu datagram%s with unknown proto received\n");
|
||||
p(ifs6_in_discard, "\t%llu input datagram%s discarded\n");
|
||||
p(ifs6_in_deliver,
|
||||
"\t%llu datagram%s delivered to an upper layer protocol\n");
|
||||
p(ifs6_out_forward, "\t%llu datagram%s forwarded to this interface\n");
|
||||
p(ifs6_out_request,
|
||||
"\t%llu datagram%s sent from an upper layer protocol\n");
|
||||
p(ifs6_out_discard, "\t%llu total discarded output datagram%s\n");
|
||||
p(ifs6_out_fragok, "\t%llu output datagram%s fragmented\n");
|
||||
p(ifs6_out_fragfail, "\t%llu output datagram%s failed on fragment\n");
|
||||
p(ifs6_out_fragcreat, "\t%llu output datagram%s succeeded on fragment\n");
|
||||
p(ifs6_reass_reqd, "\t%llu incoming datagram%s fragmented\n");
|
||||
p(ifs6_reass_ok, "\t%llu datagram%s reassembled\n");
|
||||
p(ifs6_reass_fail, "\t%llu datagram%s failed on reassembling\n");
|
||||
p(ifs6_in_mcast, "\t%llu multicast datagram%s received\n");
|
||||
p(ifs6_out_mcast, "\t%llu multicast datagram%s sent\n");
|
||||
|
||||
end:
|
||||
close(s);
|
||||
|
||||
#undef p
|
||||
#undef p_5
|
||||
}
|
||||
|
||||
static char *icmp6names[] = {
|
||||
"#0",
|
||||
"unreach",
|
||||
@ -792,9 +857,9 @@ static char *icmp6names[] = {
|
||||
"#127",
|
||||
"echo",
|
||||
"echo reply",
|
||||
"group member query",
|
||||
"group member report",
|
||||
"group member termination",
|
||||
"multicast listener query",
|
||||
"multicast listener report",
|
||||
"multicast listener done",
|
||||
"router solicitation",
|
||||
"router advertisment",
|
||||
"neighbor solicitation",
|
||||
@ -921,7 +986,7 @@ static char *icmp6names[] = {
|
||||
};
|
||||
|
||||
/*
|
||||
* Dump ICMP6 statistics.
|
||||
* Dump ICMPv6 statistics.
|
||||
*/
|
||||
void
|
||||
icmp6_stats(off, name)
|
||||
@ -965,6 +1030,73 @@ icmp6_stats(off, name)
|
||||
(unsigned long long)icmp6stat.icp6s_inhist[i]);
|
||||
}
|
||||
p(icp6s_reflect, "\t%llu message response%s generated\n");
|
||||
p(icp6s_nd_toomanyopt, "\t%llu message%s with too many ND options\n");
|
||||
#undef p
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump ICMPv6 per-interface statistics based on RFC 2466.
|
||||
*/
|
||||
void
|
||||
icmp6_ifstats(ifname)
|
||||
char *ifname;
|
||||
{
|
||||
struct in6_ifreq ifr;
|
||||
int s;
|
||||
#define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
|
||||
printf(m, (u_quad_t)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f))
|
||||
|
||||
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("Warning: socket(AF_INET6)");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(ifr.ifr_name, ifname);
|
||||
printf("icmp6 on %s:\n", ifr.ifr_name);
|
||||
|
||||
if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
|
||||
perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
|
||||
goto end;
|
||||
}
|
||||
|
||||
p(ifs6_in_msg, "\t%llu total input message%s\n");
|
||||
p(ifs6_in_error, "\t%llu total input error message%s\n");
|
||||
p(ifs6_in_dstunreach, "\t%llu input destination unreachable error%s\n");
|
||||
p(ifs6_in_adminprohib, "\t%llu input administratively prohibited error%s\n");
|
||||
p(ifs6_in_timeexceed, "\t%llu input time exceeded error%s\n");
|
||||
p(ifs6_in_paramprob, "\t%llu input parameter problem error%s\n");
|
||||
p(ifs6_in_pkttoobig, "\t%llu input packet too big error%s\n");
|
||||
p(ifs6_in_echo, "\t%llu input echo request%s\n");
|
||||
p(ifs6_in_echoreply, "\t%llu input echo reply%s\n");
|
||||
p(ifs6_in_routersolicit, "\t%llu input router solicitation%s\n");
|
||||
p(ifs6_in_routeradvert, "\t%llu input router advertisement%s\n");
|
||||
p(ifs6_in_neighborsolicit, "\t%llu input neighbor solicitation%s\n");
|
||||
p(ifs6_in_neighboradvert, "\t%llu input neighbor advertisement%s\n");
|
||||
p(ifs6_in_redirect, "\t%llu input redirect%s\n");
|
||||
p(ifs6_in_mldquery, "\t%llu input MLD query%s\n");
|
||||
p(ifs6_in_mldreport, "\t%llu input MLD report%s\n");
|
||||
p(ifs6_in_mlddone, "\t%llu input MLD done%s\n");
|
||||
|
||||
p(ifs6_out_msg, "\t%llu total output message%s\n");
|
||||
p(ifs6_out_error, "\t%llu total output error message%s\n");
|
||||
p(ifs6_out_dstunreach, "\t%llu output destination unreachable error%s\n");
|
||||
p(ifs6_out_adminprohib, "\t%llu output administratively prohibited error%s\n");
|
||||
p(ifs6_out_timeexceed, "\t%llu output time exceeded error%s\n");
|
||||
p(ifs6_out_paramprob, "\t%llu output parameter problem error%s\n");
|
||||
p(ifs6_out_pkttoobig, "\t%llu output packet too big error%s\n");
|
||||
p(ifs6_out_echo, "\t%llu output echo request%s\n");
|
||||
p(ifs6_out_echoreply, "\t%llu output echo reply%s\n");
|
||||
p(ifs6_out_routersolicit, "\t%llu output router solicitation%s\n");
|
||||
p(ifs6_out_routeradvert, "\t%llu output router advertisement%s\n");
|
||||
p(ifs6_out_neighborsolicit, "\t%llu output neighbor solicitation%s\n");
|
||||
p(ifs6_out_neighboradvert, "\t%llu output neighbor advertisement%s\n");
|
||||
p(ifs6_out_redirect, "\t%llu output redirect%s\n");
|
||||
p(ifs6_out_mldquery, "\t%llu output MLD query%s\n");
|
||||
p(ifs6_out_mldreport, "\t%llu output MLD report%s\n");
|
||||
p(ifs6_out_mlddone, "\t%llu output MLD done%s\n");
|
||||
|
||||
end:
|
||||
close(s);
|
||||
#undef p
|
||||
}
|
||||
|
||||
@ -1007,19 +1139,22 @@ inet6print(in6, port, proto)
|
||||
char *proto;
|
||||
{
|
||||
#define GETSERVBYPORT6(port, proto, ret)\
|
||||
{\
|
||||
do {\
|
||||
if (strcmp((proto), "tcp6") == 0)\
|
||||
(ret) = getservbyport((int)(port), "tcp");\
|
||||
else if (strcmp((proto), "udp6") == 0)\
|
||||
(ret) = getservbyport((int)(port), "udp");\
|
||||
else\
|
||||
(ret) = getservbyport((int)(port), (proto));\
|
||||
};
|
||||
} while (0)
|
||||
struct servent *sp = 0;
|
||||
char line[80], *cp;
|
||||
int width;
|
||||
|
||||
sprintf(line, "%.*s.", (Aflag && !nflag) ? 12 : 16, inet6name(in6));
|
||||
width = Aflag ? 12 : 16;
|
||||
if (vflag && width < strlen(inet6name(in6)))
|
||||
width = strlen(inet6name(in6));
|
||||
sprintf(line, "%.*s.", width, inet6name(in6));
|
||||
cp = index(line, '\0');
|
||||
if (!nflag && port)
|
||||
GETSERVBYPORT6(port, proto, sp);
|
||||
@ -1028,6 +1163,8 @@ inet6print(in6, port, proto)
|
||||
else
|
||||
sprintf(cp, "%d", ntohs((u_short)port));
|
||||
width = Aflag ? 18 : 22;
|
||||
if (vflag && width < strlen(line))
|
||||
width = strlen(line);
|
||||
printf(" %-*.*s", width, width, line);
|
||||
}
|
||||
|
||||
@ -1046,6 +1183,13 @@ inet6name(in6p)
|
||||
struct hostent *hp;
|
||||
static char domain[MAXHOSTNAMELEN + 1];
|
||||
static int first = 1;
|
||||
char hbuf[NI_MAXHOST];
|
||||
struct sockaddr_in6 sin6;
|
||||
#ifdef KAME_SCOPEID
|
||||
const int niflag = NI_NUMERICHOST | NI_WITHSCOPEID;
|
||||
#else
|
||||
const int niflag = NI_NUMERICHOST;
|
||||
#endif
|
||||
|
||||
if (first && !nflag) {
|
||||
first = 0;
|
||||
@ -1069,10 +1213,24 @@ inet6name(in6p)
|
||||
strcpy(line, "*");
|
||||
else if (cp)
|
||||
strcpy(line, cp);
|
||||
else
|
||||
sprintf(line, "%s",
|
||||
inet_ntop(AF_INET6, (void *)in6p, ntop_buf,
|
||||
sizeof(ntop_buf)));
|
||||
else {
|
||||
memset(&sin6, 0, sizeof(sin6));
|
||||
sin6.sin6_len = sizeof(sin6);
|
||||
sin6.sin6_family = AF_INET6;
|
||||
sin6.sin6_addr = *in6p;
|
||||
#ifdef KAME_SCOPEID
|
||||
if (IN6_IS_ADDR_LINKLOCAL(in6p)) {
|
||||
sin6.sin6_scope_id =
|
||||
ntohs(*(u_int16_t *)&in6p->s6_addr[2]);
|
||||
sin6.sin6_addr.s6_addr[2] = 0;
|
||||
sin6.sin6_addr.s6_addr[3] = 0;
|
||||
}
|
||||
#endif
|
||||
if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
|
||||
hbuf, sizeof(hbuf), NULL, 0, niflag))
|
||||
strcpy(hbuf, "?");
|
||||
sprintf(line, "%s", hbuf);
|
||||
}
|
||||
return (line);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: main.c,v 1.24 1999/09/15 20:12:18 is Exp $ */
|
||||
/* $NetBSD: main.c,v 1.25 1999/12/13 15:22:55 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1988, 1993
|
||||
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: main.c,v 1.24 1999/09/15 20:12:18 is Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.25 1999/12/13 15:22:55 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -186,84 +186,86 @@ struct protox {
|
||||
__P((u_long, char *));
|
||||
void (*pr_stats) /* statistics printing routine */
|
||||
__P((u_long, char *));
|
||||
void (*pr_istats)
|
||||
__P((char *)); /* per/if statistics printing routine */
|
||||
void (*pr_dump) /* PCB state dump routine */
|
||||
__P((u_long));
|
||||
char *pr_name; /* well-known name */
|
||||
} protox[] = {
|
||||
{ N_TCBTABLE, N_TCPSTAT, 1, protopr,
|
||||
tcp_stats, tcp_dump, "tcp" },
|
||||
tcp_stats, NULL, tcp_dump, "tcp" },
|
||||
{ N_UDBTABLE, N_UDPSTAT, 1, protopr,
|
||||
udp_stats, 0, "udp" },
|
||||
udp_stats, NULL, 0, "udp" },
|
||||
{ -1, N_IPSTAT, 1, 0,
|
||||
ip_stats, 0, "ip" },
|
||||
ip_stats, NULL, 0, "ip" },
|
||||
{ -1, N_ICMPSTAT, 1, 0,
|
||||
icmp_stats, 0, "icmp" },
|
||||
icmp_stats, NULL, 0, "icmp" },
|
||||
{ -1, N_IGMPSTAT, 1, 0,
|
||||
igmp_stats, 0, "igmp" },
|
||||
igmp_stats, NULL, 0, "igmp" },
|
||||
#ifdef IPSEC
|
||||
{ -1, N_IPSECSTAT, 1, 0,
|
||||
ipsec_stats, 0, "ipsec" },
|
||||
ipsec_stats, NULL, 0, "ipsec" },
|
||||
#endif
|
||||
{ -1, -1, 0, 0,
|
||||
0, 0, 0 }
|
||||
0, NULL, 0, 0 }
|
||||
};
|
||||
|
||||
#ifdef INET6
|
||||
struct protox ip6protox[] = {
|
||||
{ -1, N_IP6STAT, 1, 0,
|
||||
ip6_stats, 0, "ip6" },
|
||||
ip6_stats, ip6_ifstats, 0, "ip6" },
|
||||
{ -1, N_ICMP6STAT, 1, 0,
|
||||
icmp6_stats, 0, "icmp6" },
|
||||
icmp6_stats, icmp6_ifstats, 0, "icmp6" },
|
||||
#ifdef TCP6
|
||||
{ N_TCB6, N_TCP6STAT, 1, ip6protopr,
|
||||
tcp6_stats, tcp6_dump, "tcp6" },
|
||||
tcp6_stats, NULL, tcp6_dump, "tcp6" },
|
||||
#else
|
||||
{ N_TCB6, N_TCP6STAT, 1, ip6protopr,
|
||||
tcp_stats, tcp_dump, "tcp6" },
|
||||
tcp_stats, NULL, tcp_dump, "tcp6" },
|
||||
#endif
|
||||
{ N_UDB6, N_UDP6STAT, 1, ip6protopr,
|
||||
udp6_stats, 0, "udp6" },
|
||||
udp6_stats, NULL, 0, "udp6" },
|
||||
#ifdef IPSEC
|
||||
{ -1, N_IPSEC6STAT, 1, 0,
|
||||
ipsec_stats, 0, "ipsec6" },
|
||||
ipsec_stats, NULL, 0, "ipsec6" },
|
||||
#endif
|
||||
{ -1, N_PIM6STAT, 1, 0,
|
||||
pim6_stats, 0, "pim6" },
|
||||
pim6_stats, NULL, 0, "pim6" },
|
||||
{ -1, -1, 0, 0,
|
||||
0, 0, 0 }
|
||||
0, NULL, 0, 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef SMALL
|
||||
struct protox atalkprotox[] = {
|
||||
{ N_DDPCB, N_DDPSTAT, 1, atalkprotopr,
|
||||
ddp_stats, 0, "ddp" },
|
||||
ddp_stats, NULL, 0, "ddp" },
|
||||
{ -1, -1, 0, 0,
|
||||
0, 0 }
|
||||
0, NULL, 0 }
|
||||
};
|
||||
|
||||
struct protox nsprotox[] = {
|
||||
{ N_IDP, N_IDPSTAT, 1, nsprotopr,
|
||||
idp_stats, 0, "idp" },
|
||||
idp_stats, NULL, 0, "idp" },
|
||||
{ N_IDP, N_SPPSTAT, 1, nsprotopr,
|
||||
spp_stats, 0, "spp" },
|
||||
spp_stats, NULL, 0, "spp" },
|
||||
{ -1, N_NSERR, 1, 0,
|
||||
nserr_stats, 0, "ns_err" },
|
||||
nserr_stats, NULL, 0, "ns_err" },
|
||||
{ -1, -1, 0, 0,
|
||||
0, 0 }
|
||||
0, NULL, 0 }
|
||||
};
|
||||
|
||||
struct protox isoprotox[] = {
|
||||
{ ISO_TP, N_TPSTAT, 1, iso_protopr,
|
||||
tp_stats, 0, "tp" },
|
||||
tp_stats, NULL, 0, "tp" },
|
||||
{ N_CLTP, N_CLTPSTAT, 1, iso_protopr,
|
||||
cltp_stats, 0, "cltp" },
|
||||
cltp_stats, NULL, 0, "cltp" },
|
||||
{ -1, N_CLNPSTAT, 1, 0,
|
||||
clnp_stats, 0, "clnp"},
|
||||
clnp_stats, NULL, 0, "clnp"},
|
||||
{ -1, N_ESISSTAT, 1, 0,
|
||||
esis_stats, 0, "esis"},
|
||||
esis_stats, NULL, 0, "esis"},
|
||||
{ -1, -1, 0, 0,
|
||||
0, 0, 0 }
|
||||
0, NULL, 0, 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -304,8 +306,7 @@ main(argc, argv)
|
||||
af = AF_UNSPEC;
|
||||
pcbaddr = 0;
|
||||
|
||||
while ((ch = getopt(argc, argv, "Aabdf:ghI:LliM:mN:nP:p:rstuvw:"))
|
||||
!= -1)
|
||||
while ((ch = getopt(argc, argv, "Aabdf:ghI:LliM:mN:nP:p:rstuvw:")) != -1)
|
||||
switch(ch) {
|
||||
case 'A':
|
||||
Aflag = 1;
|
||||
@ -467,7 +468,9 @@ main(argc, argv)
|
||||
exit(0);
|
||||
}
|
||||
if (pflag) {
|
||||
if (tp->pr_stats)
|
||||
if (iflag && tp->pr_istats)
|
||||
intpr(interval, nl[N_IFNET].n_value, tp->pr_istats);
|
||||
else if (tp->pr_stats)
|
||||
(*tp->pr_stats)(nl[tp->pr_sindex].n_value,
|
||||
tp->pr_name);
|
||||
else
|
||||
@ -481,7 +484,10 @@ main(argc, argv)
|
||||
sethostent(1);
|
||||
setnetent(1);
|
||||
if (iflag) {
|
||||
intpr(interval, nl[N_IFNET].n_value);
|
||||
if (af != AF_UNSPEC)
|
||||
goto protostat;
|
||||
|
||||
intpr(interval, nl[N_IFNET].n_value, NULL);
|
||||
exit(0);
|
||||
}
|
||||
if (rflag) {
|
||||
@ -519,6 +525,7 @@ main(argc, argv)
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
protostat:
|
||||
if (af == AF_INET || af == AF_UNSPEC) {
|
||||
setprotoent(1);
|
||||
setservent(1);
|
||||
@ -572,8 +579,16 @@ printproto(tp, name)
|
||||
u_long off;
|
||||
|
||||
if (sflag) {
|
||||
pr = tp->pr_stats;
|
||||
off = nl[tp->pr_sindex].n_value;
|
||||
if (iflag) {
|
||||
if (tp->pr_istats)
|
||||
intpr(interval, nl[N_IFNET].n_value,
|
||||
tp->pr_istats);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
pr = tp->pr_stats;
|
||||
off = nl[tp->pr_sindex].n_value;
|
||||
}
|
||||
} else {
|
||||
pr = tp->pr_cblocks;
|
||||
off = nl[tp->pr_index].n_value;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mroute6.c,v 1.4 1999/12/02 14:31:22 tron Exp $ */
|
||||
/* $NetBSD: mroute6.c,v 1.5 1999/12/13 15:22:55 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1998 WIDE Project.
|
||||
@ -163,7 +163,7 @@ mroute6pr(mrpaddr, mfcaddr, mifaddr)
|
||||
printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ?
|
||||
"reg0" : if_indextoname(ifnet.if_index, ifname));
|
||||
|
||||
printf(" %9lu %9lu\n", mifp->m6_pkt_in, mifp->m6_pkt_out);
|
||||
printf(" %9llu %9llu\n", mifp->m6_pkt_in, mifp->m6_pkt_out);
|
||||
}
|
||||
if (!banner_printed)
|
||||
printf("\nIPv6 Multicast Interface Table is empty\n");
|
||||
@ -184,10 +184,10 @@ mroute6pr(mrpaddr, mfcaddr, mifaddr)
|
||||
}
|
||||
|
||||
printf(" %-*.*s", WID_ORG, WID_ORG,
|
||||
routename6((char *)&mfc.mf6c_origin.sin6_addr));
|
||||
routename6(&mfc.mf6c_origin));
|
||||
printf(" %-*.*s", WID_GRP, WID_GRP,
|
||||
routename6((char *)&mfc.mf6c_mcastgrp.sin6_addr));
|
||||
printf(" %9lu", mfc.mf6c_pkt_cnt);
|
||||
routename6(&mfc.mf6c_mcastgrp));
|
||||
printf(" %9llu", mfc.mf6c_pkt_cnt);
|
||||
|
||||
for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
|
||||
waitings++;
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: netstat.1,v 1.25 1999/09/15 20:12:18 is Exp $
|
||||
.\" $NetBSD: netstat.1,v 1.26 1999/12/13 15:22:55 itojun Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1983, 1990, 1992, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -65,6 +65,15 @@
|
||||
.Op Fl M Ar core
|
||||
.Op Fl N Ar system
|
||||
.Fl P Ar pcbaddr
|
||||
.Nm ""
|
||||
.Op Fl p Ar protocol
|
||||
.Op Fl i
|
||||
.Op Fl I Ar Interface
|
||||
.Nm ""
|
||||
.Op Fl s
|
||||
.Op Fl f Ar address_family
|
||||
.Op Fl i
|
||||
.Op Fl I Ar Interface
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
@ -83,6 +92,8 @@ interval specified,
|
||||
will continuously display the information regarding packet
|
||||
traffic on the configured network interfaces.
|
||||
The fourth form displays statistics about the named protocol.
|
||||
The fifth and sixth forms display per interface statistics for
|
||||
the specified protocol or address family.
|
||||
.Pp
|
||||
The options have the following meaning:
|
||||
.Bl -tag -width flag
|
||||
@ -141,6 +152,19 @@ Show information about the specified interface;
|
||||
used with a
|
||||
.Ar wait
|
||||
interval as described below.
|
||||
If the
|
||||
.Fl f Ar address_family
|
||||
option (with the
|
||||
.Fl s
|
||||
option) or the
|
||||
.Fl p Ar protocol
|
||||
option is present, show per-interface statistics on the
|
||||
.Ar interface
|
||||
for the specfied
|
||||
.Ar address_family
|
||||
or
|
||||
.Ar protocol,
|
||||
respectively.
|
||||
.It Fl i
|
||||
Show the state of interfaces which have been auto-configured
|
||||
(interfaces statically configured into a system, but not
|
||||
@ -151,6 +175,18 @@ options is also present, multicast addresses currently in use are shown
|
||||
for each Ethernet interface and for each IP interface address.
|
||||
Multicast addresses are shown on separate lines following the interface
|
||||
address with which they are associated.
|
||||
If the
|
||||
.Fl f Ar address_family
|
||||
option (with the
|
||||
.Fl s
|
||||
option) or the
|
||||
.Fl p Ar protocol
|
||||
option is present, show per-interface statistics on all interfaces
|
||||
for the specfied
|
||||
.Ar address_family
|
||||
or
|
||||
.Ar protocol,
|
||||
respectively.
|
||||
.It Fl L
|
||||
Don't show link-level routes (e.g., IPv4 ARP or IPv6 neighbour cache).
|
||||
.It Fl M
|
||||
@ -198,7 +234,9 @@ When
|
||||
.Fl s
|
||||
is also present, show routing statistics instead.
|
||||
.It Fl v
|
||||
Show extra (verbose) detail for the routing tables.
|
||||
Show extra (verbose) detail for the routing tables
|
||||
.Pq Fl r ,
|
||||
or avoid truncation of long addresses.
|
||||
.It Fl w Ar wait
|
||||
Show network interface statistics at intervals of
|
||||
.Ar wait
|
||||
@ -244,8 +282,8 @@ and
|
||||
manual pages.
|
||||
The mapping between letters and flags is:
|
||||
.Bl -column XXXX RTF_BLACKHOLE
|
||||
1 RTF_PROTO1 Protocol specific routing flag #1
|
||||
2 RTF_PROTO2 Protocol specific routing flag #2
|
||||
1 RTF_PROTO2 Protocol specific routing flag #1
|
||||
2 RTF_PROTO1 Protocol specific routing flag #2
|
||||
B RTF_BLACKHOLE Just discard pkts (during updates)
|
||||
C RTF_CLONING Generate new routes on use
|
||||
D RTF_DYNAMIC Created dynamically (by redirect)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: netstat.h,v 1.16 1999/11/22 14:13:53 itojun Exp $ */
|
||||
/* $NetBSD: netstat.h,v 1.17 1999/12/13 15:22:55 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -81,16 +81,19 @@ void ipsec_stats __P((u_long, char *));
|
||||
#endif
|
||||
|
||||
#ifdef INET6
|
||||
struct sockaddr_in6;
|
||||
void ip6protopr __P((u_long, char *));
|
||||
void tcp6_stats __P((u_long, char *));
|
||||
void tcp6_dump __P((u_long));
|
||||
void udp6_stats __P((u_long, char *));
|
||||
void ip6_stats __P((u_long, char *));
|
||||
void ip6_ifstats __P((char *));
|
||||
void icmp6_stats __P((u_long, char *));
|
||||
void icmp6_ifstats __P((char *));
|
||||
void pim6_stats __P((u_long, char *));
|
||||
void mroute6pr __P((u_long, u_long, u_long));
|
||||
void mrt6_stats __P((u_long, u_long));
|
||||
char *routename6 __P((char *));
|
||||
char *routename6 __P((struct sockaddr_in6 *));
|
||||
#endif /*INET6*/
|
||||
|
||||
void mbpr(u_long, u_long, u_long, u_long, u_long);
|
||||
@ -98,8 +101,6 @@ void mbpr(u_long, u_long, u_long, u_long, u_long);
|
||||
void hostpr __P((u_long, u_long));
|
||||
void impstats __P((u_long, u_long));
|
||||
|
||||
void intpr __P((int, u_long));
|
||||
|
||||
void pr_rthdr __P((int));
|
||||
void pr_family __P((int));
|
||||
void rt_stats __P((u_long));
|
||||
@ -122,7 +123,7 @@ void nserr_stats __P((u_long, char *));
|
||||
void atalkprotopr __P((u_long, char *));
|
||||
void ddp_stats __P((u_long, char *));
|
||||
|
||||
void intpr __P((int, u_long));
|
||||
void intpr __P((int, u_long, void (*) __P((char *))));
|
||||
|
||||
void unixpr __P((u_long));
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: route.c,v 1.43 1999/11/27 02:19:34 soren Exp $ */
|
||||
/* $NetBSD: route.c,v 1.44 1999/12/13 15:22:55 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1988, 1993
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: route.c,v 1.43 1999/11/27 02:19:34 soren Exp $");
|
||||
__RCSID("$NetBSD: route.c,v 1.44 1999/12/13 15:22:55 itojun Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -140,8 +140,7 @@ static void ntreestuff __P((void));
|
||||
static u_long forgemask __P((u_long));
|
||||
static void domask __P((char *, size_t, u_long, u_long));
|
||||
#ifdef INET6
|
||||
char *netname6 __P((struct in6_addr *, struct in6_addr *));
|
||||
static char ntop_buf[INET6_ADDRSTRLEN];
|
||||
char *netname6 __P((struct sockaddr_in6 *, struct in6_addr *));
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -230,15 +229,9 @@ pr_family(af)
|
||||
#define WID_GW(af) 18 /* width of gateway column */
|
||||
#else
|
||||
/* width of destination/gateway column */
|
||||
#ifdef KAME_SCOPEID
|
||||
/* strlen("fe80::aaaa:bbbb:cccc:dddd@gif0") == 30, strlen("/128") == 4 */
|
||||
#define WID_DST(af) ((af) == AF_INET6 ? (nflag ? 34 : 18) : 18)
|
||||
#define WID_GW(af) ((af) == AF_INET6 ? (nflag ? 30 : 18) : 18)
|
||||
#else
|
||||
/* strlen("fe80::aaaa:bbbb:cccc:dddd") == 25, strlen("/128") == 4 */
|
||||
#define WID_DST(af) ((af) == AF_INET6 ? (nflag ? 29 : 18) : 18)
|
||||
#define WID_GW(af) ((af) == AF_INET6 ? (nflag ? 25 : 18) : 18)
|
||||
#endif
|
||||
#endif /* INET6 */
|
||||
|
||||
/*
|
||||
@ -248,6 +241,7 @@ void
|
||||
pr_rthdr(af)
|
||||
int af;
|
||||
{
|
||||
|
||||
if (Aflag)
|
||||
printf("%-8.8s ","Address");
|
||||
printf("%-*.*s %-*.*s %-6.6s %6.6s%8.8s %6.6s %s\n",
|
||||
@ -405,6 +399,10 @@ np_rtentry(rtm)
|
||||
p_sockaddr(sa, NULL, 0, 36);
|
||||
else {
|
||||
p_sockaddr(sa, NULL, rtm->rtm_flags, 16);
|
||||
#if 0
|
||||
if (sa->sa_len == 0)
|
||||
sa->sa_len = sizeof(long);
|
||||
#endif
|
||||
sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
|
||||
p_sockaddr(sa, NULL, 0, 18);
|
||||
}
|
||||
@ -440,16 +438,29 @@ p_sockaddr(sa, mask, flags, width)
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
{
|
||||
struct in6_addr *in6 = &((struct sockaddr_in6 *)sa)->sin6_addr;
|
||||
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
|
||||
#ifdef KAME_SCOPEID
|
||||
struct in6_addr *in6 = &sa6->sin6_addr;
|
||||
|
||||
/*
|
||||
* XXX: This is a special workaround for KAME kernels.
|
||||
* sin6_scope_id field of SA should be set in the future.
|
||||
*/
|
||||
if (IN6_IS_ADDR_LINKLOCAL(in6) ||
|
||||
IN6_IS_ADDR_MC_LINKLOCAL(in6)) {
|
||||
/* XXX: override is ok? */
|
||||
sa6->sin6_scope_id = (u_int32_t)ntohs(*(u_short *)&in6->s6_addr[2]);
|
||||
*(u_short *)&in6->s6_addr[2] = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (flags & RTF_HOST)
|
||||
cp = routename6((char *)in6);
|
||||
cp = routename6(sa6);
|
||||
else if (mask) {
|
||||
cp = netname6(in6,
|
||||
&((struct sockaddr_in6 *)mask)->sin6_addr);
|
||||
cp = netname6(sa6,
|
||||
&((struct sockaddr_in6 *)mask)->sin6_addr);
|
||||
} else
|
||||
cp = (char *)inet_ntop(AF_INET6, in6, ntop_buf,
|
||||
sizeof(ntop_buf));
|
||||
cp = netname6(sa6, NULL);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@ -785,89 +796,121 @@ netname(in, mask)
|
||||
|
||||
#ifdef INET6
|
||||
char *
|
||||
netname6(in6, mask)
|
||||
struct in6_addr *in6;
|
||||
netname6(sa6, mask)
|
||||
struct sockaddr_in6 *sa6;
|
||||
struct in6_addr *mask;
|
||||
{
|
||||
static char line[MAXHOSTNAMELEN + 1];
|
||||
struct in6_addr net6;
|
||||
static char line[NI_MAXHOST];
|
||||
u_char *p;
|
||||
u_char *lim;
|
||||
int masklen, final = 0, illegal = 0;
|
||||
int i;
|
||||
#ifdef KAME_SCOPEID
|
||||
int flag = NI_WITHSCOPEID;
|
||||
#else
|
||||
int flag = 0;
|
||||
#endif
|
||||
int error;
|
||||
|
||||
net6 = *in6;
|
||||
for (i = 0; i < sizeof(net6); i++)
|
||||
net6.s6_addr[i] &= mask->s6_addr[i];
|
||||
|
||||
masklen = 0;
|
||||
lim = (u_char *)mask + 16;
|
||||
for (p = (u_char *)mask; p < lim; p++) {
|
||||
if (final && *p) {
|
||||
illegal++;
|
||||
continue;
|
||||
}
|
||||
if (mask) {
|
||||
masklen = 0;
|
||||
lim = (u_char *)mask + 16;
|
||||
for (p = (u_char *)mask; p < lim; p++) {
|
||||
if (final && *p) {
|
||||
illegal++;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (*p & 0xff) {
|
||||
case 0xff:
|
||||
masklen += 8;
|
||||
break;
|
||||
case 0xfe:
|
||||
masklen += 7;
|
||||
final++;
|
||||
break;
|
||||
case 0xfc:
|
||||
masklen += 6;
|
||||
final++;
|
||||
break;
|
||||
case 0xf8:
|
||||
masklen += 5;
|
||||
final++;
|
||||
break;
|
||||
case 0xf0:
|
||||
masklen += 4;
|
||||
final++;
|
||||
break;
|
||||
case 0xe0:
|
||||
masklen += 3;
|
||||
final++;
|
||||
break;
|
||||
case 0xc0:
|
||||
masklen += 2;
|
||||
final++;
|
||||
break;
|
||||
case 0x80:
|
||||
masklen += 1;
|
||||
final++;
|
||||
break;
|
||||
case 0x00:
|
||||
final++;
|
||||
break;
|
||||
default:
|
||||
final++;
|
||||
illegal++;
|
||||
break;
|
||||
switch (*p & 0xff) {
|
||||
case 0xff:
|
||||
masklen += 8;
|
||||
break;
|
||||
case 0xfe:
|
||||
masklen += 7;
|
||||
final++;
|
||||
break;
|
||||
case 0xfc:
|
||||
masklen += 6;
|
||||
final++;
|
||||
break;
|
||||
case 0xf8:
|
||||
masklen += 5;
|
||||
final++;
|
||||
break;
|
||||
case 0xf0:
|
||||
masklen += 4;
|
||||
final++;
|
||||
break;
|
||||
case 0xe0:
|
||||
masklen += 3;
|
||||
final++;
|
||||
break;
|
||||
case 0xc0:
|
||||
masklen += 2;
|
||||
final++;
|
||||
break;
|
||||
case 0x80:
|
||||
masklen += 1;
|
||||
final++;
|
||||
break;
|
||||
case 0x00:
|
||||
final++;
|
||||
break;
|
||||
default:
|
||||
final++;
|
||||
illegal++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
masklen = 128;
|
||||
|
||||
if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(in6))
|
||||
if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr))
|
||||
return("default");
|
||||
|
||||
if (illegal)
|
||||
fprintf(stderr, "illegal prefixlen\n");
|
||||
sprintf(line, "%s/%d", inet_ntop(AF_INET6, &net6, ntop_buf,
|
||||
sizeof(ntop_buf)),
|
||||
masklen);
|
||||
if (nflag)
|
||||
flag |= NI_NUMERICHOST;
|
||||
error = getnameinfo((struct sockaddr *)sa6, sa6->sin6_len,
|
||||
line, sizeof(line), NULL, 0, flag);
|
||||
if (error)
|
||||
strcpy(line, "invalid");
|
||||
|
||||
if (nflag)
|
||||
sprintf(&line[strlen(line)], "/%d", masklen);
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
char *
|
||||
routename6(in6)
|
||||
char *in6;
|
||||
routename6(sa6)
|
||||
struct sockaddr_in6 *sa6;
|
||||
{
|
||||
static char line[MAXHOSTNAMELEN + 1];
|
||||
sprintf(line, "%s", inet_ntop(AF_INET6, in6, ntop_buf,
|
||||
sizeof(ntop_buf)));
|
||||
static char line[NI_MAXHOST];
|
||||
#ifdef KAME_SCOPEID
|
||||
int flag = NI_WITHSCOPEID;
|
||||
#else
|
||||
int flag = 0;
|
||||
#endif
|
||||
/* use local variable for safety */
|
||||
struct sockaddr_in6 sa6_local;
|
||||
int error;
|
||||
|
||||
memset(&sa6_local, 0, sizeof(sa6_local));
|
||||
sa6_local.sin6_family = AF_INET6;
|
||||
sa6_local.sin6_len = sizeof(struct sockaddr_in6);
|
||||
sa6_local.sin6_addr = sa6->sin6_addr;
|
||||
sa6_local.sin6_scope_id = sa6->sin6_scope_id;
|
||||
|
||||
if (nflag)
|
||||
flag |= NI_NUMERICHOST;
|
||||
|
||||
error = getnameinfo((struct sockaddr *)&sa6_local, sa6_local.sin6_len,
|
||||
line, sizeof(line), NULL, 0, flag);
|
||||
if (error)
|
||||
strcpy(line, "invalid");
|
||||
|
||||
return line;
|
||||
}
|
||||
#endif /*INET6*/
|
||||
|
Loading…
Reference in New Issue
Block a user