]> git.sur5r.net Git - openldap/blob - include/ac/socket.h
26af7a571ad571badf8c98caa6cdb89bd932957a
[openldap] / include / ac / socket.h
1 /* Generic socket.h */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, Redwood City, California, USA
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are permitted only
8  * as authorized by the OpenLDAP Public License.  A copy of this
9  * license is available at http://www.OpenLDAP.org/license.html or
10  * in file LICENSE in the top-level directory of the distribution.
11  */
12
13 #ifndef _AC_SOCKET_H_
14 #define _AC_SOCKET_H_
15
16 #ifdef HAVE_SYS_TYPES_H
17 #include <sys/types.h>
18 #endif
19
20 #ifdef HAVE_SYS_SOCKET_H
21 #include <sys/socket.h>
22
23 #ifdef HAVE_SYS_UN_H
24 #include <sys/un.h>
25 #endif
26
27 #ifdef HAVE_SYS_SELECT_H
28 #include <sys/select.h>
29 #endif
30
31 #include <netinet/in.h>
32
33 #ifdef HAVE_NETINET_TCP_H
34 #include <netinet/tcp.h>
35 #endif
36
37 #ifdef HAVE_ARPA_INET_H
38 #include <arpa/inet.h>
39 #endif
40
41 #ifdef HAVE_ARPA_NAMESER_H
42 #include <arpa/nameser.h>
43 #endif
44
45 #include <netdb.h>
46
47 #ifdef HAVE_RESOLV_H
48 #include <resolv.h>
49 #endif
50
51 #endif /* HAVE_SYS_SOCKET_H */
52
53 #ifdef HAVE_WINSOCK2
54 #include <winsock2.h>
55 #elif HAVE_WINSOCK
56 #include <winsock.h>
57 #else
58 #define WSACleanup()
59 #endif
60
61 #ifdef HAVE_PCNFS
62 #include <tklib.h>
63 #endif /* HAVE_PCNFS */
64
65 #ifndef INADDR_LOOPBACK
66 #define INADDR_LOOPBACK (0x7f000001UL)
67 #endif
68
69 #ifndef MAXHOSTNAMELEN
70 #define MAXHOSTNAMELEN  64
71 #endif
72
73 #undef  sock_errno
74 #undef  sock_errstr
75 #define sock_errno()    errno
76 #define sock_errstr(e)  STRERROR(e)
77
78 #ifdef HAVE_WINSOCK
79 #       define tcp_read( s, buf, len )  recv( s, buf, len, 0 )
80 #       define tcp_write( s, buf, len ) send( s, buf, len, 0 )
81 #       define ioctl( s, c, a )         ioctlsocket( (s), (c), (a) )
82 #       define ioctl_t                          u_long
83 #       define AC_SOCKET_INVALID        ((unsigned int) ~0)
84
85 #       if SD_BOTH
86 #               define tcp_close( s )   (shutdown( s, SD_BOTH ), closesocket( s ))
87 #else
88 #               define tcp_close( s )           closesocket( s )
89 #endif
90
91 #define EWOULDBLOCK WSAEWOULDBLOCK
92 #define EINPROGRESS WSAEINPROGRESS
93 #define ETIMEDOUT       WSAETIMEDOUT
94
95 #undef  sock_errno
96 #undef  sock_errstr
97 #define sock_errno()    WSAGetLastError()
98 #define sock_errstr(e)  ber_pvt_wsa_err2string(e)
99
100 LBER_F( char * ) ber_pvt_wsa_err2string LDAP_P((int));
101
102 #elif MACOS
103 #       define tcp_close( s )           tcpclose( s )
104 #       define tcp_read( s, buf, len )  tcpread( s, buf, len )
105 #       define tcp_write( s, buf, len ) tcpwrite( s, buf, len )
106
107 #elif DOS
108 #       ifdef PCNFS
109 #               define tcp_close( s )   close( s )
110 #               define tcp_read( s, buf, len )  recv( s, buf, len, 0 )
111 #               define tcp_write( s, buf, len ) send( s, buf, len, 0 )
112 #       endif /* PCNFS */
113 #       ifdef NCSA
114 #               define tcp_close( s )   do { netclose( s ); netshut() } while(0)
115 #               define tcp_read( s, buf, len )  nread( s, buf, len )
116 #               define tcp_write( s, buf, len ) netwrite( s, buf, len )
117 #       endif /* NCSA */
118
119 #elif HAVE_CLOSESOCKET
120 #       define tcp_close( s )           closesocket( s )
121
122 #       ifdef __BEOS__
123 #               define tcp_read( s, buf, len )  recv( s, buf, len, 0 )
124 #               define tcp_write( s, buf, len ) send( s, buf, len, 0 )
125 #       endif
126
127 #else
128 #       define tcp_read( s, buf, len)   read( s, buf, len )
129 #       define tcp_write( s, buf, len)  write( s, buf, len )
130
131 #       if SHUT_RDWR
132 #               define tcp_close( s )   (shutdown( s, SHUT_RDWR ), close( s ))
133 #else
134 #               define tcp_close( s )           close( s )
135 #endif
136
137 #ifdef HAVE_PIPE
138 /*
139  * Only use pipe() on systems where file and socket descriptors 
140  * are interchangable
141  */
142 #define USE_PIPE HAVE_PIPE
143 #endif
144
145 #endif /* MACOS */
146
147 #ifndef ioctl_t
148 #       define ioctl_t                          int
149 #endif
150
151 #ifndef AC_SOCKET_INVALID
152 #       define AC_SOCKET_INVALID        (-1)
153 #endif
154 #ifndef AC_SOCKET_ERROR
155 #       define AC_SOCKET_ERROR          (-1)
156 #endif
157
158 #if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
159 #define inet_aton ldap_pvt_inet_aton
160 struct in_addr;
161 LDAP_F (int) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
162 #endif
163
164 #if     defined(__WIN32) && defined(_ALPHA)
165 /* NT on Alpha is hosed. */
166 #       define AC_HTONL( l ) \
167         ((((l)&0xffU)<<24) + (((l)&0xff00U)<<8) + \
168          (((l)&0xff0000U)>>8) + (((l)&0xff000000U)>>24))
169 #       define AC_NTOHL(l) AC_HTONL(l)
170
171 #else
172 #       define AC_HTONL( l ) htonl( l )
173 #       define AC_NTOHL( l ) ntohl( l )
174 #endif
175
176 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
177 #define AC_HTONS( s ) htons( s )
178 #define AC_NTOHS( s ) ntohs( s )
179
180 #ifdef LDAP_PF_LOCAL
181 #  if !defined( AF_LOCAL ) && defined( AF_UNIX )
182 #    define AF_LOCAL    AF_UNIX
183 #  endif
184 #  if !defined( PF_LOCAL ) && defined( PF_UNIX )
185 #    define PF_LOCAL    PF_UNIX
186 #  endif
187 #endif
188
189 #ifndef INET_ADDRSTRLEN
190 #       define INET_ADDRSTRLEN 16
191 #endif
192 #ifndef INET6_ADDRSTRLEN
193 #       define INET6_ADDRSTRLEN 46
194 #endif
195
196 #ifdef HAVE_GETADDRINFO
197 #       ifdef HAVE_GAI_STRERROR
198 #               define AC_GAI_STRERROR(x)       (gai_strerror((x)))
199 #       else
200 #               define AC_GAI_STRERROR(x)       (ldap_pvt_gai_strerror((x)))
201                 char * ldap_pvt_gai_strerror( int );
202 #       endif
203 #endif
204
205 #endif /* _AC_SOCKET_H_ */