diff -ur ../ruby-1.8.6-p388.org/ext/socket/socket.c ./ext/socket/socket.c
--- ../ruby-1.8.6-p388.org/ext/socket/socket.c	2009-01-27 15:17:02.000000000 +0900
+++ ./ext/socket/socket.c	2010-01-27 22:19:05.000000000 +0900
@@ -877,6 +877,14 @@
     }
     else if (FIXNUM_P(port)) {
 	snprintf(pbuf, len, "%ld", FIX2LONG(port));
+	/* It looks like getaddrinfo changed in Mac OS X 10.5.3 so that sending "0" 
+	 * as the argument for the port number makes it return EAI_NONAME
+	 * but feeding it a port number of NULL seems to do the trick.
+	 * RSD - 2008-06-05
+	 */ 
+	if (FIX2LONG(port) == 0) {
+		return "";
+	}
 	return pbuf;
     }
     else {
@@ -3591,6 +3599,14 @@
     else if (FIXNUM_P(port)) {
 	snprintf(pbuf, sizeof(pbuf), "%ld", FIX2LONG(port));
 	pptr = pbuf;
+	/* It looks like getaddrinfo changed in Mac OS X 10.5.3 so that sending "0" 
+	 * as the argument for the port number makes it return EAI_NONAME
+	 * but feeding it a port number of NULL seems to do the trick.
+	 * RSD - 2008-06-05
+	 */ 
+	if (FIX2LONG(port) == 0) {
+		pptr = NULL;
+	}
     }
     else {
 	strncpy(pbuf, StringValuePtr(port), sizeof(pbuf));
@@ -3716,7 +3732,15 @@
 	}
 	else if (FIXNUM_P(port)) {
 	    snprintf(pbuf, sizeof(pbuf), "%ld", NUM2LONG(port));
-	    pptr = pbuf;
+		pptr = pbuf;
+		/* It looks like getaddrinfo changed in Mac OS X 10.5.3 so that sending "0" 
+		 * as the argument for the port number makes it return EAI_NONAME
+		 * but feeding it a port number of NULL seems to do the trick.
+		 * RSD - 2008-06-05
+		 */ 
+		if (NUM2LONG(port) == 0) {
+			pptr = NULL;
+		}
 	}
 	else {
 	    strncpy(pbuf, StringValuePtr(port), sizeof(pbuf));
Only in ./ext/socket: socket.c.orig
diff -ur ../ruby-1.8.6-p388.org/test/socket/test_socket.rb ./test/socket/test_socket.rb
--- ../ruby-1.8.6-p388.org/test/socket/test_socket.rb	2007-02-13 08:01:19.000000000 +0900
+++ ./test/socket/test_socket.rb	2010-01-27 22:19:05.000000000 +0900
@@ -57,6 +57,14 @@
       }
     end
   end
+  
+  def test_getaddrinfo_raises_no_errors_on_port_argument_of_0
+    # Added 2008-06-05 to ensure that Mac OS X 10.5.3's changes to getaddrinfo don't cause
+    # Ruby's Socket-based classes to fail.
+    # Here are two of the situations I found that were causing erroneous errors
+    assert_nothing_raised(){Socket.getaddrinfo(Socket.gethostname, 0, Socket::AF_INET, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME)}
+    assert_nothing_raised(){TCPServer.open('localhost', 0)}
+  end
 
   def test_listen
     s = nil
