2 * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: stable/10/usr.sbin/rtadvctl/rtadvctl.c 253970 2013-08-05 20:13:02Z hrs $
30 #include <sys/queue.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
37 #include <net/if_dl.h>
38 #include <net/if_types.h>
39 #include <net/if_var.h>
40 #include <net/ethernet.h>
41 #include <netinet/in.h>
42 #include <netinet/ip6.h>
43 #include <netinet/icmp6.h>
44 #include <netinet6/in6_var.h>
45 #include <netinet6/nd6.h>
46 #include <arpa/inet.h>
60 #include "pathnames.h"
63 #include "timer_subr.h"
66 #include "control_client.h"
68 #define RA_IFSTATUS_INACTIVE 0
69 #define RA_IFSTATUS_RA_RECV 1
70 #define RA_IFSTATUS_RA_SEND 2
72 static int vflag
= LOG_ERR
;
74 static void usage(void);
76 static int action_propset(char *);
77 static int action_propget(char *, struct ctrl_msg_pl
*);
78 static int action_plgeneric(int, char *, char *);
80 static int action_enable(int, char **);
81 static int action_disable(int, char **);
82 static int action_reload(int, char **);
83 static int action_echo(int, char **);
84 static int action_version(int, char **);
85 static int action_shutdown(int, char **);
87 static int action_show(int, char **);
88 static int action_show_prefix(struct prefix
*);
89 static int action_show_rtinfo(struct rtinfo
*);
90 static int action_show_rdnss(void *);
91 static int action_show_dnssl(void *);
93 static int csock_client_open(struct sockinfo
*);
94 static size_t dname_labeldec(char *, size_t, const char *);
95 static void mysyslog(int, const char *, ...);
97 static const char *rtpref_str
[] = {
104 static struct dispatch_table
{
106 int (*dt_act
)(int, char **);
108 { "show", action_show
},
109 { "reload", action_reload
},
110 { "shutdown", action_shutdown
},
111 { "enable", action_enable
},
112 { "disable", action_disable
},
114 { "echo", action_echo
},
115 { "version", action_version
},
119 static char errmsgbuf
[1024];
120 static char *errmsg
= NULL
;
123 mysyslog(int priority
, const char * restrict fmt
, ...)
127 if (vflag
>= priority
) {
129 vfprintf(stderr
, fmt
, ap
);
130 fprintf(stderr
, "\n");
140 for (i
= 0; (size_t)i
< sizeof(dtable
)/sizeof(dtable
[0]); i
++) {
141 if (dtable
[i
].dt_comm
== NULL
)
143 printf("%s\n", dtable
[i
].dt_comm
);
150 main(int argc
, char *argv
[])
154 int (*action
)(int, char **) = NULL
;
157 while ((ch
= getopt(argc
, argv
, "Dv")) != -1) {
175 for (i
= 0; (size_t)i
< sizeof(dtable
)/sizeof(dtable
[0]); i
++) {
176 if (dtable
[i
].dt_comm
== NULL
||
177 strcmp(dtable
[i
].dt_comm
, argv
[0]) == 0) {
178 action
= dtable
[i
].dt_act
;
186 error
= (dtable
[i
].dt_act
)(--argc
, ++argv
);
188 fprintf(stderr
, "%s failed", dtable
[i
].dt_comm
);
190 fprintf(stderr
, ": %s", errmsg
);
191 fprintf(stderr
, ".\n");
198 csock_client_open(struct sockinfo
*s
)
200 struct sockaddr_un sun
;
202 if ((s
->si_fd
= socket(PF_UNIX
, SOCK_STREAM
, 0)) == -1)
203 err(1, "cannot open control socket.");
205 memset(&sun
, 0, sizeof(sun
));
206 sun
.sun_family
= AF_UNIX
;
207 sun
.sun_len
= sizeof(sun
);
208 strlcpy(sun
.sun_path
, s
->si_name
, sizeof(sun
.sun_path
));
210 if (connect(s
->si_fd
, (struct sockaddr
*)&sun
, sizeof(sun
)) == -1)
211 err(1, "connect: %s", s
->si_name
);
214 "<%s> connected to %s", __func__
, sun
.sun_path
);
220 action_plgeneric(int action
, char *plstr
, char *buf
)
222 struct ctrl_msg_hdr
*cm
;
223 struct ctrl_msg_pl cp
;
230 csock_client_open(s
);
232 cm
= (struct ctrl_msg_hdr
*)buf
;
233 msg
= (char *)buf
+ sizeof(*cm
);
235 cm
->cm_version
= CM_VERSION
;
236 cm
->cm_type
= action
;
237 cm
->cm_len
= sizeof(*cm
);
240 memset(&cp
, 0, sizeof(cp
));
241 p
= strchr(plstr
, ':');
242 q
= strchr(plstr
, '=');
243 if (p
!= NULL
&& q
!= NULL
&& p
> q
)
246 if (p
== NULL
) { /* No : */
249 } else if (p
== plstr
) { /* empty */
251 cp
.cp_key
= plstr
+ 1;
254 cp
.cp_ifname
= plstr
;
263 cm
->cm_len
+= cm_pl2bin(msg
, &cp
);
265 mysyslog(LOG_DEBUG
, "<%s> key=%s, val_len=%d, ifname=%s",
266 __func__
,cp
.cp_key
, cp
.cp_val_len
, cp
.cp_ifname
);
269 return (cm_handler_client(s
->si_fd
, CM_STATE_MSG_DISPATCH
, buf
));
273 action_propget(char *argv
, struct ctrl_msg_pl
*cp
)
276 struct ctrl_msg_hdr
*cm
;
277 char buf
[CM_MSG_MAXLEN
];
280 memset(cp
, 0, sizeof(*cp
));
281 cm
= (struct ctrl_msg_hdr
*)buf
;
282 msg
= (char *)buf
+ sizeof(*cm
);
284 error
= action_plgeneric(CM_TYPE_REQ_GET_PROP
, argv
, buf
);
285 if (error
|| cm
->cm_len
<= sizeof(*cm
))
289 mysyslog(LOG_DEBUG
, "<%s> type=%d, len=%d",
290 __func__
, cm
->cm_type
, cm
->cm_len
);
291 mysyslog(LOG_DEBUG
, "<%s> key=%s, val_len=%d, ifname=%s",
292 __func__
,cp
->cp_key
, cp
->cp_val_len
, cp
->cp_ifname
);
298 action_propset(char *argv
)
300 char buf
[CM_MSG_MAXLEN
];
302 return (action_plgeneric(CM_TYPE_REQ_SET_PROP
, argv
, buf
));
306 action_disable(int argc
, char **argv
)
309 char argv_disable
[IFNAMSIZ
+ sizeof(":disable=")];
317 for (i
= 0; i
< argc
; i
++) {
318 sprintf(argv_disable
, "%s:disable=", argv
[i
]);
319 action_argv
= argv_disable
;
320 error
+= action_propset(action_argv
);
327 action_enable(int argc
, char **argv
)
330 char argv_enable
[IFNAMSIZ
+ sizeof(":enable=")];
338 for (i
= 0; i
< argc
; i
++) {
339 sprintf(argv_enable
, "%s:enable=", argv
[i
]);
340 action_argv
= argv_enable
;
341 error
+= action_propset(action_argv
);
348 action_reload(int argc
, char **argv
)
351 char argv_reload
[IFNAMSIZ
+ sizeof(":reload=")];
356 action_argv
= strdup(":reload=");
357 return (action_propset(action_argv
));
361 for (i
= 0; i
< argc
; i
++) {
362 sprintf(argv_reload
, "%s:reload=", argv
[i
]);
363 action_argv
= argv_reload
;
364 error
+= action_propset(action_argv
);
371 action_echo(int argc __unused
, char **argv __unused
)
375 action_argv
= strdup("echo");
376 return (action_propset(action_argv
));
380 action_shutdown(int argc __unused
, char **argv __unused
)
384 action_argv
= strdup("shutdown");
385 return (action_propset(action_argv
));
390 action_version(int argc __unused
, char **argv __unused
)
393 struct ctrl_msg_pl cp
;
396 action_argv
= strdup(":version=");
397 error
= action_propget(action_argv
, &cp
);
401 printf("version=%s\n", cp
.cp_val
);
406 action_show(int argc
, char **argv
)
409 char argv_ifilist
[sizeof(":ifilist=")] = ":ifilist=";
410 char argv_ifi
[IFNAMSIZ
+ sizeof(":ifi=")];
411 char argv_rai
[IFNAMSIZ
+ sizeof(":rai=")];
412 char argv_rti
[IFNAMSIZ
+ sizeof(":rti=")];
413 char argv_pfx
[IFNAMSIZ
+ sizeof(":pfx=")];
414 char argv_ifi_ra_timer
[IFNAMSIZ
+ sizeof(":ifi_ra_timer=")];
415 char argv_rdnss
[IFNAMSIZ
+ sizeof(":rdnss=")];
416 char argv_dnssl
[IFNAMSIZ
+ sizeof(":dnssl=")];
417 char ssbuf
[SSBUFLEN
];
419 struct timespec now
, ts0
, ts
;
420 struct ctrl_msg_pl cp
;
422 TAILQ_HEAD(, ifinfo
) ifl
= TAILQ_HEAD_INITIALIZER(ifl
);
430 action_argv
= argv_ifilist
;
431 error
= action_propget(action_argv
, &cp
);
436 endp
= p
+ cp
.cp_val_len
;
438 ifi
= malloc(sizeof(*ifi
));
441 memset(ifi
, 0, sizeof(*ifi
));
443 strcpy(ifi
->ifi_ifname
, p
);
444 ifi
->ifi_ifindex
= if_nametoindex(ifi
->ifi_ifname
);
445 TAILQ_INSERT_TAIL(&ifl
, ifi
, ifi_next
);
446 p
+= strlen(ifi
->ifi_ifname
) + 1;
449 for (i
= 0; i
< argc
; i
++) {
450 ifi
= malloc(sizeof(*ifi
));
453 memset(ifi
, 0, sizeof(*ifi
));
455 strcpy(ifi
->ifi_ifname
, argv
[i
]);
456 ifi
->ifi_ifindex
= if_nametoindex(ifi
->ifi_ifname
);
457 if (ifi
->ifi_ifindex
== 0) {
458 sprintf(errmsgbuf
, "invalid interface %s",
464 TAILQ_INSERT_TAIL(&ifl
, ifi
, ifi_next
);
468 clock_gettime(CLOCK_REALTIME_FAST
, &now
);
469 clock_gettime(CLOCK_MONOTONIC_FAST
, &ts
);
470 TS_SUB(&now
, &ts
, &ts0
);
472 TAILQ_FOREACH(ifi
, &ifl
, ifi_next
) {
473 struct ifinfo
*ifi_s
;
474 struct rtadvd_timer
*rat
;
481 sprintf(argv_ifi
, "%s:ifi=", ifi
->ifi_ifname
);
482 action_argv
= argv_ifi
;
483 error
= action_propget(action_argv
, &cp
);
486 ifi_s
= (struct ifinfo
*)cp
.cp_val
;
488 if (!(ifi_s
->ifi_persist
) && vflag
< LOG_NOTICE
)
491 printf("%s: flags=<", ifi
->ifi_ifname
);
494 if (ifi_s
->ifi_ifindex
== 0)
495 c
+= printf("NONEXISTENT");
497 c
+= printf("%s", (ifi_s
->ifi_flags
& IFF_UP
) ?
499 switch (ifi_s
->ifi_state
) {
500 case IFI_STATE_CONFIGURED
:
501 c
+= printf("%s%s", (c
) ? "," : "", "CONFIGURED");
503 case IFI_STATE_TRANSITIVE
:
504 c
+= printf("%s%s", (c
) ? "," : "", "TRANSITIVE");
507 if (ifi_s
->ifi_persist
)
508 c
+= printf("%s%s", (c
) ? "," : "", "PERSIST");
511 ra_ifstatus
= RA_IFSTATUS_INACTIVE
;
512 if ((ifi_s
->ifi_flags
& IFF_UP
) &&
513 ((ifi_s
->ifi_state
== IFI_STATE_CONFIGURED
) ||
514 (ifi_s
->ifi_state
== IFI_STATE_TRANSITIVE
))) {
516 * RA_RECV: ND6_IFF_ACCEPT_RTADV
517 * RA_SEND: ip6.forwarding
519 if (ifi_s
->ifi_nd_flags
& ND6_IFF_ACCEPT_RTADV
)
520 ra_ifstatus
= RA_IFSTATUS_RA_RECV
;
521 else if (getinet6sysctl(IPV6CTL_FORWARDING
))
522 ra_ifstatus
= RA_IFSTATUS_RA_SEND
;
524 ra_ifstatus
= RA_IFSTATUS_INACTIVE
;
529 if (ra_ifstatus
== RA_IFSTATUS_INACTIVE
)
530 printf("%s%s", (c
) ? "," : "", "INACTIVE");
531 else if (ra_ifstatus
== RA_IFSTATUS_RA_RECV
)
532 printf("%s%s", (c
) ? "," : "", "RA_RECV");
533 else if (ra_ifstatus
== RA_IFSTATUS_RA_SEND
)
534 printf("%s%s", (c
) ? "," : "", "RA_SEND");
537 switch (ifi_s
->ifi_state
) {
538 case IFI_STATE_CONFIGURED
:
539 case IFI_STATE_TRANSITIVE
:
546 printf("mtu %d\n", ifi_s
->ifi_phymtu
);
548 sprintf(argv_rai
, "%s:rai=", ifi
->ifi_ifname
);
549 action_argv
= argv_rai
;
551 error
= action_propget(action_argv
, &cp
);
555 rai
= (struct rainfo
*)cp
.cp_val
;
557 printf("\tDefaultLifetime: %s",
558 sec2str(rai
->rai_lifetime
, ssbuf
));
559 if (ra_ifstatus
!= RA_IFSTATUS_RA_SEND
&&
560 rai
->rai_lifetime
== 0)
561 printf(" (RAs will be sent with zero lifetime)");
565 printf("\tMinAdvInterval/MaxAdvInterval: ");
566 printf("%s/", sec2str(rai
->rai_mininterval
, ssbuf
));
567 printf("%s\n", sec2str(rai
->rai_maxinterval
, ssbuf
));
568 if (rai
->rai_linkmtu
)
569 printf("\tAdvLinkMTU: %d", rai
->rai_linkmtu
);
571 printf("\tAdvLinkMTU: <none>");
576 if (rai
->rai_managedflg
|| rai
->rai_otherflg
) {
577 printf("%s", rai
->rai_managedflg
? "M" : "");
578 printf("%s", rai
->rai_otherflg
? "O" : "");
584 printf("Preference: %s\n",
585 rtpref_str
[(rai
->rai_rtpref
>> 3) & 0xff]);
587 printf("\tReachableTime: %s, ",
588 sec2str(rai
->rai_reachabletime
, ssbuf
));
589 printf("RetransTimer: %s, "
591 sec2str(rai
->rai_retranstimer
, ssbuf
),
593 printf("\tAdvIfPrefixes: %s\n",
594 rai
->rai_advifprefix
? "yes" : "no");
598 if (ifi_s
->ifi_ra_timer
!= NULL
) {
599 sprintf(argv_ifi_ra_timer
, "%s:ifi_ra_timer=",
601 action_argv
= argv_ifi_ra_timer
;
603 error
= action_propget(action_argv
, &cp
);
607 rat
= (struct rtadvd_timer
*)cp
.cp_val
;
609 printf("\tNext RA send: ");
613 ts
.tv_sec
= rat
->rat_tm
.tv_sec
+ ts0
.tv_sec
;
614 printf("%s", ctime(&ts
.tv_sec
));
616 printf("\tLast RA send: ");
617 if (ifi_s
->ifi_ra_lastsent
.tv_sec
== 0)
620 ts
.tv_sec
= ifi_s
->ifi_ra_lastsent
.tv_sec
+ ts0
.tv_sec
;
621 printf("%s", ctime(&ts
.tv_sec
));
623 if (rai
->rai_clockskew
)
624 printf("\tClock skew: %" PRIu16
"sec\n",
627 if (vflag
< LOG_WARNING
)
630 /* route information */
631 sprintf(argv_rti
, "%s:rti=", ifi
->ifi_ifname
);
632 action_argv
= argv_rti
;
633 error
= action_propget(action_argv
, &cp
);
637 rti
= (struct rtinfo
*)cp
.cp_val
;
638 len
= cp
.cp_val_len
/ sizeof(*rti
);
640 printf("\tRoute Info:\n");
642 for (i
= 0; i
< len
; i
++)
643 action_show_rtinfo(&rti
[i
]);
646 /* prefix information */
647 sprintf(argv_pfx
, "%s:pfx=", ifi
->ifi_ifname
);
648 action_argv
= argv_pfx
;
650 error
= action_propget(action_argv
, &cp
);
654 pfx
= (struct prefix
*)cp
.cp_val
;
655 len
= cp
.cp_val_len
/ sizeof(*pfx
);
658 printf("\tPrefixes (%d):\n", len
);
660 for (i
= 0; i
< len
; i
++)
661 action_show_prefix(&pfx
[i
]);
664 /* RDNSS information */
665 sprintf(argv_rdnss
, "%s:rdnss=", ifi
->ifi_ifname
);
666 action_argv
= argv_rdnss
;
668 error
= action_propget(action_argv
, &cp
);
672 len
= *((uint16_t *)cp
.cp_val
);
675 printf("\tRDNSS entries:\n");
676 action_show_rdnss(cp
.cp_val
);
679 /* DNSSL information */
680 sprintf(argv_dnssl
, "%s:dnssl=", ifi
->ifi_ifname
);
681 action_argv
= argv_dnssl
;
683 error
= action_propget(action_argv
, &cp
);
687 len
= *((uint16_t *)cp
.cp_val
);
690 printf("\tDNSSL entries:\n");
691 action_show_dnssl(cp
.cp_val
);
694 if (vflag
< LOG_NOTICE
)
699 printf("\tCounters\n"
700 "\t RA burst counts: %" PRIu16
" (interval: %s)\n"
701 "\t RS wait counts: %" PRIu16
"\n",
702 ifi_s
->ifi_burstcount
,
703 sec2str(ifi_s
->ifi_burstinterval
, ssbuf
),
704 ifi_s
->ifi_rs_waitcount
);
707 "\t RA: %" PRIu64
"\n", ifi_s
->ifi_raoutput
);
710 "\t RA: %" PRIu64
" (normal)\n"
711 "\t RA: %" PRIu64
" (inconsistent)\n"
712 "\t RS: %" PRIu64
"\n",
714 ifi_s
->ifi_rainconsistent
,
719 #if 0 /* Not implemented yet */
720 printf("\tReceived RAs:\n");
728 action_show_rtinfo(struct rtinfo
*rti
)
730 char ntopbuf
[INET6_ADDRSTRLEN
];
731 char ssbuf
[SSBUFLEN
];
733 printf("\t %s/%d (pref: %s, ltime: %s)\n",
734 inet_ntop(AF_INET6
, &rti
->rti_prefix
,
735 ntopbuf
, sizeof(ntopbuf
)),
737 rtpref_str
[0xff & (rti
->rti_rtpref
>> 3)],
738 (rti
->rti_ltime
== ND6_INFINITE_LIFETIME
) ?
739 "infinity" : sec2str(rti
->rti_ltime
, ssbuf
));
745 action_show_prefix(struct prefix
*pfx
)
747 char ntopbuf
[INET6_ADDRSTRLEN
];
748 char ssbuf
[SSBUFLEN
];
751 clock_gettime(CLOCK_MONOTONIC_FAST
, &now
);
752 printf("\t %s/%d", inet_ntop(AF_INET6
, &pfx
->pfx_prefix
,
753 ntopbuf
, sizeof(ntopbuf
)), pfx
->pfx_prefixlen
);
756 switch (pfx
->pfx_origin
) {
757 case PREFIX_FROM_KERNEL
:
760 case PREFIX_FROM_CONFIG
:
763 case PREFIX_FROM_DYNAMIC
:
771 (pfx
->pfx_validlifetime
== ND6_INFINITE_LIFETIME
) ?
772 "infinity" : sec2str(pfx
->pfx_validlifetime
, ssbuf
));
774 if (pfx
->pfx_vltimeexpire
> 0)
775 printf("(expire: %s)",
776 ((long)pfx
->pfx_vltimeexpire
> now
.tv_sec
) ?
777 sec2str(pfx
->pfx_vltimeexpire
- now
.tv_sec
, ssbuf
) :
783 (pfx
->pfx_preflifetime
== ND6_INFINITE_LIFETIME
) ?
784 "infinity" : sec2str(pfx
->pfx_preflifetime
, ssbuf
));
786 if (pfx
->pfx_pltimeexpire
> 0)
787 printf("(expire %s)",
788 ((long)pfx
->pfx_pltimeexpire
> now
.tv_sec
) ?
789 sec2str(pfx
->pfx_pltimeexpire
- now
.tv_sec
, ssbuf
) :
795 if (pfx
->pfx_onlinkflg
|| pfx
->pfx_autoconfflg
) {
796 printf("%s", pfx
->pfx_onlinkflg
? "L" : "");
797 printf("%s", pfx
->pfx_autoconfflg
? "A" : "");
801 if (pfx
->pfx_timer
) {
802 struct timespec
*rest
;
804 rest
= rtadvd_timer_rest(pfx
->pfx_timer
);
805 if (rest
) { /* XXX: what if not? */
806 printf(" expire=%s", sec2str(rest
->tv_sec
, ssbuf
));
816 action_show_rdnss(void *msg
)
819 struct rdnss_addr
*rda
;
826 char ntopbuf
[INET6_ADDRSTRLEN
];
827 char ssbuf
[SSBUFLEN
];
830 rdn_cnt
= (uint16_t *)p
;
831 p
+= sizeof(*rdn_cnt
);
834 for (i
= 0; i
< *rdn_cnt
; i
++) {
835 rdn
= (struct rdnss
*)p
;
836 ltime
= rdn
->rd_ltime
;
839 rda_cnt
= (uint16_t *)p
;
840 p
+= sizeof(*rda_cnt
);
842 for (j
= 0; j
< *rda_cnt
; j
++) {
843 rda
= (struct rdnss_addr
*)p
;
844 printf("\t %s (ltime=%s)\n",
849 sec2str(ltime
, ssbuf
));
859 action_show_dnssl(void *msg
)
862 struct dnssl_addr
*dna
;
869 char hbuf
[NI_MAXHOST
];
870 char ssbuf
[SSBUFLEN
];
873 dns_cnt
= (uint16_t *)p
;
874 p
+= sizeof(*dns_cnt
);
877 for (i
= 0; i
< *dns_cnt
; i
++) {
878 dns
= (struct dnssl
*)p
;
879 ltime
= dns
->dn_ltime
;
882 dna_cnt
= (uint16_t *)p
;
883 p
+= sizeof(*dna_cnt
);
885 for (j
= 0; j
< *dna_cnt
; j
++) {
886 dna
= (struct dnssl_addr
*)p
;
887 dname_labeldec(hbuf
, sizeof(hbuf
),
889 printf("\t %s (ltime=%s)\n",
890 hbuf
, sec2str(ltime
, ssbuf
));
899 /* Decode domain name label encoding in RFC 1035 Section 3.1 */
901 dname_labeldec(char *dst
, size_t dlen
, const char *src
)
904 const char *src_origin
;
905 const char *src_last
;
906 const char *dst_origin
;
909 src_last
= strchr(src
, '\0');
911 memset(dst
, '\0', dlen
);
912 while (src
&& (len
= (uint8_t)(*src
++) & 0x3f) &&
913 (src
+ len
) <= src_last
) {
914 if (dst
!= dst_origin
)
916 mysyslog(LOG_DEBUG
, "<%s> labellen = %zd", __func__
, len
);
917 memcpy(dst
, src
, len
);
923 return (src
- src_origin
);