Ticket #15528: patch-socket.c

File patch-socket.c, 1.5 KB (added by aguynamedryan+macports@…, 16 years ago)

Adds a some code that replaces a servname of "0" with NULL before calling getaddrinfo

Line 
1--- ext/socket/socket.c.orig    2008-06-05 23:02:57.000000000 -0700
2+++ ext/socket/socket.c 2008-06-05 23:07:36.000000000 -0700
3@@ -877,6 +877,14 @@
4     }
5     else if (FIXNUM_P(port)) {
6        snprintf(pbuf, len, "%ld", FIX2LONG(port));
7+       /* It looks like getaddrinfo changed in Mac OS X 10.5.3 so that sending "0"
8+        * as the argument for the port number makes it return EAI_NONAME
9+        * but feeding it a port number of NULL seems to do the trick.
10+        * RSD - 2008-06-05
11+        */ 
12+       if (FIX2LONG(port) == 0) {
13+               return "";
14+       }
15        return pbuf;
16     }
17     else {
18@@ -3572,6 +3580,14 @@
19     else if (FIXNUM_P(port)) {
20        snprintf(pbuf, sizeof(pbuf), "%ld", FIX2LONG(port));
21        pptr = pbuf;
22+       /* It looks like getaddrinfo changed in Mac OS X 10.5.3 so that sending "0"
23+        * as the argument for the port number makes it return EAI_NONAME
24+        * but feeding it a port number of NULL seems to do the trick.
25+        * RSD - 2008-06-05
26+        */ 
27+       if (FIX2LONG(port) == 0) {
28+               pptr = NULL;
29+       }
30     }
31     else {
32        strncpy(pbuf, StringValuePtr(port), sizeof(pbuf));
33@@ -3697,7 +3713,15 @@
34        }
35        else if (FIXNUM_P(port)) {
36            snprintf(pbuf, sizeof(pbuf), "%ld", NUM2LONG(port));
37-           pptr = pbuf;
38+               pptr = pbuf;
39+               /* It looks like getaddrinfo changed in Mac OS X 10.5.3 so that sending "0"
40+                * as the argument for the port number makes it return EAI_NONAME
41+                * but feeding it a port number of NULL seems to do the trick.
42+                * RSD - 2008-06-05
43+                */ 
44+               if (NUM2LONG(port) == 0) {
45+                       pptr = NULL;
46+               }
47        }
48        else {
49            strncpy(pbuf, StringValuePtr(port), sizeof(pbuf));