[pptp-server] pppd netmask problem - can we track it down?

tmk tmk at netmagic.net
Wed Jul 14 17:43:11 CDT 1999


I looked at the code, and there's nothing wrong with it. I took the
liberty of commenting it fully and attaching it to this message. 

I fear that the problem with the ppp netmask is that this particlar bit of
code isn't getting called, or the results aren't being used. What seems to
happen is that a netmask of 255.255.0.0 is usually given out, no matter
what you tell it to do. It supposedly guesses the netmask based on the ip
you give it (ie 172.16.x.x gives 255.255.0.0 because that's how the
reserved IP RFC tells it) but that feature seems broken.

anyhow, for your learning pleasure ;) the explained code you sent earlier
is attached.

Kevin
-------------- next part --------------
/*
 * setnetmask - set the netmask to be used on the interface.
 */
static int
setnetmask(argv)
    char **argv;
{
    u_int32_t mask, b;
    int n, ok;
    char *p, *endp;

    /*
     * Unfortunately, if we use inet_addr, we can't tell whether
     * a result of all 1s is an error or a valid 255.255.255.255.
     */
    p = *argv;
    ok = 0;
    mask = 0;
    for (n = 3;; --n) {
     //returns the first section of an IP (ie x in x.y.z.a) and sets 
     // endp to the dot after the x.
     b = strtoul(p, &endp, 0);
     if (endp == p)
       break; //invalid string
     if (b < 0 || b > 255) {  //this case the user gave the netmask in hex
       if (n == 3) {
         /* accept e.g. 0xffffff00 */
         p = endp;
         mask = b;
       }
       break;
     }
     mask |= b << (n * 8); //shift and OR the number with the netmask
     p = endp;
     if (*p != '.' || n == 0) //get ready for the next one
       break;
     ++p;
    }

    mask = htonl(mask);

    //p must point to the null terminator of the string, and 
    // the bits of netmask (whatever that is) must intersect with the 
    // bits of the user defined one, or else error.
    if (*p != 0 || (netmask & ~mask) != 0) {
      option_error("invalid netmask value '%s'", *argv);
      return 0;
    }

    netmask = mask;
    return (1);
}



More information about the pptp-server mailing list