summaryrefslogtreecommitdiff
path: root/ext/socket/option.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-25 09:29:24 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-25 09:29:24 +0000
commit1b40391d3d41ed361bae41896315e18fc77ba759 (patch)
treee357e98270dc45d11efc89fdb4907278242ef9dd /ext/socket/option.c
parent08d99ac9e35ddcd22885303306116cb10c6a992c (diff)
* ext/socket/option.c (inspect_ipv6_mreq): new function to inspect
struct ipv6_mreq for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. Socket::Option.new(:INET6, :IPV6, :JOIN_GROUP, [0xff12,0,0,0,0,0,0,1, 2].pack("nnnnnnnnI!")).inspect is now: "#<Socket::Option: INET6 IPV6 JOIN_GROUP ff12::1 eth0>" * ext/socket/extconf.rb: check struct ipv6_mreq. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/option.c')
-rw-r--r--ext/socket/option.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/ext/socket/option.c b/ext/socket/option.c
index 6d437db..6ebe6c7 100644
--- a/ext/socket/option.c
+++ b/ext/socket/option.c
@@ -396,6 +396,30 @@ inspect_timeval_as_interval(int level, int optname, VALUE data, VALUE ret)
}
}
+#if defined(IPPROTO_IPV6) && defined(HAVE_TYPE_STRUCT_IPV6_MREQ) /* POSIX, RFC 3493 */
+static int
+inspect_ipv6_mreq(int level, int optname, VALUE data, VALUE ret)
+{
+ if (RSTRING_LEN(data) == sizeof(struct ipv6_mreq)) {
+ struct ipv6_mreq s;
+ char addrbuf[INET6_ADDRSTRLEN], ifbuf[IFNAMSIZ];
+ memcpy((char*)&s, RSTRING_PTR(data), sizeof(s));
+ if (inet_ntop(AF_INET6, &s.ipv6mr_multiaddr, addrbuf, (socklen_t)sizeof(addrbuf)) == NULL)
+ rb_str_cat2(ret, " invalid-address");
+ else
+ rb_str_catf(ret, " %s", addrbuf);
+ if (if_indextoname(s.ipv6mr_interface, ifbuf) == NULL)
+ rb_str_catf(ret, " interface:%u", s.ipv6mr_interface);
+ else
+ rb_str_catf(ret, " %s", ifbuf);
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+#endif
+
#if defined(SOL_SOCKET) && defined(SO_PEERCRED) /* GNU/Linux, OpenBSD */
#if defined(__OpenBSD__)
#define RUBY_SOCK_PEERCRED struct sockpeercred
@@ -590,7 +614,6 @@ sockopt_inspect(VALUE self)
# if defined(IPPROTO_IPV6)
case IPPROTO_IPV6:
switch (optname) {
- /* IPV6_JOIN_GROUP ipv6_mreq, IPV6_LEAVE_GROUP ipv6_mreq */
# if defined(IPV6_MULTICAST_HOPS) /* POSIX */
case IPV6_MULTICAST_HOPS: inspected = inspect_int(level, optname, data, ret); break;
# endif
@@ -600,6 +623,12 @@ sockopt_inspect(VALUE self)
# if defined(IPV6_MULTICAST_LOOP) /* POSIX */
case IPV6_MULTICAST_LOOP: inspected = inspect_uint(level, optname, data, ret); break;
# endif
+# if defined(IPV6_JOIN_GROUP) /* POSIX */
+ case IPV6_JOIN_GROUP: inspected = inspect_ipv6_mreq(level, optname, data, ret); break;
+# endif
+# if defined(IPV6_LEAVE_GROUP) /* POSIX */
+ case IPV6_LEAVE_GROUP: inspected = inspect_ipv6_mreq(level, optname, data, ret); break;
+# endif
# if defined(IPV6_UNICAST_HOPS) /* POSIX */
case IPV6_UNICAST_HOPS: inspected = inspect_int(level, optname, data, ret); break;
# endif