aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorKris Kennaway <kris@FreeBSD.org>2000-07-15 07:29:31 +0000
committerKris Kennaway <kris@FreeBSD.org>2000-07-15 07:29:31 +0000
commite6d0854e13b64e40140480e08569e93f3c6b93cb (patch)
tree4ad1df1e542a1f3513ccb842e719aa03ea938119 /usr.bin
parent8b0561f1900283a280aa406a12c2db7e4c7eaea0 (diff)
Notes
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/kdump/mkioctls3
-rw-r--r--usr.bin/netstat/Makefile3
-rw-r--r--usr.bin/netstat/inet.c106
-rw-r--r--usr.bin/netstat/inet6.c324
-rw-r--r--usr.bin/netstat/main.c23
-rw-r--r--usr.bin/netstat/mroute.c7
-rw-r--r--usr.bin/netstat/mroute6.c70
-rw-r--r--usr.bin/netstat/netstat.h9
-rw-r--r--usr.bin/netstat/route.c78
-rw-r--r--usr.bin/telnet/commands.c38
-rw-r--r--usr.bin/whois/whois.c82
11 files changed, 383 insertions, 360 deletions
diff --git a/usr.bin/kdump/mkioctls b/usr.bin/kdump/mkioctls
index a295a591f449..fbce2a929ad2 100644
--- a/usr.bin/kdump/mkioctls
+++ b/usr.bin/kdump/mkioctls
@@ -53,6 +53,9 @@ BEGIN {
print "#include <netinet/ip_frag.h>"
print "#include <netinet/ip_state.h>"
print "#include <netinet/ip_mroute.h>"
+ print "#include <netinet6/in6_var.h>"
+ print "#include <netinet6/nd6.h>"
+ print "#include <netinet6/ip6_mroute.h>"
print "#include <cam/cam.h>"
print "#include <stdio.h>"
print ""
diff --git a/usr.bin/netstat/Makefile b/usr.bin/netstat/Makefile
index f52e79269815..7f88c3bfef64 100644
--- a/usr.bin/netstat/Makefile
+++ b/usr.bin/netstat/Makefile
@@ -3,8 +3,9 @@
PROG= netstat
SRCS= if.c inet.c inet6.c main.c mbuf.c mroute.c ipx.c route.c \
- unix.c atalk.c netgraph.c mroute6.c # iso.c ns.c tp_astring.c
+ unix.c atalk.c netgraph.c mroute6.c ipsec.c # iso.c ns.c tp_astring.c
CFLAGS+=-Wall
+CFLAGS+=-DIPSEC
#CFLAGS+=-g
#.PATH: ${.CURDIR}/../../sys/netiso
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index ac09c4b66a37..c14c7a202ad6 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -68,9 +68,6 @@ static const char rcsid[] =
#include <netinet/tcp_debug.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
-#ifdef IPSEC
-#include <netinet6/ipsec.h>
-#endif
#include <arpa/inet.h>
#include <err.h>
@@ -682,109 +679,6 @@ igmp_stats(off, name)
#undef py
}
-#ifdef IPSEC
-static char *ipsec_ahnames[] = {
- "none",
- "hmac MD5",
- "hmac SHA1",
- "keyed MD5",
- "keyed SHA1",
- "null",
-};
-
-static char *ipsec_espnames[] = {
- "none",
- "DES CBC",
- "3DES CBC",
- "simple",
- "blowfish CBC",
- "CAST128 CBC",
- "RC5 CBC",
-};
-
-/*
- * Dump IPSEC statistics structure.
- */
-void
-ipsec_stats(off, name)
- u_long off;
- char *name;
-{
- struct ipsecstat ipsecstat;
- int first, proto;
-
- if (off == 0)
- return;
- printf ("%s:\n", name);
- kread(off, (char *)&ipsecstat, sizeof (ipsecstat));
-
-#define p(f, m) if (ipsecstat.f || sflag <= 1) \
- printf(m, ipsecstat.f, plural(ipsecstat.f))
-
- p(in_success, "\t%lu inbound packet%s processed successfully\n");
- p(in_polvio, "\t%lu inbound packet%s violated process security "
- "policy\n");
- p(in_nosa, "\t%lu inbound packet%s with no SA available\n");
- p(in_inval, "\t%lu inbound packet%s failed processing due to EINVAL\n");
- p(in_badspi, "\t%lu inbound packet%s failed getting SPI\n");
- p(in_ahreplay, "\t%lu inbound packet%s failed on AH replay check\n");
- p(in_espreplay, "\t%lu inbound packet%s failed on ESP replay check\n");
- p(in_ahauthsucc, "\t%lu inbound AH packet%s considered authentic\n");
- p(in_ahauthfail, "\t%lu inbound AH packet%s failed on authentication\n");
- p(in_espauthsucc, "\t%lu inbound ESP packet%s considered authentic\n");
- p(in_espauthfail, "\t%lu inbound ESP packet%s failed on authentication\n");
- for (first = 1, proto = 0; proto < SADB_AALG_MAX; proto++) {
- if (ipsecstat.in_ahhist[proto] <= 0)
- continue;
- if (first) {
- printf("\tAH input histogram:\n");
- first = 0;
- }
- printf("\t\t%s: %lu\n", ipsec_ahnames[proto],
- ipsecstat.in_ahhist[proto]);
- }
- for (first = 1, proto = 0; proto < SADB_EALG_MAX; proto++) {
- if (ipsecstat.in_esphist[proto] <= 0)
- continue;
- if (first) {
- printf("\tESP input histogram:\n");
- first = 0;
- }
- printf("\t\t%s: %lu\n", ipsec_espnames[proto],
- ipsecstat.in_esphist[proto]);
- }
-
- p(out_success, "\t%lu outbound packet%s processed successfully\n");
- p(out_polvio, "\t%lu outbound packet%s violated process security "
- "policy\n");
- p(out_nosa, "\t%lu outbound packet%s with no SA available\n");
- p(out_inval, "\t%lu outbound packet%s failed processing due to "
- "EINVAL\n");
- p(out_noroute, "\t%lu outbound packet%s with no route\n");
- for (first = 1, proto = 0; proto < SADB_AALG_MAX; proto++) {
- if (ipsecstat.out_ahhist[proto] <= 0)
- continue;
- if (first) {
- printf("\tAH output histogram:\n");
- first = 0;
- }
- printf("\t\t%s: %lu\n", ipsec_ahnames[proto],
- ipsecstat.out_ahhist[proto]);
- }
- for (first = 1, proto = 0; proto < SADB_EALG_MAX; proto++) {
- if (ipsecstat.out_esphist[proto] <= 0)
- continue;
- if (first) {
- printf("\tESP output histogram:\n");
- first = 0;
- }
- printf("\t\t%s: %lu\n", ipsec_espnames[proto],
- ipsecstat.out_esphist[proto]);
- }
-#undef p
-}
-#endif /*IPSEC*/
-
/*
* Pretty print an Internet address (net address + port).
*/
diff --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c
index c1c65f289b1f..c078b33053d7 100644
--- a/usr.bin/netstat/inet6.c
+++ b/usr.bin/netstat/inet6.c
@@ -164,7 +164,7 @@ static char *ip6nh[] = {
"#86",
"#87",
"#88",
- "#89",
+ "OSPF",
"#80",
"#91",
"#92",
@@ -351,44 +351,44 @@ ip6_stats(off, name)
printf("%s:\n", name);
#define p(f, m) if (ip6stat.f || sflag <= 1) \
- printf(m, ip6stat.f, plural(ip6stat.f))
+ printf(m, (unsigned long long)ip6stat.f, plural(ip6stat.f))
#define p1a(f, m) if (ip6stat.f || sflag <= 1) \
- printf(m, ip6stat.f)
+ printf(m, (unsigned long long)ip6stat.f)
- p(ip6s_total, "\t%lu total packet%s received\n");
- p1a(ip6s_toosmall, "\t%lu with size smaller than minimum\n");
- p1a(ip6s_tooshort, "\t%lu with data size < data length\n");
- p1a(ip6s_badoptions, "\t%lu with bad options\n");
- p1a(ip6s_badvers, "\t%lu with incorrect version number\n");
- p(ip6s_fragments, "\t%lu fragment%s received\n");
- p(ip6s_fragdropped, "\t%lu fragment%s dropped (dup or out of space)\n");
- p(ip6s_fragtimeout, "\t%lu fragment%s dropped after timeout\n");
- p(ip6s_fragoverflow, "\t%lu fragment%s that exceeded limit\n");
- p(ip6s_reassembled, "\t%lu packet%s reassembled ok\n");
- p(ip6s_delivered, "\t%lu packet%s for this host\n");
- p(ip6s_forward, "\t%lu packet%s forwarded\n");
- p(ip6s_cantforward, "\t%lu packet%s not forwardable\n");
- p(ip6s_redirectsent, "\t%lu redirect%s sent\n");
- p(ip6s_localout, "\t%lu packet%s sent from this host\n");
- p(ip6s_rawout, "\t%lu packet%s sent with fabricated ip header\n");
- p(ip6s_odropped, "\t%lu output packet%s dropped due to no bufs, etc.\n");
- p(ip6s_noroute, "\t%lu output packet%s discarded due to no route\n");
- p(ip6s_fragmented, "\t%lu output datagram%s fragmented\n");
- p(ip6s_ofragments, "\t%lu fragment%s created\n");
- p(ip6s_cantfrag, "\t%lu datagram%s that can't be fragmented\n");
- p(ip6s_badscope, "\t%lu packet%s that violated scope rules\n");
- p(ip6s_notmember, "\t%lu multicast packet%s which we don't join\n");
+ p(ip6s_total, "\t%llu total packet%s received\n");
+ p1a(ip6s_toosmall, "\t%llu with size smaller than minimum\n");
+ p1a(ip6s_tooshort, "\t%llu with data size < data length\n");
+ p1a(ip6s_badoptions, "\t%llu with bad options\n");
+ p1a(ip6s_badvers, "\t%llu with incorrect version number\n");
+ p(ip6s_fragments, "\t%llu fragment%s received\n");
+ p(ip6s_fragdropped, "\t%llu fragment%s dropped (dup or out of space)\n");
+ p(ip6s_fragtimeout, "\t%llu fragment%s dropped after timeout\n");
+ p(ip6s_fragoverflow, "\t%llu fragment%s that exceeded limit\n");
+ p(ip6s_reassembled, "\t%llu packet%s reassembled ok\n");
+ p(ip6s_delivered, "\t%llu packet%s for this host\n");
+ p(ip6s_forward, "\t%llu packet%s forwarded\n");
+ p(ip6s_cantforward, "\t%llu packet%s not forwardable\n");
+ p(ip6s_redirectsent, "\t%llu redirect%s sent\n");
+ p(ip6s_localout, "\t%llu packet%s sent from this host\n");
+ p(ip6s_rawout, "\t%llu packet%s sent with fabricated ip header\n");
+ p(ip6s_odropped, "\t%llu output packet%s dropped due to no bufs, etc.\n");
+ p(ip6s_noroute, "\t%llu output packet%s discarded due to no route\n");
+ p(ip6s_fragmented, "\t%llu output datagram%s fragmented\n");
+ p(ip6s_ofragments, "\t%llu fragment%s created\n");
+ p(ip6s_cantfrag, "\t%llu datagram%s that can't be fragmented\n");
+ p(ip6s_badscope, "\t%llu packet%s that violated scope rules\n");
+ p(ip6s_notmember, "\t%llu multicast packet%s which we don't join\n");
for (first = 1, i = 0; i < 256; i++)
if (ip6stat.ip6s_nxthist[i] != 0) {
if (first) {
printf("\tInput histogram:\n");
first = 0;
}
- printf("\t\t%s: %lu\n", ip6nh[i],
- ip6stat.ip6s_nxthist[i]);
+ printf("\t\t%s: %llu\n", ip6nh[i],
+ (unsigned long long)ip6stat.ip6s_nxthist[i]);
}
printf("\tMbuf statistics:\n");
- printf("\t\t%lu one mbuf\n", ip6stat.ip6s_m1);
+ printf("\t\t%llu one mbuf\n", (unsigned long long)ip6stat.ip6s_m1);
for (first = 1, i = 0; i < 32; i++) {
char ifbuf[IFNAMSIZ];
if (ip6stat.ip6s_m2m[i] != 0) {
@@ -396,17 +396,94 @@ ip6_stats(off, name)
printf("\t\ttwo or more mbuf:\n");
first = 0;
}
- printf("\t\t\t%s= %ld\n",
- if_indextoname(i, ifbuf),
- ip6stat.ip6s_m2m[i]);
+ printf("\t\t\t%s= %llu\n",
+ if_indextoname(i, ifbuf),
+ (unsigned long long)ip6stat.ip6s_m2m[i]);
+ }
+ }
+ printf("\t\t%llu one ext mbuf\n",
+ (unsigned long long)ip6stat.ip6s_mext1);
+ printf("\t\t%llu two or more ext mbuf\n",
+ (unsigned long long)ip6stat.ip6s_mext2m);
+ 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%llu packet%s discarded due to too may headers\n");
+
+ /* for debugging source address selection */
+#define PRINT_SCOPESTAT(s,i) do {\
+ switch(i) { /* XXX hardcoding in each case */\
+ case 1:\
+ p(s, "\t\t%llu node-local%s\n");\
+ break;\
+ case 2:\
+ p(s,"\t\t%llu link-local%s\n");\
+ break;\
+ case 5:\
+ p(s,"\t\t%llu site-local%s\n");\
+ break;\
+ case 14:\
+ p(s,"\t\t%llu global%s\n");\
+ break;\
+ default:\
+ printf("\t\t%llu addresses scope=%x\n",\
+ (unsigned long long)ip6stat.s, i);\
+ }\
+ } while (0);
+
+ p(ip6s_sources_none,
+ "\t%llu failure%s of source address selection\n");
+ for (first = 1, i = 0; i < 16; i++) {
+ if (ip6stat.ip6s_sources_sameif[i]) {
+ if (first) {
+ printf("\tsource addresses on an outgoing I/F\n");
+ first = 0;
+ }
+ PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
+ }
+ }
+ for (first = 1, i = 0; i < 16; i++) {
+ if (ip6stat.ip6s_sources_otherif[i]) {
+ if (first) {
+ printf("\tsource addresses on a non-outgoing I/F\n");
+ first = 0;
+ }
+ PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
+ }
+ }
+ for (first = 1, i = 0; i < 16; i++) {
+ if (ip6stat.ip6s_sources_samescope[i]) {
+ if (first) {
+ printf("\tsource addresses of same scope\n");
+ first = 0;
+ }
+ PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
+ }
+ }
+ for (first = 1, i = 0; i < 16; i++) {
+ if (ip6stat.ip6s_sources_otherscope[i]) {
+ if (first) {
+ printf("\tsource addresses of a different scope\n");
+ first = 0;
+ }
+ PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
}
}
- printf("\t\t%lu one ext mbuf\n", ip6stat.ip6s_mext1);
- printf("\t\t%lu two or more ext mbuf\n", ip6stat.ip6s_mext2m);
- p(ip6s_exthdrtoolong, "\t%lu packet%s whose headers are not continuous\n");
- p(ip6s_nogif, "\t%lu tunneling packet%s that can't find gif\n");
- p(ip6s_toomanyhdr, "\t%lu packet%s discarded due to too may headers\n");
+ for (first = 1, i = 0; i < 16; i++) {
+ if (ip6stat.ip6s_sources_deprecated[i]) {
+ if (first) {
+ printf("\tdeprecated source addresses\n");
+ first = 0;
+ }
+ PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
+ }
+ }
+
+ p1a(ip6s_forward_cachehit, "\t%llu forward cache hit\n");
+ p1a(ip6s_forward_cachemiss, "\t%llu forward cache miss\n");
#undef p
+#undef p1a
}
/*
@@ -419,9 +496,9 @@ ip6_ifstats(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))
+ printf(m, (unsigned long long)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)
+ printf(m, (unsigned long long)ip6stat.f)
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
perror("Warning: socket(AF_INET6)");
@@ -436,28 +513,28 @@ ip6_ifstats(ifname)
goto end;
}
- p(ifs6_in_receive, "\t%qu total input datagram%s\n");
- p(ifs6_in_hdrerr, "\t%qu datagram%s with invalid header received\n");
- p(ifs6_in_toobig, "\t%qu datagram%s exceeded MTU received\n");
- p(ifs6_in_noroute, "\t%qu datagram%s with no route received\n");
- p(ifs6_in_addrerr, "\t%qu datagram%s with invalid dst received\n");
- p(ifs6_in_protounknown, "\t%qu datagram%s with unknown proto received\n");
- p(ifs6_in_truncated, "\t%qu truncated datagram%s received\n");
- p(ifs6_in_discard, "\t%qu input datagram%s discarded\n");
+ 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_protounknown, "\t%llu datagram%s with unknown proto received\n");
+ p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n");
+ p(ifs6_in_discard, "\t%llu input datagram%s discarded\n");
p(ifs6_in_deliver,
- "\t%qu datagram%s delivered to an upper layer protocol\n");
- p(ifs6_out_forward, "\t%qu datagram%s forwarded to this interface\n");
+ "\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%qu datagram%s sent from an upper layer protocol\n");
- p(ifs6_out_discard, "\t%qu total discarded output datagram%s\n");
- p(ifs6_out_fragok, "\t%qu output datagram%s fragmented\n");
- p(ifs6_out_fragfail, "\t%qu output datagram%s failed on fragment\n");
- p(ifs6_out_fragcreat, "\t%qu output datagram%s succeeded on fragment\n");
- p(ifs6_reass_reqd, "\t%qu incoming datagram%s fragmented\n");
- p(ifs6_reass_ok, "\t%qu datagram%s reassembled\n");
- p(ifs6_reass_fail, "\t%qu datagram%s failed on reassembling\n");
- p(ifs6_in_mcast, "\t%qu multicast datagram%s received\n");
- p(ifs6_out_mcast, "\t%qu multicast datagram%s sent\n");
+ "\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);
@@ -742,36 +819,53 @@ icmp6_stats(off, name)
printf("%s:\n", name);
#define p(f, m) if (icmp6stat.f || sflag <= 1) \
- printf(m, icmp6stat.f, plural(icmp6stat.f))
+ printf(m, (unsigned long long)icmp6stat.f, plural(icmp6stat.f))
+#define p_5(f, m) printf(m, (unsigned long long)icmp6stat.f)
- p(icp6s_error, "\t%lu call%s to icmp_error\n");
+ p(icp6s_error, "\t%llu call%s to icmp_error\n");
p(icp6s_canterror,
- "\t%lu error%s not generated because old message was icmp error or so\n");
+ "\t%llu error%s not generated because old message was icmp error or so\n");
p(icp6s_toofreq,
- "\t%lu error%s not generated because rate limitation\n");
+ "\t%llu error%s not generated because rate limitation\n");
for (first = 1, i = 0; i < 256; i++)
if (icmp6stat.icp6s_outhist[i] != 0) {
if (first) {
printf("\tOutput histogram:\n");
first = 0;
}
- printf("\t\t%s: %lu\n", icmp6names[i],
- icmp6stat.icp6s_outhist[i]);
+ printf("\t\t%s: %llu\n", icmp6names[i],
+ (unsigned long long)icmp6stat.icp6s_outhist[i]);
}
- p(icp6s_badcode, "\t%lu message%s with bad code fields\n");
- p(icp6s_tooshort, "\t%lu message%s < minimum length\n");
- p(icp6s_checksum, "\t%lu bad checksum%s\n");
- p(icp6s_badlen, "\t%lu message%s with bad length\n");
+ p(icp6s_badcode, "\t%llu message%s with bad code fields\n");
+ p(icp6s_tooshort, "\t%llu message%s < minimum length\n");
+ p(icp6s_checksum, "\t%llu bad checksum%s\n");
+ p(icp6s_badlen, "\t%llu message%s with bad length\n");
for (first = 1, i = 0; i < ICMP6_MAXTYPE; i++)
if (icmp6stat.icp6s_inhist[i] != 0) {
if (first) {
printf("\tInput histogram:\n");
first = 0;
}
- printf("\t\t%s: %lu\n", icmp6names[i],
- icmp6stat.icp6s_inhist[i]);
+ printf("\t\t%s: %llu\n", icmp6names[i],
+ (unsigned long long)icmp6stat.icp6s_inhist[i]);
}
- p(icp6s_reflect, "\t%lu message response%s generated\n");
+ printf("\tHistgram of error messages to be generated:\n");
+ p_5(icp6s_odst_unreach_noroute, "\t\t%llu no route\n");
+ p_5(icp6s_odst_unreach_admin, "\t\t%llu administratively prohibited\n");
+ p_5(icp6s_odst_unreach_beyondscope, "\t\t%llu beyond scope\n");
+ p_5(icp6s_odst_unreach_addr, "\t\t%llu address unreachable\n");
+ p_5(icp6s_odst_unreach_noport, "\t\t%llu port unreachable\n");
+ p_5(icp6s_opacket_too_big, "\t\t%llu packet too big\n");
+ p_5(icp6s_otime_exceed_transit, "\t\t%llu time exceed transit\n");
+ p_5(icp6s_otime_exceed_reassembly, "\t\t%llu time exceed reassembly\n");
+ p_5(icp6s_oparamprob_header, "\t\t%llu erroneous header field\n");
+ p_5(icp6s_oparamprob_nextheader, "\t\t%llu unrecognized next header\n");
+ p_5(icp6s_oparamprob_option, "\t\t%llu unrecognized option\n");
+ p_5(icp6s_oredirect, "\t\t%llu redirect\n");
+ p_5(icp6s_ounknown, "\t\t%llu unknown\n");
+
+ 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
#undef p_5
}
@@ -786,7 +880,7 @@ icmp6_ifstats(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))
+ printf(m, (unsigned long long)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)");
@@ -801,41 +895,41 @@ icmp6_ifstats(ifname)
goto end;
}
- p(ifs6_in_msg, "\t%qu total input message%s\n");
- p(ifs6_in_error, "\t%qu total input error message%s\n");
- p(ifs6_in_dstunreach, "\t%qu input destination unreachable error%s\n");
- p(ifs6_in_adminprohib, "\t%qu input administratively prohibited error%s\n");
- p(ifs6_in_timeexceed, "\t%qu input time exceeded error%s\n");
- p(ifs6_in_paramprob, "\t%qu input parameter problem error%s\n");
- p(ifs6_in_pkttoobig, "\t%qu input packet too big error%s\n");
- p(ifs6_in_echo, "\t%qu input echo request%s\n");
- p(ifs6_in_echoreply, "\t%qu input echo reply%s\n");
- p(ifs6_in_routersolicit, "\t%qu input router solicitation%s\n");
- p(ifs6_in_routeradvert, "\t%qu input router advertisement%s\n");
- p(ifs6_in_neighborsolicit, "\t%qu input neighbor solicitation%s\n");
- p(ifs6_in_neighboradvert, "\t%qu input neighbor advertisement%s\n");
- p(ifs6_in_redirect, "\t%qu input redirect%s\n");
- p(ifs6_in_mldquery, "\t%qu input MLD query%s\n");
- p(ifs6_in_mldreport, "\t%qu input MLD report%s\n");
- p(ifs6_in_mlddone, "\t%qu input MLD done%s\n");
+ 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%qu total output message%s\n");
- p(ifs6_out_error, "\t%qu total output error message%s\n");
- p(ifs6_out_dstunreach, "\t%qu output destination unreachable error%s\n");
- p(ifs6_out_adminprohib, "\t%qu output administratively prohibited error%s\n");
- p(ifs6_out_timeexceed, "\t%qu output time exceeded error%s\n");
- p(ifs6_out_paramprob, "\t%qu output parameter problem error%s\n");
- p(ifs6_out_pkttoobig, "\t%qu output packet too big error%s\n");
- p(ifs6_out_echo, "\t%qu output echo request%s\n");
- p(ifs6_out_echoreply, "\t%qu output echo reply%s\n");
- p(ifs6_out_routersolicit, "\t%qu output router solicitation%s\n");
- p(ifs6_out_routeradvert, "\t%qu output router advertisement%s\n");
- p(ifs6_out_neighborsolicit, "\t%qu output neighbor solicitation%s\n");
- p(ifs6_out_neighboradvert, "\t%qu output neighbor advertisement%s\n");
- p(ifs6_out_redirect, "\t%qu output redirect%s\n");
- p(ifs6_out_mldquery, "\t%qu output MLD query%s\n");
- p(ifs6_out_mldreport, "\t%qu output MLD report%s\n");
- p(ifs6_out_mlddone, "\t%qu output 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);
@@ -858,14 +952,14 @@ pim6_stats(off, name)
printf("%s:\n", name);
#define p(f, m) if (pim6stat.f || sflag <= 1) \
- printf(m, pim6stat.f, plural(pim6stat.f))
- p(pim6s_rcv_total, "\t%u message%s received\n");
- p(pim6s_rcv_tooshort, "\t%u message%s received with too few bytes\n");
- p(pim6s_rcv_badsum, "\t%u message%s received with bad checksum\n");
- p(pim6s_rcv_badversion, "\t%u message%s received with bad version\n");
- p(pim6s_rcv_registers, "\t%u register%s received\n");
- p(pim6s_rcv_badregisters, "\t%u bad register%s received\n");
- p(pim6s_snd_registers, "\t%u register%s sent\n");
+ printf(m, (unsigned long long)pim6stat.f, plural(pim6stat.f))
+ p(pim6s_rcv_total, "\t%llu message%s received\n");
+ p(pim6s_rcv_tooshort, "\t%llu message%s received with too few bytes\n");
+ p(pim6s_rcv_badsum, "\t%llu message%s received with bad checksum\n");
+ p(pim6s_rcv_badversion, "\t%llu message%s received with bad version\n");
+ p(pim6s_rcv_registers, "\t%llu register%s received\n");
+ p(pim6s_rcv_badregisters, "\t%llu bad register%s received\n");
+ p(pim6s_snd_registers, "\t%llu register%s sent\n");
#undef p
}
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 87c3a73f930d..453eb791c905 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -143,6 +143,8 @@ static struct nlist nl[] = {
{ "_mf6ctable" },
#define N_MIF6TABLE 36
{ "_mif6table" },
+#define N_PFKEYSTAT 37
+ { "_pfkeystat" },
{ "" },
};
@@ -203,6 +205,15 @@ struct protox ip6protox[] = {
};
#endif /*INET6*/
+#ifdef IPSEC
+struct protox pfkeyprotox[] = {
+ { -1, N_PFKEYSTAT, 1, 0,
+ pfkey_stats, NULL, "pfkey", 0 },
+ { -1, -1, 0, 0,
+ 0, NULL, 0, 0 }
+};
+#endif
+
struct protox atalkprotox[] = {
{ N_DDPCB, N_DDPSTAT, 1, atalkprotopr,
ddp_stats, NULL, "ddp" },
@@ -261,6 +272,9 @@ struct protox *protoprotox[] = {
#ifdef INET6
ip6protox,
#endif
+#ifdef IPSEC
+ pfkeyprotox,
+#endif
ipxprotox, atalkprotox,
#ifdef NS
nsprotox,
@@ -316,6 +330,10 @@ main(argc, argv)
else if (strcmp(optarg, "inet6") == 0)
af = AF_INET6;
#endif /*INET6*/
+#ifdef INET6
+ else if (strcmp(optarg, "pfkey") == 0)
+ af = PF_KEY;
+#endif /*INET6*/
else if (strcmp(optarg, "unix") == 0)
af = AF_UNIX;
else if (strcmp(optarg, "atalk") == 0)
@@ -505,6 +523,11 @@ main(argc, argv)
for (tp = ip6protox; tp->pr_name; tp++)
printproto(tp, tp->pr_name);
#endif /*INET6*/
+#ifdef IPSEC
+ if (af == PF_KEY || af == AF_UNSPEC)
+ for (tp = pfkeyprotox; tp->pr_name; tp++)
+ printproto(tp, tp->pr_name);
+#endif /*IPSEC*/
if (af == AF_IPX || af == AF_UNSPEC) {
kread(0, 0, 0);
for (tp = ipxprotox; tp->pr_name; tp++)
diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c
index 74706c7eb0fe..46e0dfe68be6 100644
--- a/usr.bin/netstat/mroute.c
+++ b/usr.bin/netstat/mroute.c
@@ -48,7 +48,6 @@ static const char rcsid[] =
* MROUTING 1.0
*/
-
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/socket.h>
@@ -123,7 +122,7 @@ mroutepr(mfcaddr, vifaddr)
kread((u_long)m, (char *)&mfc, sizeof mfc);
if (!banner_printed) {
- printf("\nMulticast Forwarding Cache\n"
+ printf("\nIPv4 Multicast Forwarding Cache\n"
" Origin Group "
" Packets In-Vif Out-Vifs:Ttls\n");
banner_printed = 1;
@@ -157,12 +156,12 @@ mrt_stats(mstaddr)
struct mrtstat mrtstat;
if (mstaddr == 0) {
- printf("No multicast routing compiled into this system.\n");
+ printf("No IPv4 multicast routing compiled into this system.\n");
return;
}
kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
- printf("multicast forwarding:\n");
+ printf("IPv4 multicast forwarding:\n");
printf(" %10lu multicast forwarding cache lookup%s\n",
mrtstat.mrts_mfc_lookups, plural(mrtstat.mrts_mfc_lookups));
printf(" %10lu multicast forwarding cache miss%s\n",
diff --git a/usr.bin/netstat/mroute6.c b/usr.bin/netstat/mroute6.c
index 3730a9e49ee9..f605a039ac40 100644
--- a/usr.bin/netstat/mroute6.c
+++ b/usr.bin/netstat/mroute6.c
@@ -139,7 +139,8 @@ mroute6pr(mfcaddr, mifaddr)
printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ?
"reg0" : if_indextoname(ifnet.if_index, ifname));
- printf(" %9qu %9qu\n", mifp->m6_pkt_in, mifp->m6_pkt_out);
+ printf(" %9llu %9llu\n", (unsigned long long)mifp->m6_pkt_in,
+ (unsigned long long)mifp->m6_pkt_out);
}
if (!banner_printed)
printf("\nIPv6 Multicast Interface Table is empty\n");
@@ -163,7 +164,7 @@ mroute6pr(mfcaddr, mifaddr)
routename6(&mfc.mf6c_origin));
printf(" %-*.*s", WID_GRP, WID_GRP,
routename6(&mfc.mf6c_mcastgrp));
- printf(" %9qu", mfc.mf6c_pkt_cnt);
+ printf(" %9llu", (unsigned long long)mfc.mf6c_pkt_cnt);
for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
waitings++;
@@ -206,30 +207,43 @@ mrt6_stats(mstaddr)
kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
printf("IPv6 multicast forwarding:\n");
- printf(" %10qu multicast forwarding cache lookup%s\n",
- mrtstat.mrt6s_mfc_lookups, plural(mrtstat.mrt6s_mfc_lookups));
- printf(" %10qu multicast forwarding cache miss%s\n",
- mrtstat.mrt6s_mfc_misses, plurales(mrtstat.mrt6s_mfc_misses));
- printf(" %10qu upcall%s to mrouted\n",
- mrtstat.mrt6s_upcalls, plural(mrtstat.mrt6s_upcalls));
- printf(" %10qu upcall queue overflow%s\n",
- mrtstat.mrt6s_upq_ovflw, plural(mrtstat.mrt6s_upq_ovflw));
- printf(" %10qu upcall%s dropped due to full socket buffer\n",
- mrtstat.mrt6s_upq_sockfull, plural(mrtstat.mrt6s_upq_sockfull));
- printf(" %10qu cache cleanup%s\n",
- mrtstat.mrt6s_cache_cleanups, plural(mrtstat.mrt6s_cache_cleanups));
- printf(" %10qu datagram%s with no route for origin\n",
- mrtstat.mrt6s_no_route, plural(mrtstat.mrt6s_no_route));
- printf(" %10qu datagram%s arrived with bad tunneling\n",
- mrtstat.mrt6s_bad_tunnel, plural(mrtstat.mrt6s_bad_tunnel));
- printf(" %10qu datagram%s could not be tunneled\n",
- mrtstat.mrt6s_cant_tunnel, plural(mrtstat.mrt6s_cant_tunnel));
- printf(" %10qu datagram%s arrived on wrong interface\n",
- mrtstat.mrt6s_wrong_if, plural(mrtstat.mrt6s_wrong_if));
- printf(" %10qu datagram%s selectively dropped\n",
- mrtstat.mrt6s_drop_sel, plural(mrtstat.mrt6s_drop_sel));
- printf(" %10qu datagram%s dropped due to queue overflow\n",
- mrtstat.mrt6s_q_overflow, plural(mrtstat.mrt6s_q_overflow));
- printf(" %10qu datagram%s dropped for being too large\n",
- mrtstat.mrt6s_pkt2large, plural(mrtstat.mrt6s_pkt2large));
+ printf(" %10llu multicast forwarding cache lookup%s\n",
+ (unsigned long long)mrtstat.mrt6s_mfc_lookups,
+ plural(mrtstat.mrt6s_mfc_lookups));
+ printf(" %10llu multicast forwarding cache miss%s\n",
+ (unsigned long long)mrtstat.mrt6s_mfc_misses,
+ plurales(mrtstat.mrt6s_mfc_misses));
+ printf(" %10llu upcall%s to mrouted\n",
+ (unsigned long long)mrtstat.mrt6s_upcalls,
+ plural(mrtstat.mrt6s_upcalls));
+ printf(" %10llu upcall llueue overflow%s\n",
+ (unsigned long long)mrtstat.mrt6s_upq_ovflw,
+ plural(mrtstat.mrt6s_upq_ovflw));
+ printf(" %10llu upcall%s dropped due to full socket buffer\n",
+ (unsigned long long)mrtstat.mrt6s_upq_sockfull,
+ plural(mrtstat.mrt6s_upq_sockfull));
+ printf(" %10llu cache cleanup%s\n",
+ (unsigned long long)mrtstat.mrt6s_cache_cleanups,
+ plural(mrtstat.mrt6s_cache_cleanups));
+ printf(" %10llu datagram%s with no route for origin\n",
+ (unsigned long long)mrtstat.mrt6s_no_route,
+ plural(mrtstat.mrt6s_no_route));
+ printf(" %10llu datagram%s arrived with bad tunneling\n",
+ (unsigned long long)mrtstat.mrt6s_bad_tunnel,
+ plural(mrtstat.mrt6s_bad_tunnel));
+ printf(" %10llu datagram%s could not be tunneled\n",
+ (unsigned long long)mrtstat.mrt6s_cant_tunnel,
+ plural(mrtstat.mrt6s_cant_tunnel));
+ printf(" %10llu datagram%s arrived on wrong interface\n",
+ (unsigned long long)mrtstat.mrt6s_wrong_if,
+ plural(mrtstat.mrt6s_wrong_if));
+ printf(" %10llu datagram%s selectively dropped\n",
+ (unsigned long long)mrtstat.mrt6s_drop_sel,
+ plural(mrtstat.mrt6s_drop_sel));
+ printf(" %10llu datagram%s dropped due to llueue overflow\n",
+ (unsigned long long)mrtstat.mrt6s_q_overflow,
+ plural(mrtstat.mrt6s_q_overflow));
+ printf(" %10llu datagram%s dropped for being too large\n",
+ (unsigned long long)mrtstat.mrt6s_pkt2large,
+ plural(mrtstat.mrt6s_pkt2large));
}
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index 3b435c2f6ae6..70bfbf0c6471 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -81,8 +81,17 @@ void icmp6_ifstats __P((char *));
void pim6_stats __P((u_long, char *));
void mroute6pr __P((u_long, u_long));
void mrt6_stats __P((u_long));
+
+struct sockaddr_in6;
+struct in6_addr;
+char *routename6 __P((struct sockaddr_in6 *));
+char *netname6 __P((struct sockaddr_in6 *, struct in6_addr *));
#endif /*INET6*/
+#ifdef IPSEC
+void pfkey_stats __P((u_long, char *));
+#endif
+
void bdg_stats __P((u_long, char *));
void mbpr __P((void));
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index 9d43a8188ed5..b6b638215a7d 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -73,6 +73,12 @@ static const char rcsid[] =
#define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d)))
+
+/* alignment constraint for routing socket */
+#define ROUNDUP(a) \
+ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
+#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
+
/*
* Definitions for showing gateway flags.
*/
@@ -222,44 +228,35 @@ pr_family(af)
}
/* column widths; each followed by one space */
-#define WID_DST 18 /* width of destination column */
-#define WID_GW 18 /* width of gateway column */
-#ifdef INET6
-#define WID_DST6 (lflag ? 39 : (nflag ? 33: 18)) /* width of dest column */
-#define WID_GW6 (lflag ? 31 : (nflag ? 29 : 18)) /* width of gateway column */
+#ifndef INET6
+#define WID_DST(af) 18 /* width of destination column */
+#define WID_GW(af) 18 /* width of gateway column */
+#else
+#define WID_DST(af) \
+ ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 33: 18)) : 18)
+#define WID_GW(af) \
+ ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 29 : 18)) : 18)
#endif /*INET6*/
/*
* Print header for routing table columns.
*/
void
-pr_rthdr(wid_af)
- int wid_af;
+pr_rthdr(af)
+ int af;
{
- int wid_dst, wid_gw;
-
- wid_dst =
-#ifdef INET6
- wid_af == AF_INET6 ? WID_DST6 :
-#endif
- WID_DST;
- wid_gw =
-#ifdef INET6
- wid_af == AF_INET6 ? WID_GW6 :
-#endif
- WID_GW;
if (Aflag)
printf("%-8.8s ","Address");
- if (wid_af == AF_INET || lflag)
+ if (lflag)
printf("%-*.*s %-*.*s %-6.6s %6.6s%8.8s %8.8s %6s\n",
- wid_dst, wid_dst, "Destination",
- wid_gw, wid_gw, "Gateway",
+ WID_DST(af), WID_DST(af), "Destination",
+ WID_GW(af), WID_GW(af), "Gateway",
"Flags", "Refs", "Use", "Netif", "Expire");
else
printf("%-*.*s %-*.*s %-6.6s %8.8s %6s\n",
- wid_dst, wid_dst, "Destination",
- wid_gw, wid_gw, "Gateway",
+ WID_DST(af), WID_DST(af), "Destination",
+ WID_GW(af), WID_GW(af), "Gateway",
"Flags", "Netif", "Expire");
}
@@ -414,7 +411,7 @@ np_rtentry(rtm)
p_sockaddr(sa, NULL, 0, 36);
else {
p_sockaddr(sa, NULL, rtm->rtm_flags, 16);
- sa = (struct sockaddr *)(sa->sa_len + (char *)sa);
+ sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
p_sockaddr(sa, NULL, 0, 18);
}
p_flags(rtm->rtm_flags & interesting, "%-6.6s ");
@@ -602,15 +599,9 @@ p_rtentry(rt)
if (rt_mask(rt) && (sa = kgetsa(rt_mask(rt))))
bcopy(sa, &mask, sa->sa_len);
p_sockaddr(&addr.u_sa, &mask.u_sa, rt->rt_flags,
-#ifdef INET6
- addr.u_sa.sa_family == AF_INET6 ? WID_DST6 :
-#endif
- WID_DST);
+ WID_DST(addr.u_sa.sa_family));
p_sockaddr(kgetsa(rt->rt_gateway), NULL, RTF_HOST,
-#ifdef INET6
- addr.u_sa.sa_family == AF_INET6 ? WID_GW6 :
-#endif
- WID_GW);
+ WID_GW(addr.u_sa.sa_family));
p_flags(rt->rt_flags, "%-6.6s ");
if (addr.u_sa.sa_family == AF_INET || lflag)
printf("%6ld %8ld ", rt->rt_refcnt, rt->rt_use);
@@ -765,18 +756,14 @@ netname6(sa6, mask)
static char line[MAXHOSTNAMELEN + 1];
u_char *p = (u_char *)mask;
u_char *lim;
- int masklen, illegal = 0;
- int flag = NI_WITHSCOPEID;
+ int masklen, illegal = 0, flag = NI_WITHSCOPEID;
if (mask) {
for (masklen = 0, lim = p + 16; p < lim; p++) {
- if (*p == 0xff)
- masklen += 8;
- else
- break;
- }
- if (p < lim) {
switch (*p) {
+ case 0xff:
+ masklen += 8;
+ break;
case 0xfe:
masklen += 7;
break;
@@ -831,12 +818,17 @@ routename6(sa6)
{
static char line[MAXHOSTNAMELEN + 1];
int flag = NI_WITHSCOPEID;
+ /* use local variable for safety */
+ struct sockaddr_in6 sa6_local = {AF_INET6, sizeof(sa6_local),};
+
+ sa6_local.sin6_addr = sa6->sin6_addr;
+ sa6_local.sin6_scope_id = sa6->sin6_scope_id;
if (nflag)
flag |= NI_NUMERICHOST;
- getnameinfo((struct sockaddr *)sa6, sa6->sin6_len, line, sizeof(line),
- NULL, 0, flag);
+ getnameinfo((struct sockaddr *)&sa6_local, sa6_local.sin6_len,
+ line, sizeof(line), NULL, 0, flag);
return line;
}
diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c
index c0c6b2cb4a53..12904b833c8e 100644
--- a/usr.bin/telnet/commands.c
+++ b/usr.bin/telnet/commands.c
@@ -2254,7 +2254,7 @@ tn(argc, argv)
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(src_addr, 0, &hints, &src_res);
- if (error == EAI_NONAME) {
+ if (error == EAI_NODATA) {
hints.ai_flags = 0;
error = getaddrinfo(src_addr, 0, &hints, &src_res);
}
@@ -2292,7 +2292,19 @@ tn(argc, argv)
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(hostname, portp, &hints, &res);
- if (error == 0) {
+ if (error) {
+ hints.ai_flags = AI_CANONNAME;
+ error = getaddrinfo(hostname, portp, &hints, &res);
+ }
+ if (error != 0) {
+ fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error));
+ if (error == EAI_SYSTEM)
+ fprintf(stderr, "%s: %s\n", hostname, strerror(errno));
+ setuid(getuid());
+ goto fail;
+ }
+ if (hints.ai_flags == AI_NUMERICHOST) {
+ /* hostname has numeric */
int gni_err = 1;
if (doaddrlookup)
@@ -2300,19 +2312,11 @@ tn(argc, argv)
_hostname, sizeof(_hostname) - 1, NULL, 0,
NI_NAMEREQD);
if (gni_err != 0)
- (void) strncpy(_hostname, hostp, sizeof(_hostname) - 1);
+ (void) strncpy(_hostname, hostp, sizeof(_hostname) - 1);
_hostname[sizeof(_hostname)-1] = '\0';
hostname = _hostname;
- } else if (error == EAI_NONAME) {
- hints.ai_flags = AI_CANONNAME;
- error = getaddrinfo(hostname, portp, &hints, &res);
- if (error != 0) {
- fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error));
- if (error == EAI_SYSTEM)
- fprintf(stderr, "%s: %s\n", hostname, strerror(errno));
- setuid(getuid());
- goto fail;
- }
+ } else {
+ /* hostname has FQDN */
if (srcroute != 0)
(void) strncpy(_hostname, hostname, sizeof(_hostname) - 1);
else if (res->ai_canonname != NULL)
@@ -2321,12 +2325,6 @@ tn(argc, argv)
(void) strncpy(_hostname, hostp, sizeof(_hostname) - 1);
_hostname[sizeof(_hostname)-1] = '\0';
hostname = _hostname;
- } else if (error != 0) {
- fprintf(stderr, "%s: %s\n", hostname, gai_strerror(error));
- if (error == EAI_SYSTEM)
- fprintf(stderr, "%s: %s\n", hostname, strerror(errno));
- setuid(getuid());
- goto fail;
}
res0 = res;
af_again:
@@ -2982,7 +2980,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
hints.ai_flags = AI_NUMERICHOST;
error = getaddrinfo(cp, NULL, &hints, &res);
- if (error == EAI_NONAME) {
+ if (error == EAI_NODATA) {
hints.ai_flags = 0;
error = getaddrinfo(cp, NULL, &hints, &res);
}
diff --git a/usr.bin/whois/whois.c b/usr.bin/whois/whois.c
index 0ef3d4b5c30f..af03a1235b27 100644
--- a/usr.bin/whois/whois.c
+++ b/usr.bin/whois/whois.c
@@ -75,20 +75,18 @@ static const char rcsid[] =
#define WHOIS_QUICK 0x04
static void usage __P((void));
-static void whois __P((char *, struct sockaddr_in *, int));
+static void whois __P((char *, struct addrinfo *, int));
int
main(argc, argv)
int argc;
char **argv;
{
- int ch, i, j;
+ int ch, i, j, error;
int use_qnichost, flags;
char *host;
char *qnichost;
- struct servent *sp;
- struct hostent *hp;
- struct sockaddr_in sin;
+ struct addrinfo hints, *res;
#ifdef SOCKS
SOCKSinit(argv[0]);
@@ -145,16 +143,6 @@ main(argc, argv)
usage();
}
- memset(&sin, 0, sizeof(sin));
- sin.sin_len = sizeof(sin);
- sin.sin_family = AF_INET;
- sp = getservbyname("whois", "tcp");
- if (sp == NULL) {
- sin.sin_port = htons(WHOIS_PORT);
- } else {
- sin.sin_port = sp->s_port;
- }
-
/*
* If no nic host is specified, use whois-servers.net
* if there is a '.' in the name, else fall back to NICHOST.
@@ -186,36 +174,38 @@ main(argc, argv)
strcpy(qnichost, *argv + j + 1);
strcat(qnichost, QNICHOST_TAIL);
- if (inet_aton(qnichost, &sin.sin_addr) == 0) {
- hp = gethostbyname2(qnichost, AF_INET);
- if (hp == NULL) {
- free(qnichost);
- qnichost = NULL;
- } else {
- sin.sin_addr = *(struct in_addr *)hp->h_addr_list[0];
- }
- }
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = 0;
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ error = getaddrinfo(qnichost, "whois",
+ &hints, &res);
+ if (error != 0)
+ errx(EX_NOHOST, "%s: %s", qnichost,
+ gai_strerror(error));
}
}
- if (!qnichost && inet_aton(host, &sin.sin_addr) == 0) {
- hp = gethostbyname2(host, AF_INET);
- if (hp == NULL) {
+ if (!qnichost) {
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = 0;
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ error = getaddrinfo(host, "whois", &hints, &res);
+ if (error != 0)
errx(EX_NOHOST, "%s: %s", host,
- hstrerror(h_errno));
- }
- host = hp->h_name;
- sin.sin_addr = *(struct in_addr *)hp->h_addr_list[0];
+ gai_strerror(error));
}
- whois(*argv++, &sin, flags);
+ whois(*argv++, res, flags);
+ freeaddrinfo(res);
}
exit(0);
}
static void
-whois(name, sinp, flags)
+whois(name, res, flags)
char *name;
- struct sockaddr_in *sinp;
+ struct addrinfo *res;
int flags;
{
FILE *sfi, *sfo;
@@ -223,12 +213,12 @@ whois(name, sinp, flags)
size_t len;
int s, nomatch;
- s = socket(PF_INET, SOCK_STREAM, 0);
+ s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (s < 0) {
err(EX_OSERR, "socket");
}
- if (connect(s, (struct sockaddr *)sinp, sizeof(*sinp)) < 0) {
+ if (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
err(EX_OSERR, "connect");
}
@@ -278,17 +268,23 @@ whois(name, sinp, flags)
nhost = INICHOST;
}
if (nhost) {
- if (inet_aton(nhost, &sinp->sin_addr) == 0) {
- struct hostent *hp = gethostbyname2(nhost, AF_INET);
- if (hp == NULL) {
- return;
- }
- sinp->sin_addr = *(struct in_addr *)hp->h_addr_list[0];
+ struct addrinfo hints, *res2;
+ int error;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = 0;
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ error = getaddrinfo(nhost, "whois", &hints, &res2);
+ if (error != 0) {
+ warnx("%s: %s", nhost, gai_strerror(error));
+ return;
}
if (!nomatch) {
free(nhost);
}
- whois(name, sinp, 0);
+ whois(name, res2, 0);
+ freeaddrinfo(res2);
}
}