3 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
4 snprintf instead of sprintf
10 #include <asm/types.h>
11 #include <asm/param.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <arpa/inet.h>
16 #include <arpa/nameser.h>
17 /* #include <net/route.h> realy broken */
27 #include <netinet6/ipv6_route.h> /* glibc doesn't have this */
30 #include "net-support.h"
31 #include "pathnames.h"
33 #include "net-features.h"
35 /* neighbour discovery from linux-2.4.0/include/net/neighbour.h */
37 #define NUD_INCOMPLETE 0x01
38 #define NUD_REACHABLE 0x02
39 #define NUD_STALE 0x04
40 #define NUD_DELAY 0x08
41 #define NUD_PROBE 0x10
42 #define NUD_FAILED 0x20
44 #define NUD_NOARP 0x40
45 #define NUD_PERMANENT 0x80
48 #define NTF_PROXY 0x08 /* == ATF_PUBL */
49 #define NTF_ROUTER 0x80
50 #define NTF_02 0x02 /* waiting for answer of Alexey -eckes */
51 #define NTF_04 0x04 /* waiting for answer of Alexey -eckes */
56 extern struct aftype inet6_aftype;
59 int rprint_fib6(int ext, int numeric)
61 char buff[4096], iface[16], flags[16];
62 char addr6[128], naddr6[128];
63 struct sockaddr_in6 saddr6, snaddr6;
64 int num, iflags, metric, refcnt, use, prefix_len, slen;
65 FILE *fp = fopen(_PATH_PROCNET_ROUTE6, "r");
67 char addr6p[8][5], saddr6p[8][5], naddr6p[8][5];
70 perror(_PATH_PROCNET_ROUTE6);
71 printf(_("INET6 (IPv6) not configured in this system.\n"));
75 if (numeric & RTF_CACHE)
76 printf(_("Kernel IPv6 routing cache\n"));
78 printf(_("Kernel IPv6 routing table\n"));
80 printf(_("Destination "
82 "Flag Met Ref Use If\n"));
84 while (fgets(buff, 1023, fp)) {
85 num = sscanf(buff, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %4s%4s%4s%4s%4s%4s%4s%4s %02x %4s%4s%4s%4s%4s%4s%4s%4s %08x %08x %08x %08x %s\n",
86 addr6p[0], addr6p[1], addr6p[2], addr6p[3],
87 addr6p[4], addr6p[5], addr6p[6], addr6p[7],
89 saddr6p[0], saddr6p[1], saddr6p[2], saddr6p[3],
90 saddr6p[4], saddr6p[5], saddr6p[6], saddr6p[7],
92 naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3],
93 naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7],
94 &metric, &refcnt, &use, &iflags, iface);
99 if (iflags & RTF_CACHE) {
100 if (!(numeric & RTF_CACHE))
103 if (numeric & RTF_CACHE)
107 /* Fetch and resolve the target address. */
108 snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
109 addr6p[0], addr6p[1], addr6p[2], addr6p[3],
110 addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
111 inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6);
112 snprintf(addr6, sizeof(addr6), "%s/%d",
113 inet6_aftype.sprint((struct sockaddr *) &saddr6, 1),
116 /* Fetch and resolve the nexthop address. */
117 snprintf(naddr6, sizeof(naddr6), "%s:%s:%s:%s:%s:%s:%s:%s",
118 naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3],
119 naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7]);
120 inet6_aftype.input(1, naddr6, (struct sockaddr *) &snaddr6);
121 snprintf(naddr6, sizeof(naddr6), "%s",
122 inet6_aftype.sprint((struct sockaddr *) &snaddr6, 1));
124 /* Decode the flags. */
129 if (iflags & RTF_REJECT)
131 if (iflags & RTF_GATEWAY)
133 if (iflags & RTF_HOST)
135 if (iflags & RTF_DEFAULT)
137 if (iflags & RTF_ADDRCONF)
139 if (iflags & RTF_CACHE)
141 if (iflags & RTF_ALLONLINK)
143 if (iflags & RTF_EXPIRES)
145 if (iflags & RTF_MODIFIED)
147 if (iflags & RTF_NONEXTHOP)
149 if (iflags & RTF_FLOW)
152 /* Print the info. */
153 printf("%-30s %-26s %-4s %-3d %-1d%6d %s\n",
154 addr6, naddr6, flags, metric, refcnt, use, iface);
161 int rprint_cache6(int ext, int numeric)
163 char buff[4096], iface[16], flags[16];
164 char addr6[128], haddr[20], statestr[20];
165 struct sockaddr_in6 saddr6;
166 int type, num, refcnt, prefix_len, location, state, gc;
167 long tstamp, expire, ndflags, reachable, stale, delete;
168 FILE *fp = fopen(_PATH_PROCNET_NDISC, "r");
169 char addr6p[8][5], haddrp[6][3];
172 return rprint_fib6(ext, numeric | RTF_CACHE);
174 printf(_("Kernel IPv6 Neighbour Cache\n"));
177 printf(_("Neighbour "
179 "Iface Flags Ref State\n"));
181 printf(_("Neighbour "
183 "Iface Flags Ref State Stale(sec) Delete(sec)\n"));
186 while (fgets(buff, 1023, fp)) {
187 num = sscanf(buff, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %08lx %08lx %08lx %04x %04x %04lx %8s %2s%2s%2s%2s%2s%2s\n",
188 addr6p[0], addr6p[1], addr6p[2], addr6p[3],
189 addr6p[4], addr6p[5], addr6p[6], addr6p[7],
190 &location, &prefix_len, &type, &state, &expire, &tstamp, &reachable, &gc, &refcnt,
192 haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]);
194 /* Fetch and resolve the nexthop address. */
195 snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
196 addr6p[0], addr6p[1], addr6p[2], addr6p[3],
197 addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
198 inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6);
199 snprintf(addr6, sizeof(addr6), "%s/%d",
200 inet6_aftype.sprint((struct sockaddr *) &saddr6, numeric),
203 /* Fetch the hardware address. */
204 snprintf(haddr, sizeof(haddr), "%s:%s:%s:%s:%s:%s",
205 haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]);
207 /* Decode the flags. */
209 if (ndflags & NTF_ROUTER)
211 if (ndflags & NTF_04)
213 if (ndflags & NTF_02)
215 if (ndflags & NTF_PROXY)
218 /* Decode the state */
221 strcpy(statestr, "NONE");
224 strcpy(statestr, "INCOMPLETE");
227 strcpy(statestr, "REACHABLE");
230 strcpy(statestr, "STALE");
233 strcpy(statestr, "DELAY");
236 strcpy(statestr, "PROBE");
239 strcpy(statestr, "FAILED");
242 strcpy(statestr, "NOARP");
245 strcpy(statestr, "PERM");
248 snprintf(statestr, sizeof(statestr), "UNKNOWN(%02x)", state);
252 /* Print the info. */
253 printf("%-43s %-17s %-8s %-5s %-3d %-16s",
254 addr6, haddr, iface, flags, refcnt, statestr);
257 if (state == NUD_REACHABLE)
258 stale = reachable > tstamp ? reachable - tstamp : 0;
259 delete = gc > tstamp ? gc - tstamp : 0;
261 printf(" %-9ld ", stale / HZ);
265 printf(" %-7ld ", delete / HZ);
274 int INET6_rprint(int options)
276 int ext = options & FLAG_EXT;
277 int numeric = options & (FLAG_NUM_HOST | FLAG_SYM);
280 if (options & FLAG_FIB)
281 if ((rc = rprint_fib6(ext, numeric)))
284 if (options & FLAG_CACHE)
285 if ((rc = rprint_cache6(ext, numeric)))
290 #endif /* HAVE_AFINET6 */