X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblutil%2Fsockpair.c;h=b351f0a8a57d28387b32c3baf8229d3155e52e4d;hb=4d0d12db27b3b44cc36acc089b0e640320480fe7;hp=f45bdd753c6657b4dce0f629ac8ccf51784bc3e4;hpb=b509dd4d8cbd8b8e388a02ca9d8f7eaa5d8b21fa;p=openldap
diff --git a/libraries/liblutil/sockpair.c b/libraries/liblutil/sockpair.c
index f45bdd753c..b351f0a8a5 100644
--- a/libraries/liblutil/sockpair.c
+++ b/libraries/liblutil/sockpair.c
@@ -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 .
+ *
+ * Copyright 1998-2012 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
+ * .
*/
#include "portable.h"
#include
+#include
#include
@@ -18,36 +29,50 @@
* 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 < 0)
+ 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 );
- if ( rc = bind( sd, (struct sockaddr *)&si, len ) ) {
+ rc = bind( sd, (struct sockaddr *)&si, len );
+ if ( rc == AC_SOCKET_ERROR ) {
tcp_close(sd);
return rc;
}
- if ( rc = getsockname( sd, (struct sockaddr *)&si, &len ) ) {
+ rc = getsockname( sd, (struct sockaddr *)&si, &len );
+ if ( rc == AC_SOCKET_ERROR ) {
tcp_close(sd);
return rc;
}
- if ( rc = connect( sd, (struct sockaddr *)&si, len ) ) {
+ rc = connect( sd, (struct sockaddr *)&si, len );
+ if ( rc == AC_SOCKET_ERROR ) {
tcp_close(sd);
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
}