4 * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
7 * Redistribution and use in source and binary forms are permitted only
8 * as authorized by the OpenLDAP Public License. A copy of this
9 * license is available at http://www.OpenLDAP.org/license.html or
10 * in file LICENSE in the top-level directory of the distribution.
16 #ifdef HAVE_SYS_TYPES_H
17 #include <sys/types.h>
20 #ifdef HAVE_SYS_SOCKET_H
21 #include <sys/socket.h>
23 #ifdef HAVE_SYS_SELECT_H
24 #include <sys/select.h>
27 #include <netinet/in.h>
29 #ifdef HAVE_NETINET_TCP_H
30 #include <netinet/tcp.h>
33 #ifdef HAVE_ARPA_INET_H
34 #include <arpa/inet.h>
37 #ifdef HAVE_ARPA_NAMESER_H
38 #include <arpa/nameser.h>
47 #endif /* HAVE_SYS_SOCKET_H */
59 #endif /* HAVE_PCNFS */
61 #ifndef INADDR_LOOPBACK
62 #define INADDR_LOOPBACK (0x7f000001UL)
65 #ifndef MAXHOSTNAMELEN
66 #define MAXHOSTNAMELEN 64
71 #define sock_errno() errno
72 #define sock_errstr(e) STRERROR(e)
75 # define tcp_close( s ) closesocket( s )
76 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
77 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
78 # define ioctl( s, c, a ) ioctlsocket( (s), (c), (a) )
79 # define ioctl_t u_long
80 # define AC_SOCKET_INVALID ((unsigned int) ~0)
82 #define EWOULDBLOCK WSAEWOULDBLOCK
83 #define EINPROGRESS WSAEINPROGRESS
84 #define ETIMEDOUT WSAETIMEDOUT
88 #define sock_errno() WSAGetLastError()
89 #define sock_errstr(e) WSAGetErrorString(e)
91 extern char* WSAGetErrorString LDAP_P((int));
94 # define tcp_close( s ) tcpclose( s )
95 # define tcp_read( s, buf, len ) tcpread( s, buf, len )
96 # define tcp_write( s, buf, len ) tcpwrite( s, buf, len )
100 # define tcp_close( s ) close( s )
101 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
102 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
105 # define tcp_close( s ) do { netclose( s ); netshut() } while(0)
106 # define tcp_read( s, buf, len ) nread( s, buf, len )
107 # define tcp_write( s, buf, len ) netwrite( s, buf, len )
110 #elif HAVE_CLOSESOCKET
111 # define tcp_close( s ) closesocket( s )
114 # define tcp_close( s ) close( s )
115 # define tcp_read( s, buf, len) read( s, buf, len )
116 # define tcp_write( s, buf, len) write( s, buf, len )
119 #define USE_PAIR HAVE_PAIR
128 #ifndef AC_SOCKET_INVALID
129 # define AC_SOCKET_INVALID (-1)
131 #ifndef AC_SOCKET_ERROR
132 # define AC_SOCKET_ERROR (-1)
135 #if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
136 #define inet_aton ldap_pvt_inet_aton
138 int ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
141 #if defined(__WIN32) && defined(_ALPHA)
142 /* NT on Alpha is hosed. */
143 #define AC_HTONL( l ) \
144 ((((l)&0xff)<<24) + (((l)&0xff00)<<8) + \
145 (((l)&0xff0000)>>8) + (((l)&0xff000000)>>24))
146 #define AC_NTOHL(l) AC_HTONL(l)
148 #elif defined(__alpha) && !defined(VMS)
150 * htonl and ntohl on the DEC Alpha under OSF 1 seem to only swap the
151 * lower-order 32-bits of a (64-bit) long, so we define correct versions
154 #define AC_HTONL( l ) (((long)htonl( (l) & 0x00000000FFFFFFFF )) << 32 \
155 | htonl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
157 #define AC_NTOHL( l ) (((long)ntohl( (l) & 0x00000000FFFFFFFF )) << 32 \
158 | ntohl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
161 #define AC_HTONL( l ) htonl( l )
162 #define AC_NTOHL( l ) ntohl( l )
165 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
166 #define AC_HTONS( s ) htons( s )
167 #define AC_NTOHS( s ) ntohs( s )
170 #endif /* _AC_SOCKET_H_ */