]> git.sur5r.net Git - openldap/blob - include/ac/socket.h
Generate OpenLDAP id for configure
[openldap] / include / ac / socket.h
1 /* Generic socket.h */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998,1999 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_SELECT_H
24 #include <sys/select.h>
25 #endif
26
27 #include <netinet/in.h>
28
29 #ifdef HAVE_NETINET_TCP_H
30 #include <netinet/tcp.h>
31 #endif
32
33 #ifdef HAVE_ARPA_INET_H
34 #include <arpa/inet.h>
35 #endif
36
37 #ifdef HAVE_ARPA_NAMESER_H
38 #include <arpa/nameser.h>
39 #endif
40
41 #include <netdb.h>
42
43 #ifdef HAVE_RESOLV_H
44 #include <resolv.h>
45 #endif
46
47 #endif /* HAVE_SYS_SOCKET_H */
48
49 #ifdef HAVE_WINSOCK2
50 #include <winsock2.h>
51 #elif HAVE_WINSOCK
52 #include <winsock.h>
53 #else
54 #define WSACleanup()
55 #endif
56
57 #ifdef HAVE_PCNFS
58 #include <tklib.h>
59 #endif /* HAVE_PCNFS */
60
61 #ifndef INADDR_LOOPBACK
62 #define INADDR_LOOPBACK (0x7f000001UL)
63 #endif
64
65 #ifndef MAXHOSTNAMELEN
66 #define MAXHOSTNAMELEN  64
67 #endif
68
69 #undef  sock_errno
70 #undef  sock_errstr
71 #define sock_errno()    errno
72 #define sock_errstr(e)  STRERROR(e)
73
74 #ifdef HAVE_WINSOCK
75 #       define tcp_close( s )           closesocket( s )
76 #       define tcp_read( s, buf, len )  recv( s, buf, len, 0 )
77 #       define tcp_write( s, buf, len ) send( s, buf, len, 0 )
78 #       define ioctl( s, c, a )         ioctlsocket( (s), (c), (a) )
79 #       define ioctl_t                          u_long
80 #       define AC_SOCKET_INVALID        ((unsigned int) ~0)
81
82 #define EWOULDBLOCK WSAEWOULDBLOCK
83 #define EINPROGRESS WSAEINPROGRESS
84 #define ETIMEDOUT       WSAETIMEDOUT
85
86 #undef  sock_errno
87 #undef  sock_errstr
88 #define sock_errno()    WSAGetLastError()
89 #define sock_errstr(e)  WSAGetErrorString(e)
90
91 extern char* WSAGetErrorString LDAP_P((int));
92
93 #elif MACOS
94 #       define tcp_close( s )           tcpclose( s )
95 #       define tcp_read( s, buf, len )  tcpread( s, buf, len )
96 #       define tcp_write( s, buf, len ) tcpwrite( s, buf, len )
97
98 #elif DOS
99 #       ifdef PCNFS
100 #               define tcp_close( s )   close( s )
101 #               define tcp_read( s, buf, len )  recv( s, buf, len, 0 )
102 #               define tcp_write( s, buf, len ) send( s, buf, len, 0 )
103 #       endif /* PCNFS */
104 #       ifdef NCSA
105 #               define tcp_close( s )   do { netclose( s ); netshut() } while(0)
106 #               define tcp_read( s, buf, len )  nread( s, buf, len )
107 #               define tcp_write( s, buf, len ) netwrite( s, buf, len )
108 #       endif /* NCSA */
109
110 #elif HAVE_CLOSESOCKET
111 #       define tcp_close( s )           closesocket( s )
112
113 #else
114 #       define tcp_close( s )           close( s )
115 #       define tcp_read( s, buf, len)   read( s, buf, len )
116 #       define tcp_write( s, buf, len)  write( s, buf, len )
117
118 #ifdef HAVE_PIPE
119 /*
120  * Only use pipe() on systems where file and socket descriptors 
121  * are interchangable
122  */
123 #define USE_PIPE HAVE_PIPE
124 #endif
125
126 #endif /* MACOS */
127
128 #ifndef ioctl_t
129 #       define ioctl_t                          int
130 #endif
131
132 #ifndef AC_SOCKET_INVALID
133 #       define AC_SOCKET_INVALID        (-1)
134 #endif
135 #ifndef AC_SOCKET_ERROR
136 #       define AC_SOCKET_ERROR          (-1)
137 #endif
138
139 #if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
140 #define inet_aton ldap_pvt_inet_aton
141 struct in_addr;
142 int ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
143 #endif
144
145 #if     defined(__WIN32) && defined(_ALPHA)
146 /* NT on Alpha is hosed. */
147 #define AC_HTONL( l ) \
148         ((((l)&0xff)<<24) + (((l)&0xff00)<<8) + \
149          (((l)&0xff0000)>>8) + (((l)&0xff000000)>>24))
150 #define AC_NTOHL(l) AC_HTONL(l)
151
152 #elif defined(__alpha) && !defined(VMS)
153 /*
154  * htonl and ntohl on the DEC Alpha under OSF 1 seem to only swap the
155  * lower-order 32-bits of a (64-bit) long, so we define correct versions
156  * here.
157  */ 
158 #define AC_HTONL( l )   (((long)htonl( (l) & 0x00000000FFFFFFFF )) << 32 \
159         | htonl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
160
161 #define AC_NTOHL( l ) (((long)ntohl( (l) & 0x00000000FFFFFFFF )) << 32 \
162         | ntohl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
163
164 #else
165 #define AC_HTONL( l ) htonl( l )
166 #define AC_NTOHL( l ) ntohl( l )
167 #endif
168
169 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
170 #define AC_HTONS( s ) htons( s )
171 #define AC_NTOHS( s ) ntohs( s )
172
173
174 #endif /* _AC_SOCKET_H_ */