/* * Show IPv4/6 or ARP entries from the routing table */ int conf_routes(FILE *output, char *delim, int af, int flags) { char *next; struct rt_msghdr *rtm; struct rtdump *rtdump; rtdump = getrtdump(0, flags, 0); if (rtdump == NULL) { return(-1); } /* walk through routing table */ for (next = rtdump->buf; next < rtdump->lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; if ((rtm->rtm_flags & flags) == 0) continue; if (!rtm->rtm_errno) { if (rtm->rtm_addrs) conf_print_rtm(output, rtm, delim, af); } else if (verbose) printf("%% conf_routes: rtm: %s (errno %d)\n", strerror(rtm->rtm_errno), rtm->rtm_errno); } freertdump(rtdump); return(1); }
/* * Show IPv4/6 or ARP entries from the routing table */ int conf_routes(FILE *output, char *delim, int af, int flags, int tableid) { char *next; struct rt_msghdr *rtm; struct rtdump *rtdump; struct sockaddr *sa; if (tableid < 0 || tableid > RT_TABLEID_MAX) { printf("%% conf_routes: tableid %d out of range\n", tableid); return(1); } rtdump = getrtdump(0, flags, tableid); if (rtdump == NULL) { printf("%% conf_routes: getrtdump failure\n"); return(1); } /* walk through routing table */ for (next = rtdump->buf; next < rtdump->lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; if (rtm->rtm_version != RTM_VERSION) continue; sa = (struct sockaddr *)(next + rtm->rtm_hdrlen); if (af != AF_UNSPEC && sa->sa_family != af) continue; if (!rtm->rtm_errno) { if (rtm->rtm_addrs) conf_print_rtm(output, rtm, delim, af); } else if (verbose) printf("%% conf_routes: rtm: %s (errno %d)\n", strerror(rtm->rtm_errno), rtm->rtm_errno); } freertdump(rtdump); return(1); }