[前][次][番号順一覧][スレッド一覧]

ruby-changes:9833

From: akr <ko1@a...>
Date: Thu, 8 Jan 2009 00:22:03 +0900 (JST)
Subject: [ruby-changes:9833] Ruby:r21373 (trunk): * ext/socket/socket.c (host_str): add flags_ptr argument to specify

akr	2009-01-08 00:21:43 +0900 (Thu, 08 Jan 2009)

  New Revision: 21373

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21373

  Log:
    * ext/socket/socket.c (host_str): add flags_ptr argument to specify
      AI_NUMERICHOST if host is numeric form.
      (port_str): add flags_ptr argument to specify AI_NUMERICSERV if port
      is numeric form.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/socket.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 21372)
+++ ChangeLog	(revision 21373)
@@ -1,3 +1,10 @@
+Thu Jan  8 00:16:22 2009  Tanaka Akira  <akr@f...>
+
+	* ext/socket/socket.c (host_str): add flags_ptr argument to specify
+	  AI_NUMERICHOST if host is numeric form.
+	  (port_str): add flags_ptr argument to specify AI_NUMERICSERV if port
+	  is numeric form.
+
 Wed Jan  7 22:24:12 2009  Tanaka Akira  <akr@f...>
 
 	* ext/socket/socket.c (rb_cAddrInfo): new class AddrInfo.
Index: ext/socket/socket.c
===================================================================
--- ext/socket/socket.c	(revision 21372)
+++ ext/socket/socket.c	(revision 21373)
@@ -1101,7 +1101,7 @@
 }
 
 static char*
-host_str(VALUE host, char *hbuf, size_t len)
+host_str(VALUE host, char *hbuf, size_t len, int *flags_ptr)
 {
     if (NIL_P(host)) {
 	return NULL;
@@ -1110,6 +1110,7 @@
 	unsigned long i = NUM2ULONG(host);
 
 	make_inetaddr(htonl(i), hbuf, len);
+        if (flags_ptr) *flags_ptr |= AI_NUMERICHOST;
 	return hbuf;
     }
     else {
@@ -1119,9 +1120,11 @@
 	name = RSTRING_PTR(host);
 	if (!name || *name == 0 || (name[0] == '<' && strcmp(name, "<any>") == 0)) {
 	    make_inetaddr(INADDR_ANY, hbuf, len);
+            if (flags_ptr) *flags_ptr |= AI_NUMERICHOST;
 	}
 	else if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) {
 	    make_inetaddr(INADDR_BROADCAST, hbuf, len);
+            if (flags_ptr) *flags_ptr |= AI_NUMERICHOST;
 	}
 	else if (strlen(name) >= len) {
 	    rb_raise(rb_eArgError, "hostname too long (%"PRIuSIZE")",
@@ -1135,13 +1138,14 @@
 }
 
 static char*
-port_str(VALUE port, char *pbuf, size_t len)
+port_str(VALUE port, char *pbuf, size_t len, int *flags_ptr)
 {
     if (NIL_P(port)) {
 	return 0;
     }
     else if (FIXNUM_P(port)) {
 	snprintf(pbuf, len, "%ld", FIX2LONG(port));
+        if (flags_ptr) *flags_ptr |= AI_NUMERICSERV;
 	return pbuf;
     }
     else {
@@ -1172,13 +1176,15 @@
     char *hostp, *portp;
     int error;
     char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
+    int additional_flags = 0;
 
-    hostp = host_str(host, hbuf, sizeof(hbuf));
-    portp = port_str(port, pbuf, sizeof(pbuf));
+    hostp = host_str(host, hbuf, sizeof(hbuf), &additional_flags);
+    portp = port_str(port, pbuf, sizeof(pbuf), &additional_flags);
 
     if (socktype_hack && hints->ai_socktype == 0 && str_isnumber(portp)) {
        hints->ai_socktype = SOCK_DGRAM;
     }
+    hints->ai_flags |= additional_flags;
 
     error = rb_getaddrinfo(hostp, portp, hints, &res);
     if (error) {
@@ -1662,7 +1668,7 @@
 	hostp = addr->ai_canonname;
     }
     else {
-	hostp = host_str(host, hbuf, sizeof(hbuf));
+	hostp = host_str(host, hbuf, sizeof(hbuf), NULL);
     }
     rb_ary_push(ary, rb_str_new2(hostp));
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]