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