]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/sockpair.c
ITS#5615 return success on Solaris 10
[openldap] / libraries / liblutil / sockpair.c
index 5c33eb26d781c0bead2dadf64cad2b3564bd8f7a..9e0a660e49d2ecb4fec5453a22a8b4740faf04f9 100644 (file)
@@ -1,10 +1,21 @@
-/*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2008 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
 
 #include "portable.h"
 #include <ac/socket.h>
+#include <ac/unistd.h>
 
 #include <lutil.h>
 
  * this function is best implemented using a single pipe() call.
  */
 
-int lutil_pair( LBER_SOCKET_T sds[2] )
+int lutil_pair( ber_socket_t sds[2] )
 {
+#ifdef USE_PIPE
+       return pipe( sds );
+#else
        struct sockaddr_in si;
-       int rc, len = sizeof(si);
-       LBER_SOCKET_T sd;
+       int rc;
+       ber_socklen_t len = sizeof(si);
+       ber_socket_t sd;
 
        sd = socket( AF_INET, SOCK_DGRAM, 0 );
-       if ( sd == AC_SOCKET_INVALID )
+       if ( sd == AC_SOCKET_INVALID ) {
                return sd;
+       }
        
-       (void) memset( (void*) &si, 0, len );
+       (void) memset( (void*) &si, '\0', len );
        si.sin_family = AF_INET;
        si.sin_port = 0;
        si.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
@@ -51,6 +67,12 @@ int lutil_pair( LBER_SOCKET_T sds[2] )
                return rc;
        }
 
-       sds[0] = sds[1] = sd;
+       sds[0] = sd;
+#if !HAVE_WINSOCK
+       sds[1] = dup( sds[0] );
+#else
+       sds[1] = sds[0];
+#endif
        return 0;
+#endif
 }