void inetroute_list_print(inetroute_list_t * list_p) { int i; for (i = 0; i < list_p->count; i++) { inetroute_t * entry = list_p->list + i; if (entry->gateway.link.sdl_family == AF_LINK) { printf("%s ==> link %d\n", inet_nettoa(entry->dest, entry->mask), entry->gateway.link.sdl_index); } else { printf("%s ==> %s\n", inet_nettoa(entry->dest, entry->mask), inet_ntoa(entry->gateway.inet.sin_addr)); } } }
static int putnetmask(const struct in_addr key, const struct in_addr netmask, FILE *fp) { int rc = 0; struct in_addr net; net.s_addr = ntohl(key.s_addr); if (fprintf(fp, "%-20s", inet_nettoa(net)) == EOF) rc = 1; if (fprintf(fp, " %s", inet_ntoa(netmask)) == EOF) rc = 1; if (putc('\n', fp) == EOF) rc = 1; return (rc); }
static int putnetent(const struct netent *np, FILE *fp) { char **p; int rc = 0; struct in_addr in; if (np == NULL) { return (1); } in.s_addr = np->n_net; if (fprintf(fp, "%-20s %s", np->n_name, inet_nettoa(in)) == EOF) rc = 1; for (p = np->n_aliases; *p != 0; p++) { if (fprintf(fp, " %s", *p) == EOF) rc = 1; } if (putc('\n', fp) == EOF) rc = 1; return (rc); }
/* * Given a 32 bit key look it up in the netmasks database * based on the "netmasks" policy in /etc/nsswitch.conf. * If the key is a network number with the trailing zero's removed * (e.g. "192.9.200") this routine can't use inet_ntoa to convert * the address to the string key. * Returns zero if successful, non-zero otherwise. */ static int getnetmaskbykey(const struct in_addr addr, struct in_addr *mask) { nss_XbyY_args_t arg; nss_status_t res; char tmp[NSS_LINELEN_NETMASKS]; /* * let the backend do the allocation to store stuff for parsing. * To simplify things, we put the dotted internet address form of * the network address in the 'name' field as a filter to speed * up the lookup. */ if (inet_nettoa(addr, tmp, NSS_LINELEN_NETMASKS) == NULL) return (NSS_NOTFOUND); NSS_XbyY_INIT(&arg, mask, NULL, 0, str2addr); arg.key.name = tmp; res = nss_search(&db_root, _nss_initf_netmasks, NSS_DBOP_NETMASKS_BYNET, &arg); (void) NSS_XbyY_FINI(&arg); return (arg.status = res); }