Deleted Added
full compact
route.c (186119) route.c (193232)
1/*-
2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 24 unchanged lines hidden (view full) ---

33
34#if 0
35#ifndef lint
36static char sccsid[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95";
37#endif /* not lint */
38#endif
39
40#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 24 unchanged lines hidden (view full) ---

33
34#if 0
35#ifndef lint
36static char sccsid[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95";
37#endif /* not lint */
38#endif
39
40#include <sys/cdefs.h>
41__FBSDID("$FreeBSD: head/usr.bin/netstat/route.c 186119 2008-12-15 06:10:57Z qingli $");
41__FBSDID("$FreeBSD: head/usr.bin/netstat/route.c 193232 2009-06-01 15:49:42Z bz $");
42
43#include <sys/param.h>
44#include <sys/protosw.h>
45#include <sys/socket.h>
46#include <sys/socketvar.h>
47#include <sys/time.h>
48
49#include <net/ethernet.h>

--- 67 unchanged lines hidden (view full) ---

117
118static sa_u pt_u;
119
120int fibnum;
121int do_rtent = 0;
122struct rtentry rtentry;
123struct radix_node rnode;
124struct radix_mask rmask;
42
43#include <sys/param.h>
44#include <sys/protosw.h>
45#include <sys/socket.h>
46#include <sys/socketvar.h>
47#include <sys/time.h>
48
49#include <net/ethernet.h>

--- 67 unchanged lines hidden (view full) ---

117
118static sa_u pt_u;
119
120int fibnum;
121int do_rtent = 0;
122struct rtentry rtentry;
123struct radix_node rnode;
124struct radix_mask rmask;
125struct rtline {
126 struct radix_node_head *tables[AF_MAX+1]; /*xxx*/
127};
128struct rtline *rt_tables;
125struct radix_node_head **rt_tables;
129
126
130struct radix_node_head *rt_tables_line[1][AF_MAX+1]; /*xxx*/
131
132int NewTree = 0;
133
134struct timespec uptime;
135
136static struct sockaddr *kgetsa(struct sockaddr *);
137static void size_cols(int ef, struct radix_node *rn);
138static void size_cols_tree(struct radix_node *rn);
139static void size_cols_rtentry(struct rtentry *rt);

--- 10 unchanged lines hidden (view full) ---

150static void domask(char *, in_addr_t, u_long);
151
152/*
153 * Print routing tables.
154 */
155void
156routepr(u_long rtree)
157{
127int NewTree = 0;
128
129struct timespec uptime;
130
131static struct sockaddr *kgetsa(struct sockaddr *);
132static void size_cols(int ef, struct radix_node *rn);
133static void size_cols_tree(struct radix_node *rn);
134static void size_cols_rtentry(struct rtentry *rt);

--- 10 unchanged lines hidden (view full) ---

145static void domask(char *, in_addr_t, u_long);
146
147/*
148 * Print routing tables.
149 */
150void
151routepr(u_long rtree)
152{
158 struct radix_node_head *rnh, head;
153 struct radix_node_head **rnhp, *rnh, head;
159 size_t intsize;
160 int i;
161 int numfibs;
162
163 intsize = sizeof(int);
164 if (sysctlbyname("net.my_fibnum", &fibnum, &intsize, NULL, 0) == -1)
165 fibnum = 0;
166 if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1)
167 numfibs = 1;
154 size_t intsize;
155 int i;
156 int numfibs;
157
158 intsize = sizeof(int);
159 if (sysctlbyname("net.my_fibnum", &fibnum, &intsize, NULL, 0) == -1)
160 fibnum = 0;
161 if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1)
162 numfibs = 1;
168 rt_tables = calloc(numfibs, sizeof(struct rtline));
163 rt_tables = calloc(numfibs * (AF_MAX+1),
164 sizeof(struct radix_node_head *));
169 if (rt_tables == NULL)
170 err(EX_OSERR, "memory allocation failed");
171 /*
172 * Since kernel & userland use different timebase
173 * (time_uptime vs time_second) and we are reading kernel memory
174 * directly we should do rt_rmx.rmx_expire --> expire_time conversion.
175 */
176 if (clock_gettime(CLOCK_UPTIME, &uptime) < 0)

--- 4 unchanged lines hidden (view full) ---

181 if (Aflag == 0 && NewTree)
182 ntreestuff();
183 else {
184 if (rtree == 0) {
185 printf("rt_tables: symbol not in namelist\n");
186 return;
187 }
188
165 if (rt_tables == NULL)
166 err(EX_OSERR, "memory allocation failed");
167 /*
168 * Since kernel & userland use different timebase
169 * (time_uptime vs time_second) and we are reading kernel memory
170 * directly we should do rt_rmx.rmx_expire --> expire_time conversion.
171 */
172 if (clock_gettime(CLOCK_UPTIME, &uptime) < 0)

--- 4 unchanged lines hidden (view full) ---

177 if (Aflag == 0 && NewTree)
178 ntreestuff();
179 else {
180 if (rtree == 0) {
181 printf("rt_tables: symbol not in namelist\n");
182 return;
183 }
184
189 if (kread((u_long)(rtree), (char *)(rt_tables),
190 (numfibs * sizeof(struct rtline))) != 0)
185 if (kread((u_long)(rtree), (char *)(rt_tables), (numfibs *
186 (AF_MAX+1) * sizeof(struct radix_node_head *))) != 0)
191 return;
192 for (i = 0; i <= AF_MAX; i++) {
193 int tmpfib;
194 if (i != AF_INET)
195 tmpfib = 0;
196 else
197 tmpfib = fibnum;
187 return;
188 for (i = 0; i <= AF_MAX; i++) {
189 int tmpfib;
190 if (i != AF_INET)
191 tmpfib = 0;
192 else
193 tmpfib = fibnum;
198 if ((rnh = rt_tables[tmpfib].tables[i]) == 0)
194 rnhp = (struct radix_node_head **)*rt_tables;
195 /* Calculate the in-kernel address. */
196 rnhp += tmpfib * (AF_MAX+1) + i;
197 /* Read the in kernel rhn pointer. */
198 if (kget(rnhp, rnh) != 0)
199 continue;
199 continue;
200 if (rnh == NULL)
201 continue;
202 /* Read the rnh data. */
200 if (kget(rnh, head) != 0)
201 continue;
202 if (i == AF_UNSPEC) {
203 if (Aflag && af == 0) {
204 printf("Netmasks:\n");
205 p_tree(head.rnh_treetop);
206 }
207 } else if (af == AF_UNSPEC || af == i) {

--- 919 unchanged lines hidden ---
203 if (kget(rnh, head) != 0)
204 continue;
205 if (i == AF_UNSPEC) {
206 if (Aflag && af == 0) {
207 printf("Netmasks:\n");
208 p_tree(head.rnh_treetop);
209 }
210 } else if (af == AF_UNSPEC || af == i) {

--- 919 unchanged lines hidden ---