On Tue, 4 Dec 2007 14:58:18 +0100
Andreas Henriksson <[EMAIL PROTECTED]> wrote:

> Suggested patch for allowing netmask to be specified in dotted quad format.
> See http://bugs.debian.org/357172
> 
> (Known problem: this will not prevent some invalid syntaxes,
> ie. "255.0.255.0" will be treated as "255.255.255.0")
> 
> Comments? Suggestions? Improvements?

Fix the bug you mentioned?

/* a valid netmask must be 2^n - 1 (n = 1..31) */
static int is_valid_netmask(const inet_prefix *addr)
{
        uint32_t host;

        if (addr->family != AF_INET)
                return 0;

        host = ~ntohl(addr->data[0]);
        if (host == 0 || ~host == 0)
                return 0;

        return (host & (host + 1)) == 0;
}
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to