]> git.sur5r.net Git - openldap/blob - include/ac/socket.h
- Added autoconf test for CRL capable OpenSSL Version
[openldap] / include / ac / socket.h
1 /* Generic socket.h */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2004 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16
17 #ifndef _AC_SOCKET_H_
18 #define _AC_SOCKET_H_
19
20 #ifdef HAVE_SYS_TYPES_H
21 #include <sys/types.h>
22 #endif
23
24 #ifdef HAVE_POLL_H
25 #include <poll.h>
26 #endif
27
28 #ifdef HAVE_SYS_SOCKET_H
29 #include <sys/socket.h>
30
31 #ifdef HAVE_SYS_UN_H
32 #include <sys/un.h>
33 #endif
34
35 #ifdef HAVE_SYS_SELECT_H
36 #include <sys/select.h>
37 #endif
38
39 #include <netinet/in.h>
40
41 #ifdef HAVE_NETINET_TCP_H
42 #include <netinet/tcp.h>
43 #endif
44
45 #ifdef HAVE_ARPA_INET_H
46 #include <arpa/inet.h>
47 #endif
48
49 #ifdef HAVE_ARPA_NAMESER_H
50 #include <arpa/nameser.h>
51 #endif
52
53 #include <netdb.h>
54
55 #ifdef HAVE_RESOLV_H
56 #include <resolv.h>
57 #endif
58
59 #endif /* HAVE_SYS_SOCKET_H */
60
61 #ifdef HAVE_WINSOCK2
62 #include <winsock2.h>
63 #elif HAVE_WINSOCK
64 #include <winsock.h>
65 #endif
66
67 #ifdef HAVE_PCNFS
68 #include <tklib.h>
69 #endif /* HAVE_PCNFS */
70
71 #ifndef INADDR_LOOPBACK
72 #define INADDR_LOOPBACK (0x7f000001UL)
73 #endif
74
75 #ifndef MAXHOSTNAMELEN
76 #define MAXHOSTNAMELEN  64
77 #endif
78
79 #undef  sock_errno
80 #undef  sock_errstr
81 #define sock_errno()    errno
82 #define sock_errstr(e)  STRERROR(e)
83
84 #ifdef HAVE_WINSOCK
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)
90
91 #       ifdef SD_BOTH
92 #               define tcp_close( s )   (shutdown( s, SD_BOTH ), closesocket( s ))
93 #       else
94 #               define tcp_close( s )           closesocket( s )
95 #       endif
96
97 #define EWOULDBLOCK WSAEWOULDBLOCK
98 #define EINPROGRESS WSAEINPROGRESS
99 #define ETIMEDOUT       WSAETIMEDOUT
100
101 #undef  sock_errno
102 #undef  sock_errstr
103 #define sock_errno()    WSAGetLastError()
104 #define sock_errstr(e)  ber_pvt_wsa_err2string(e)
105
106 LBER_F( char * ) ber_pvt_wsa_err2string LDAP_P((int));
107
108 #elif MACOS
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 )
112
113 #elif DOS
114 #       ifdef PCNFS
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 )
118 #       endif /* PCNFS */
119 #       ifdef NCSA
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 )
123 #       endif /* NCSA */
124
125 #elif HAVE_CLOSESOCKET
126 #       define tcp_close( s )           closesocket( s )
127
128 #       ifdef __BEOS__
129 #               define tcp_read( s, buf, len )  recv( s, buf, len, 0 )
130 #               define tcp_write( s, buf, len ) send( s, buf, len, 0 )
131 #       endif
132
133 #else
134 #       define tcp_read( s, buf, len)   read( s, buf, len )
135 #       define tcp_write( s, buf, len)  write( s, buf, len )
136
137 #       ifdef SHUT_RDWR
138 #               define tcp_close( s )   (shutdown( s, SHUT_RDWR ), close( s ))
139 #       else
140 #               define tcp_close( s )   close( s )
141 #       endif
142
143 #ifdef HAVE_PIPE
144 /*
145  * Only use pipe() on systems where file and socket descriptors
146  * are interchangable
147  */
148 #       define USE_PIPE HAVE_PIPE
149 #endif
150
151 #endif /* MACOS */
152
153 #ifndef ioctl_t
154 #       define ioctl_t                          int
155 #endif
156
157 #ifndef AC_SOCKET_INVALID
158 #       define AC_SOCKET_INVALID        (-1)
159 #endif
160 #ifndef AC_SOCKET_ERROR
161 #       define AC_SOCKET_ERROR          (-1)
162 #endif
163
164 #if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
165 #       define inet_aton ldap_pvt_inet_aton
166 struct in_addr;
167 LDAP_F (int) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
168 #endif
169
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)
176
177 #else
178 #       define AC_HTONL( l ) htonl( l )
179 #       define AC_NTOHL( l ) ntohl( l )
180 #endif
181
182 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
183 #define AC_HTONS( s ) htons( s )
184 #define AC_NTOHS( s ) ntohs( s )
185
186 #ifdef LDAP_PF_LOCAL
187 #  if !defined( AF_LOCAL ) && defined( AF_UNIX )
188 #    define AF_LOCAL    AF_UNIX
189 #  endif
190 #  if !defined( PF_LOCAL ) && defined( PF_UNIX )
191 #    define PF_LOCAL    PF_UNIX
192 #  endif
193 #endif
194
195 #ifndef INET_ADDRSTRLEN
196 #       define INET_ADDRSTRLEN 16
197 #endif
198 #ifndef INET6_ADDRSTRLEN
199 #       define INET6_ADDRSTRLEN 46
200 #endif
201
202 #if defined( HAVE_GETADDRINFO ) || defined( HAVE_GETNAMEINFO )
203 #       ifdef HAVE_GAI_STRERROR
204 #               define AC_GAI_STRERROR(x)       (gai_strerror((x)))
205 #       else
206 #               define AC_GAI_STRERROR(x)       (ldap_pvt_gai_strerror((x)))
207                 LDAP_F (char *) ldap_pvt_gai_strerror( int );
208 #       endif
209 #endif
210
211 #ifndef HAVE_GETPEEREID
212 LDAP_LUTIL_F( int ) getpeereid( int s, uid_t *, gid_t * );
213 #endif
214
215 /* DNS RFC defines max host name as 255. New systems seem to use 1024 */
216 #ifndef NI_MAXHOST
217 #define NI_MAXHOST      256
218 #endif
219
220 #ifdef HAVE_POLL_H
221 # ifndef INFTIM
222 #  define INFTIM (-1)
223 # endif
224 #undef POLL_OTHER
225 #define POLL_OTHER   (POLLERR|POLLHUP)
226 #undef POLL_READ
227 #define POLL_READ    (POLLIN|POLLPRI|POLL_OTHER)
228 #undef POLL_WRITE              
229 #define POLL_WRITE   (POLLOUT|POLL_OTHER)
230 #endif
231
232 #endif /* _AC_SOCKET_H_ */