]> git.sur5r.net Git - openldap/blob - include/ac/socket.h
s/Id/OpenLDAP/ in RCSids
[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 #elif MACOS
92 #       define tcp_close( s )           tcpclose( s )
93 #       define tcp_read( s, buf, len )  tcpread( s, buf, len )
94 #       define tcp_write( s, buf, len ) tcpwrite( s, buf, len )
95
96 #elif DOS
97 #       ifdef PCNFS
98 #               define tcp_close( s )   close( s )
99 #               define tcp_read( s, buf, len )  recv( s, buf, len, 0 )
100 #               define tcp_write( s, buf, len ) send( s, buf, len, 0 )
101 #       endif /* PCNFS */
102 #       ifdef NCSA
103 #               define tcp_close( s )   do { netclose( s ); netshut() } while(0)
104 #               define tcp_read( s, buf, len )  nread( s, buf, len )
105 #               define tcp_write( s, buf, len ) netwrite( s, buf, len )
106 #       endif /* NCSA */
107
108 #elif HAVE_CLOSESOCKET
109 #       define tcp_close( s )           closesocket( s )
110
111 #else
112 #       define tcp_close( s )           close( s )
113 #       define tcp_read( s, buf, len)   read( s, buf, len )
114 #       define tcp_write( s, buf, len)  write( s, buf, len )
115 #endif /* MACOS */
116
117 #ifndef ioctl_t
118 #       define ioctl_t                          int
119 #endif
120
121 #ifndef AC_SOCKET_INVALID
122 #       define AC_SOCKET_INVALID        (-1)
123 #endif
124
125 #if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
126 #define inet_aton ldap_pvt_inet_aton
127 struct in_addr;
128 int ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
129 #endif
130
131 #if     defined(__WIN32) && defined(_ALPHA)
132 /* NT on Alpha is hosed. */
133 #define AC_HTONL( l ) \
134         ((((l)&0xff)<<24) + (((l)&0xff00)<<8) + \
135          (((l)&0xff0000)>>8) + (((l)&0xff000000)>>24))
136 #define AC_NTOHL(l) AC_HTONL(l)
137
138 #elif defined(__alpha) && !defined(VMS)
139 /*
140  * htonl and ntohl on the DEC Alpha under OSF 1 seem to only swap the
141  * lower-order 32-bits of a (64-bit) long, so we define correct versions
142  * here.
143  */ 
144 #define AC_HTONL( l )   (((long)htonl( (l) & 0x00000000FFFFFFFF )) << 32 \
145         | htonl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
146
147 #define AC_NTOHL( l ) (((long)ntohl( (l) & 0x00000000FFFFFFFF )) << 32 \
148         | ntohl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
149
150 #else
151 #define AC_HTONL( l ) htonl( l )
152 #define AC_NTOHL( l ) ntohl( l )
153 #endif
154
155 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
156 #define AC_HTONS( s ) htons( s )
157 #define AC_NTOHS( s ) ntohs( s )
158
159
160 #endif /* _AC_SOCKET_H_ */