From c7a66ff8043562c9d8e2cbb5c588b80d83ef1a90 Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 11 Feb 2009 03:56:13 +0000 Subject: * ext/socket/ancdata.c (anc_inspect_ip_pktinfo): make result bit succinct. (Init_ancdata): fix number of arguments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22223 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++ ext/socket/ancdata.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 102 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 318e2549ca..f97f3381f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Feb 11 12:55:07 2009 Tanaka Akira + + * ext/socket/ancdata.c (anc_inspect_ip_pktinfo): make result bit + succinct. + (Init_ancdata): fix number of arguments. + Wed Feb 11 11:47:41 2009 Tanaka Akira * ext/socket/ipsocket.c (Init_ipsocket): undef getpeereid at IPSocket. diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c index 7f55f3b4fd..e9b2eb6364 100644 --- a/ext/socket/ancdata.c +++ b/ext/socket/ancdata.c @@ -219,6 +219,23 @@ ancillary_int(VALUE self) return INT2NUM(i); } +/* + * call-seq: + * Socket::AncillaryData.ip_pktinfo(addr, ifindex, spec_dst) => ancdata + * + * Returns new ancillary data for IP_PKTINFO. + * + * IP_PKTINFO is not standard. + * + * Supported platform: GNU/Linux + * + * addr = Addrinfo.ip("127.0.0.1") + * ifindex = 0 + * spec_dst = Addrinfo.ip("127.0.0.1") + * p Socket::AncillaryData.ip_pktinfo(addr, ifindex, spec_dst) + * #=> # + * + */ static VALUE ancillary_s_ip_pktinfo(VALUE self, VALUE v_addr, VALUE v_ifindex, VALUE v_spec_dst) { @@ -257,6 +274,25 @@ ancillary_s_ip_pktinfo(VALUE self, VALUE v_addr, VALUE v_ifindex, VALUE v_spec_d #endif } +/* + * call-seq: + * ancdata.ip_pktinfo => [addr, ifindex, spec_dst] + * + * Extracts addr, ifindex and spec_dst from IP_PKTINFO ancillary data. + * + * IP_PKTINFO is not standard. + * + * Supported platform: GNU/Linux + * + * addr = Addrinfo.ip("127.0.0.1") + * ifindex = 0 + * spec_dest = Addrinfo.ip("127.0.0.1") + * ancdata = Socket::AncillaryData.ip_pktinfo(addr, ifindex, spec_dest) + * p ancdata.ip_pktinfo + * #=> [#, 0, #] + * + * + */ static VALUE ancillary_ip_pktinfo(VALUE self) { @@ -293,6 +329,20 @@ ancillary_ip_pktinfo(VALUE self) #endif } +/* + * call-seq: + * Socket::AncillaryData.ipv6_pktinfo(addr, ifindex) => ancdata + * + * Returns new ancillary data for IPV6_PKTINFO. + * + * IPV6_PKTINFO is defined by RFC 3542. + * + * addr = Addrinfo.ip("::1") + * ifindex = 0 + * p Socket::AncillaryData.ipv6_pktinfo(addr, ifindex) + * #=> # + * + */ static VALUE ancillary_s_ipv6_pktinfo(VALUE self, VALUE v_addr, VALUE v_ifindex) { @@ -348,6 +398,20 @@ extract_ipv6_pktinfo(VALUE self, struct in6_pktinfo *pktinfo_ptr, struct sockadd } #endif +/* + * call-seq: + * ancdata.ipv6_pktinfo => [addr, ifindex] + * + * Extracts addr and ifindex from IPV6_PKTINFO ancillary data. + * + * IPV6_PKTINFO is defined by RFC 3542. + * + * addr = Addrinfo.ip("::1") + * ifindex = 0 + * ancdata = Socket::AncillaryData.ipv6_pktinfo(addr, ifindex) + * p ancdata.ipv6_pktinfo #=> [#, 0] + * + */ static VALUE ancillary_ipv6_pktinfo(VALUE self) { @@ -364,6 +428,20 @@ ancillary_ipv6_pktinfo(VALUE self) #endif } +/* + * call-seq: + * ancdata.ipv6_pktinfo_addr => addr + * + * Extracts addr from IPV6_PKTINFO ancillary data. + * + * IPV6_PKTINFO is defined by RFC 3542. + * + * addr = Addrinfo.ip("::1") + * ifindex = 0 + * ancdata = Socket::AncillaryData.ipv6_pktinfo(addr, ifindex) + * p ancdata.ipv6_pktinfo_addr #=> # + * + */ static VALUE ancillary_ipv6_pktinfo_addr(VALUE self) { @@ -377,6 +455,20 @@ ancillary_ipv6_pktinfo_addr(VALUE self) #endif } +/* + * call-seq: + * ancdata.ipv6_pktinfo_ifindex => addr + * + * Extracts ifindex from IPV6_PKTINFO ancillary data. + * + * IPV6_PKTINFO is defined by RFC 3542. + * + * addr = Addrinfo.ip("::1") + * ifindex = 0 + * ancdata = Socket::AncillaryData.ipv6_pktinfo(addr, ifindex) + * p ancdata.ipv6_pktinfo_ifindex #=> 0 + * + */ static VALUE ancillary_ipv6_pktinfo_ifindex(VALUE self) { @@ -526,9 +618,9 @@ anc_inspect_ip_pktinfo(int level, int type, VALUE data, VALUE ret) char buf[INET_ADDRSTRLEN > IFNAMSIZ ? INET_ADDRSTRLEN : IFNAMSIZ]; memcpy(&pktinfo, RSTRING_PTR(data), sizeof(pktinfo)); if (inet_ntop(AF_INET, &pktinfo.ipi_addr, buf, sizeof(buf)) == NULL) - rb_str_cat2(ret, " addr:invalid-address"); + rb_str_cat2(ret, " invalid-address"); else - rb_str_catf(ret, " addr:%s", buf); + rb_str_catf(ret, " %s", buf); if (if_indextoname(pktinfo.ipi_ifindex, buf) == NULL) rb_str_catf(ret, " ifindex:%d", pktinfo.ipi_ifindex); else @@ -1201,9 +1293,9 @@ Init_ancdata(void) rb_define_method(rb_cAncillaryData, "cmsg_is?", ancillary_cmsg_is_p, 2); rb_define_singleton_method(rb_cAncillaryData, "int", ancillary_s_int, 4); rb_define_method(rb_cAncillaryData, "int", ancillary_int, 0); - rb_define_singleton_method(rb_cAncillaryData, "ip_pktinfo", ancillary_s_ip_pktinfo, 4); + rb_define_singleton_method(rb_cAncillaryData, "ip_pktinfo", ancillary_s_ip_pktinfo, 3); rb_define_method(rb_cAncillaryData, "ip_pktinfo", ancillary_ip_pktinfo, 0); - rb_define_singleton_method(rb_cAncillaryData, "ipv6_pktinfo", ancillary_s_ipv6_pktinfo, 3); + rb_define_singleton_method(rb_cAncillaryData, "ipv6_pktinfo", ancillary_s_ipv6_pktinfo, 2); rb_define_method(rb_cAncillaryData, "ipv6_pktinfo", ancillary_ipv6_pktinfo, 0); rb_define_method(rb_cAncillaryData, "ipv6_pktinfo_addr", ancillary_ipv6_pktinfo_addr, 0); rb_define_method(rb_cAncillaryData, "ipv6_pktinfo_ifindex", ancillary_ipv6_pktinfo_ifindex, 0); -- cgit v1.2.3