--- interface.c (revision 260) +++ interface.c (working copy) @@ -885,7 +885,8 @@ else { nlm.hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL; nlm.rt.rtm_protocol = RTPROT_BOOT; - if (gateway.s_addr == INADDR_ANY) + if (gateway.s_addr == INADDR_ANY || + gateway.s_addr == destination.s_addr) nlm.rt.rtm_scope = RT_SCOPE_LINK; else nlm.rt.rtm_scope = RT_SCOPE_UNIVERSE; --- dhcp.c (revision 257) +++ dhcp.c (working copy) @@ -492,6 +492,33 @@ return (sip); } +/* This calculates the netmask that we should use for static routes. + * This IS different from the calculation used to calculate the netmask + * for an interface address. */ +static unsigned long route_netmask (unsigned long ip_in) +{ + unsigned long p = ntohl (ip_in); + unsigned long t; + + if (IN_CLASSA (p)) + t = ~IN_CLASSA_NET; + else { + if (IN_CLASSB (p)) + t = ~IN_CLASSB_NET; + else { + if (IN_CLASSC (p)) + t = ~IN_CLASSC_NET; + else + t = 0; + } + } + + while (t & p) + t >>= 1; + + return (htonl (~t)); +} + int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message) { const unsigned char *p = message->options; @@ -705,7 +732,7 @@ memcpy (&static_routesp->destination.s_addr, p + i, 4); memcpy (&static_routesp->gateway.s_addr, p + i + 4, 4); static_routesp->netmask.s_addr = - get_netmask (static_routesp->destination.s_addr); + route_netmask (static_routesp->destination.s_addr); } break;