1 /* $NetBSD: ndp.c,v 1.45 2015/08/03 09:51:40 ozaki-r Exp $ */
2 /* $KAME: ndp.c,v 1.121 2005/07/13 11:30:13 keiichi Exp $ */
5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Copyright (c) 1984, 1993
34 * The Regents of the University of California. All rights reserved.
36 * This code is derived from software contributed to Berkeley by
37 * Sun Microsystems, Inc.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * "@(#) Copyright (c) 1984, 1993\n\
67 * The Regents of the University of California. All rights reserved.\n";
69 * "@(#)arp.c 8.2 (Berkeley) 1/2/94";
73 * ndp - display, set, delete and flush neighbor cache
77 #include <sys/param.h>
79 #include <sys/ioctl.h>
80 #include <sys/socket.h>
81 #include <sys/sysctl.h>
85 #include <net/if_dl.h>
86 #include <net/if_types.h>
87 #include <net/route.h>
89 #include <netinet/in.h>
91 #include <netinet/icmp6.h>
92 #include <netinet6/in6_var.h>
93 #include <netinet6/nd6.h>
95 #include <arpa/inet.h>
108 #include "gmt2local.h"
109 #include "prog_ops.h"
114 static int32_t thiszone
; /* time difference with gmt */
115 static int my_s
= -1;
116 static unsigned int repeat
= 0;
119 static char host_buf
[NI_MAXHOST
]; /* getnameinfo() */
120 static char ifix_buf
[IFNAMSIZ
]; /* if_indextoname() */
122 static void getsocket(void);
123 static int set(int, char **);
124 static void get(char *);
125 static int delete(char *);
126 static void dump(struct in6_addr
*, int);
127 static struct in6_nbrinfo
*getnbrinfo(struct in6_addr
*, unsigned int, int);
128 static char *ether_str(struct sockaddr_dl
*);
129 static int ndp_ether_aton(char *, u_char
*);
130 __dead
static void usage(void);
131 static int rtmsg(int);
132 static void ifinfo(char *, int, char **);
133 static void rtrlist(void);
134 static void plist(void);
135 static void pfx_flush(void);
136 static void rtrlist(void);
137 static void rtr_flush(void);
138 static void harmonize_rtr(void);
139 #ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */
140 static void getdefif(void);
141 static void setdefif(char *);
143 static const char *sec2str(time_t);
144 static char *ether_str(struct sockaddr_dl
*);
145 static void ts_print(const struct timeval
*);
147 #ifdef ICMPV6CTL_ND6_DRLIST
148 static const char *rtpref_str
[] = {
157 static char *arg
= NULL
;
160 main(int argc
, char **argv
)
164 while ((ch
= getopt(argc
, argv
, "acd:f:Ii:nprstA:HPR")) != -1)
204 repeat
= atoi(optarg
);
213 if (prog_init
&& prog_init() == -1)
214 err(1, "init failed");
217 thiszone
= gmt2local(0L);
226 dump(0, mode
== 'c');
236 #ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */
240 } else if (argc
== 1) {
241 if (strcmp(*argv
, "delete") == 0 ||
242 if_nametoindex(*argv
))
245 errx(1, "invalid interface %s", *argv
);
247 getdefif(); /* always call it to print the result */
250 errx(1, "not supported yet");
261 ifinfo(arg
, argc
, argv
);
271 if (argc
< 2 || argc
> 4)
273 return(set(argc
, argv
) ? 1 : 0);
310 my_s
= prog_socket(PF_ROUTE
, SOCK_RAW
, 0);
317 static struct sockaddr_in6 so_mask
= {
318 .sin6_len
= sizeof(so_mask
),
319 .sin6_family
= AF_INET6
322 static struct sockaddr_in6 blank_sin
= {
323 .sin6_len
= sizeof(blank_sin
),
324 .sin6_family
= AF_INET6
326 static struct sockaddr_in6 sin_m
;
327 static struct sockaddr_dl blank_sdl
= {
328 .sdl_len
= sizeof(blank_sdl
),
329 .sdl_family
= AF_LINK
,
331 static struct sockaddr_dl sdl_m
;
332 static int expire_time
, flags
, found_entry
;
334 struct rt_msghdr m_rtm
;
339 * Set an individual neighbor cache entry
342 set(int argc
, char **argv
)
344 register struct sockaddr_in6
*mysin
= &sin_m
;
345 register struct sockaddr_dl
*sdl
;
346 register struct rt_msghdr
*rtm
= &(m_rtmsg
.m_rtm
);
347 struct addrinfo hints
, *res
;
350 char *host
= argv
[0], *eaddr
= argv
[1];
358 (void)memset(&hints
, 0, sizeof(hints
));
359 hints
.ai_family
= AF_INET6
;
360 gai_error
= getaddrinfo(host
, NULL
, &hints
, &res
);
362 warnx("%s: %s", host
, gai_strerror(gai_error
));
365 mysin
->sin6_addr
= ((struct sockaddr_in6
*)(void *)res
->ai_addr
)->sin6_addr
;
366 inet6_putscopeid(mysin
, INET6_IS_ADDR_LINKLOCAL
);
367 ea
= (u_char
*)LLADDR(&sdl_m
);
368 if (ndp_ether_aton(eaddr
, ea
) == 0)
370 flags
= expire_time
= 0;
372 if (strncmp(argv
[0], "temp", 4) == 0) {
375 (void)gettimeofday(&tim
, 0);
376 expire_time
= tim
.tv_sec
+ 20 * 60;
377 } else if (strncmp(argv
[0], "proxy", 5) == 0)
378 flags
|= RTF_ANNOUNCE
;
381 if (rtmsg(RTM_GET
) < 0) {
382 errx(1, "RTM_GET(%s) failed", host
);
385 mysin
= (struct sockaddr_in6
*)(void *)(rtm
+ 1);
386 sdl
= (struct sockaddr_dl
*)(void *)(RT_ROUNDUP(mysin
->sin6_len
) + (char *)(void *)mysin
);
387 if (IN6_ARE_ADDR_EQUAL(&mysin
->sin6_addr
, &sin_m
.sin6_addr
)) {
388 if (sdl
->sdl_family
== AF_LINK
&&
389 (rtm
->rtm_flags
& RTF_LLINFO
) &&
390 !(rtm
->rtm_flags
& RTF_GATEWAY
)) {
391 switch (sdl
->sdl_type
) {
392 case IFT_ETHER
: case IFT_FDDI
: case IFT_ISO88023
:
393 case IFT_ISO88024
: case IFT_ISO88025
:
398 * IPv4 arp command retries with sin_other = SIN_PROXY here.
400 (void)fprintf(stderr
, "set: cannot configure a new entry\n");
405 if (sdl
->sdl_family
!= AF_LINK
) {
406 warnx("cannot intuit interface index and type for %s", host
);
409 sdl_m
.sdl_type
= sdl
->sdl_type
;
410 sdl_m
.sdl_index
= sdl
->sdl_index
;
411 return (rtmsg(RTM_ADD
));
415 * Display an individual neighbor cache entry
420 struct sockaddr_in6
*mysin
= &sin_m
;
421 struct addrinfo hints
, *res
;
425 (void)memset(&hints
, 0, sizeof(hints
));
426 hints
.ai_family
= AF_INET6
;
427 gai_error
= getaddrinfo(host
, NULL
, &hints
, &res
);
429 warnx("%s: %s", host
, gai_strerror(gai_error
));
432 mysin
->sin6_addr
= ((struct sockaddr_in6
*)(void *)res
->ai_addr
)->sin6_addr
;
433 inet6_putscopeid(mysin
, INET6_IS_ADDR_LINKLOCAL
);
434 dump(&mysin
->sin6_addr
, 0);
435 if (found_entry
== 0) {
436 (void)getnameinfo((struct sockaddr
*)(void *)mysin
,
437 (socklen_t
)mysin
->sin6_len
,
438 host_buf
, sizeof(host_buf
), NULL
,0,
439 (nflag
? NI_NUMERICHOST
: 0));
440 errx(1, "%s (%s) -- no entry", host
, host_buf
);
445 * Delete a neighbor cache entry
450 struct sockaddr_in6
*mysin
= &sin_m
;
451 register struct rt_msghdr
*rtm
= &m_rtmsg
.m_rtm
;
452 struct sockaddr_dl
*sdl
;
453 struct addrinfo hints
, *res
;
459 bzero(&hints
, sizeof(hints
));
460 hints
.ai_family
= AF_INET6
;
461 gai_error
= getaddrinfo(host
, NULL
, &hints
, &res
);
463 warnx("%s: %s", host
, gai_strerror(gai_error
));
466 mysin
->sin6_addr
= ((struct sockaddr_in6
*)(void *)res
->ai_addr
)->sin6_addr
;
467 inet6_putscopeid(mysin
, INET6_IS_ADDR_LINKLOCAL
);
468 if (rtmsg(RTM_GET
) < 0)
469 errx(1, "RTM_GET(%s) failed", host
);
470 mysin
= (struct sockaddr_in6
*)(void *)(rtm
+ 1);
471 sdl
= (struct sockaddr_dl
*)(void *)(RT_ROUNDUP(mysin
->sin6_len
) +
472 (char *)(void *)mysin
);
473 if (IN6_ARE_ADDR_EQUAL(&mysin
->sin6_addr
, &sin_m
.sin6_addr
)) {
474 if (sdl
->sdl_family
== AF_LINK
&&
475 (rtm
->rtm_flags
& RTF_LLINFO
) &&
476 !(rtm
->rtm_flags
& RTF_GATEWAY
)) {
480 * IPv4 arp command retries with sin_other = SIN_PROXY here.
482 warnx("delete: cannot delete non-NDP entry");
487 if (sdl
->sdl_family
!= AF_LINK
) {
488 (void)printf("cannot locate %s\n", host
);
491 if (rtmsg(RTM_DELETE
) == 0) {
492 struct sockaddr_in6 s6
= *mysin
; /* XXX: for safety */
494 mysin
->sin6_scope_id
= 0;
495 inet6_putscopeid(mysin
, INET6_IS_ADDR_LINKLOCAL
);
496 (void)getnameinfo((struct sockaddr
*)(void *)&s6
,
497 (socklen_t
)s6
.sin6_len
, host_buf
,
498 sizeof(host_buf
), NULL
, 0,
499 (nflag
? NI_NUMERICHOST
: 0));
500 (void)printf("%s (%s) deleted\n", host
, host_buf
);
511 * Dump the entire neighbor cache
514 dump(struct in6_addr
*addr
, int cflag
)
518 char *lim
, *buf
, *next
;
519 struct rt_msghdr
*rtm
;
520 struct sockaddr_in6
*mysin
;
521 struct sockaddr_dl
*sdl
;
522 struct in6_nbrinfo
*nbi
;
531 if (!tflag
&& !cflag
)
532 (void)printf("%-*.*s %-*.*s %*.*s %-9.9s %1s %5s\n",
533 W_ADDR
, W_ADDR
, "Neighbor", W_LL
, W_LL
, "Linklayer Address",
534 W_IF
, W_IF
, "Netif", "Expire", "S", "Flags");
541 mib
[4] = NET_RT_FLAGS
;
543 if (prog_sysctl(mib
, 6, NULL
, &needed
, NULL
, 0) < 0)
544 err(1, "sysctl(PF_ROUTE estimate)");
546 if ((buf
= malloc(needed
)) == NULL
)
548 if (prog_sysctl(mib
, 6, buf
, &needed
, NULL
, 0) < 0)
549 err(1, "sysctl(PF_ROUTE, NET_RT_FLAGS)");
554 for (next
= buf
; next
&& next
< lim
; next
+= rtm
->rtm_msglen
) {
555 int isrouter
= 0, prbs
= 0;
557 rtm
= (struct rt_msghdr
*)(void *)next
;
558 mysin
= (struct sockaddr_in6
*)(void *)(rtm
+ 1);
559 sdl
= (struct sockaddr_dl
*)(void *)((char *)(void *)mysin
+ RT_ROUNDUP(mysin
->sin6_len
));
562 * Some OSes can produce a route that has the LINK flag but
563 * has a non-AF_LINK gateway (e.g. fe80::xx%lo0 on FreeBSD
564 * and BSD/OS, where xx is not the interface identifier on
565 * lo0). Such routes entry would annoy getnbrinfo() below,
567 * XXX: such routes should have the GATEWAY flag, not the
568 * LINK flag. However, there is rotten routing software
569 * that advertises all routes that have the GATEWAY flag.
570 * Thus, KAME kernel intentionally does not set the LINK flag.
571 * What is to be fixed is not ndp, but such routing software
572 * (and the kernel workaround)...
574 if (sdl
->sdl_family
!= AF_LINK
)
577 if (!(rtm
->rtm_flags
& RTF_HOST
))
581 if (!IN6_ARE_ADDR_EQUAL(addr
, &mysin
->sin6_addr
))
584 } else if (IN6_IS_ADDR_MULTICAST(&mysin
->sin6_addr
))
586 if (IN6_IS_ADDR_LINKLOCAL(&mysin
->sin6_addr
) ||
587 IN6_IS_ADDR_MC_LINKLOCAL(&mysin
->sin6_addr
)) {
588 uint16_t scopeid
= mysin
->sin6_scope_id
;
589 inet6_getscopeid(mysin
, INET6_IS_ADDR_LINKLOCAL
|
590 INET6_IS_ADDR_MC_LINKLOCAL
);
592 mysin
->sin6_scope_id
= sdl
->sdl_index
;
594 (void)getnameinfo((struct sockaddr
*)(void *)mysin
,
595 (socklen_t
)mysin
->sin6_len
,
596 host_buf
, sizeof(host_buf
), NULL
, 0,
597 (nflag
? NI_NUMERICHOST
: 0));
600 if (rtm
->rtm_flags
& RTF_WASCLONED
)
601 (void)delete(host_buf
);
602 #elif defined(RTF_CLONED)
603 if (rtm
->rtm_flags
& RTF_CLONED
)
604 (void)delete(host_buf
);
606 (void)delete(host_buf
);
610 (void)gettimeofday(&tim
, 0);
614 addrwidth
= strlen(host_buf
);
615 if (addrwidth
< W_ADDR
)
617 llwidth
= strlen(ether_str(sdl
));
618 if (W_ADDR
+ W_LL
- addrwidth
> llwidth
)
619 llwidth
= W_ADDR
+ W_LL
- addrwidth
;
620 ifname
= if_indextoname((unsigned int)sdl
->sdl_index
, ifix_buf
);
623 ifwidth
= strlen(ifname
);
624 if (W_ADDR
+ W_LL
+ W_IF
- addrwidth
- llwidth
> ifwidth
)
625 ifwidth
= W_ADDR
+ W_LL
+ W_IF
- addrwidth
- llwidth
;
627 (void)printf("%-*.*s %-*.*s %*.*s", addrwidth
, addrwidth
,
628 host_buf
, llwidth
, llwidth
, ether_str(sdl
), ifwidth
,
631 /* Print neighbor discovery specific informations */
632 nbi
= getnbrinfo(&mysin
->sin6_addr
,
633 (unsigned int)sdl
->sdl_index
, 1);
635 if (nbi
->expire
> tim
.tv_sec
) {
636 (void)printf(" %-9.9s",
637 sec2str(nbi
->expire
- tim
.tv_sec
));
638 } else if (nbi
->expire
== 0)
639 (void)printf(" %-9.9s", "permanent");
641 (void)printf(" %-9.9s", "expired");
643 switch (nbi
->state
) {
644 case ND6_LLINFO_NOSTATE
:
647 #ifdef ND6_LLINFO_WAITDELETE
648 case ND6_LLINFO_WAITDELETE
:
652 case ND6_LLINFO_INCOMPLETE
:
655 case ND6_LLINFO_REACHABLE
:
658 case ND6_LLINFO_STALE
:
661 case ND6_LLINFO_DELAY
:
664 case ND6_LLINFO_PROBE
:
672 isrouter
= nbi
->isrouter
;
675 warnx("failed to get neighbor information");
680 * other flags. R: router, P: proxy, W: ??
682 if ((rtm
->rtm_addrs
& RTA_NETMASK
) == 0) {
683 (void)snprintf(flgbuf
, sizeof(flgbuf
), "%s%s",
685 (rtm
->rtm_flags
& RTF_ANNOUNCE
) ? "p" : "");
687 mysin
= (struct sockaddr_in6
*)(void *)
688 (sdl
->sdl_len
+ (char *)(void *)sdl
);
689 #if 0 /* W and P are mystery even for us */
690 (void)snprintf(flgbuf
, sizeof(flgbuf
), "%s%s%s%s",
692 !IN6_IS_ADDR_UNSPECIFIED(&sin
->sin6_addr
) ? "P" : "",
693 (sin
->sin6_len
!= sizeof(struct sockaddr_in6
)) ? "W" : "",
694 (rtm
->rtm_flags
& RTF_ANNOUNCE
) ? "p" : "");
696 (void)snprintf(flgbuf
, sizeof(flgbuf
), "%s%s",
698 (rtm
->rtm_flags
& RTF_ANNOUNCE
) ? "p" : "");
701 (void)printf(" %s", flgbuf
);
704 (void)printf(" %d", prbs
);
713 (void)fflush(stdout
);
719 static struct in6_nbrinfo
*
720 getnbrinfo(struct in6_addr
*addr
, unsigned int ifindex
, int warning
)
722 static struct in6_nbrinfo nbi
;
725 if ((s
= prog_socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
728 (void)memset(&nbi
, 0, sizeof(nbi
));
729 (void)if_indextoname(ifindex
, nbi
.ifname
);
731 if (prog_ioctl(s
, SIOCGNBRINFO_IN6
, &nbi
) < 0) {
733 warn("ioctl(SIOCGNBRINFO_IN6)");
743 ether_str(struct sockaddr_dl
*sdl
)
745 static char hbuf
[NI_MAXHOST
];
748 if (getnameinfo((struct sockaddr
*)(void *)sdl
,
749 (socklen_t
)sdl
->sdl_len
,
750 hbuf
, sizeof(hbuf
), NULL
, 0, NI_NUMERICHOST
) != 0)
751 (void)snprintf(hbuf
, sizeof(hbuf
), "<invalid>");
753 (void)snprintf(hbuf
, sizeof(hbuf
), "(incomplete)");
759 ndp_ether_aton(char *a
, u_char
*n
)
763 i
= sscanf(a
, "%x:%x:%x:%x:%x:%x", &o
[0], &o
[1], &o
[2],
764 &o
[3], &o
[4], &o
[5]);
766 warnx("invalid Ethernet address '%s'", a
);
769 for (i
= 0; i
< 6; i
++)
777 const char *pn
= getprogname();
779 (void)fprintf(stderr
, "Usage: %s [-nt] hostname\n", pn
);
780 (void)fprintf(stderr
,
781 " %s [-nt] -a | -c | -p | -r | -H | -P | -R\n", pn
);
782 (void)fprintf(stderr
, " %s [-nt] -A wait\n", pn
);
783 (void)fprintf(stderr
, " %s [-nt] -d hostname\n", pn
);
784 (void)fprintf(stderr
, " %s [-nt] -f filename\n", pn
);
785 (void)fprintf(stderr
, " %s [-nt] -i interface [flags...]\n", pn
);
786 #ifdef SIOCSDEFIFACE_IN6
787 (void)fprintf(stderr
, " %s [-nt] -I [interface|delete]\n", pn
);
789 (void)fprintf(stderr
,
790 " %s [-nt] -s nodename etheraddr [temp] [proxy]\n", pn
);
798 register struct rt_msghdr
*rtm
= &m_rtmsg
.m_rtm
;
799 register char *cp
= m_rtmsg
.m_space
;
803 if (cmd
== RTM_DELETE
)
805 (void)memset(&m_rtmsg
, 0, sizeof(m_rtmsg
));
806 rtm
->rtm_flags
= flags
;
807 rtm
->rtm_version
= RTM_VERSION
;
811 errx(1, "internal wrong cmd");
814 rtm
->rtm_addrs
|= RTA_GATEWAY
;
816 rtm
->rtm_rmx
.rmx_expire
= expire_time
;
817 rtm
->rtm_inits
= RTV_EXPIRE
;
819 rtm
->rtm_flags
|= (RTF_HOST
| RTF_STATIC
);
820 #ifdef notdef /* we don't support ipv6addr/128 type proxying. */
821 if (rtm
->rtm_flags
& RTF_ANNOUNCE
) {
822 rtm
->rtm_flags
&= ~RTF_HOST
;
823 rtm
->rtm_addrs
|= RTA_NETMASK
;
828 rtm
->rtm_addrs
|= RTA_DST
;
830 #define NEXTADDR(w, s) \
831 if (rtm->rtm_addrs & (w)) { \
832 (void)memcpy(cp, &s, sizeof(s)); \
833 RT_ADVANCE(cp, (struct sockaddr *)(void *)&s); \
836 NEXTADDR(RTA_DST
, sin_m
);
837 NEXTADDR(RTA_GATEWAY
, sdl_m
);
838 #ifdef notdef /* we don't support ipv6addr/128 type proxying. */
839 (void)memset(&so_mask
.sin6_addr
, 0xff, sizeof(so_mask
.sin6_addr
));
840 NEXTADDR(RTA_NETMASK
, so_mask
);
843 rtm
->rtm_msglen
= cp
- (char *)(void *)&m_rtmsg
;
846 rtm
->rtm_seq
= ++seq
;
850 * Borrow from the future by setting the "this is a link-local request"
851 * flag on all routing socket requests. IMPORTANT: this change may be
852 * dropped with the resync to NetBSD 8 as it will do the same thing,
853 * although slightly differently (and hence may not create a conflict).
855 rtm
->rtm_flags
|= RTF_LLDATA
;
857 if (prog_write(my_s
, &m_rtmsg
, (size_t)l
) == -1) {
858 if (errno
!= ESRCH
|| cmd
!= RTM_DELETE
)
859 err(1, "writing to routing socket");
862 l
= prog_read(my_s
, &m_rtmsg
, sizeof(m_rtmsg
));
863 } while (l
> 0 && (rtm
->rtm_seq
!= seq
|| rtm
->rtm_pid
!= pid
));
865 warn("read from routing socket");
870 ifinfo(char *ifname
, int argc
, char **argv
)
872 struct in6_ndireq nd
;
875 #ifdef IPV6CTL_USETEMPADDR
879 if ((s
= prog_socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
881 (void)memset(&nd
, 0, sizeof(nd
));
882 (void)strlcpy(nd
.ifname
, ifname
, sizeof(nd
.ifname
));
883 if (prog_ioctl(s
, SIOCGIFINFO_IN6
, &nd
) < 0)
884 err(1, "ioctl(SIOCGIFINFO_IN6)");
887 for (i
= 0; i
< argc
; i
++) {
896 #define SETFLAG(s, f) \
898 if (strcmp(cp, (s)) == 0) {\
904 } while (/*CONSTCOND*/0)
906 * XXX: this macro is not 100% correct, in that it matches "nud" against
907 * "nudbogus". But we just let it go since this is minor.
909 #define SETVALUE(f, v) \
912 unsigned long newval; \
913 v = 0; /* unspecified */ \
914 if (strncmp(cp, f, strlen(f)) == 0) { \
915 valptr = strchr(cp, '='); \
916 if (valptr == NULL) \
917 err(1, "syntax error in %s field", (f)); \
919 newval = strtoul(++valptr, NULL, 0); \
921 err(1, "syntax error in %s's value", (f)); \
924 } while (/*CONSTCOND*/0)
926 #ifdef ND6_IFF_IFDISABLED
927 SETFLAG("disabled", ND6_IFF_IFDISABLED
);
929 SETFLAG("nud", ND6_IFF_PERFORMNUD
);
930 #ifdef ND6_IFF_ACCEPT_RTADV
931 SETFLAG("accept_rtadv", ND6_IFF_ACCEPT_RTADV
);
933 #ifdef ND6_IFF_OVERRIDE_RTADV
934 SETFLAG("override_rtadv", ND6_IFF_OVERRIDE_RTADV
);
936 #ifdef ND6_IFF_AUTO_LINKLOCAL
937 SETFLAG("auto_linklocal", ND6_IFF_AUTO_LINKLOCAL
);
939 #ifdef ND6_IFF_PREFER_SOURCE
940 SETFLAG("prefer_source", ND6_IFF_PREFER_SOURCE
);
942 #ifdef ND6_IFF_DONT_SET_IFROUTE
943 SETFLAG("dont_set_ifroute", ND6_IFF_DONT_SET_IFROUTE
);
945 SETVALUE("basereachable", ND
.basereachable
);
946 SETVALUE("retrans", ND
.retrans
);
947 SETVALUE("curhlim", ND
.chlim
);
950 #ifdef SIOCSIFINFO_IN6
951 if (prog_ioctl(s
, SIOCSIFINFO_IN6
, &nd
) < 0)
952 err(1, "ioctl(SIOCSIFINFO_IN6)");
954 if (prog_ioctl(s
, SIOCSIFINFO_FLAGS
, &nd
) < 0)
955 err(1, "ioctl(SIOCSIFINFO_FLAGS)");
962 errx(1, "%s: not initialized yet", ifname
);
964 if (prog_ioctl(s
, SIOCGIFINFO_IN6
, &nd
) < 0)
965 err(1, "ioctl(SIOCGIFINFO_IN6)");
966 (void)printf("linkmtu=%d", ND
.linkmtu
);
967 (void)printf(", maxmtu=%d", ND
.maxmtu
);
968 (void)printf(", curhlim=%d", ND
.chlim
);
969 (void)printf(", basereachable=%ds%dms",
970 ND
.basereachable
/ 1000, ND
.basereachable
% 1000);
971 (void)printf(", reachable=%ds", ND
.reachable
);
972 (void)printf(", retrans=%ds%dms", ND
.retrans
/ 1000, ND
.retrans
% 1000);
973 #ifdef IPV6CTL_USETEMPADDR
974 (void)memset(nullbuf
, 0, sizeof(nullbuf
));
975 if (memcmp(nullbuf
, ND
.randomid
, sizeof(nullbuf
)) != 0) {
979 for (i
= 0; i
< 3; i
++) {
982 (void)printf("\nRandom seed(0): ");
983 rbuf
= ND
.randomseed0
;
986 (void)printf("\nRandom seed(1): ");
987 rbuf
= ND
.randomseed1
;
990 (void)printf("\nRandom ID: ");
994 errx(1, "impossible case for tempaddr display");
996 for (j
= 0; j
< 8; j
++)
997 (void)printf("%02x", rbuf
[j
]);
1002 (void)printf("\nFlags: ");
1003 if ((ND
.flags
& ND6_IFF_PERFORMNUD
))
1004 (void)printf("nud ");
1005 #ifdef ND6_IFF_IFDISABLED
1006 if ((ND
.flags
& ND6_IFF_IFDISABLED
))
1007 (void)printf("disabled ");
1009 #ifdef ND6_IFF_ACCEPT_RTADV
1010 if ((ND
.flags
& ND6_IFF_ACCEPT_RTADV
))
1011 (void)printf("accept_rtadv ");
1013 #ifdef ND6_IFF_OVERRIDE_RTADV
1014 if ((ND
.flags
& ND6_IFF_OVERRIDE_RTADV
))
1015 (void)printf("override_rtadv ");
1017 #ifdef ND6_IFF_AUTO_LINKLOCAL
1018 if ((ND
.flags
& ND6_IFF_AUTO_LINKLOCAL
))
1019 (void)printf("auto_linklocal ");
1021 #ifdef ND6_IFF_PREFER_SOURCE
1022 if ((ND
.flags
& ND6_IFF_PREFER_SOURCE
))
1023 (void)printf("prefer_source ");
1026 (void)putc('\n', stdout
);
1029 (void)prog_close(s
);
1032 #ifndef ND_RA_FLAG_RTPREF_MASK /* XXX: just for compilation on *BSD release */
1033 #define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
1039 #ifdef ICMPV6CTL_ND6_DRLIST
1040 int mib
[] = { CTL_NET
, PF_INET6
, IPPROTO_ICMPV6
, ICMPV6CTL_ND6_DRLIST
};
1042 struct in6_defrouter
*p
, *ep
;
1046 if (prog_sysctl(mib
, sizeof(mib
) / sizeof(mib
[0]), NULL
, &l
, NULL
, 0) < 0) {
1047 err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
1057 if (prog_sysctl(mib
, sizeof(mib
) / sizeof(mib
[0]), buf
, &l
, NULL
, 0) < 0) {
1058 err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
1062 ep
= (struct in6_defrouter
*)(void *)(buf
+ l
);
1063 for (p
= (struct in6_defrouter
*)(void *)buf
; p
< ep
; p
++) {
1066 if (getnameinfo((struct sockaddr
*)(void *)&p
->rtaddr
,
1067 (socklen_t
)p
->rtaddr
.sin6_len
, host_buf
, sizeof(host_buf
),
1068 NULL
, 0, (nflag
? NI_NUMERICHOST
: 0)) != 0)
1069 (void)strlcpy(host_buf
, "?", sizeof(host_buf
));
1071 (void)printf("%s if=%s", host_buf
,
1072 if_indextoname((unsigned int)p
->if_index
, ifix_buf
));
1073 (void)printf(", flags=%s%s",
1074 p
->flags
& ND_RA_FLAG_MANAGED
? "M" : "",
1075 p
->flags
& ND_RA_FLAG_OTHER
? "O" : "");
1076 rtpref
= ((uint32_t)(p
->flags
& ND_RA_FLAG_RTPREF_MASK
) >> 3) & 0xff;
1077 (void)printf(", pref=%s", rtpref_str
[rtpref
]);
1079 (void)gettimeofday(&tim
, 0);
1081 (void)printf(", expire=Never\n");
1083 (void)printf(", expire=%s\n",
1084 sec2str((time_t)(p
->expire
- tim
.tv_sec
)));
1088 struct in6_drlist dr
;
1090 struct timeval time
;
1092 if ((s
= prog_socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0) {
1096 (void)memset(&dr
, 0, sizeof(dr
));
1097 (void)strlcpy(dr
.ifname
, "lo0", sizeof(dr
.ifname
)); /* dummy */
1098 if (prog_ioctl(s
, SIOCGDRLST_IN6
, (caddr_t
)&dr
) < 0) {
1099 err(1, "ioctl(SIOCGDRLST_IN6)");
1102 #define DR dr.defrouter[i]
1103 for (i
= 0 ; DR
.if_index
&& i
< DRLSTSIZ
; i
++) {
1104 struct sockaddr_in6 sin6
;
1106 (void)memset(&sin6
, 0, sizeof(sin6
));
1107 sin6
.sin6_family
= AF_INET6
;
1108 sin6
.sin6_len
= sizeof(sin6
);
1109 sin6
.sin6_addr
= DR
.rtaddr
;
1110 (void)getnameinfo((struct sockaddr
*)&sin6
, sin6
.sin6_len
,
1111 host_buf
, sizeof(host_buf
), NULL
, 0,
1112 (nflag
? NI_NUMERICHOST
: 0));
1114 (void)printf("%s if=%s", host_buf
,
1115 if_indextoname(DR
.if_index
, ifix_buf
));
1116 (void)printf(", flags=%s%s",
1117 DR
.flags
& ND_RA_FLAG_MANAGED
? "M" : "",
1118 DR
.flags
& ND_RA_FLAG_OTHER
? "O" : "");
1119 gettimeofday(&time
, 0);
1121 (void)printf(", expire=Never\n");
1123 (void)printf(", expire=%s\n",
1124 sec2str(DR
.expire
- time
.tv_sec
));
1127 (void)prog_close(s
);
1134 #ifdef ICMPV6CTL_ND6_PRLIST
1135 int mib
[] = { CTL_NET
, PF_INET6
, IPPROTO_ICMPV6
, ICMPV6CTL_ND6_PRLIST
};
1137 struct in6_prefix pfx
;
1140 const int niflags
= NI_NUMERICHOST
;
1141 int ninflags
= nflag
? NI_NUMERICHOST
: 0;
1142 char namebuf
[NI_MAXHOST
];
1144 if (prog_sysctl(mib
, sizeof(mib
) / sizeof(mib
[0]), NULL
, &l
, NULL
, 0) < 0) {
1145 err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
1153 if (prog_sysctl(mib
, sizeof(mib
) / sizeof(mib
[0]), buf
, &l
, NULL
, 0) < 0) {
1154 err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
1159 for (p
= buf
; p
< ep
; ) {
1160 memcpy(&pfx
, p
, sizeof(pfx
));
1163 if (getnameinfo((struct sockaddr
*)&pfx
.prefix
,
1164 (socklen_t
)pfx
.prefix
.sin6_len
, namebuf
, sizeof(namebuf
),
1165 NULL
, 0, niflags
) != 0)
1166 (void)strlcpy(namebuf
, "?", sizeof(namebuf
));
1167 (void)printf("%s/%d if=%s\n", namebuf
, pfx
.prefixlen
,
1168 if_indextoname((unsigned int)pfx
.if_index
, ifix_buf
));
1170 (void)gettimeofday(&tim
, 0);
1172 * meaning of fields, especially flags, is very different
1173 * by origin. notify the difference to the users.
1175 (void)printf("flags=%s%s%s%s%s",
1176 pfx
.raflags
.onlink
? "L" : "",
1177 pfx
.raflags
.autonomous
? "A" : "",
1178 (pfx
.flags
& NDPRF_ONLINK
) != 0 ? "O" : "",
1179 (pfx
.flags
& NDPRF_DETACHED
) != 0 ? "D" : "",
1181 (pfx
.flags
& NDPRF_HOME
) != 0 ? "H" : ""
1186 if (pfx
.vltime
== ND6_INFINITE_LIFETIME
)
1187 (void)printf(" vltime=infinity");
1189 (void)printf(" vltime=%lu", (unsigned long)pfx
.vltime
);
1190 if (pfx
.pltime
== ND6_INFINITE_LIFETIME
)
1191 (void)printf(", pltime=infinity");
1193 (void)printf(", pltime=%lu", (unsigned long)pfx
.pltime
);
1194 if (pfx
.expire
== 0)
1195 (void)printf(", expire=Never");
1196 else if (pfx
.expire
>= tim
.tv_sec
)
1197 (void)printf(", expire=%s",
1198 sec2str(pfx
.expire
- tim
.tv_sec
));
1200 (void)printf(", expired");
1201 (void)printf(", ref=%d", pfx
.refcnt
);
1204 * "advertising router" list is meaningful only if the prefix
1205 * information is from RA.
1209 struct sockaddr_in6 sin6
;
1211 (void)printf(" advertised by\n");
1212 for (j
= 0; j
< pfx
.advrtrs
&& p
<= ep
; j
++) {
1213 struct in6_nbrinfo
*nbi
;
1215 memcpy(&sin6
, p
, sizeof(sin6
));
1218 if (getnameinfo((struct sockaddr
*)&sin6
,
1219 (socklen_t
)sin6
.sin6_len
, namebuf
,
1220 sizeof(namebuf
), NULL
, 0, ninflags
) != 0)
1221 (void)strlcpy(namebuf
, "?", sizeof(namebuf
));
1222 (void)printf(" %s", namebuf
);
1224 nbi
= getnbrinfo(&sin6
.sin6_addr
,
1225 (unsigned int)pfx
.if_index
, 0);
1227 switch (nbi
->state
) {
1228 case ND6_LLINFO_REACHABLE
:
1229 case ND6_LLINFO_STALE
:
1230 case ND6_LLINFO_DELAY
:
1231 case ND6_LLINFO_PROBE
:
1232 (void)printf(" (reachable)\n");
1235 (void)printf(" (unreachable)\n");
1238 (void)printf(" (no neighbor state)\n");
1241 (void)printf(" No advertising router\n");
1245 struct in6_prlist pr
;
1247 struct timeval time
;
1249 (void)gettimeofday(&time
, 0);
1251 if ((s
= prog_socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0) {
1255 (void)memset(&pr
, 0, sizeof(pr
));
1256 (void)strlcpy(pr
.ifname
, "lo0", sizeof(pr
.ifname
)); /* dummy */
1257 if (prog_ioctl(s
, SIOCGPRLST_IN6
, (caddr_t
)&pr
) < 0) {
1258 err(1, "ioctl(SIOCGPRLST_IN6)");
1261 #define PR pr.prefix[i]
1262 for (i
= 0; PR
.if_index
&& i
< PRLSTSIZ
; i
++) {
1263 struct sockaddr_in6 p6
;
1264 char namebuf
[NI_MAXHOST
];
1270 (void)memset(&p6
, 0, sizeof(p6
));
1271 p6
.sin6_family
= AF_INET6
;
1272 p6
.sin6_len
= sizeof(p6
);
1273 p6
.sin6_addr
= PR
.prefix
;
1276 niflags
= NI_NUMERICHOST
;
1277 if (getnameinfo((struct sockaddr
*)&p6
,
1278 sizeof(p6
), namebuf
, sizeof(namebuf
),
1279 NULL
, 0, niflags
)) {
1280 warnx("getnameinfo failed");
1283 (void)printf("%s/%d if=%s\n", namebuf
, PR
.prefixlen
,
1284 if_indextoname(PR
.if_index
, ifix_buf
));
1286 (void)gettimeofday(&time
, 0);
1288 * meaning of fields, especially flags, is very different
1289 * by origin. notify the difference to the users.
1293 PR
.origin
== PR_ORIG_RA
? "" : "advertise: ");
1296 (void)printf("flags=%s%s%s%s%s",
1297 PR
.raflags
.onlink
? "L" : "",
1298 PR
.raflags
.autonomous
? "A" : "",
1299 (PR
.flags
& NDPRF_ONLINK
) != 0 ? "O" : "",
1300 (PR
.flags
& NDPRF_DETACHED
) != 0 ? "D" : "",
1302 (PR
.flags
& NDPRF_HOME
) != 0 ? "H" : ""
1308 (void)printf("flags=%s%s",
1309 PR
.raflags
.onlink
? "L" : "",
1310 PR
.raflags
.autonomous
? "A" : "");
1312 if (PR
.vltime
== ND6_INFINITE_LIFETIME
)
1313 (void)printf(" vltime=infinity");
1315 (void)printf(" vltime=%lu", PR
.vltime
);
1316 if (PR
.pltime
== ND6_INFINITE_LIFETIME
)
1317 (void)printf(", pltime=infinity");
1319 (void)printf(", pltime=%lu", PR
.pltime
);
1321 (void)printf(", expire=Never");
1322 else if (PR
.expire
>= time
.tv_sec
)
1323 (void)printf(", expire=%s",
1324 sec2str(PR
.expire
- time
.tv_sec
));
1326 (void)printf(", expired");
1328 (void)printf(", ref=%d", PR
.refcnt
);
1331 switch (PR
.origin
) {
1333 (void)printf(", origin=RA");
1336 (void)printf(", origin=RR");
1338 case PR_ORIG_STATIC
:
1339 (void)printf(", origin=static");
1341 case PR_ORIG_KERNEL
:
1342 (void)printf(", origin=kernel");
1345 (void)printf(", origin=?");
1351 * "advertising router" list is meaningful only if the prefix
1352 * information is from RA.
1354 if (0 && /* prefix origin is almost obsolted */
1355 PR
.origin
!= PR_ORIG_RA
)
1357 else if (PR
.advrtrs
) {
1359 (void)printf(" advertised by\n");
1360 for (j
= 0; j
< PR
.advrtrs
; j
++) {
1361 struct sockaddr_in6 sin6
;
1362 struct in6_nbrinfo
*nbi
;
1364 bzero(&sin6
, sizeof(sin6
));
1365 sin6
.sin6_family
= AF_INET6
;
1366 sin6
.sin6_len
= sizeof(sin6
);
1367 sin6
.sin6_addr
= PR
.advrtr
[j
];
1368 sin6
.sin6_scope_id
= PR
.if_index
; /* XXX */
1369 (void)getnameinfo((struct sockaddr
*)&sin6
,
1370 sin6
.sin6_len
, host_buf
,
1371 sizeof(host_buf
), NULL
, 0,
1372 (nflag
? NI_NUMERICHOST
: 0));
1373 (void)printf(" %s", host_buf
);
1375 nbi
= getnbrinfo(&sin6
.sin6_addr
,
1378 switch (nbi
->state
) {
1379 case ND6_LLINFO_REACHABLE
:
1380 case ND6_LLINFO_STALE
:
1381 case ND6_LLINFO_DELAY
:
1382 case ND6_LLINFO_PROBE
:
1383 (void)printf(" (reachable)\n");
1386 (void)printf(" (unreachable)\n");
1389 (void)printf(" (no neighbor state)\n");
1391 if (PR
.advrtrs
> DRLSTSIZ
)
1392 (void)printf(" and %d routers\n",
1393 PR
.advrtrs
- DRLSTSIZ
);
1395 (void)printf(" No advertising router\n");
1398 (void)prog_close(s
);
1405 char dummyif
[IFNAMSIZ
+8];
1408 if ((s
= prog_socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
1410 (void)strlcpy(dummyif
, "lo0", sizeof(dummyif
)); /* dummy */
1411 if (prog_ioctl(s
, SIOCSPFXFLUSH_IN6
, (caddr_t
)&dummyif
) < 0)
1412 err(1, "ioctl(SIOCSPFXFLUSH_IN6)");
1413 (void)prog_close(s
);
1419 char dummyif
[IFNAMSIZ
+8];
1422 if ((s
= prog_socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
1424 (void)strlcpy(dummyif
, "lo0", sizeof(dummyif
)); /* dummy */
1425 if (prog_ioctl(s
, SIOCSRTRFLUSH_IN6
, (caddr_t
)&dummyif
) < 0)
1426 err(1, "ioctl(SIOCSRTRFLUSH_IN6)");
1428 (void)prog_close(s
);
1434 char dummyif
[IFNAMSIZ
+8];
1437 if ((s
= prog_socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
1439 (void)strlcpy(dummyif
, "lo0", sizeof(dummyif
)); /* dummy */
1440 if (prog_ioctl(s
, SIOCSNDFLUSH_IN6
, (caddr_t
)&dummyif
) < 0)
1441 err(1, "ioctl(SIOCSNDFLUSH_IN6)");
1443 (void)prog_close(s
);
1446 #ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */
1448 setdefif(char *ifname
)
1450 struct in6_ndifreq ndifreq
;
1451 unsigned int ifindex
;
1454 if (strcasecmp(ifname
, "delete") == 0)
1457 if ((ifindex
= if_nametoindex(ifname
)) == 0)
1458 err(1, "failed to resolve i/f index for %s", ifname
);
1461 if ((s
= prog_socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
1464 (void)strlcpy(ndifreq
.ifname
, "lo0", sizeof(ndifreq
.ifname
)); /* dummy */
1465 ndifreq
.ifindex
= ifindex
;
1467 if (prog_ioctl(s
, SIOCSDEFIFACE_IN6
, &ndifreq
) < 0)
1468 err(1, "ioctl(SIOCSDEFIFACE_IN6)");
1470 (void)prog_close(s
);
1476 struct in6_ndifreq ndifreq
;
1477 char ifname
[IFNAMSIZ
+8];
1480 if ((s
= prog_socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
1483 (void)memset(&ndifreq
, 0, sizeof(ndifreq
));
1484 (void)strlcpy(ndifreq
.ifname
, "lo0", sizeof(ndifreq
.ifname
)); /* dummy */
1486 if (prog_ioctl(s
, SIOCGDEFIFACE_IN6
, &ndifreq
) < 0)
1487 err(1, "ioctl(SIOCGDEFIFACE_IN6)");
1489 if (ndifreq
.ifindex
== 0)
1490 (void)printf("No default interface.\n");
1492 if ((if_indextoname((unsigned int)ndifreq
.ifindex
, ifname
)) == NULL
)
1493 err(1, "failed to resolve ifname for index %lu",
1495 (void)printf("ND default interface = %s\n", ifname
);
1498 (void)prog_close(s
);
1503 sec2str(time_t total
)
1505 static char result
[256];
1506 int days
, hours
, mins
, secs
;
1509 char *ep
= &result
[sizeof(result
)];
1512 days
= total
/ 3600 / 24;
1513 hours
= (total
/ 3600) % 24;
1514 mins
= (total
/ 60) % 60;
1519 n
= snprintf(p
, (size_t)(ep
- p
), "%dd", days
);
1520 if (n
< 0 || n
>= ep
- p
)
1524 if (!first
|| hours
) {
1526 n
= snprintf(p
, (size_t)(ep
- p
), "%dh", hours
);
1527 if (n
< 0 || n
>= ep
- p
)
1531 if (!first
|| mins
) {
1533 n
= snprintf(p
, (size_t)(ep
- p
), "%dm", mins
);
1534 if (n
< 0 || n
>= ep
- p
)
1538 (void)snprintf(p
, (size_t)(ep
- p
), "%ds", secs
);
1544 * Print the timestamp
1545 * from tcpdump/util.c
1548 ts_print(const struct timeval
*tvp
)
1553 s
= (tvp
->tv_sec
+ thiszone
) % 86400;
1554 (void)printf("%02d:%02d:%02d.%06u ",
1555 s
/ 3600, (s
% 3600) / 60, s
% 60, (u_int32_t
)tvp
->tv_usec
);