/* * Given a host-order address, calculate client's default net mask. * Consult netmasks database to see if net is further subnetted. * We'll only snag the first netmask that matches our criteria. * We return the resultant netmask in host order. */ void get_netmask4(const struct in_addr *n_addrp, struct in_addr *s_addrp) { struct in_addr hp, tp; /* * First check if VLSM is in use. */ hp.s_addr = htonl(n_addrp->s_addr); if (getnetmaskbyaddr(hp, &tp) == 0) { s_addrp->s_addr = ntohl(tp.s_addr); return; } /* * Fall back on standard classed networks. */ if (IN_CLASSA(n_addrp->s_addr)) s_addrp->s_addr = IN_CLASSA_NET; else if (IN_CLASSB(n_addrp->s_addr)) s_addrp->s_addr = IN_CLASSB_NET; else if (IN_CLASSC(n_addrp->s_addr)) s_addrp->s_addr = IN_CLASSC_NET; else s_addrp->s_addr = IN_CLASSE_NET; }
/* * getnetmaskbyaddr - get entries from network database */ int dogetnetmask(const char **list) { int rc = EXC_SUCCESS; struct in_addr addr, netmask; if (list == NULL || *list == NULL) return (EXC_ENUM_NOT_SUPPORTED); for (; *list != NULL; list++) { addr.s_addr = htonl(inet_network(*list)); if (addr.s_addr != -1) { if (getnetmaskbyaddr(addr, &netmask) == 0) { (void) putnetmask(addr, netmask, stdout); } else { rc = EXC_NAME_NOT_FOUND; } } else { rc = EXC_NAME_NOT_FOUND; } } return (rc); }