3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 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)
85 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
86 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
87 # define ioctl( s, c, a ) ioctlsocket( (s), (c), (a) )
88 # define ioctl_t u_long
89 # define AC_SOCKET_INVALID ((unsigned int) ~0)
92 # define tcp_close( s ) (shutdown( s, SD_BOTH ), closesocket( s ))
94 # define tcp_close( s ) closesocket( s )
97 #define EWOULDBLOCK WSAEWOULDBLOCK
98 #define EINPROGRESS WSAEINPROGRESS
99 #define ETIMEDOUT WSAETIMEDOUT
103 #define sock_errno() WSAGetLastError()
104 #define sock_errstr(e) ber_pvt_wsa_err2string(e)
106 LBER_F( char * ) ber_pvt_wsa_err2string LDAP_P((int));
109 # define tcp_close( s ) tcpclose( s )
110 # define tcp_read( s, buf, len ) tcpread( s, buf, len )
111 # define tcp_write( s, buf, len ) tcpwrite( s, buf, len )
115 # define tcp_close( s ) close( s )
116 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
117 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
120 # define tcp_close( s ) do { netclose( s ); netshut() } while(0)
121 # define tcp_read( s, buf, len ) nread( s, buf, len )
122 # define tcp_write( s, buf, len ) netwrite( s, buf, len )
125 #elif HAVE_CLOSESOCKET
126 # define tcp_close( s ) closesocket( s )
129 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
130 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
134 # define tcp_read( s, buf, len) read( s, buf, len )
135 # define tcp_write( s, buf, len) write( s, buf, len )
138 # define tcp_close( s ) (shutdown( s, SHUT_RDWR ), close( s ))
140 # define tcp_close( s ) close( s )
145 * Only use pipe() on systems where file and socket descriptors
148 # define USE_PIPE HAVE_PIPE
157 #ifndef AC_SOCKET_INVALID
158 # define AC_SOCKET_INVALID (-1)
160 #ifndef AC_SOCKET_ERROR
161 # define AC_SOCKET_ERROR (-1)
164 #if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
165 # define inet_aton ldap_pvt_inet_aton
167 LDAP_F (int) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
170 #if defined(__WIN32) && defined(_ALPHA)
171 /* NT on Alpha is hosed. */
172 # define AC_HTONL( l ) \
173 ((((l)&0xffU)<<24) + (((l)&0xff00U)<<8) + \
174 (((l)&0xff0000U)>>8) + (((l)&0xff000000U)>>24))
175 # define AC_NTOHL(l) AC_HTONL(l)
178 # define AC_HTONL( l ) htonl( l )
179 # define AC_NTOHL( l ) ntohl( l )
182 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
183 #define AC_HTONS( s ) htons( s )
184 #define AC_NTOHS( s ) ntohs( s )
187 # if !defined( AF_LOCAL ) && defined( AF_UNIX )
188 # define AF_LOCAL AF_UNIX
190 # if !defined( PF_LOCAL ) && defined( PF_UNIX )
191 # define PF_LOCAL PF_UNIX
195 #ifndef INET_ADDRSTRLEN
196 # define INET_ADDRSTRLEN 16
198 #ifndef INET6_ADDRSTRLEN
199 # define INET6_ADDRSTRLEN 46
202 #if defined( HAVE_GETADDRINFO ) || defined( HAVE_GETNAMEINFO )
203 # ifdef HAVE_GAI_STRERROR
204 # define AC_GAI_STRERROR(x) (gai_strerror((x)))
206 # define AC_GAI_STRERROR(x) (ldap_pvt_gai_strerror((x)))
207 LDAP_F (char *) ldap_pvt_gai_strerror( int );
211 #ifndef HAVE_GETPEEREID
212 LDAP_LUTIL_F( int ) getpeereid( int s, uid_t *, gid_t * );
215 /* DNS RFC defines max host name as 255. New systems seem to use 1024 */
217 #define NI_MAXHOST 256
226 #endif /* _AC_SOCKET_H_ */