MCPcopy Create free account
hub / github.com/F-Stack/f-stack / p_rtable_sysctl

Function p_rtable_sysctl

tools/netstat/route.c:244–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242}
243
244static void
245p_rtable_sysctl(int fibnum, int af)
246{
247 size_t needed;
248 int mib[7];
249 char *buf, *next, *lim;
250 struct rt_msghdr *rtm;
251 struct sockaddr *sa;
252 int fam = AF_UNSPEC;
253 int need_table_close = false;
254
255 ifmap = prepare_ifmap(&ifmap_size);
256
257 mib[0] = CTL_NET;
258 mib[1] = PF_ROUTE;
259 mib[2] = 0;
260 mib[3] = af;
261 mib[4] = NET_RT_DUMP;
262 mib[5] = 0;
263 mib[6] = fibnum;
264 if (sysctl(mib, nitems(mib), NULL, &needed, NULL, 0) < 0)
265 err(EX_OSERR, "sysctl: net.route.0.%d.dump.%d estimate", af,
266 fibnum);
267 if ((buf = malloc(needed)) == NULL)
268 errx(2, "malloc(%lu)", (unsigned long)needed);
269 if (sysctl(mib, nitems(mib), buf, &needed, NULL, 0) < 0)
270 err(1, "sysctl: net.route.0.%d.dump.%d", af, fibnum);
271 lim = buf + needed;
272 xo_open_container("route-table");
273 xo_open_list("rt-family");
274 for (next = buf; next < lim; next += rtm->rtm_msglen) {
275 rtm = (struct rt_msghdr *)next;
276 if (rtm->rtm_version != RTM_VERSION)
277 continue;
278 /*
279 * Peek inside header to determine AF
280 */
281 sa = (struct sockaddr *)(rtm + 1);
282 /* Only print family first time. */
283 if (fam != sa->sa_family) {
284 if (need_table_close) {
285 xo_close_list("rt-entry");
286 xo_close_instance("rt-family");
287 }
288 need_table_close = true;
289
290 fam = sa->sa_family;
291 wid_dst = WID_DST_DEFAULT(fam);
292 wid_gw = WID_GW_DEFAULT(fam);
293 wid_flags = 6;
294 wid_pksent = 8;
295 wid_mtu = 6;
296 wid_if = WID_IF_DEFAULT(fam);
297 wid_expire = 6;
298 xo_open_instance("rt-family");
299 pr_family(fam);
300 xo_open_list("rt-entry");
301

Callers 1

routeprFunction · 0.85

Calls 13

prepare_ifmapFunction · 0.85
sysctlFunction · 0.85
mallocFunction · 0.85
xo_open_containerFunction · 0.85
xo_open_listFunction · 0.85
xo_close_listFunction · 0.85
xo_close_instanceFunction · 0.85
xo_open_instanceFunction · 0.85
pr_familyFunction · 0.85
pr_rthdrFunction · 0.85
p_rtentry_sysctlFunction · 0.85
xo_close_containerFunction · 0.85

Tested by

no test coverage detected