* os-ip.c -- platform-specific TCP & UDP related code
*/
-#ifndef lint
-static char copyright[] = "@(#) Copyright (c) 1995 Regents of the University of Michigan.\nAll rights reserved.\n";
-#endif
+#include "portable.h"
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#ifdef _WIN32
-#include <io.h>
-#include "msdos.h"
-#else /* _WIN32 */
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <unistd.h>
-#endif /* _WIN32 */
-#ifdef _AIX
-#include <sys/select.h>
-#endif /* _AIX */
-#ifdef VMS
-#include "ucx_select.h"
-#endif /* VMS */
+#include <ac/errno.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
+#include <ac/unistd.h>
-#include "portable.h"
-#include "lber.h"
-#include "ldap.h"
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif /* HAVE_IO_H */
-#ifdef LDAP_REFERRALS
-#ifdef USE_SYSCONF
-#include <unistd.h>
-#endif /* USE_SYSCONF */
-#ifdef notyet
-#ifdef NEED_FILIO
+#if defined( HAVE_SYS_FILIO_H )
#include <sys/filio.h>
-#else /* NEED_FILIO */
+#elif defined( HAVE_SYS_IOCTL_H )
#include <sys/ioctl.h>
-#endif /* NEED_FILIO */
-#endif /* notyet */
-#endif /* LDAP_REFERRALS */
-
-#ifdef MACOS
-#define tcp_close( s ) tcpclose( s )
-#else /* MACOS */
-#ifdef DOS
-#ifdef PCNFS
-#define tcp_close( s ) close( s )
-#endif /* PCNFS */
-#ifdef NCSA
-#define tcp_close( s ) netclose( s ); netshut()
-#endif /* NCSA */
-#ifdef WINSOCK
-#define tcp_close( s ) closesocket( s ); WSACleanup();
-#endif /* WINSOCK */
-#else /* DOS */
-#define tcp_close( s ) close( s )
-#endif /* DOS */
-#endif /* MACOS */
+#endif
+#include "lber.h"
+#include "ldap.h"
#include "ldap-int.h"
int
#endif /* notyet */
Debug( LDAP_DEBUG_TRACE, "ldap_connect_to_host: %s:%d\n",
- ( host == NULL ) ? "(by address)" : host, ntohs( port ), 0 );
+ ( host == NULL ) ? "(by address)" : host, (int) ntohs( (short) port ), 0 );
connected = use_hp = 0;
if ( host != NULL && ( address = inet_addr( host )) == -1 ) {
if ( (hp = gethostbyname( host )) == NULL ) {
+#ifdef HAVE_WINSOCK
+ errno = WSAGetLastError();
+#else
errno = EHOSTUNREACH; /* not exactly right, but... */
+#endif
return( -1 );
}
use_hp = 1;
rc = 0;
break;
} else {
+#ifdef HAVE_WINSOCK
+ errno = WSAGetLastError();
+#endif
#ifdef notyet
#ifdef LDAP_REFERRALS
#ifdef EAGAIN
perror( (char *)inet_ntoa( sin.sin_addr ));
}
#endif
- close( s );
+ tcp_close( s );
if ( !use_hp ) {
break;
}
#endif /* notyet */
Debug( LDAP_DEBUG_TRACE, "sd %d connected to: %s\n",
- s, inet_ntoa( sin.sin_addr ), 0 );
+ s, (char *) inet_ntoa( sin.sin_addr ), 0 );
}
return( rc );
}
-#ifdef KERBEROS
+#ifdef HAVE_KERBEROS
char *
ldap_host_connected_to( Sockbuf *sb )
{
return( NULL );
}
-#endif /* KERBEROS */
+#endif /* HAVE_KERBEROS */
#ifdef LDAP_REFERRALS
sip = (struct selectinfo *)ld->ld_selectinfo;
if ( !FD_ISSET( sb->sb_sd, &sip->si_writefds )) {
- FD_SET( sb->sb_sd, &sip->si_writefds );
+ FD_SET( (u_int) sb->sb_sd, &sip->si_writefds );
}
}
sip = (struct selectinfo *)ld->ld_selectinfo;
if ( !FD_ISSET( sb->sb_sd, &sip->si_readfds )) {
- FD_SET( sb->sb_sd, &sip->si_readfds );
+ FD_SET( (u_int) sb->sb_sd, &sip->si_readfds );
}
}
sip = (struct selectinfo *)ld->ld_selectinfo;
- FD_CLR( sb->sb_sd, &sip->si_writefds );
- FD_CLR( sb->sb_sd, &sip->si_readfds );
+ FD_CLR( (u_int) sb->sb_sd, &sip->si_writefds );
+ FD_CLR( (u_int) sb->sb_sd, &sip->si_readfds );
}
Debug( LDAP_DEBUG_TRACE, "do_ldap_select\n", 0, 0, 0 );
if ( tblsize == 0 ) {
-#ifdef USE_SYSCONF
+#if defined( HAVE_SYSCONF )
tblsize = sysconf( _SC_OPEN_MAX );
-#else /* !USE_SYSCONF */
+#elif defined( HAVE_GETDTABLESIZE )
tblsize = getdtablesize();
#endif /* !USE_SYSCONF */
* - DB_DBT_MALLOC ; 1998/03/22, /KSp
*/
-#include <stdio.h>
-#include "ldbm.h"
-
-#ifdef LDBM_USE_GDBM
-
-#include <sys/types.h>
-#include <sys/stat.h>
-
-/*****************************************************************
- * *
- * use gdbm *
- * *
- *****************************************************************/
-
-LDBM
-ldbm_open( char *name, int rw, int mode, int dbcachesize )
-{
- LDBM db;
- struct stat st;
-
- if ( (db = gdbm_open( name, 0, rw | GDBM_FAST, mode, 0 )) == NULL ) {
- return( NULL );
- }
- if ( dbcachesize > 0 && stat( name, &st ) == 0 ) {
- dbcachesize = (dbcachesize / st.st_blksize);
- gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
- }
-
- return( db );
-}
-
-void
-ldbm_close( LDBM ldbm )
-{
- gdbm_close( ldbm );
-}
-
-void
-ldbm_sync( LDBM ldbm )
-{
- gdbm_sync( ldbm );
-}
-
-void
-ldbm_datum_free( LDBM ldbm, Datum data )
-{
- free( data.dptr );
-}
-
-Datum
-ldbm_datum_dup( LDBM ldbm, Datum data )
-{
- Datum dup;
-
- if ( data.dsize == 0 ) {
- dup.dsize = 0;
- dup.dptr = NULL;
+#include "portable.h"
- return( dup );
- }
- dup.dsize = data.dsize;
- if ( dup.dptr = (char *) malloc( data.dsize ) )
- memcpy( dup.dptr, data.dptr, data.dsize );
-
- return( dup );
-}
-
-Datum
-ldbm_fetch( LDBM ldbm, Datum key )
-{
- return( gdbm_fetch( ldbm, key ) );
-}
+#ifdef SLAPD_LDBM
-int
-ldbm_store( LDBM ldbm, Datum key, Datum data, int flags )
-{
- int rc;
-
- rc = gdbm_store( ldbm, key, data, flags & ~LDBM_SYNC );
- if ( flags & LDBM_SYNC )
- gdbm_sync( ldbm );
- return( rc );
-}
-
-int
-ldbm_delete( LDBM ldbm, Datum key )
-{
- int rc;
-
- rc = gdbm_delete( ldbm, key );
- gdbm_sync( ldbm );
- return( rc );
-}
-
-Datum
-ldbm_firstkey( LDBM ldbm )
-{
- return( gdbm_firstkey( ldbm ) );
-}
-
-Datum
-ldbm_nextkey( LDBM ldbm, Datum key )
-{
- return( gdbm_nextkey( ldbm, key ) );
-}
+#include <stdio.h>
+#include <stdlib.h>
+#include <ac/errno.h>
-int
-ldbm_errno( LDBM ldbm )
-{
- return( (int) gdbm_errno );
-}
+#include "ldbm.h"
-#else
#if defined( LDBM_USE_DBHASH ) || defined( LDBM_USE_DBBTREE )
/*****************************************************************
* *
*****************************************************************/
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
/*************************************************
* *
* A malloc routine for use with DB_DBT_MALLOC *
* *
*************************************************/
-#include <stdlib.h>
-
-
void *
ldbm_malloc( size_t size )
{
{
LDBM ret = NULL;
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
DB_INFO dbinfo;
memset( &dbinfo, 0, sizeof( dbinfo ));
void
ldbm_close( LDBM ldbm )
{
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
(*ldbm->close)( ldbm, 0 );
#else
(*ldbm->close)( ldbm );
{
Datum dup;
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
memset( &dup, 0, sizeof( dup ));
#endif
Datum data;
int rc;
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
memset( &data, 0, sizeof( data ));
data.flags = DB_DBT_MALLOC;
{
int rc;
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
rc = (*ldbm->put)( ldbm, NULL, &key, &data, flags & ~LDBM_SYNC );
rc = (-1 ) * rc;
#else
{
int rc;
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
rc = (*ldbm->del)( ldbm, NULL, &key, 0 );
rc = (-1 ) * rc;
#else
}
Datum
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
ldbm_firstkey( LDBM ldbm, DBC **dbch )
#else
ldbm_firstkey( LDBM ldbm )
Datum key, data;
int rc;
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
DBC *dbci;
memset( &key, 0, sizeof( key ));
key.dsize = 0;
}
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
}
#endif
}
Datum
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
ldbm_nextkey( LDBM ldbm, Datum key, DBC *dbcp )
#else
ldbm_nextkey( LDBM ldbm, Datum key )
Datum data;
int rc;
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
void *oldKey = key.dptr;
memset( &data, 0, sizeof( data ));
key.dptr = NULL;
key.dsize = 0;
}
-#ifdef LDBM_USE_DB2
+#ifdef HAVE_BERKELEY_DB2
if ( oldKey ) free( oldKey );
#endif
return( errno );
}
-#else
+#elif defined( HAVE_GDBM )
+
+#include <sys/stat.h>
+
+/*****************************************************************
+ * *
+ * use gdbm *
+ * *
+ *****************************************************************/
+
+LDBM
+ldbm_open( char *name, int rw, int mode, int dbcachesize )
+{
+ LDBM db;
+ struct stat st;
+
+ if ( (db = gdbm_open( name, 0, rw | GDBM_FAST, mode, 0 )) == NULL ) {
+ return( NULL );
+ }
+ if ( dbcachesize > 0 && stat( name, &st ) == 0 ) {
+ dbcachesize = (dbcachesize / st.st_blksize);
+ gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
+ }
+
+ return( db );
+}
+
+void
+ldbm_close( LDBM ldbm )
+{
+ gdbm_close( ldbm );
+}
+
+void
+ldbm_sync( LDBM ldbm )
+{
+ gdbm_sync( ldbm );
+}
+
+void
+ldbm_datum_free( LDBM ldbm, Datum data )
+{
+ free( data.dptr );
+}
+
+Datum
+ldbm_datum_dup( LDBM ldbm, Datum data )
+{
+ Datum dup;
+
+ if ( data.dsize == 0 ) {
+ dup.dsize = 0;
+ dup.dptr = NULL;
+
+ return( dup );
+ }
+ dup.dsize = data.dsize;
+ if ( dup.dptr = (char *) malloc( data.dsize ) )
+ memcpy( dup.dptr, data.dptr, data.dsize );
+
+ return( dup );
+}
+
+Datum
+ldbm_fetch( LDBM ldbm, Datum key )
+{
+ return( gdbm_fetch( ldbm, key ) );
+}
+
+int
+ldbm_store( LDBM ldbm, Datum key, Datum data, int flags )
+{
+ int rc;
+
+ rc = gdbm_store( ldbm, key, data, flags & ~LDBM_SYNC );
+ if ( flags & LDBM_SYNC )
+ gdbm_sync( ldbm );
+ return( rc );
+}
+
+int
+ldbm_delete( LDBM ldbm, Datum key )
+{
+ int rc;
+
+ rc = gdbm_delete( ldbm, key );
+ gdbm_sync( ldbm );
+ return( rc );
+}
+
+Datum
+ldbm_firstkey( LDBM ldbm )
+{
+ return( gdbm_firstkey( ldbm ) );
+}
+
+Datum
+ldbm_nextkey( LDBM ldbm, Datum key )
+{
+ return( gdbm_nextkey( ldbm, key ) );
+}
+
+int
+ldbm_errno( LDBM ldbm )
+{
+ return( (int) gdbm_errno );
+}
-#ifdef LDBM_USE_NDBM
+#elif defined( HAVE_NDBM )
/*****************************************************************
* *
}
#endif /* ndbm */
-#endif /* db */
-#endif /* gdbm */
+#endif /* ldbm */