| 1474 | |
| 1475 | #ifndef FSTACK |
| 1476 | static void |
| 1477 | interfaces(void) |
| 1478 | { |
| 1479 | size_t needed; |
| 1480 | int mib[6]; |
| 1481 | char *buf, *lim, *next, count = 0; |
| 1482 | struct rt_msghdr *rtm; |
| 1483 | |
| 1484 | retry2: |
| 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 | |
| 1512 | static void |
| 1513 | monitor(int argc, char *argv[]) |
no test coverage detected