summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-17 16:39:03 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-17 16:39:03 +0000
commite2f88006670866382c47efb8a10318d7ca0bcb1a (patch)
tree53261e416788e28c116a55d2dd71c5b28c0e03ed
parent858987b06bac789b9de8c1e99571ef1d2cd6845d (diff)
* ext/socket/socket.c (sock_s_getnameinfo): accept AddrInfo object.
* ext/socket/raddrinfo.c (rb_check_sockaddr_string_type): defined. * ext/socket/rubysocket.h (rb_check_sockaddr_string_type): declared. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--ext/socket/raddrinfo.c8
-rw-r--r--ext/socket/rubysocket.h1
-rw-r--r--ext/socket/socket.c2
-rw-r--r--test/socket/test_addrinfo.rb5
5 files changed, 23 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index d649a49..aa7ad18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sun Jan 18 01:37:50 2009 Tanaka Akira <akr@fsij.org>
+
+ * ext/socket/socket.c (sock_s_getnameinfo): accept AddrInfo object.
+
+ * ext/socket/raddrinfo.c (rb_check_sockaddr_string_type): defined.
+
+ * ext/socket/rubysocket.h (rb_check_sockaddr_string_type): declared.
+
Sat Jan 17 22:01:15 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/lib/socket.rb: new file.
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index f3ed2ca..b324283 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -1520,6 +1520,14 @@ sockaddr_string_value_ptr(volatile VALUE *v)
}
VALUE
+rb_check_sockaddr_string_type(VALUE val)
+{
+ if (TYPE(val) == RUBY_T_DATA && IS_ADDRINFO(val))
+ return addrinfo_to_sockaddr(val);
+ return rb_check_string_type(val);
+}
+
+VALUE
fd_socket_addrinfo(int fd, struct sockaddr *addr, socklen_t len)
{
int family;
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h
index 486409c..464649f 100644
--- a/ext/socket/rubysocket.h
+++ b/ext/socket/rubysocket.h
@@ -150,6 +150,7 @@ int Rconnect();
#define SockAddrStringValuePtr(v) sockaddr_string_value_ptr(&(v))
VALUE sockaddr_string_value(volatile VALUE *);
char *sockaddr_string_value_ptr(volatile VALUE *);
+VALUE rb_check_sockaddr_string_type(VALUE);
NORETURN(void raise_socket_error(const char *, int));
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index def79ba..6334dd2 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -1134,7 +1134,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
if (!NIL_P(flags)) {
fl = NUM2INT(flags);
}
- tmp = rb_check_string_type(sa);
+ tmp = rb_check_sockaddr_string_type(sa);
if (!NIL_P(tmp)) {
sa = tmp;
if (sizeof(ss) < RSTRING_LEN(sa)) {
diff --git a/test/socket/test_addrinfo.rb b/test/socket/test_addrinfo.rb
index 519279c..d6c264b 100644
--- a/test/socket/test_addrinfo.rb
+++ b/test/socket/test_addrinfo.rb
@@ -134,6 +134,11 @@ class TestSocketAddrInfo < Test::Unit::TestCase
s3.close if s3 && !s3.closed?
end
+ def test_socket_getnameinfo
+ ai = AddrInfo.udp("127.0.0.1", 8888)
+ assert_equal(["127.0.0.1", "8888"], Socket.getnameinfo(ai, Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV))
+ end
+
def test_basicsocket_local_address
s1 = Socket.new(:INET, :DGRAM, 0)
s1.bind(Socket.sockaddr_in(0, "127.0.0.1"))