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