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

Function interfaces

tools/route/route.c:1476–1510  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1474
1475#ifndef FSTACK
1476static void
1477interfaces(void)
1478{
1479 size_t needed;
1480 int mib[6];
1481 char *buf, *lim, *next, count = 0;
1482 struct rt_msghdr *rtm;
1483
1484retry2:
1485 mib[0] = CTL_NET;
1486 mib[1] = PF_ROUTE;
1487 mib[2] = 0; /* protocol */
1488 mib[3] = AF_UNSPEC;
1489 mib[4] = NET_RT_IFLIST;
1490 mib[5] = 0; /* no flags */
1491 if (sysctl(mib, nitems(mib), NULL, &needed, NULL, 0) < 0)
1492 err(EX_OSERR, "route-sysctl-estimate");
1493 if ((buf = malloc(needed)) == NULL)
1494 errx(EX_OSERR, "malloc failed");
1495 if (sysctl(mib, nitems(mib), buf, &needed, NULL, 0) < 0) {
1496 if (errno == ENOMEM && count++ < 10) {
1497 warnx("Routing table grew, retrying");
1498 sleep(1);
1499 free(buf);
1500 goto retry2;
1501 }
1502 err(EX_OSERR, "actual retrieval of interface table");
1503 }
1504 lim = buf + needed;
1505 for (next = buf; next < lim; next += rtm->rtm_msglen) {
1506 rtm = (struct rt_msghdr *)(void *)next;
1507 print_rtmsg(rtm, rtm->rtm_msglen);
1508 }
1509 free(buf);
1510}
1511
1512static void
1513monitor(int argc, char *argv[])

Callers 1

monitorFunction · 0.85

Calls 4

sysctlFunction · 0.85
mallocFunction · 0.85
print_rtmsgFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected