--- platform/linux/net.orig.h	2011-12-23 14:16:22.907469604 +0000
+++ platform/linux/net.h	2011-12-23 14:08:12.856557766 +0000
@@ -22,6 +22,8 @@
 #ifndef _MONGO_NET_H_
 #define _MONGO_NET_H_
 
+#define _GNU_SOURCE 1
+
 #include "mongo.h"
 
 #include <arpa/inet.h>
@@ -33,6 +35,8 @@
 #include <netinet/tcp.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <unistd.h>
+
 #define mongo_close_socket(sock) ( close(sock) )
 
 #if defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE) || _POSIX_C_SOURCE >= 1
--- platform/linux/net.orig.c	2011-12-23 14:16:14.817344493 +0000
+++ platform/linux/net.c	2011-12-23 14:18:22.129313328 +0000
@@ -49,10 +49,10 @@
     return MONGO_OK;
 }
 
-static int mongo_create_socket( mongo *conn ) {
+static int mongo_create_socket( mongo *conn, int sock_type ) {
     int fd;
 
-    if( ( fd = socket( AF_INET, SOCK_STREAM, 0 ) ) == -1 ) {
+    if( ( fd = socket( sock_type, SOCK_STREAM, 0 ) ) == -1 ) {
         conn->err = MONGO_CONN_NO_SOCKET;
         return MONGO_ERROR;
     }
@@ -113,28 +113,29 @@
     int flag = 1;
     char port_str[12];
     int ret;
-
+    
     conn->sock = 0;
     conn->connected = 0;
 
     memset( &hints, 0, sizeof( hints ) );
-    hints.ai_family = AF_INET;
+    hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
-
-    if( mongo_create_socket( conn ) != MONGO_OK )
-        return MONGO_ERROR;
-
-    if( getaddrinfo( host, port_str, &hints, &addrs ) != 0 ) {
+    sprintf(port_str,"%d",port);
+    
+    if( (ret = getaddrinfo( host, port_str, &hints, &addrs )) != 0 ) {
         bson_errprintf( "getaddrinfo failed: %s", gai_strerror( ret ) );
         conn->err = MONGO_CONN_ADDR_FAIL;
         return MONGO_ERROR;
     }
 
+    if( mongo_create_socket(conn, addrs->ai_family) != MONGO_OK )
+        return MONGO_ERROR;
+    
     if ( connect( conn->sock, addrs->ai_addr, addrs->ai_addrlen ) == -1 ) {
         mongo_close_socket( conn->sock );
         freeaddrinfo( addrs );
         conn->err = MONGO_CONN_FAIL;
-        return MONGO_ERROR:
+        return MONGO_ERROR;
     }
 
     setsockopt( conn->sock, IPPROTO_TCP, TCP_NODELAY, ( char * )&flag, sizeof( flag ) );
@@ -152,7 +153,7 @@
     socklen_t addressSize;
     int flag = 1;
 
-    if( mongo_create_socket( conn ) != MONGO_OK )
+    if( mongo_create_socket(conn, AF_INET) != MONGO_OK )
         return MONGO_ERROR;
 
     memset( sa.sin_zero , 0 , sizeof( sa.sin_zero ) );
