]> git.sur5r.net Git - openldap/blob - include/ac/socket.h
e0b7ec945d2a3033a9f08e600d13a7ad2cd29eb7
[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_SYS_SOCKET_H
25 #include <sys/socket.h>
26
27 #ifdef HAVE_SYS_UN_H
28 #include <sys/un.h>
29 #endif
30
31 #ifdef HAVE_SYS_SELECT_H
32 #include <sys/select.h>
33 #endif
34
35 #include <netinet/in.h>
36
37 #ifdef HAVE_NETINET_TCP_H
38 #include <netinet/tcp.h>
39 #endif
40
41 #ifdef HAVE_ARPA_INET_H
42 #include <arpa/inet.h>
43 #endif
44
45 #ifdef HAVE_ARPA_NAMESER_H
46 #include <arpa/nameser.h>
47 #endif
48
49 #include <netdb.h>
50
51 #ifdef HAVE_RESOLV_H
52 #include <resolv.h>
53 #endif
54
55 #endif /* HAVE_SYS_SOCKET_H */
56
57 #ifdef HAVE_WINSOCK2
58 #include <winsock2.h>
59 #elif HAVE_WINSOCK
60 #include <winsock.h>
61 #endif
62
63 #ifdef HAVE_PCNFS
64 #include <tklib.h>
65 #endif /* HAVE_PCNFS */
66
67 #ifndef INADDR_LOOPBACK
68 #define INADDR_LOOPBACK (0x7f000001UL)
69 #endif
70
71 #ifndef MAXHOSTNAMELEN
72 #define MAXHOSTNAMELEN  64
73 #endif
74
75 #undef  sock_errno
76 #undef  sock_errstr
77 #define sock_errno()    errno
78 #define sock_errstr(e)  STRERROR(e)
79
80 #ifdef HAVE_WINSOCK
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)
86
87 #       ifdef SD_BOTH
88 #               define tcp_close( s )   (shutdown( s, SD_BOTH ), closesocket( s ))
89 #       else
90 #               define tcp_close( s )           closesocket( s )
91 #       endif
92
93 #define EWOULDBLOCK WSAEWOULDBLOCK
94 #define EINPROGRESS WSAEINPROGRESS
95 #define ETIMEDOUT       WSAETIMEDOUT
96
97 #undef  sock_errno
98 #undef  sock_errstr
99 #define sock_errno()    WSAGetLastError()
100 #define sock_errstr(e)  ber_pvt_wsa_err2string(e)
101
102 LBER_F( char * ) ber_pvt_wsa_err2string LDAP_P((int));
103
104 #elif MACOS
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 )
108
109 #elif DOS
110 #       ifdef PCNFS
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 )
114 #       endif /* PCNFS */
115 #       ifdef NCSA
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 )
119 #       endif /* NCSA */
120
121 #elif HAVE_CLOSESOCKET
122 #       define tcp_close( s )           closesocket( s )
123
124 #       ifdef __BEOS__
125 #               define tcp_read( s, buf, len )  recv( s, buf, len, 0 )
126 #               define tcp_write( s, buf, len ) send( s, buf, len, 0 )
127 #       endif
128
129 #else
130 #       define tcp_read( s, buf, len)   read( s, buf, len )
131 #       define tcp_write( s, buf, len)  write( s, buf, len )
132
133 #       ifdef SHUT_RDWR
134 #               define tcp_close( s )   (shutdown( s, SHUT_RDWR ), close( s ))
135 #       else
136 #               define tcp_close( s )   close( s )
137 #       endif
138
139 #ifdef HAVE_PIPE
140 /*
141  * Only use pipe() on systems where file and socket descriptors
142  * are interchangable
143  */
144 #       define USE_PIPE HAVE_PIPE
145 #endif
146
147 #endif /* MACOS */
148
149 #ifndef ioctl_t
150 #       define ioctl_t                          int
151 #endif
152
153 #ifndef AC_SOCKET_INVALID
154 #       define AC_SOCKET_INVALID        (-1)
155 #endif
156 #ifndef AC_SOCKET_ERROR
157 #       define AC_SOCKET_ERROR          (-1)
158 #endif
159
160 #if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
161 #       define inet_aton ldap_pvt_inet_aton
162 struct in_addr;
163 LDAP_F (int) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
164 #endif
165
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)
172
173 #else
174 #       define AC_HTONL( l ) htonl( l )
175 #       define AC_NTOHL( l ) ntohl( l )
176 #endif
177
178 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
179 #define AC_HTONS( s ) htons( s )
180 #define AC_NTOHS( s ) ntohs( s )
181
182 #ifdef LDAP_PF_LOCAL
183 #  if !defined( AF_LOCAL ) && defined( AF_UNIX )
184 #    define AF_LOCAL    AF_UNIX
185 #  endif
186 #  if !defined( PF_LOCAL ) && defined( PF_UNIX )
187 #    define PF_LOCAL    PF_UNIX
188 #  endif
189 #endif
190
191 #ifndef INET_ADDRSTRLEN
192 #       define INET_ADDRSTRLEN 16
193 #endif
194 #ifndef INET6_ADDRSTRLEN
195 #       define INET6_ADDRSTRLEN 46
196 #endif
197
198 #if defined( HAVE_GETADDRINFO ) || defined( HAVE_GETNAMEINFO )
199 #       ifdef HAVE_GAI_STRERROR
200 #               define AC_GAI_STRERROR(x)       (gai_strerror((x)))
201 #       else
202 #               define AC_GAI_STRERROR(x)       (ldap_pvt_gai_strerror((x)))
203                 LDAP_F (char *) ldap_pvt_gai_strerror( int );
204 #       endif
205 #endif
206
207 #ifndef HAVE_GETPEEREID
208 LDAP_LUTIL_F( int ) getpeereid( int s, uid_t *, gid_t * );
209 #endif
210
211 /* DNS RFC defines max host name as 255. New systems seem to use 1024 */
212 #ifndef NI_MAXHOST
213 #define NI_MAXHOST      256
214 #endif
215
216 #endif /* _AC_SOCKET_H_ */