1 /* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */
3 * Copyright (c) 1983, 1988, 1993
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $FreeBSD: src/usr.bin/netstat/inet6.c,v 1.3.2.9 2001/08/10 09:07:09 ru Exp $
39 static char sccsid[] = "@(#)inet6.c 8.4 (Berkeley) 4/20/94";
44 #include <sys/param.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
47 #include <sys/ioctl.h>
48 #include <sys/sysctl.h>
50 #include <net/route.h>
52 #include <net/if_var.h>
53 #include <netinet/in.h>
54 #include <netinet/ip6.h>
55 #include <netinet/icmp6.h>
56 #include <netinet/in_systm.h>
57 #include <netinet6/in6_pcb.h>
58 #include <netinet6/in6_var.h>
59 #include <netinet6/ip6_var.h>
60 #include <netinet6/pim6_var.h>
61 #include <netinet6/raw_ip6.h>
63 #include <arpa/inet.h>
75 char *inet6name (struct in6_addr
*);
76 void inet6print (struct in6_addr
*, int, char *, int);
78 static char ntop_buf
[INET6_ADDRSTRLEN
];
80 static char *ip6nh
[] = {
141 "destination option",
340 * Dump IP6 statistics structure.
343 ip6_stats(u_long off __unused
, char *name
, int af __unused
)
345 struct ip6stat ip6stat
;
352 mib
[2] = IPPROTO_IPV6
;
353 mib
[3] = IPV6CTL_STATS
;
355 len
= sizeof ip6stat
;
356 memset(&ip6stat
, 0, len
);
357 if (sysctl(mib
, 4, &ip6stat
, &len
, (void *)0, 0) < 0)
359 printf("%s:\n", name
);
361 #define p(f, m) if (ip6stat.f || sflag <= 1) \
362 printf(m, (unsigned long long)ip6stat.f, plural(ip6stat.f))
363 #define p1a(f, m) if (ip6stat.f || sflag <= 1) \
364 printf(m, (unsigned long long)ip6stat.f)
366 p(ip6s_total
, "\t%llu total packet%s received\n");
367 p1a(ip6s_toosmall
, "\t%llu with size smaller than minimum\n");
368 p1a(ip6s_tooshort
, "\t%llu with data size < data length\n");
369 p1a(ip6s_badoptions
, "\t%llu with bad options\n");
370 p1a(ip6s_badvers
, "\t%llu with incorrect version number\n");
371 p(ip6s_fragments
, "\t%llu fragment%s received\n");
372 p(ip6s_fragdropped
, "\t%llu fragment%s dropped (dup or out of space)\n");
373 p(ip6s_fragtimeout
, "\t%llu fragment%s dropped after timeout\n");
374 p(ip6s_fragoverflow
, "\t%llu fragment%s that exceeded limit\n");
375 p(ip6s_reassembled
, "\t%llu packet%s reassembled ok\n");
376 p(ip6s_delivered
, "\t%llu packet%s for this host\n");
377 p(ip6s_forward
, "\t%llu packet%s forwarded\n");
378 p(ip6s_cantforward
, "\t%llu packet%s not forwardable\n");
379 p(ip6s_redirectsent
, "\t%llu redirect%s sent\n");
380 p(ip6s_localout
, "\t%llu packet%s sent from this host\n");
381 p(ip6s_rawout
, "\t%llu packet%s sent with fabricated ip header\n");
382 p(ip6s_odropped
, "\t%llu output packet%s dropped due to no bufs, etc.\n");
383 p(ip6s_noroute
, "\t%llu output packet%s discarded due to no route\n");
384 p(ip6s_fragmented
, "\t%llu output datagram%s fragmented\n");
385 p(ip6s_ofragments
, "\t%llu fragment%s created\n");
386 p(ip6s_cantfrag
, "\t%llu datagram%s that can't be fragmented\n");
387 p(ip6s_badscope
, "\t%llu packet%s that violated scope rules\n");
388 p(ip6s_notmember
, "\t%llu multicast packet%s which we don't join\n");
389 for (first
= 1, i
= 0; i
< 256; i
++)
390 if (ip6stat
.ip6s_nxthist
[i
] != 0) {
392 printf("\tInput histogram:\n");
395 printf("\t\t%s: %llu\n", ip6nh
[i
],
396 (unsigned long long)ip6stat
.ip6s_nxthist
[i
]);
398 printf("\tMbuf statistics:\n");
399 printf("\t\t%llu one mbuf\n", (unsigned long long)ip6stat
.ip6s_m1
);
400 for (first
= 1, i
= 0; i
< 32; i
++) {
401 char ifbuf
[IFNAMSIZ
];
402 if (ip6stat
.ip6s_m2m
[i
] != 0) {
404 printf("\t\ttwo or more mbuf:\n");
407 printf("\t\t\t%s= %llu\n",
408 if_indextoname(i
, ifbuf
),
409 (unsigned long long)ip6stat
.ip6s_m2m
[i
]);
412 printf("\t\t%llu one ext mbuf\n",
413 (unsigned long long)ip6stat
.ip6s_mext1
);
414 printf("\t\t%llu two or more ext mbuf\n",
415 (unsigned long long)ip6stat
.ip6s_mext2m
);
416 p(ip6s_exthdrtoolong
,
417 "\t%llu packet%s whose headers are not continuous\n");
418 p(ip6s_nogif
, "\t%llu tunneling packet%s that can't find gif\n");
420 "\t%llu packet%s discarded due to too may headers\n");
422 /* for debugging source address selection */
423 #define PRINT_SCOPESTAT(s,i) do {\
424 switch(i) { /* XXX hardcoding in each case */\
426 p(s, "\t\t%llu node-local%s\n");\
429 p(s,"\t\t%llu link-local%s\n");\
432 p(s,"\t\t%llu site-local%s\n");\
435 p(s,"\t\t%llu global%s\n");\
438 printf("\t\t%llu addresses scope=%x\n",\
439 (unsigned long long)ip6stat.s, i);\
444 "\t%llu failure%s of source address selection\n");
445 for (first
= 1, i
= 0; i
< 16; i
++) {
446 if (ip6stat
.ip6s_sources_sameif
[i
]) {
448 printf("\tsource addresses on an outgoing I/F\n");
451 PRINT_SCOPESTAT(ip6s_sources_sameif
[i
], i
);
454 for (first
= 1, i
= 0; i
< 16; i
++) {
455 if (ip6stat
.ip6s_sources_otherif
[i
]) {
457 printf("\tsource addresses on a non-outgoing I/F\n");
460 PRINT_SCOPESTAT(ip6s_sources_otherif
[i
], i
);
463 for (first
= 1, i
= 0; i
< 16; i
++) {
464 if (ip6stat
.ip6s_sources_samescope
[i
]) {
466 printf("\tsource addresses of same scope\n");
469 PRINT_SCOPESTAT(ip6s_sources_samescope
[i
], i
);
472 for (first
= 1, i
= 0; i
< 16; i
++) {
473 if (ip6stat
.ip6s_sources_otherscope
[i
]) {
475 printf("\tsource addresses of a different scope\n");
478 PRINT_SCOPESTAT(ip6s_sources_otherscope
[i
], i
);
481 for (first
= 1, i
= 0; i
< 16; i
++) {
482 if (ip6stat
.ip6s_sources_deprecated
[i
]) {
484 printf("\tdeprecated source addresses\n");
487 PRINT_SCOPESTAT(ip6s_sources_deprecated
[i
], i
);
491 p1a(ip6s_forward_cachehit
, "\t%llu forward cache hit\n");
492 p1a(ip6s_forward_cachemiss
, "\t%llu forward cache miss\n");
498 * Dump IPv6 per-interface statistics based on RFC 2465.
501 ip6_ifstats(char *ifname
)
503 struct in6_ifreq ifr
;
505 #define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
506 printf(m, (unsigned long long)ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f))
507 #define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
508 printf(m, (unsigned long long)ip6stat.f)
510 if ((s
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0) {
511 perror("Warning: socket(AF_INET6)");
515 strcpy(ifr
.ifr_name
, ifname
);
516 printf("ip6 on %s:\n", ifr
.ifr_name
);
518 if (ioctl(s
, SIOCGIFSTAT_IN6
, (char *)&ifr
) < 0) {
519 perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
523 p(ifs6_in_receive
, "\t%llu total input datagram%s\n");
524 p(ifs6_in_hdrerr
, "\t%llu datagram%s with invalid header received\n");
525 p(ifs6_in_toobig
, "\t%llu datagram%s exceeded MTU received\n");
526 p(ifs6_in_noroute
, "\t%llu datagram%s with no route received\n");
527 p(ifs6_in_addrerr
, "\t%llu datagram%s with invalid dst received\n");
528 p(ifs6_in_protounknown
, "\t%llu datagram%s with unknown proto received\n");
529 p(ifs6_in_truncated
, "\t%llu truncated datagram%s received\n");
530 p(ifs6_in_discard
, "\t%llu input datagram%s discarded\n");
532 "\t%llu datagram%s delivered to an upper layer protocol\n");
533 p(ifs6_out_forward
, "\t%llu datagram%s forwarded to this interface\n");
535 "\t%llu datagram%s sent from an upper layer protocol\n");
536 p(ifs6_out_discard
, "\t%llu total discarded output datagram%s\n");
537 p(ifs6_out_fragok
, "\t%llu output datagram%s fragmented\n");
538 p(ifs6_out_fragfail
, "\t%llu output datagram%s failed on fragment\n");
539 p(ifs6_out_fragcreat
, "\t%llu output datagram%s succeeded on fragment\n");
540 p(ifs6_reass_reqd
, "\t%llu incoming datagram%s fragmented\n");
541 p(ifs6_reass_ok
, "\t%llu datagram%s reassembled\n");
542 p(ifs6_reass_fail
, "\t%llu datagram%s failed on reassembling\n");
543 p(ifs6_in_mcast
, "\t%llu multicast datagram%s received\n");
544 p(ifs6_out_mcast
, "\t%llu multicast datagram%s sent\n");
553 static char *icmp6names
[] = {
684 "multicast listener query",
685 "multicast listener report",
686 "multicast listener done",
687 "router solicitation",
688 "router advertisement",
689 "neighbor solicitation",
690 "neighbor advertisement",
692 "router renumbering",
693 "node information request",
694 "node information reply",
695 "inverse neighbor solicitation",
696 "inverse neighbor advertisement",
813 * Dump ICMP6 statistics.
816 icmp6_stats(u_long off __unused
, char *name
, int af __unused
)
818 struct icmp6stat icmp6stat
;
819 register int i
, first
;
825 mib
[2] = IPPROTO_ICMPV6
;
826 mib
[3] = ICMPV6CTL_STATS
;
828 len
= sizeof icmp6stat
;
829 memset(&icmp6stat
, 0, len
);
830 if (sysctl(mib
, 4, &icmp6stat
, &len
, (void *)0, 0) < 0)
832 printf("%s:\n", name
);
834 #define p(f, m) if (icmp6stat.f || sflag <= 1) \
835 printf(m, (unsigned long long)icmp6stat.f, plural(icmp6stat.f))
836 #define p_5(f, m) printf(m, (unsigned long long)icmp6stat.f)
838 p(icp6s_error
, "\t%llu call%s to icmp_error\n");
840 "\t%llu error%s not generated because old message was icmp error or so\n");
842 "\t%llu error%s not generated because rate limitation\n");
843 #define NELEM (sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0]))
844 for (first
= 1, i
= 0; i
< NELEM
; i
++)
845 if (icmp6stat
.icp6s_outhist
[i
] != 0) {
847 printf("\tOutput histogram:\n");
850 printf("\t\t%s: %llu\n", icmp6names
[i
],
851 (unsigned long long)icmp6stat
.icp6s_outhist
[i
]);
854 p(icp6s_badcode
, "\t%llu message%s with bad code fields\n");
855 p(icp6s_tooshort
, "\t%llu message%s < minimum length\n");
856 p(icp6s_checksum
, "\t%llu bad checksum%s\n");
857 p(icp6s_badlen
, "\t%llu message%s with bad length\n");
858 #define NELEM (sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0]))
859 for (first
= 1, i
= 0; i
< NELEM
; i
++)
860 if (icmp6stat
.icp6s_inhist
[i
] != 0) {
862 printf("\tInput histogram:\n");
865 printf("\t\t%s: %llu\n", icmp6names
[i
],
866 (unsigned long long)icmp6stat
.icp6s_inhist
[i
]);
869 printf("\tHistogram of error messages to be generated:\n");
870 p_5(icp6s_odst_unreach_noroute
, "\t\t%llu no route\n");
871 p_5(icp6s_odst_unreach_admin
, "\t\t%llu administratively prohibited\n");
872 p_5(icp6s_odst_unreach_beyondscope
, "\t\t%llu beyond scope\n");
873 p_5(icp6s_odst_unreach_addr
, "\t\t%llu address unreachable\n");
874 p_5(icp6s_odst_unreach_noport
, "\t\t%llu port unreachable\n");
875 p_5(icp6s_opacket_too_big
, "\t\t%llu packet too big\n");
876 p_5(icp6s_otime_exceed_transit
, "\t\t%llu time exceed transit\n");
877 p_5(icp6s_otime_exceed_reassembly
, "\t\t%llu time exceed reassembly\n");
878 p_5(icp6s_oparamprob_header
, "\t\t%llu erroneous header field\n");
879 p_5(icp6s_oparamprob_nextheader
, "\t\t%llu unrecognized next header\n");
880 p_5(icp6s_oparamprob_option
, "\t\t%llu unrecognized option\n");
881 p_5(icp6s_oredirect
, "\t\t%llu redirect\n");
882 p_5(icp6s_ounknown
, "\t\t%llu unknown\n");
884 p(icp6s_reflect
, "\t%llu message response%s generated\n");
885 p(icp6s_nd_toomanyopt
, "\t%llu message%s with too many ND options\n");
886 p(icp6s_nd_badopt
, "\t%qu message%s with bad ND options\n");
887 p(icp6s_badns
, "\t%qu bad neighbor solicitation message%s\n");
888 p(icp6s_badna
, "\t%qu bad neighbor advertisement message%s\n");
889 p(icp6s_badrs
, "\t%qu bad router solicitation message%s\n");
890 p(icp6s_badra
, "\t%qu bad router advertisement message%s\n");
891 p(icp6s_badredirect
, "\t%qu bad redirect message%s\n");
892 p(icp6s_pmtuchg
, "\t%llu path MTU change%s\n");
898 * Dump ICMPv6 per-interface statistics based on RFC 2466.
901 icmp6_ifstats(char *ifname
)
903 struct in6_ifreq ifr
;
905 #define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
906 printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f))
908 if ((s
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0) {
909 perror("Warning: socket(AF_INET6)");
913 strcpy(ifr
.ifr_name
, ifname
);
914 printf("icmp6 on %s:\n", ifr
.ifr_name
);
916 if (ioctl(s
, SIOCGIFSTAT_ICMP6
, (char *)&ifr
) < 0) {
917 perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
921 p(ifs6_in_msg
, "\t%llu total input message%s\n");
922 p(ifs6_in_error
, "\t%llu total input error message%s\n");
923 p(ifs6_in_dstunreach
, "\t%llu input destination unreachable error%s\n");
924 p(ifs6_in_adminprohib
, "\t%llu input administratively prohibited error%s\n");
925 p(ifs6_in_timeexceed
, "\t%llu input time exceeded error%s\n");
926 p(ifs6_in_paramprob
, "\t%llu input parameter problem error%s\n");
927 p(ifs6_in_pkttoobig
, "\t%llu input packet too big error%s\n");
928 p(ifs6_in_echo
, "\t%llu input echo request%s\n");
929 p(ifs6_in_echoreply
, "\t%llu input echo reply%s\n");
930 p(ifs6_in_routersolicit
, "\t%llu input router solicitation%s\n");
931 p(ifs6_in_routeradvert
, "\t%llu input router advertisement%s\n");
932 p(ifs6_in_neighborsolicit
, "\t%llu input neighbor solicitation%s\n");
933 p(ifs6_in_neighboradvert
, "\t%llu input neighbor advertisement%s\n");
934 p(ifs6_in_redirect
, "\t%llu input redirect%s\n");
935 p(ifs6_in_mldquery
, "\t%llu input MLD query%s\n");
936 p(ifs6_in_mldreport
, "\t%llu input MLD report%s\n");
937 p(ifs6_in_mlddone
, "\t%llu input MLD done%s\n");
939 p(ifs6_out_msg
, "\t%llu total output message%s\n");
940 p(ifs6_out_error
, "\t%llu total output error message%s\n");
941 p(ifs6_out_dstunreach
, "\t%llu output destination unreachable error%s\n");
942 p(ifs6_out_adminprohib
, "\t%llu output administratively prohibited error%s\n");
943 p(ifs6_out_timeexceed
, "\t%llu output time exceeded error%s\n");
944 p(ifs6_out_paramprob
, "\t%llu output parameter problem error%s\n");
945 p(ifs6_out_pkttoobig
, "\t%llu output packet too big error%s\n");
946 p(ifs6_out_echo
, "\t%llu output echo request%s\n");
947 p(ifs6_out_echoreply
, "\t%llu output echo reply%s\n");
948 p(ifs6_out_routersolicit
, "\t%llu output router solicitation%s\n");
949 p(ifs6_out_routeradvert
, "\t%llu output router advertisement%s\n");
950 p(ifs6_out_neighborsolicit
, "\t%llu output neighbor solicitation%s\n");
951 p(ifs6_out_neighboradvert
, "\t%llu output neighbor advertisement%s\n");
952 p(ifs6_out_redirect
, "\t%llu output redirect%s\n");
953 p(ifs6_out_mldquery
, "\t%llu output MLD query%s\n");
954 p(ifs6_out_mldreport
, "\t%llu output MLD report%s\n");
955 p(ifs6_out_mlddone
, "\t%llu output MLD done%s\n");
963 * Dump PIM statistics structure.
969 struct pim6stat pim6stat
;
970 size_t len
= sizeof(struct pim6stat
);
972 if (sysctlbyname("net.inet6.ip6.pim6stat", &pim6stat
, &len
, 0, 0) == -1)
974 printf("%s:\n", name
);
976 #define p(f, m) if (pim6stat.f || sflag <= 1) \
977 printf(m, (unsigned long long)pim6stat.f, plural(pim6stat.f))
978 p(pim6s_rcv_total
, "\t%llu message%s received\n");
979 p(pim6s_rcv_tooshort
, "\t%llu message%s received with too few bytes\n");
980 p(pim6s_rcv_badsum
, "\t%llu message%s received with bad checksum\n");
981 p(pim6s_rcv_badversion
, "\t%llu message%s received with bad version\n");
982 p(pim6s_rcv_registers
, "\t%llu register%s received\n");
983 p(pim6s_rcv_badregisters
, "\t%llu bad register%s received\n");
984 p(pim6s_snd_registers
, "\t%llu register%s sent\n");
990 * Dump raw ip6 statistics structure.
993 rip6_stats(u_long off __unused
, char *name
, int af __unused
)
995 struct rip6stat rip6stat
;
1002 mib
[2] = IPPROTO_IPV6
;
1003 mib
[3] = IPV6CTL_RIP6STATS
;
1004 l
= sizeof(rip6stat
);
1005 if (sysctl(mib
, 4, &rip6stat
, &l
, NULL
, 0) < 0) {
1006 perror("Warning: sysctl(net.inet6.ip6.rip6stats)");
1010 printf("%s:\n", name
);
1012 #define p(f, m) if (rip6stat.f || sflag <= 1) \
1013 printf(m, (unsigned long long)rip6stat.f, plural(rip6stat.f))
1014 p(rip6s_ipackets
, "\t%llu message%s received\n");
1015 p(rip6s_isum
, "\t%llu checksum calcuration%s on inbound\n");
1016 p(rip6s_badsum
, "\t%llu message%s with bad checksum\n");
1017 p(rip6s_nosock
, "\t%llu message%s dropped due to no socket\n");
1018 p(rip6s_nosockmcast
,
1019 "\t%llu multicast message%s dropped due to no socket\n");
1021 "\t%llu message%s dropped due to full socket buffers\n");
1022 delivered
= rip6stat
.rip6s_ipackets
-
1023 rip6stat
.rip6s_badsum
-
1024 rip6stat
.rip6s_nosock
-
1025 rip6stat
.rip6s_nosockmcast
-
1026 rip6stat
.rip6s_fullsock
;
1027 if (delivered
|| sflag
<= 1)
1028 printf("\t%llu delivered\n", (unsigned long long)delivered
);
1029 p(rip6s_opackets
, "\t%llu datagram%s output\n");
1034 * Pretty print an Internet address (net address + port).
1035 * If the nflag was specified, use numbers instead of names.
1038 extern struct servent
* _serv_cache_getservbyport(int port
, char *proto
);
1040 #define GETSERVBYPORT6(port, proto, ret)\
1042 if (strcmp((proto), "tcp6") == 0)\
1043 (ret) = _serv_cache_getservbyport((int)(port), "tcp");\
1044 else if (strcmp((proto), "udp6") == 0)\
1045 (ret) = _serv_cache_getservbyport((int)(port), "udp");\
1047 (ret) = _serv_cache_getservbyport((int)(port), (proto));\
1050 #define GETSERVBYPORT6(port, proto, ret)\
1052 if (strcmp((proto), "tcp6") == 0)\
1053 (ret) = getservbyport((int)(port), "tcp");\
1054 else if (strcmp((proto), "udp6") == 0)\
1055 (ret) = getservbyport((int)(port), "udp");\
1057 (ret) = getservbyport((int)(port), (proto));\
1061 inet6print(struct in6_addr
*in6
, int port
, char *proto
, int numeric
)
1063 struct servent
*sp
= 0;
1067 sprintf(line
, "%.*s.", lflag
? 39 :
1068 (Aflag
&& !numeric
) ? 12 : 16, inet6name(in6
));
1069 cp
= index(line
, '\0');
1070 if (!numeric
&& port
)
1071 GETSERVBYPORT6(port
, proto
, sp
);
1072 if (sp
|| port
== 0)
1073 sprintf(cp
, "%.8s", sp
? sp
->s_name
: "*");
1075 sprintf(cp
, "%d", ntohs((u_short
)port
));
1076 width
= lflag
? 45 : Aflag
? 18 : 22;
1077 printf("%-*.*s ", width
, width
, line
);
1081 * Construct an Internet address representation.
1082 * If the nflag has been supplied, give
1083 * numeric value, otherwise try for symbolic name.
1087 inet6name(struct in6_addr
*in6p
)
1090 static char line
[50];
1092 static char domain
[MAXHOSTNAMELEN
];
1093 static int first
= 1;
1095 if (first
&& !nflag
) {
1097 if (gethostname(domain
, MAXHOSTNAMELEN
) == 0 &&
1098 (cp
= index(domain
, '.')))
1099 (void) strcpy(domain
, cp
+ 1);
1104 if (!nflag
&& !IN6_IS_ADDR_UNSPECIFIED(in6p
)) {
1105 hp
= gethostbyaddr((char *)in6p
, sizeof(*in6p
), AF_INET6
);
1107 if ((cp
= index(hp
->h_name
, '.')) &&
1108 !strcmp(cp
+ 1, domain
))
1113 if (IN6_IS_ADDR_UNSPECIFIED(in6p
))
1119 inet_ntop(AF_INET6
, (void *)in6p
, ntop_buf
,