3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2007 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #ifdef HAVE_SYS_TYPES_H
21 #include <sys/types.h>
28 #ifdef HAVE_SYS_SOCKET_H
29 #include <sys/socket.h>
35 #ifdef HAVE_SYS_SELECT_H
36 #include <sys/select.h>
39 #include <netinet/in.h>
41 #ifdef HAVE_NETINET_TCP_H
42 #include <netinet/tcp.h>
45 #ifdef HAVE_ARPA_INET_H
46 #include <arpa/inet.h>
49 #ifdef HAVE_ARPA_NAMESER_H
50 #include <arpa/nameser.h>
59 #endif /* HAVE_SYS_SOCKET_H */
69 #endif /* HAVE_PCNFS */
71 #ifndef INADDR_LOOPBACK
72 #define INADDR_LOOPBACK (0x7f000001UL)
75 #ifndef MAXHOSTNAMELEN
76 #define MAXHOSTNAMELEN 64
81 #define sock_errno() errno
82 #define sock_errstr(e) STRERROR(e)
83 #define sock_errset(e) errno = (e)
86 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
87 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
88 # define ioctl( s, c, a ) ioctlsocket( (s), (c), (a) )
89 # define ioctl_t u_long
90 # define AC_SOCKET_INVALID ((unsigned int) ~0)
93 # define tcp_close( s ) (shutdown( s, SD_BOTH ), closesocket( s ))
95 # define tcp_close( s ) closesocket( s )
98 #define EWOULDBLOCK WSAEWOULDBLOCK
99 #define EINPROGRESS WSAEINPROGRESS
100 #define ETIMEDOUT WSAETIMEDOUT
105 #define sock_errno() WSAGetLastError()
106 #define sock_errstr(e) ber_pvt_wsa_err2string(e)
107 #define sock_errset(e) WSASetLastError(e)
109 LBER_F( char * ) ber_pvt_wsa_err2string LDAP_P((int));
112 # define tcp_close( s ) tcpclose( s )
113 # define tcp_read( s, buf, len ) tcpread( s, buf, len )
114 # define tcp_write( s, buf, len ) tcpwrite( s, buf, len )
118 # define tcp_close( s ) close( s )
119 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
120 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
123 # define tcp_close( s ) do { netclose( s ); netshut() } while(0)
124 # define tcp_read( s, buf, len ) nread( s, buf, len )
125 # define tcp_write( s, buf, len ) netwrite( s, buf, len )
128 #elif HAVE_CLOSESOCKET
129 # define tcp_close( s ) closesocket( s )
132 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
133 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
137 # define tcp_read( s, buf, len) read( s, buf, len )
138 # define tcp_write( s, buf, len) write( s, buf, len )
141 # define tcp_close( s ) (shutdown( s, SHUT_RDWR ), close( s ))
143 # define tcp_close( s ) close( s )
148 * Only use pipe() on systems where file and socket descriptors
151 # define USE_PIPE HAVE_PIPE
160 #ifndef AC_SOCKET_INVALID
161 # define AC_SOCKET_INVALID (-1)
163 #ifndef AC_SOCKET_ERROR
164 # define AC_SOCKET_ERROR (-1)
167 #if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
168 # define inet_aton ldap_pvt_inet_aton
170 LDAP_F (int) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
173 #if defined(__WIN32) && defined(_ALPHA)
174 /* NT on Alpha is hosed. */
175 # define AC_HTONL( l ) \
176 ((((l)&0xffU)<<24) + (((l)&0xff00U)<<8) + \
177 (((l)&0xff0000U)>>8) + (((l)&0xff000000U)>>24))
178 # define AC_NTOHL(l) AC_HTONL(l)
181 # define AC_HTONL( l ) htonl( l )
182 # define AC_NTOHL( l ) ntohl( l )
185 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
186 #define AC_HTONS( s ) htons( s )
187 #define AC_NTOHS( s ) ntohs( s )
190 # if !defined( AF_LOCAL ) && defined( AF_UNIX )
191 # define AF_LOCAL AF_UNIX
193 # if !defined( PF_LOCAL ) && defined( PF_UNIX )
194 # define PF_LOCAL PF_UNIX
198 #ifndef INET_ADDRSTRLEN
199 # define INET_ADDRSTRLEN 16
201 #ifndef INET6_ADDRSTRLEN
202 # define INET6_ADDRSTRLEN 46
205 #if defined( HAVE_GETADDRINFO ) || defined( HAVE_GETNAMEINFO )
206 # ifdef HAVE_GAI_STRERROR
207 # define AC_GAI_STRERROR(x) (gai_strerror((x)))
209 # define AC_GAI_STRERROR(x) (ldap_pvt_gai_strerror((x)))
210 LDAP_F (char *) ldap_pvt_gai_strerror( int );
214 #ifndef HAVE_GETPEEREID
215 LDAP_LUTIL_F( int ) getpeereid( int s, uid_t *, gid_t * );
218 /* DNS RFC defines max host name as 255. New systems seem to use 1024 */
220 #define NI_MAXHOST 256
228 #define POLL_OTHER (POLLERR|POLLHUP)
230 #define POLL_READ (POLLIN|POLLPRI|POLL_OTHER)
232 #define POLL_WRITE (POLLOUT|POLL_OTHER)
235 #endif /* _AC_SOCKET_H_ */