1 /* $NetBSD: dump.c,v 1.8 2004/01/03 01:40:31 itojun Exp $ */
2 /* $KAME: dump.c,v 1.10 2002/05/31 10:10:03 itojun Exp $ */
5 * Copyright (C) 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 #include <sys/types.h>
35 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <netinet/icmp6.h>
51 extern struct ifinfo
*iflist
;
53 static void dump_interface_status
__P((void));
54 static const char *sec2str
__P((time_t));
55 const char *ifstatstr
[] = {"IDLE", "DELAY", "PROBE", "DOWN", "TENTATIVE"};
58 dump_interface_status(void)
60 struct ifinfo
*ifinfo
;
63 gettimeofday(&now
, NULL
);
65 for (ifinfo
= iflist
; ifinfo
; ifinfo
= ifinfo
->next
) {
66 fprintf(fp
, "Interface %s\n", ifinfo
->ifname
);
67 fprintf(fp
, " probe interval: ");
68 if (ifinfo
->probeinterval
) {
69 fprintf(fp
, "%d\n", ifinfo
->probeinterval
);
70 fprintf(fp
, " probe timer: %d\n", ifinfo
->probetimer
);
72 fprintf(fp
, "infinity\n");
73 fprintf(fp
, " no probe timer\n");
75 fprintf(fp
, " interface status: %s\n",
76 ifinfo
->active
> 0 ? "active" : "inactive");
77 fprintf(fp
, " rtsold status: %s\n", ifstatstr
[ifinfo
->state
]);
78 fprintf(fp
, " carrier detection: %s\n",
79 ifinfo
->mediareqok
? "available" : "unavailable");
80 fprintf(fp
, " probes: %d, dadcount = %d\n",
81 ifinfo
->probes
, ifinfo
->dadcount
);
82 if (ifinfo
->timer
.tv_sec
== tm_max
.tv_sec
&&
83 ifinfo
->timer
.tv_usec
== tm_max
.tv_usec
)
84 fprintf(fp
, " no timer\n");
86 fprintf(fp
, " timer: interval=%d:%d, expire=%s\n",
87 (int)ifinfo
->timer
.tv_sec
,
88 (int)ifinfo
->timer
.tv_usec
,
89 (ifinfo
->expire
.tv_sec
< now
.tv_sec
) ? "expired"
90 : sec2str(ifinfo
->expire
.tv_sec
- now
.tv_sec
));
92 fprintf(fp
, " number of valid RAs: %d\n", ifinfo
->racnt
);
97 rtsold_dump_file(const char *dumpfile
)
99 if ((fp
= fopen(dumpfile
, "w")) == NULL
) {
100 warnmsg(LOG_WARNING
, __func__
, "open a dump file(%s): %s",
101 dumpfile
, strerror(errno
));
104 dump_interface_status();
109 sec2str(time_t total
)
111 static char result
[256];
112 int days
, hours
, mins
, secs
;
115 char *ep
= &result
[sizeof(result
)];
118 days
= total
/ 3600 / 24;
119 hours
= (total
/ 3600) % 24;
120 mins
= (total
/ 60) % 60;
125 n
= snprintf(p
, ep
- p
, "%dd", days
);
126 if (n
< 0 || n
>= ep
- p
)
130 if (!first
|| hours
) {
132 n
= snprintf(p
, ep
- p
, "%dh", hours
);
133 if (n
< 0 || n
>= ep
- p
)
137 if (!first
|| mins
) {
139 n
= snprintf(p
, ep
- p
, "%dm", mins
);
140 if (n
< 0 || n
>= ep
- p
)
144 snprintf(p
, ep
- p
, "%ds", secs
);