All pastes #458284 Raw Edit

Miscellany

public text v1 · immutable
#458284 ·published 2007-04-25 20:17 UTC
rendered paste body
BOOL PrivateIP(const char *ip) {
        if (ip) {
                if (strcmp(ip, "") != 0) {
                        char *token, ipbuf[32];
                        strncpy(ipbuf, ip, sizeof(ipbuf));
                        if ((token=strtok(ipbuf, ".")) != NULL) {
                                int ip1 = atoi(token);
                                if ((token=strtok(NULL, ".")) != NULL) {
                                        int ip2 = atoi(token);

                                        if ((ip1 == 10)                                 // Class A Private Network
                                                || (ip1 == 172 && ip2 > 15 && ip2 < 32) // Class B Private Network
                                                || (ip1 == 192 && ip2 == 168))          // Class C Private Network
                                                return TRUE;
                                }
                        }
                }
        }
        return FALSE;
}