X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=miscutil.c;fp=miscutil.c;h=fe0cd9b53fc921d4dbc317a1c950259f54cb8e31;hp=831f3c5d60f2a2c51ada6c6343b5e3d719f9f66f;hb=6d67d8973b484f5a781fd46a04dc2410b769f970;hpb=1547dac5126fa35db78b737af31f3c2044173881 diff --git a/miscutil.c b/miscutil.c index 831f3c5d..fe0cd9b5 100644 --- a/miscutil.c +++ b/miscutil.c @@ -1002,6 +1002,49 @@ time_t timegm(struct tm *tm) #endif /* !defined(HAVE_TIMEGM) && defined(HAVE_TZSET) && defined(HAVE_PUTENV) */ +/********************************************************************* + * + * Function : host_is_ip_address + * + * Description : Checks whether or not a host is specified by + * IP address. Does not actually validate the + * address. + * + * Parameters : + * 1 : host = The host name to check + * + * Returns : 1 => Yes + * 0 => No + * + *********************************************************************/ +extern int host_is_ip_address(const char *host) +{ + const char *p; + + if (NULL != strstr(host, ":")) + { + /* Assume an IPv6 address. */ + return 1; + } + + for (p = host; *p; p++) + { + if ((*p != '.') && !privoxy_isdigit(*p)) + { + /* Not a dot or digit so it can't be an IPv4 address. */ + return 0; + } + } + + /* + * Host only consists of dots and digits so + * assume that is an IPv4 address. + */ + return 1; + +} + + /* Local Variables: tab-width: 3