summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-11 07:44:53 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-11 07:44:53 +0000
commitff955766d496954140ed9c72ac0be898cbb913da (patch)
tree170698375f640f27aef59accf92018bb93aac7c8
parentf23292afb45db6a52e8e4949620162a230a2eea7 (diff)
* ext/socket/ancdata.c (ancillary_s_ip_pktinfo): make 3rd argument
optional. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22232 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/socket/ancdata.c15
-rw-r--r--test/socket/test_ancdata.rb2
3 files changed, 19 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 00bad3641b..24ddce1a89 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Feb 11 16:44:20 2009 Tanaka Akira <akr@fsij.org>
+
+ * ext/socket/ancdata.c (ancillary_s_ip_pktinfo): make 3rd argument
+ optional.
+
Wed Feb 11 15:47:10 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (ary_make_shared): returns shared root array itself, and
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index 0313955a9f..b2c246260d 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -221,10 +221,13 @@ ancillary_int(VALUE self)
/*
* call-seq:
+ * Socket::AncillaryData.ip_pktinfo(addr, ifindex) => ancdata
* Socket::AncillaryData.ip_pktinfo(addr, ifindex, spec_dst) => ancdata
*
* Returns new ancillary data for IP_PKTINFO.
*
+ * If spec_dst is not given, addr is used.
+ *
* IP_PKTINFO is not standard.
*
* Supported platform: GNU/Linux
@@ -237,16 +240,22 @@ ancillary_int(VALUE self)
*
*/
static VALUE
-ancillary_s_ip_pktinfo(VALUE self, VALUE v_addr, VALUE v_ifindex, VALUE v_spec_dst)
+ancillary_s_ip_pktinfo(int argc, VALUE *argv, VALUE self)
{
#if defined(IPPROTO_IP) && defined(IP_PKTINFO) && defined(HAVE_TYPE_STRUCT_IN_PKTINFO) /* GNU/Linux */
+ VALUE v_addr, v_ifindex, v_spec_dst;
unsigned int ifindex;
struct sockaddr_in sa;
struct in_pktinfo pktinfo;
+ rb_scan_args(argc, argv, "21", &v_addr, &v_ifindex, &v_spec_dst);
+
SockAddrStringValue(v_addr);
ifindex = NUM2UINT(v_ifindex);
- SockAddrStringValue(v_spec_dst);
+ if (NIL_P(v_spec_dst))
+ v_spec_dst = v_addr;
+ else
+ SockAddrStringValue(v_spec_dst);
memset(&pktinfo, 0, sizeof(pktinfo));
@@ -1322,7 +1331,7 @@ 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, 3);
+ rb_define_singleton_method(rb_cAncillaryData, "ip_pktinfo", ancillary_s_ip_pktinfo, -1);
rb_define_method(rb_cAncillaryData, "ip_pktinfo", ancillary_ip_pktinfo, 0);
rb_define_singleton_method(rb_cAncillaryData, "ipv6_pktinfo", ancillary_s_ipv6_pktinfo, 2);
rb_define_method(rb_cAncillaryData, "ipv6_pktinfo", ancillary_ipv6_pktinfo, 0);
diff --git a/test/socket/test_ancdata.rb b/test/socket/test_ancdata.rb
index f0ce09638f..8ba7fad2f0 100644
--- a/test/socket/test_ancdata.rb
+++ b/test/socket/test_ancdata.rb
@@ -29,6 +29,8 @@ class TestSocketAncData < Test::Unit::TestCase
if defined? Socket::IPV6_PKTINFO
assert(!ancdata.cmsg_is?(:IPV6, :PKTINFO))
end
+ ancdata2 = Socket::AncillaryData.ip_pktinfo(addr, ifindex)
+ assert_equal(addr.ip_address, ancdata2.ip_pktinfo[2].ip_address)
end
def test_ipv6_pktinfo