1 /* $KAME: dump.c,v 1.8 2000/10/05 22:20:39 itojun Exp $ */
4 * Copyright (C) 1999 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * $FreeBSD: src/usr.sbin/rtsold/dump.c,v 1.1.2.3 2001/07/03 11:02:16 ume Exp $
32 * $DragonFly: src/usr.sbin/rtsold/dump.c,v 1.5 2005/02/17 14:00:10 joerg Exp $
35 #include <sys/types.h>
37 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <netinet/icmp6.h>
53 extern struct ifinfo *iflist;
55 static void dump_interface_status(void);
56 static char *sec2str(time_t);
57 const char *ifstatstr[] = {"IDLE", "DELAY", "PROBE", "DOWN", "TENTATIVE"};
60 dump_interface_status()
62 struct ifinfo *ifinfo;
65 gettimeofday(&now, NULL);
67 for (ifinfo = iflist; ifinfo; ifinfo = ifinfo->next) {
68 fprintf(fp, "Interface %s\n", ifinfo->ifname);
69 fprintf(fp, " probe interval: ");
70 if (ifinfo->probeinterval) {
71 fprintf(fp, "%d\n", ifinfo->probeinterval);
72 fprintf(fp, " probe timer: %d\n", ifinfo->probetimer);
75 fprintf(fp, "infinity\n");
76 fprintf(fp, " no probe timer\n");
78 fprintf(fp, " interface status: %s\n",
79 ifinfo->active > 0 ? "active" : "inactive");
80 fprintf(fp, " rtsold status: %s\n", ifstatstr[ifinfo->state]);
81 fprintf(fp, " carrier detection: %s\n",
82 ifinfo->mediareqok ? "available" : "unavailable");
83 fprintf(fp, " probes: %d, dadcount = %d\n",
84 ifinfo->probes, ifinfo->dadcount);
85 if (ifinfo->timer.tv_sec == tm_max.tv_sec &&
86 ifinfo->timer.tv_usec == tm_max.tv_usec)
87 fprintf(fp, " no timer\n");
89 fprintf(fp, " timer: interval=%d:%d, expire=%s\n",
90 (int)ifinfo->timer.tv_sec,
91 (int)ifinfo->timer.tv_usec,
92 (ifinfo->expire.tv_sec < now.tv_sec) ? "expired"
93 : sec2str(ifinfo->expire.tv_sec - now.tv_sec));
95 fprintf(fp, " number of valid RAs: %d\n", ifinfo->racnt);
100 rtsold_dump_file(const char *dumpfile)
102 if ((fp = fopen(dumpfile, "w")) == NULL) {
103 warnmsg(LOG_WARNING, __func__, "open a dump file(%s): %s",
104 dumpfile, strerror(errno));
108 dump_interface_status();
117 static char result[256];
118 int days, hours, mins, secs;
122 days = total / 3600 / 24;
123 hours = (total / 3600) % 24;
124 mins = (total / 60) % 60;
129 p += sprintf(p, "%dd", days);
131 if (!first || hours) {
133 p += sprintf(p, "%dh", hours);
135 if (!first || mins) {
137 p += sprintf(p, "%dm", mins);
139 sprintf(p, "%ds", secs);