summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-15 17:06:37 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-15 17:06:37 +0000
commitaaddab6dea1381b5491121b6b36c21d65fadcf56 (patch)
tree43371c9b0c7118c451af1af3f8ccf08990941fd1 /ext/socket
parentd9395fc46630c113204cece80781f31373b5a818 (diff)
* ext/socket/socket.c (addrinfo_s_ip): new method AddrInfo.ip.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21579 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/socket.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index cd6acd46471..f361e49ba7d 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -5362,6 +5362,27 @@ addrinfo_s_getaddrinfo(int argc, VALUE *argv, VALUE self)
/*
* call-seq:
+ * AddrInfo.ip(host) => addrinfo
+ *
+ * returns an addrinfo object for IP address.
+ *
+ * AddrInfo.ip("localhost") #=> #<AddrInfo: 127.0.0.1 (localhost)>
+ */
+static VALUE
+addrinfo_s_ip(VALUE self, VALUE host)
+{
+ VALUE ret;
+ rb_addrinfo_t *rai;
+ ret = addrinfo_firstonly_new(host, Qnil,
+ INT2NUM(PF_UNSPEC), INT2FIX(0), INT2FIX(0), INT2FIX(0));
+ rai = get_addrinfo(ret);
+ rai->socktype = 0;
+ rai->protocol = 0;
+ return ret;
+}
+
+/*
+ * call-seq:
* AddrInfo.tcp(host, port) => addrinfo
*
* returns an addrinfo object for TCP address.
@@ -5372,7 +5393,7 @@ static VALUE
addrinfo_s_tcp(VALUE self, VALUE host, VALUE port)
{
return addrinfo_firstonly_new(host, port,
- INT2NUM(PF_UNSPEC), INT2NUM(SOCK_STREAM), INT2FIX(IPPROTO_TCP), INT2FIX(0));
+ INT2NUM(PF_UNSPEC), INT2NUM(SOCK_STREAM), INT2NUM(IPPROTO_TCP), INT2FIX(0));
}
/*
@@ -5387,7 +5408,7 @@ static VALUE
addrinfo_s_udp(VALUE self, VALUE host, VALUE port)
{
return addrinfo_firstonly_new(host, port,
- INT2NUM(PF_UNSPEC), INT2NUM(SOCK_DGRAM), INT2FIX(IPPROTO_UDP), INT2FIX(0));
+ INT2NUM(PF_UNSPEC), INT2NUM(SOCK_DGRAM), INT2NUM(IPPROTO_UDP), INT2FIX(0));
}
#ifdef HAVE_SYS_UN_H
@@ -5592,6 +5613,7 @@ Init_socket()
rb_define_method(rb_cAddrInfo, "initialize", addrinfo_initialize, -1);
rb_define_method(rb_cAddrInfo, "inspect", addrinfo_inspect, 0);
rb_define_singleton_method(rb_cAddrInfo, "getaddrinfo", addrinfo_s_getaddrinfo, -1);
+ rb_define_singleton_method(rb_cAddrInfo, "ip", addrinfo_s_ip, 1);
rb_define_singleton_method(rb_cAddrInfo, "tcp", addrinfo_s_tcp, 2);
rb_define_singleton_method(rb_cAddrInfo, "udp", addrinfo_s_udp, 2);
#ifdef HAVE_SYS_UN_H