1 /* $NetBSD: ndp.c,v 1.37 2007/01/16 17:32:04 hubertf 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>
107 #include "gmt2local.h"
109 /* packing rule for routing socket */
111 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
112 #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
117 static int32_t thiszone
; /* time difference with gmt */
118 static int my_s
= -1;
119 static unsigned int repeat
= 0;
122 static char host_buf
[NI_MAXHOST
]; /* getnameinfo() */
123 static char ifix_buf
[IFNAMSIZ
]; /* if_indextoname() */
125 static void getsocket(void);
126 static int set(int, char **);
127 static void get(char *);
128 static int delete(char *);
129 static void dump(struct in6_addr
*, int);
130 static struct in6_nbrinfo
*getnbrinfo(struct in6_addr
*, unsigned int, int);
131 static char *ether_str(struct sockaddr_dl
*);
132 static int ndp_ether_aton(char *, u_char
*);
133 static void usage(void);
134 static int rtmsg(int);
135 static void ifinfo(char *, int, char **);
136 static void rtrlist(void);
137 static void plist(void);
138 static void pfx_flush(void);
139 static void rtrlist(void);
140 static void rtr_flush(void);
141 static void harmonize_rtr(void);
142 #ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */
143 static void getdefif(void);
144 static void setdefif(char *);
146 static const char *sec2str(time_t);
147 static char *ether_str(struct sockaddr_dl
*);
148 static void ts_print(const struct timeval
*);
150 #ifdef ICMPV6CTL_ND6_DRLIST
151 static const char *rtpref_str
[] = {
160 static char *arg
= NULL
;
163 main(int argc
, char **argv
)
168 thiszone
= gmt2local(0L);
169 while ((ch
= getopt(argc
, argv
, "acd:f:Ii:nprstA:HPR")) != -1)
209 repeat
= atoi(optarg
);
225 dump(0, mode
== 'c');
235 #ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */
239 } else if (argc
== 1) {
240 if (strcmp(*argv
, "delete") == 0 ||
241 if_nametoindex(*argv
))
244 errx(1, "invalid interface %s", *argv
);
246 getdefif(); /* always call it to print the result */
249 errx(1, "not supported yet");
260 ifinfo(arg
, argc
, argv
);
270 if (argc
< 2 || argc
> 4)
272 return(set(argc
, argv
) ? 1 : 0);
309 my_s
= socket(PF_ROUTE
, SOCK_RAW
, 0);
316 static struct sockaddr_in6 so_mask
= {
317 .sin6_len
= sizeof(so_mask
),
318 .sin6_family
= AF_INET6
321 static struct sockaddr_in6 blank_sin
= {
322 .sin6_len
= sizeof(blank_sin
),
323 .sin6_family
= AF_INET6
325 static struct sockaddr_in6 sin_m
;
326 static struct sockaddr_dl blank_sdl
= {
327 .sdl_len
= sizeof(blank_sdl
),
328 .sdl_family
= AF_LINK
,
330 static struct sockaddr_dl sdl_m
;
331 static int expire_time
, flags
, found_entry
;
333 struct rt_msghdr m_rtm
;
338 * Set an individual neighbor cache entry
341 set(int argc
, char **argv
)
343 register struct sockaddr_in6
*mysin
= &sin_m
;
344 register struct sockaddr_dl
*sdl
;
345 register struct rt_msghdr
*rtm
= &(m_rtmsg
.m_rtm
);
346 struct addrinfo hints
, *res
;
349 char *host
= argv
[0], *eaddr
= argv
[1];
357 (void)memset(&hints
, 0, sizeof(hints
));
358 hints
.ai_family
= AF_INET6
;
359 gai_error
= getaddrinfo(host
, NULL
, &hints
, &res
);
361 warnx("%s: %s\n", host
, gai_strerror(gai_error
));
364 mysin
->sin6_addr
= ((struct sockaddr_in6
*)(void *)res
->ai_addr
)->sin6_addr
;
366 if (IN6_IS_ADDR_LINKLOCAL(&mysin
->sin6_addr
)) {
367 *(u_int16_t
*)(void *)&mysin
->sin6_addr
.s6_addr
[2] =
368 htons(((struct sockaddr_in6
*)(void *)res
->ai_addr
)->sin6_scope_id
);
371 ea
= (u_char
*)LLADDR(&sdl_m
);
372 if (ndp_ether_aton(eaddr
, ea
) == 0)
374 flags
= expire_time
= 0;
376 if (strncmp(argv
[0], "temp", 4) == 0) {
379 (void)gettimeofday(&tim
, 0);
380 expire_time
= tim
.tv_sec
+ 20 * 60;
381 } else if (strncmp(argv
[0], "proxy", 5) == 0)
382 flags
|= RTF_ANNOUNCE
;
385 if (rtmsg(RTM_GET
) < 0) {
386 errx(1, "RTM_GET(%s) failed", host
);
389 mysin
= (struct sockaddr_in6
*)(void *)(rtm
+ 1);
390 sdl
= (struct sockaddr_dl
*)(void *)(ROUNDUP(mysin
->sin6_len
) + (char *)(void *)mysin
);
391 if (IN6_ARE_ADDR_EQUAL(&mysin
->sin6_addr
, &sin_m
.sin6_addr
)) {
392 if (sdl
->sdl_family
== AF_LINK
&&
393 (rtm
->rtm_flags
& RTF_LLINFO
) &&
394 !(rtm
->rtm_flags
& RTF_GATEWAY
)) {
395 switch (sdl
->sdl_type
) {
396 case IFT_ETHER
: case IFT_FDDI
: case IFT_ISO88023
:
397 case IFT_ISO88024
: case IFT_ISO88025
:
402 * IPv4 arp command retries with sin_other = SIN_PROXY here.
404 (void)fprintf(stderr
, "set: cannot configure a new entry\n");
409 if (sdl
->sdl_family
!= AF_LINK
) {
410 warnx("cannot intuit interface index and type for %s", host
);
413 sdl_m
.sdl_type
= sdl
->sdl_type
;
414 sdl_m
.sdl_index
= sdl
->sdl_index
;
415 return (rtmsg(RTM_ADD
));
419 * Display an individual neighbor cache entry
424 struct sockaddr_in6
*mysin
= &sin_m
;
425 struct addrinfo hints
, *res
;
429 (void)memset(&hints
, 0, sizeof(hints
));
430 hints
.ai_family
= AF_INET6
;
431 gai_error
= getaddrinfo(host
, NULL
, &hints
, &res
);
433 warnx("%s: %s\n", host
, gai_strerror(gai_error
));
436 mysin
->sin6_addr
= ((struct sockaddr_in6
*)(void *)res
->ai_addr
)->sin6_addr
;
438 if (IN6_IS_ADDR_LINKLOCAL(&mysin
->sin6_addr
)) {
439 *(u_int16_t
*)(void *)&mysin
->sin6_addr
.s6_addr
[2] =
440 htons(((struct sockaddr_in6
*)(void *)res
->ai_addr
)->sin6_scope_id
);
443 dump(&mysin
->sin6_addr
, 0);
444 if (found_entry
== 0) {
445 (void)getnameinfo((struct sockaddr
*)(void *)mysin
,
446 (socklen_t
)mysin
->sin6_len
,
447 host_buf
, sizeof(host_buf
), NULL
,0,
448 (nflag
? NI_NUMERICHOST
: 0));
449 errx(1, "%s (%s) -- no entry", host
, host_buf
);
454 * Delete a neighbor cache entry
459 struct sockaddr_in6
*mysin
= &sin_m
;
460 register struct rt_msghdr
*rtm
= &m_rtmsg
.m_rtm
;
461 struct sockaddr_dl
*sdl
;
462 struct addrinfo hints
, *res
;
468 bzero(&hints
, sizeof(hints
));
469 hints
.ai_family
= AF_INET6
;
470 gai_error
= getaddrinfo(host
, NULL
, &hints
, &res
);
472 warnx("%s: %s\n", host
, gai_strerror(gai_error
));
475 mysin
->sin6_addr
= ((struct sockaddr_in6
*)(void *)res
->ai_addr
)->sin6_addr
;
477 if (IN6_IS_ADDR_LINKLOCAL(&mysin
->sin6_addr
)) {
478 *(u_int16_t
*)(void *)&mysin
->sin6_addr
.s6_addr
[2] =
479 htons(((struct sockaddr_in6
*)(void *)res
->ai_addr
)->sin6_scope_id
);
482 if (rtmsg(RTM_GET
) < 0)
483 errx(1, "RTM_GET(%s) failed", host
);
484 mysin
= (struct sockaddr_in6
*)(void *)(rtm
+ 1);
485 sdl
= (struct sockaddr_dl
*)(void *)(ROUNDUP(mysin
->sin6_len
) +
486 (char *)(void *)mysin
);
487 if (IN6_ARE_ADDR_EQUAL(&mysin
->sin6_addr
, &sin_m
.sin6_addr
)) {
488 if (sdl
->sdl_family
== AF_LINK
&&
489 (rtm
->rtm_flags
& RTF_LLINFO
) &&
490 !(rtm
->rtm_flags
& RTF_GATEWAY
)) {
494 * IPv4 arp command retries with sin_other = SIN_PROXY here.
496 warnx("delete: cannot delete non-NDP entry");
501 if (sdl
->sdl_family
!= AF_LINK
) {
502 (void)printf("cannot locate %s\n", host
);
505 if (rtmsg(RTM_DELETE
) == 0) {
506 struct sockaddr_in6 s6
= *mysin
; /* XXX: for safety */
509 if (IN6_IS_ADDR_LINKLOCAL(&s6
.sin6_addr
)) {
510 s6
.sin6_scope_id
= ntohs(*(u_int16_t
*)(void *)&s6
.sin6_addr
.s6_addr
[2]);
511 *(u_int16_t
*)(void *)&s6
.sin6_addr
.s6_addr
[2] = 0;
514 (void)getnameinfo((struct sockaddr
*)(void *)&s6
,
515 (socklen_t
)s6
.sin6_len
, host_buf
,
516 sizeof(host_buf
), NULL
, 0,
517 (nflag
? NI_NUMERICHOST
: 0));
518 (void)printf("%s (%s) deleted\n", host
, host_buf
);
529 * Dump the entire neighbor cache
532 dump(struct in6_addr
*addr
, int cflag
)
536 char *lim
, *buf
, *next
;
537 struct rt_msghdr
*rtm
;
538 struct sockaddr_in6
*mysin
;
539 struct sockaddr_dl
*sdl
;
540 struct in6_nbrinfo
*nbi
;
549 if (!tflag
&& !cflag
)
550 (void)printf("%-*.*s %-*.*s %*.*s %-9.9s %1s %5s\n",
551 W_ADDR
, W_ADDR
, "Neighbor", W_LL
, W_LL
, "Linklayer Address",
552 W_IF
, W_IF
, "Netif", "Expire", "S", "Flags");
559 mib
[4] = NET_RT_FLAGS
;
561 if (sysctl(mib
, 6, NULL
, &needed
, NULL
, 0) < 0)
562 err(1, "sysctl(PF_ROUTE estimate)");
564 if ((buf
= malloc(needed
)) == NULL
)
566 if (sysctl(mib
, 6, buf
, &needed
, NULL
, 0) < 0)
567 err(1, "sysctl(PF_ROUTE, NET_RT_FLAGS)");
572 for (next
= buf
; next
&& next
< lim
; next
+= rtm
->rtm_msglen
) {
573 int isrouter
= 0, prbs
= 0;
575 rtm
= (struct rt_msghdr
*)(void *)next
;
576 mysin
= (struct sockaddr_in6
*)(void *)(rtm
+ 1);
577 sdl
= (struct sockaddr_dl
*)(void *)((char *)(void *)mysin
+ ROUNDUP(mysin
->sin6_len
));
580 * Some OSes can produce a route that has the LINK flag but
581 * has a non-AF_LINK gateway (e.g. fe80::xx%lo0 on FreeBSD
582 * and BSD/OS, where xx is not the interface identifier on
583 * lo0). Such routes entry would annoy getnbrinfo() below,
585 * XXX: such routes should have the GATEWAY flag, not the
586 * LINK flag. However, there is rotten routing software
587 * that advertises all routes that have the GATEWAY flag.
588 * Thus, KAME kernel intentionally does not set the LINK flag.
589 * What is to be fixed is not ndp, but such routing software
590 * (and the kernel workaround)...
592 if (sdl
->sdl_family
!= AF_LINK
)
595 if (!(rtm
->rtm_flags
& RTF_HOST
))
599 if (!IN6_ARE_ADDR_EQUAL(addr
, &mysin
->sin6_addr
))
602 } else if (IN6_IS_ADDR_MULTICAST(&mysin
->sin6_addr
))
604 if (IN6_IS_ADDR_LINKLOCAL(&mysin
->sin6_addr
) ||
605 IN6_IS_ADDR_MC_LINKLOCAL(&mysin
->sin6_addr
)) {
606 /* XXX: should scope id be filled in the kernel? */
607 if (mysin
->sin6_scope_id
== 0)
608 mysin
->sin6_scope_id
= sdl
->sdl_index
;
610 /* KAME specific hack; removed the embedded id */
611 *(u_int16_t
*)(void *)&mysin
->sin6_addr
.s6_addr
[2] = 0;
614 (void)getnameinfo((struct sockaddr
*)(void *)mysin
,
615 (socklen_t
)mysin
->sin6_len
,
616 host_buf
, sizeof(host_buf
), NULL
, 0,
617 (nflag
? NI_NUMERICHOST
: 0));
620 if (rtm
->rtm_flags
& RTF_WASCLONED
)
621 (void)delete(host_buf
);
622 #elif defined(RTF_CLONED)
623 if (rtm
->rtm_flags
& RTF_CLONED
)
624 (void)delete(host_buf
);
626 (void)delete(host_buf
);
630 (void)gettimeofday(&tim
, 0);
634 addrwidth
= strlen(host_buf
);
635 if (addrwidth
< W_ADDR
)
637 llwidth
= strlen(ether_str(sdl
));
638 if (W_ADDR
+ W_LL
- addrwidth
> llwidth
)
639 llwidth
= W_ADDR
+ W_LL
- addrwidth
;
640 ifname
= if_indextoname((unsigned int)sdl
->sdl_index
, ifix_buf
);
643 ifwidth
= strlen(ifname
);
644 if (W_ADDR
+ W_LL
+ W_IF
- addrwidth
- llwidth
> ifwidth
)
645 ifwidth
= W_ADDR
+ W_LL
+ W_IF
- addrwidth
- llwidth
;
647 (void)printf("%-*.*s %-*.*s %*.*s", addrwidth
, addrwidth
,
648 host_buf
, llwidth
, llwidth
, ether_str(sdl
), ifwidth
,
651 /* Print neighbor discovery specific informations */
652 nbi
= getnbrinfo(&mysin
->sin6_addr
,
653 (unsigned int)sdl
->sdl_index
, 1);
655 if (nbi
->expire
> tim
.tv_sec
) {
656 (void)printf(" %-9.9s",
657 sec2str(nbi
->expire
- tim
.tv_sec
));
658 } else if (nbi
->expire
== 0)
659 (void)printf(" %-9.9s", "permanent");
661 (void)printf(" %-9.9s", "expired");
663 switch (nbi
->state
) {
664 case ND6_LLINFO_NOSTATE
:
667 #ifdef ND6_LLINFO_WAITDELETE
668 case ND6_LLINFO_WAITDELETE
:
672 case ND6_LLINFO_INCOMPLETE
:
675 case ND6_LLINFO_REACHABLE
:
678 case ND6_LLINFO_STALE
:
681 case ND6_LLINFO_DELAY
:
684 case ND6_LLINFO_PROBE
:
692 isrouter
= nbi
->isrouter
;
695 warnx("failed to get neighbor information");
700 * other flags. R: router, P: proxy, W: ??
702 if ((rtm
->rtm_addrs
& RTA_NETMASK
) == 0) {
703 (void)snprintf(flgbuf
, sizeof(flgbuf
), "%s%s",
705 (rtm
->rtm_flags
& RTF_ANNOUNCE
) ? "p" : "");
707 mysin
= (struct sockaddr_in6
*)(void *)
708 (sdl
->sdl_len
+ (char *)(void *)sdl
);
709 #if 0 /* W and P are mystery even for us */
710 (void)snprintf(flgbuf
, sizeof(flgbuf
), "%s%s%s%s",
712 !IN6_IS_ADDR_UNSPECIFIED(&sin
->sin6_addr
) ? "P" : "",
713 (sin
->sin6_len
!= sizeof(struct sockaddr_in6
)) ? "W" : "",
714 (rtm
->rtm_flags
& RTF_ANNOUNCE
) ? "p" : "");
716 (void)snprintf(flgbuf
, sizeof(flgbuf
), "%s%s",
718 (rtm
->rtm_flags
& RTF_ANNOUNCE
) ? "p" : "");
721 (void)printf(" %s", flgbuf
);
724 (void)printf(" %d", prbs
);
733 (void)fflush(stdout
);
739 static struct in6_nbrinfo
*
740 getnbrinfo(struct in6_addr
*addr
, unsigned int ifindex
, int warning
)
742 static struct in6_nbrinfo nbi
;
745 if ((s
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
748 (void)memset(&nbi
, 0, sizeof(nbi
));
749 (void)if_indextoname(ifindex
, nbi
.ifname
);
751 if (ioctl(s
, SIOCGNBRINFO_IN6
, &nbi
) < 0) {
753 warn("ioctl(SIOCGNBRINFO_IN6)");
763 ether_str(struct sockaddr_dl
*sdl
)
765 static char hbuf
[NI_MAXHOST
];
768 if (getnameinfo((struct sockaddr
*)(void *)sdl
,
769 (socklen_t
)sdl
->sdl_len
,
770 hbuf
, sizeof(hbuf
), NULL
, 0, NI_NUMERICHOST
) != 0)
771 (void)snprintf(hbuf
, sizeof(hbuf
), "<invalid>");
773 (void)snprintf(hbuf
, sizeof(hbuf
), "(incomplete)");
779 ndp_ether_aton(char *a
, u_char
*n
)
783 i
= sscanf(a
, "%x:%x:%x:%x:%x:%x", &o
[0], &o
[1], &o
[2],
784 &o
[3], &o
[4], &o
[5]);
786 warnx("invalid Ethernet address '%s'", a
);
789 for (i
= 0; i
< 6; i
++)
797 const char *pn
= getprogname();
799 (void)fprintf(stderr
, "Usage: %s [-nt] hostname\n", pn
);
800 (void)fprintf(stderr
,
801 " %s [-nt] -a | -c | -p | -r | -H | -P | -R\n", pn
);
802 (void)fprintf(stderr
, " %s [-nt] -A wait\n", pn
);
803 (void)fprintf(stderr
, " %s [-nt] -d hostname\n", pn
);
804 (void)fprintf(stderr
, " %s [-nt] -f filename\n", pn
);
805 (void)fprintf(stderr
, " %s [-nt] -i interface [flags...]\n", pn
);
806 #ifdef SIOCSDEFIFACE_IN6
807 (void)fprintf(stderr
, " %s [-nt] -I [interface|delete]\n", pn
);
809 (void)fprintf(stderr
,
810 " %s [-nt] -s nodename etheraddr [temp] [proxy]\n", pn
);
818 register struct rt_msghdr
*rtm
= &m_rtmsg
.m_rtm
;
819 register char *cp
= m_rtmsg
.m_space
;
823 if (cmd
== RTM_DELETE
)
825 (void)memset(&m_rtmsg
, 0, sizeof(m_rtmsg
));
826 rtm
->rtm_flags
= flags
;
827 rtm
->rtm_version
= RTM_VERSION
;
831 errx(1, "internal wrong cmd");
834 rtm
->rtm_addrs
|= RTA_GATEWAY
;
836 rtm
->rtm_rmx
.rmx_expire
= expire_time
;
837 rtm
->rtm_inits
= RTV_EXPIRE
;
839 rtm
->rtm_flags
|= (RTF_HOST
| RTF_STATIC
);
840 #ifdef notdef /* we don't support ipv6addr/128 type proxying. */
841 if (rtm
->rtm_flags
& RTF_ANNOUNCE
) {
842 rtm
->rtm_flags
&= ~RTF_HOST
;
843 rtm
->rtm_addrs
|= RTA_NETMASK
;
848 rtm
->rtm_addrs
|= RTA_DST
;
850 #define NEXTADDR(w, s) \
851 if (rtm->rtm_addrs & (w)) { \
852 (void)memcpy(cp, &s, sizeof(s)); \
853 ADVANCE(cp, (struct sockaddr *)(void *)&s); \
856 NEXTADDR(RTA_DST
, sin_m
);
857 NEXTADDR(RTA_GATEWAY
, sdl_m
);
858 #ifdef notdef /* we don't support ipv6addr/128 type proxying. */
859 (void)memset(&so_mask
.sin6_addr
, 0xff, sizeof(so_mask
.sin6_addr
));
860 NEXTADDR(RTA_NETMASK
, so_mask
);
863 rtm
->rtm_msglen
= cp
- (char *)(void *)&m_rtmsg
;
866 rtm
->rtm_seq
= ++seq
;
868 if (write(my_s
, &m_rtmsg
, (size_t)l
) == -1) {
869 if (errno
!= ESRCH
|| cmd
!= RTM_DELETE
)
870 err(1, "writing to routing socket");
873 l
= read(my_s
, &m_rtmsg
, sizeof(m_rtmsg
));
874 } while (l
> 0 && (rtm
->rtm_seq
!= seq
|| rtm
->rtm_pid
!= pid
));
876 warn("read from routing socket");
881 ifinfo(char *ifname
, int argc
, char **argv
)
883 struct in6_ndireq nd
;
886 #ifdef IPV6CTL_USETEMPADDR
890 if ((s
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
892 (void)memset(&nd
, 0, sizeof(nd
));
893 (void)strlcpy(nd
.ifname
, ifname
, sizeof(nd
.ifname
));
894 if (ioctl(s
, SIOCGIFINFO_IN6
, &nd
) < 0)
895 err(1, "ioctl(SIOCGIFINFO_IN6)");
898 for (i
= 0; i
< argc
; i
++) {
907 #define SETFLAG(s, f) \
909 if (strcmp(cp, (s)) == 0) {\
915 } while (/*CONSTCOND*/0)
917 * XXX: this macro is not 100% correct, in that it matches "nud" against
918 * "nudbogus". But we just let it go since this is minor.
920 #define SETVALUE(f, v) \
923 unsigned long newval; \
924 v = 0; /* unspecified */ \
925 if (strncmp(cp, f, strlen(f)) == 0) { \
926 valptr = strchr(cp, '='); \
927 if (valptr == NULL) \
928 err(1, "syntax error in %s field", (f)); \
930 newval = strtoul(++valptr, NULL, 0); \
932 err(1, "syntax error in %s's value", (f)); \
935 } while (/*CONSTCOND*/0)
937 #ifdef ND6_IFF_IFDISABLED
938 SETFLAG("disabled", ND6_IFF_IFDISABLED
);
940 SETFLAG("nud", ND6_IFF_PERFORMNUD
);
941 #ifdef ND6_IFF_ACCEPT_RTADV
942 SETFLAG("accept_rtadv", ND6_IFF_ACCEPT_RTADV
);
944 #ifdef ND6_IFF_OVERRIDE_RTADV
945 SETFLAG("override_rtadv", ND6_IFF_OVERRIDE_RTADV
);
947 #ifdef ND6_IFF_PREFER_SOURCE
948 SETFLAG("prefer_source", ND6_IFF_PREFER_SOURCE
);
950 #ifdef ND6_IFF_DONT_SET_IFROUTE
951 SETFLAG("dont_set_ifroute", ND6_IFF_DONT_SET_IFROUTE
);
953 SETVALUE("basereachable", ND
.basereachable
);
954 SETVALUE("retrans", ND
.retrans
);
955 SETVALUE("curhlim", ND
.chlim
);
958 #ifdef SIOCSIFINFO_IN6
959 if (ioctl(s
, SIOCSIFINFO_IN6
, &nd
) < 0)
960 err(1, "ioctl(SIOCSIFINFO_IN6)");
962 if (ioctl(s
, SIOCSIFINFO_FLAGS
, &nd
) < 0)
963 err(1, "ioctl(SIOCSIFINFO_FLAGS)");
970 errx(1, "%s: not initialized yet", ifname
);
972 if (ioctl(s
, SIOCGIFINFO_IN6
, &nd
) < 0)
973 err(1, "ioctl(SIOCGIFINFO_IN6)");
974 (void)printf("linkmtu=%d", ND
.linkmtu
);
975 (void)printf(", maxmtu=%d", ND
.maxmtu
);
976 (void)printf(", curhlim=%d", ND
.chlim
);
977 (void)printf(", basereachable=%ds%dms",
978 ND
.basereachable
/ 1000, ND
.basereachable
% 1000);
979 (void)printf(", reachable=%ds", ND
.reachable
);
980 (void)printf(", retrans=%ds%dms", ND
.retrans
/ 1000, ND
.retrans
% 1000);
981 #ifdef IPV6CTL_USETEMPADDR
982 (void)memset(nullbuf
, 0, sizeof(nullbuf
));
983 if (memcmp(nullbuf
, ND
.randomid
, sizeof(nullbuf
)) != 0) {
987 for (i
= 0; i
< 3; i
++) {
990 (void)printf("\nRandom seed(0): ");
991 rbuf
= ND
.randomseed0
;
994 (void)printf("\nRandom seed(1): ");
995 rbuf
= ND
.randomseed1
;
998 (void)printf("\nRandom ID: ");
1002 errx(1, "impossible case for tempaddr display");
1004 for (j
= 0; j
< 8; j
++)
1005 (void)printf("%02x", rbuf
[j
]);
1010 (void)printf("\nFlags: ");
1011 if ((ND
.flags
& ND6_IFF_PERFORMNUD
))
1012 (void)printf("nud ");
1013 #ifdef ND6_IFF_IFDISABLED
1014 if ((ND
.flags
& ND6_IFF_IFDISABLED
))
1015 (void)printf("disabled ");
1017 #ifdef ND6_IFF_ACCEPT_RTADV
1018 if ((ND
.flags
& ND6_IFF_ACCEPT_RTADV
))
1019 (void)printf("accept_rtadv ");
1021 #ifdef ND6_IFF_OVERRIDE_RTADV
1022 if ((ND
.flags
& ND6_IFF_OVERRIDE_RTADV
))
1023 (void)printf("override_rtadv ");
1025 #ifdef ND6_IFF_PREFER_SOURCE
1026 if ((ND
.flags
& ND6_IFF_PREFER_SOURCE
))
1027 (void)printf("prefer_source ");
1030 (void)putc('\n', stdout
);
1036 #ifndef ND_RA_FLAG_RTPREF_MASK /* XXX: just for compilation on *BSD release */
1037 #define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
1043 #ifdef ICMPV6CTL_ND6_DRLIST
1044 int mib
[] = { CTL_NET
, PF_INET6
, IPPROTO_ICMPV6
, ICMPV6CTL_ND6_DRLIST
};
1046 struct in6_defrouter
*p
, *ep
;
1050 if (sysctl(mib
, sizeof(mib
) / sizeof(mib
[0]), NULL
, &l
, NULL
, 0) < 0) {
1051 err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
1061 if (sysctl(mib
, sizeof(mib
) / sizeof(mib
[0]), buf
, &l
, NULL
, 0) < 0) {
1062 err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
1066 ep
= (struct in6_defrouter
*)(void *)(buf
+ l
);
1067 for (p
= (struct in6_defrouter
*)(void *)buf
; p
< ep
; p
++) {
1070 if (getnameinfo((struct sockaddr
*)(void *)&p
->rtaddr
,
1071 (socklen_t
)p
->rtaddr
.sin6_len
, host_buf
, sizeof(host_buf
),
1072 NULL
, 0, (nflag
? NI_NUMERICHOST
: 0)) != 0)
1073 (void)strlcpy(host_buf
, "?", sizeof(host_buf
));
1075 (void)printf("%s if=%s", host_buf
,
1076 if_indextoname((unsigned int)p
->if_index
, ifix_buf
));
1077 (void)printf(", flags=%s%s",
1078 p
->flags
& ND_RA_FLAG_MANAGED
? "M" : "",
1079 p
->flags
& ND_RA_FLAG_OTHER
? "O" : "");
1080 rtpref
= ((uint32_t)(p
->flags
& ND_RA_FLAG_RTPREF_MASK
) >> 3) & 0xff;
1081 (void)printf(", pref=%s", rtpref_str
[rtpref
]);
1083 (void)gettimeofday(&tim
, 0);
1085 (void)printf(", expire=Never\n");
1087 (void)printf(", expire=%s\n",
1088 sec2str((time_t)(p
->expire
- tim
.tv_sec
)));
1092 struct in6_drlist dr
;
1094 struct timeval time
;
1096 if ((s
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0) {
1100 (void)memset(&dr
, 0, sizeof(dr
));
1101 (void)strlcpy(dr
.ifname
, "lo0", sizeof(dr
.ifname
)); /* dummy */
1102 if (ioctl(s
, SIOCGDRLST_IN6
, (caddr_t
)&dr
) < 0) {
1103 err(1, "ioctl(SIOCGDRLST_IN6)");
1106 #define DR dr.defrouter[i]
1107 for (i
= 0 ; DR
.if_index
&& i
< DRLSTSIZ
; i
++) {
1108 struct sockaddr_in6 sin6
;
1110 (void)memset(&sin6
, 0, sizeof(sin6
));
1111 sin6
.sin6_family
= AF_INET6
;
1112 sin6
.sin6_len
= sizeof(sin6
);
1113 sin6
.sin6_addr
= DR
.rtaddr
;
1114 (void)getnameinfo((struct sockaddr
*)&sin6
, sin6
.sin6_len
,
1115 host_buf
, sizeof(host_buf
), NULL
, 0,
1116 (nflag
? NI_NUMERICHOST
: 0));
1118 (void)printf("%s if=%s", host_buf
,
1119 if_indextoname(DR
.if_index
, ifix_buf
));
1120 (void)printf(", flags=%s%s",
1121 DR
.flags
& ND_RA_FLAG_MANAGED
? "M" : "",
1122 DR
.flags
& ND_RA_FLAG_OTHER
? "O" : "");
1123 gettimeofday(&time
, 0);
1125 (void)printf(", expire=Never\n");
1127 (void)printf(", expire=%s\n",
1128 sec2str(DR
.expire
- time
.tv_sec
));
1138 #ifdef ICMPV6CTL_ND6_PRLIST
1139 int mib
[] = { CTL_NET
, PF_INET6
, IPPROTO_ICMPV6
, ICMPV6CTL_ND6_PRLIST
};
1141 struct in6_prefix
*p
, *ep
, *n
;
1142 struct sockaddr_in6
*advrtr
;
1145 const int niflags
= NI_NUMERICHOST
;
1146 int ninflags
= nflag
? NI_NUMERICHOST
: 0;
1147 char namebuf
[NI_MAXHOST
];
1149 if (sysctl(mib
, sizeof(mib
) / sizeof(mib
[0]), NULL
, &l
, NULL
, 0) < 0) {
1150 err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
1158 if (sysctl(mib
, sizeof(mib
) / sizeof(mib
[0]), buf
, &l
, NULL
, 0) < 0) {
1159 err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
1163 ep
= (struct in6_prefix
*)(void *)(buf
+ l
);
1164 for (p
= (struct in6_prefix
*)(void *)buf
; p
< ep
; p
= n
) {
1165 advrtr
= (struct sockaddr_in6
*)(void *)(p
+ 1);
1166 n
= (struct in6_prefix
*)(void *)&advrtr
[p
->advrtrs
];
1168 if (getnameinfo((struct sockaddr
*)(void *)&p
->prefix
,
1169 (socklen_t
)p
->prefix
.sin6_len
, namebuf
, sizeof(namebuf
),
1170 NULL
, 0, niflags
) != 0)
1171 (void)strlcpy(namebuf
, "?", sizeof(namebuf
));
1172 (void)printf("%s/%d if=%s\n", namebuf
, p
->prefixlen
,
1173 if_indextoname((unsigned int)p
->if_index
, ifix_buf
));
1175 (void)gettimeofday(&tim
, 0);
1177 * meaning of fields, especially flags, is very different
1178 * by origin. notify the difference to the users.
1180 (void)printf("flags=%s%s%s%s%s",
1181 p
->raflags
.onlink
? "L" : "",
1182 p
->raflags
.autonomous
? "A" : "",
1183 (p
->flags
& NDPRF_ONLINK
) != 0 ? "O" : "",
1184 (p
->flags
& NDPRF_DETACHED
) != 0 ? "D" : "",
1186 (p
->flags
& NDPRF_HOME
) != 0 ? "H" : ""
1191 if (p
->vltime
== ND6_INFINITE_LIFETIME
)
1192 (void)printf(" vltime=infinity");
1194 (void)printf(" vltime=%lu", (unsigned long)p
->vltime
);
1195 if (p
->pltime
== ND6_INFINITE_LIFETIME
)
1196 (void)printf(", pltime=infinity");
1198 (void)printf(", pltime=%lu", (unsigned long)p
->pltime
);
1200 (void)printf(", expire=Never");
1201 else if (p
->expire
>= tim
.tv_sec
)
1202 (void)printf(", expire=%s",
1203 sec2str(p
->expire
- tim
.tv_sec
));
1205 (void)printf(", expired");
1206 (void)printf(", ref=%d", p
->refcnt
);
1209 * "advertising router" list is meaningful only if the prefix
1210 * information is from RA.
1214 struct sockaddr_in6
*sin6
;
1217 (void)printf(" advertised by\n");
1218 for (j
= 0; j
< p
->advrtrs
; j
++) {
1219 struct in6_nbrinfo
*nbi
;
1221 if (getnameinfo((struct sockaddr
*)(void *)sin6
,
1222 (socklen_t
)sin6
->sin6_len
, namebuf
,
1223 sizeof(namebuf
), NULL
, 0, ninflags
) != 0)
1224 (void)strlcpy(namebuf
, "?", sizeof(namebuf
));
1225 (void)printf(" %s", namebuf
);
1227 nbi
= getnbrinfo(&sin6
->sin6_addr
,
1228 (unsigned int)p
->if_index
, 0);
1230 switch (nbi
->state
) {
1231 case ND6_LLINFO_REACHABLE
:
1232 case ND6_LLINFO_STALE
:
1233 case ND6_LLINFO_DELAY
:
1234 case ND6_LLINFO_PROBE
:
1235 (void)printf(" (reachable)\n");
1238 (void)printf(" (unreachable)\n");
1241 (void)printf(" (no neighbor state)\n");
1245 (void)printf(" No advertising router\n");
1249 struct in6_prlist pr
;
1251 struct timeval time
;
1253 (void)gettimeofday(&time
, 0);
1255 if ((s
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0) {
1259 (void)memset(&pr
, 0, sizeof(pr
));
1260 (void)strlcpy(pr
.ifname
, "lo0", sizeof(pr
.ifname
)); /* dummy */
1261 if (ioctl(s
, SIOCGPRLST_IN6
, (caddr_t
)&pr
) < 0) {
1262 err(1, "ioctl(SIOCGPRLST_IN6)");
1265 #define PR pr.prefix[i]
1266 for (i
= 0; PR
.if_index
&& i
< PRLSTSIZ
; i
++) {
1267 struct sockaddr_in6 p6
;
1268 char namebuf
[NI_MAXHOST
];
1274 (void)memset(&p6
, 0, sizeof(p6
));
1275 p6
.sin6_family
= AF_INET6
;
1276 p6
.sin6_len
= sizeof(p6
);
1277 p6
.sin6_addr
= PR
.prefix
;
1280 niflags
= NI_NUMERICHOST
;
1281 if (getnameinfo((struct sockaddr
*)&p6
,
1282 sizeof(p6
), namebuf
, sizeof(namebuf
),
1283 NULL
, 0, niflags
)) {
1284 warnx("getnameinfo failed");
1287 (void)printf("%s/%d if=%s\n", namebuf
, PR
.prefixlen
,
1288 if_indextoname(PR
.if_index
, ifix_buf
));
1290 (void)gettimeofday(&time
, 0);
1292 * meaning of fields, especially flags, is very different
1293 * by origin. notify the difference to the users.
1297 PR
.origin
== PR_ORIG_RA
? "" : "advertise: ");
1300 (void)printf("flags=%s%s%s%s%s",
1301 PR
.raflags
.onlink
? "L" : "",
1302 PR
.raflags
.autonomous
? "A" : "",
1303 (PR
.flags
& NDPRF_ONLINK
) != 0 ? "O" : "",
1304 (PR
.flags
& NDPRF_DETACHED
) != 0 ? "D" : "",
1306 (PR
.flags
& NDPRF_HOME
) != 0 ? "H" : ""
1312 (void)printf("flags=%s%s",
1313 PR
.raflags
.onlink
? "L" : "",
1314 PR
.raflags
.autonomous
? "A" : "");
1316 if (PR
.vltime
== ND6_INFINITE_LIFETIME
)
1317 (void)printf(" vltime=infinity");
1319 (void)printf(" vltime=%lu", PR
.vltime
);
1320 if (PR
.pltime
== ND6_INFINITE_LIFETIME
)
1321 (void)printf(", pltime=infinity");
1323 (void)printf(", pltime=%lu", PR
.pltime
);
1325 (void)printf(", expire=Never");
1326 else if (PR
.expire
>= time
.tv_sec
)
1327 (void)printf(", expire=%s",
1328 sec2str(PR
.expire
- time
.tv_sec
));
1330 (void)printf(", expired");
1332 (void)printf(", ref=%d", PR
.refcnt
);
1335 switch (PR
.origin
) {
1337 (void)printf(", origin=RA");
1340 (void)printf(", origin=RR");
1342 case PR_ORIG_STATIC
:
1343 (void)printf(", origin=static");
1345 case PR_ORIG_KERNEL
:
1346 (void)printf(", origin=kernel");
1349 (void)printf(", origin=?");
1355 * "advertising router" list is meaningful only if the prefix
1356 * information is from RA.
1358 if (0 && /* prefix origin is almost obsolted */
1359 PR
.origin
!= PR_ORIG_RA
)
1361 else if (PR
.advrtrs
) {
1363 (void)printf(" advertised by\n");
1364 for (j
= 0; j
< PR
.advrtrs
; j
++) {
1365 struct sockaddr_in6 sin6
;
1366 struct in6_nbrinfo
*nbi
;
1368 bzero(&sin6
, sizeof(sin6
));
1369 sin6
.sin6_family
= AF_INET6
;
1370 sin6
.sin6_len
= sizeof(sin6
);
1371 sin6
.sin6_addr
= PR
.advrtr
[j
];
1372 sin6
.sin6_scope_id
= PR
.if_index
; /* XXX */
1373 (void)getnameinfo((struct sockaddr
*)&sin6
,
1374 sin6
.sin6_len
, host_buf
,
1375 sizeof(host_buf
), NULL
, 0,
1376 (nflag
? NI_NUMERICHOST
: 0));
1377 (void)printf(" %s", host_buf
);
1379 nbi
= getnbrinfo(&sin6
.sin6_addr
,
1382 switch (nbi
->state
) {
1383 case ND6_LLINFO_REACHABLE
:
1384 case ND6_LLINFO_STALE
:
1385 case ND6_LLINFO_DELAY
:
1386 case ND6_LLINFO_PROBE
:
1387 (void)printf(" (reachable)\n");
1390 (void)printf(" (unreachable)\n");
1393 (void)printf(" (no neighbor state)\n");
1395 if (PR
.advrtrs
> DRLSTSIZ
)
1396 (void)printf(" and %d routers\n",
1397 PR
.advrtrs
- DRLSTSIZ
);
1399 (void)printf(" No advertising router\n");
1409 char dummyif
[IFNAMSIZ
+8];
1412 if ((s
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
1414 (void)strlcpy(dummyif
, "lo0", sizeof(dummyif
)); /* dummy */
1415 if (ioctl(s
, SIOCSPFXFLUSH_IN6
, (caddr_t
)&dummyif
) < 0)
1416 err(1, "ioctl(SIOCSPFXFLUSH_IN6)");
1423 char dummyif
[IFNAMSIZ
+8];
1426 if ((s
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
1428 (void)strlcpy(dummyif
, "lo0", sizeof(dummyif
)); /* dummy */
1429 if (ioctl(s
, SIOCSRTRFLUSH_IN6
, (caddr_t
)&dummyif
) < 0)
1430 err(1, "ioctl(SIOCSRTRFLUSH_IN6)");
1438 char dummyif
[IFNAMSIZ
+8];
1441 if ((s
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
1443 (void)strlcpy(dummyif
, "lo0", sizeof(dummyif
)); /* dummy */
1444 if (ioctl(s
, SIOCSNDFLUSH_IN6
, (caddr_t
)&dummyif
) < 0)
1445 err(1, "ioctl(SIOCSNDFLUSH_IN6)");
1450 #ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */
1452 setdefif(char *ifname
)
1454 struct in6_ndifreq ndifreq
;
1455 unsigned int ifindex
;
1458 if (strcasecmp(ifname
, "delete") == 0)
1461 if ((ifindex
= if_nametoindex(ifname
)) == 0)
1462 err(1, "failed to resolve i/f index for %s", ifname
);
1465 if ((s
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
1468 (void)strlcpy(ndifreq
.ifname
, "lo0", sizeof(ndifreq
.ifname
)); /* dummy */
1469 ndifreq
.ifindex
= ifindex
;
1471 if (ioctl(s
, SIOCSDEFIFACE_IN6
, &ndifreq
) < 0)
1472 err(1, "ioctl(SIOCSDEFIFACE_IN6)");
1480 struct in6_ndifreq ndifreq
;
1481 char ifname
[IFNAMSIZ
+8];
1484 if ((s
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0)
1487 (void)memset(&ndifreq
, 0, sizeof(ndifreq
));
1488 (void)strlcpy(ndifreq
.ifname
, "lo0", sizeof(ndifreq
.ifname
)); /* dummy */
1490 if (ioctl(s
, SIOCGDEFIFACE_IN6
, &ndifreq
) < 0)
1491 err(1, "ioctl(SIOCGDEFIFACE_IN6)");
1493 if (ndifreq
.ifindex
== 0)
1494 (void)printf("No default interface.\n");
1496 if ((if_indextoname((unsigned int)ndifreq
.ifindex
, ifname
)) == NULL
)
1497 err(1, "failed to resolve ifname for index %lu",
1499 (void)printf("ND default interface = %s\n", ifname
);
1507 sec2str(time_t total
)
1509 static char result
[256];
1510 int days
, hours
, mins
, secs
;
1513 char *ep
= &result
[sizeof(result
)];
1516 days
= total
/ 3600 / 24;
1517 hours
= (total
/ 3600) % 24;
1518 mins
= (total
/ 60) % 60;
1523 n
= snprintf(p
, (size_t)(ep
- p
), "%dd", days
);
1524 if (n
< 0 || n
>= ep
- p
)
1528 if (!first
|| hours
) {
1530 n
= snprintf(p
, (size_t)(ep
- p
), "%dh", hours
);
1531 if (n
< 0 || n
>= ep
- p
)
1535 if (!first
|| mins
) {
1537 n
= snprintf(p
, (size_t)(ep
- p
), "%dm", mins
);
1538 if (n
< 0 || n
>= ep
- p
)
1542 (void)snprintf(p
, (size_t)(ep
- p
), "%ds", secs
);
1548 * Print the timestamp
1549 * from tcpdump/util.c
1552 ts_print(const struct timeval
*tvp
)
1557 s
= (tvp
->tv_sec
+ thiszone
) % 86400;
1558 (void)printf("%02d:%02d:%02d.%06u ",
1559 s
/ 3600, (s
% 3600) / 60, s
% 60, (u_int32_t
)tvp
->tv_usec
);