summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--ext/socket/raddrinfo.c13
-rw-r--r--ext/socket/rubysocket.h4
-rw-r--r--test/socket/test_addrinfo.rb3
4 files changed, 28 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index f9172f419a..10da419ac6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Fri Jul 20 09:32:14 2012 Eric Hodel <drbrain@segment7.net>
+
+ * ext/socket/raddrinfo.c (addrinfo_ipv6_unique_local_p): Added
+ Addrinfo#ipv6_unique_local? to detect RFC 4193 unique local
+ addresses. Part of #6692
+ * ext/socket/rubysocket.h: Add IN6_IS_ADDR_UNIQUE_LOCAL macro if
+ missing.
+ * test/socket/test_addrinfo.rb: Test for ipv6_unqiue_local?
+
Fri Jul 20 07:40:32 2012 Eric Hodel <drbrain@segment7.net>
* lib/net/http/response.rb: Automatically inflate gzip and
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index eeb7f78f45..6a5129efa8 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -1793,6 +1793,18 @@ addrinfo_ipv6_sitelocal_p(VALUE self)
}
/*
+ * Returns true for IPv6 unique local address (fc00::/7, RFC4193).
+ * It returns false otherwise.
+ */
+static VALUE
+addrinfo_ipv6_unique_local_p(VALUE self)
+{
+ struct in6_addr *addr = extract_in6_addr(self);
+ if (addr && IN6_IS_ADDR_UNIQUE_LOCAL(addr)) return Qtrue;
+ return Qfalse;
+}
+
+/*
* Returns true for IPv4-mapped IPv6 address (::ffff:0:0/80).
* It returns false otherwise.
*/
@@ -2207,6 +2219,7 @@ rsock_init_addrinfo(void)
rb_define_method(rb_cAddrinfo, "ipv6_multicast?", addrinfo_ipv6_multicast_p, 0);
rb_define_method(rb_cAddrinfo, "ipv6_linklocal?", addrinfo_ipv6_linklocal_p, 0);
rb_define_method(rb_cAddrinfo, "ipv6_sitelocal?", addrinfo_ipv6_sitelocal_p, 0);
+ rb_define_method(rb_cAddrinfo, "ipv6_unique_local?", addrinfo_ipv6_unique_local_p, 0);
rb_define_method(rb_cAddrinfo, "ipv6_v4mapped?", addrinfo_ipv6_v4mapped_p, 0);
rb_define_method(rb_cAddrinfo, "ipv6_v4compat?", addrinfo_ipv6_v4compat_p, 0);
rb_define_method(rb_cAddrinfo, "ipv6_mc_nodelocal?", addrinfo_ipv6_mc_nodelocal_p, 0);
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h
index bbc8249f00..33cb51a5c9 100644
--- a/ext/socket/rubysocket.h
+++ b/ext/socket/rubysocket.h
@@ -117,6 +117,10 @@
# define IS_IP_FAMILY(af) ((af) == AF_INET)
#endif
+#ifndef IN6_IS_ADDR_UNIQUE_LOCAL
+# define IN6_IS_ADDR_UNIQUE_LOCAL(a) (((a)->s6_addr[0] == 0xfc) || ((a)->s6_addr[0] == 0xfd))
+#endif
+
#ifndef HAVE_SOCKADDR_STORAGE
/*
* RFC 2553: protocol-independent placeholder for socket addresses
diff --git a/test/socket/test_addrinfo.rb b/test/socket/test_addrinfo.rb
index 3240b9d814..8870fe5e3d 100644
--- a/test/socket/test_addrinfo.rb
+++ b/test/socket/test_addrinfo.rb
@@ -512,7 +512,8 @@ class TestSocketAddrinfo < Test::Unit::TestCase
[:ipv6_v4mapped?, "::ffff:0.0.0.0", "::ffff:255.255.255.255"],
[:ipv6_linklocal?, "fe80::", "febf::"],
[:ipv6_sitelocal?, "fec0::", "feef::"],
- [:ipv6_multicast?, "ff00::", "ffff::"]
+ [:ipv6_multicast?, "ff00::", "ffff::"],
+ [:ipv6_unique_local?, "fc00::", "fd00::"],
]
mlist = [
[:ipv6_mc_nodelocal?, "ff01::", "ff11::"],