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>
24 #ifdef HAVE_SYS_SOCKET_H
25 #include <sys/socket.h>
31 #ifdef HAVE_SYS_SELECT_H
32 #include <sys/select.h>
35 #include <netinet/in.h>
37 #ifdef HAVE_NETINET_TCP_H
38 #include <netinet/tcp.h>
41 #ifdef HAVE_ARPA_INET_H
42 #include <arpa/inet.h>
45 #ifdef HAVE_ARPA_NAMESER_H
46 #include <arpa/nameser.h>
55 #endif /* HAVE_SYS_SOCKET_H */
65 #endif /* HAVE_PCNFS */
67 #ifndef INADDR_LOOPBACK
68 #define INADDR_LOOPBACK (0x7f000001UL)
71 #ifndef MAXHOSTNAMELEN
72 #define MAXHOSTNAMELEN 64
77 #define sock_errno() errno
78 #define sock_errstr(e) STRERROR(e)
81 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
82 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
83 # define ioctl( s, c, a ) ioctlsocket( (s), (c), (a) )
84 # define ioctl_t u_long
85 # define AC_SOCKET_INVALID ((unsigned int) ~0)
88 # define tcp_close( s ) (shutdown( s, SD_BOTH ), closesocket( s ))
90 # define tcp_close( s ) closesocket( s )
93 #define EWOULDBLOCK WSAEWOULDBLOCK
94 #define EINPROGRESS WSAEINPROGRESS
95 #define ETIMEDOUT WSAETIMEDOUT
99 #define sock_errno() WSAGetLastError()
100 #define sock_errstr(e) ber_pvt_wsa_err2string(e)
102 LBER_F( char * ) ber_pvt_wsa_err2string LDAP_P((int));
105 # define tcp_close( s ) tcpclose( s )
106 # define tcp_read( s, buf, len ) tcpread( s, buf, len )
107 # define tcp_write( s, buf, len ) tcpwrite( s, buf, len )
111 # define tcp_close( s ) close( s )
112 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
113 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
116 # define tcp_close( s ) do { netclose( s ); netshut() } while(0)
117 # define tcp_read( s, buf, len ) nread( s, buf, len )
118 # define tcp_write( s, buf, len ) netwrite( s, buf, len )
121 #elif HAVE_CLOSESOCKET
122 # define tcp_close( s ) closesocket( s )
125 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
126 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
130 # define tcp_read( s, buf, len) read( s, buf, len )
131 # define tcp_write( s, buf, len) write( s, buf, len )
134 # define tcp_close( s ) (shutdown( s, SHUT_RDWR ), close( s ))
136 # define tcp_close( s ) close( s )
141 * Only use pipe() on systems where file and socket descriptors
144 # define USE_PIPE HAVE_PIPE
153 #ifndef AC_SOCKET_INVALID
154 # define AC_SOCKET_INVALID (-1)
156 #ifndef AC_SOCKET_ERROR
157 # define AC_SOCKET_ERROR (-1)
160 #if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
161 # define inet_aton ldap_pvt_inet_aton
163 LDAP_F (int) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
166 #if defined(__WIN32) && defined(_ALPHA)
167 /* NT on Alpha is hosed. */
168 # define AC_HTONL( l ) \
169 ((((l)&0xffU)<<24) + (((l)&0xff00U)<<8) + \
170 (((l)&0xff0000U)>>8) + (((l)&0xff000000U)>>24))
171 # define AC_NTOHL(l) AC_HTONL(l)
174 # define AC_HTONL( l ) htonl( l )
175 # define AC_NTOHL( l ) ntohl( l )
178 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
179 #define AC_HTONS( s ) htons( s )
180 #define AC_NTOHS( s ) ntohs( s )
183 # if !defined( AF_LOCAL ) && defined( AF_UNIX )
184 # define AF_LOCAL AF_UNIX
186 # if !defined( PF_LOCAL ) && defined( PF_UNIX )
187 # define PF_LOCAL PF_UNIX
191 #ifndef INET_ADDRSTRLEN
192 # define INET_ADDRSTRLEN 16
194 #ifndef INET6_ADDRSTRLEN
195 # define INET6_ADDRSTRLEN 46
198 #if defined( HAVE_GETADDRINFO ) || defined( HAVE_GETNAMEINFO )
199 # ifdef HAVE_GAI_STRERROR
200 # define AC_GAI_STRERROR(x) (gai_strerror((x)))
202 # define AC_GAI_STRERROR(x) (ldap_pvt_gai_strerror((x)))
203 LDAP_F (char *) ldap_pvt_gai_strerror( int );
207 #ifndef HAVE_GETPEEREID
208 LDAP_LUTIL_F( int ) getpeereid( int s, uid_t *, gid_t * );
211 /* DNS RFC defines max host name as 255. New systems seem to use 1024 */
213 #define NI_MAXHOST 256
216 #endif /* _AC_SOCKET_H_ */