diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2014-10-14 21:53:48 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-11-04 00:37:21 -0500 |
commit | 2f1068e68a95a2ad9ba058297b54622323b216c6 (patch) | |
tree | 1d992a4164414e0740df2a7a2504c1f39f282c48 | |
parent | 2862b769deaaaa40347ffe808349c4e139e7eb45 (diff) | |
download | tor-2f1068e68a95a2ad9ba058297b54622323b216c6.tar.gz tor-2f1068e68a95a2ad9ba058297b54622323b216c6.zip |
Adding helper function that checks if string is a valid IPv6 address.
-rw-r--r-- | src/common/util.c | 11 | ||||
-rw-r--r-- | src/common/util.h | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index ba9d78afac..e9ee437190 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -968,6 +968,17 @@ string_is_valid_ipv4_address(const char *string) return (tor_inet_pton(AF_INET,string,&sockaddr) == 1); } +/** Return true if <b>string</b> represents a valid IPv6 address in + * a form that inet_pton() can parse. + */ +int +string_is_valid_ipv6_address(const char *string) +{ + struct sockaddr_in sockaddr_dummy; + + return (inet_pton(AF_INET6,string,&sockaddr_dummy) == 1); +} + /** Return true iff <b>string</b> matches a pattern of DNS names * that we allow Tor clients to connect to. */ diff --git a/src/common/util.h b/src/common/util.h index dcb54f0aea..5eecfada28 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -229,6 +229,7 @@ int string_is_C_identifier(const char *string); int string_is_key_value(int severity, const char *string); int string_is_valid_hostname(const char *string); int string_is_valid_ipv4_address(const char *string); +int string_is_valid_ipv6_address(const char *string); int tor_mem_is_zero(const char *mem, size_t len); int tor_digest_is_zero(const char *digest); |