[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Adding helper function that checks if string is a valid IPv6 address.



commit 2f1068e68a95a2ad9ba058297b54622323b216c6
Author: rl1987 <rl1987@xxxxxxxxxxxxxxxx>
Date:   Tue Oct 14 21:53:48 2014 +0300

    Adding helper function that checks if string is a valid IPv6 address.
---
 src/common/util.c |   11 +++++++++++
 src/common/util.h |    1 +
 2 files changed, 12 insertions(+)

diff --git a/src/common/util.c b/src/common/util.c
index ba9d78a..e9ee437 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 dcb54f0..5eecfad 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);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits