socket.h 4.92 KB
Newer Older
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1
/* Generic socket.h */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
2
/* $OpenLDAP$ */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
3
4
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 *
Kurt Zeilenga's avatar
Kurt Zeilenga committed
5
 * Copyright 1998-2004 The OpenLDAP Foundation.
6
7
 * All rights reserved.
 *
8
9
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted only as authorized by the OpenLDAP
Kurt Zeilenga's avatar
Kurt Zeilenga committed
10
11
12
13
14
 * Public License.
 *
 * A copy of this license is available in file LICENSE in the
 * top-level directory of the distribution or, alternatively, at
 * <http://www.OpenLDAP.org/license.html>.
15
 */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
16
17
18
19
20
21
22
23

#ifndef _AC_SOCKET_H_
#define _AC_SOCKET_H_

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
24
25
26
27
#ifdef HAVE_POLL_H
#include <poll.h>
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
28
29
30
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>

31
32
33
34
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
35
36
37
38
39
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif

#include <netinet/in.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
40
41

#ifdef HAVE_NETINET_TCP_H
42
#include <netinet/tcp.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
43
#endif
Ben Collins's avatar
Ben Collins committed
44
45

#ifdef HAVE_ARPA_INET_H
Kurt Zeilenga's avatar
Kurt Zeilenga committed
46
#include <arpa/inet.h>
Ben Collins's avatar
Ben Collins committed
47
#endif
48
49

#ifdef HAVE_ARPA_NAMESER_H
Kurt Zeilenga's avatar
Kurt Zeilenga committed
50
#include <arpa/nameser.h>
51
52
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
53
#include <netdb.h>
54
55

#ifdef HAVE_RESOLV_H
Kurt Zeilenga's avatar
Kurt Zeilenga committed
56
57
58
#include <resolv.h>
#endif

59
60
#endif /* HAVE_SYS_SOCKET_H */

Kurt Zeilenga's avatar
Kurt Zeilenga committed
61
#ifdef HAVE_WINSOCK2
62
63
64
#include <winsock2.h>
#elif HAVE_WINSOCK
#include <winsock.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
65
66
67
68
69
70
71
#endif

#ifdef HAVE_PCNFS
#include <tklib.h>
#endif /* HAVE_PCNFS */

#ifndef INADDR_LOOPBACK
Kurt Zeilenga's avatar
Kurt Zeilenga committed
72
#define INADDR_LOOPBACK	(0x7f000001UL)
Kurt Zeilenga's avatar
Kurt Zeilenga committed
73
74
75
76
77
78
#endif

#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN  64
#endif

79
80
81
82
#undef	sock_errno
#undef	sock_errstr
#define sock_errno()	errno
#define sock_errstr(e)	STRERROR(e)
83

84
#ifdef HAVE_WINSOCK
85
86
#	define tcp_read( s, buf, len )	recv( s, buf, len, 0 )
#	define tcp_write( s, buf, len )	send( s, buf, len, 0 )
87
#	define ioctl( s, c, a )		ioctlsocket( (s), (c), (a) )
88
#	define ioctl_t				u_long
89
#	define AC_SOCKET_INVALID	((unsigned int) ~0)
90

91
#	ifdef SD_BOTH
92
#		define tcp_close( s )	(shutdown( s, SD_BOTH ), closesocket( s ))
Kurt Zeilenga's avatar
Kurt Zeilenga committed
93
#	else
94
#		define tcp_close( s )		closesocket( s )
Kurt Zeilenga's avatar
Kurt Zeilenga committed
95
#	endif
96

97
#define EWOULDBLOCK WSAEWOULDBLOCK
98
99
#define EINPROGRESS WSAEINPROGRESS
#define ETIMEDOUT	WSAETIMEDOUT
100

101
102
103
#undef	sock_errno
#undef	sock_errstr
#define	sock_errno()	WSAGetLastError()
104
#define	sock_errstr(e)	ber_pvt_wsa_err2string(e)
105

106
LBER_F( char * ) ber_pvt_wsa_err2string LDAP_P((int));
107

108
109
#elif MACOS
#	define tcp_close( s )		tcpclose( s )
110
111
#	define tcp_read( s, buf, len )	tcpread( s, buf, len )
#	define tcp_write( s, buf, len )	tcpwrite( s, buf, len )
112

113
114
115
#elif DOS
#	ifdef PCNFS
#		define tcp_close( s )	close( s )
116
117
#		define tcp_read( s, buf, len )	recv( s, buf, len, 0 )
#		define tcp_write( s, buf, len )	send( s, buf, len, 0 )
118
119
120
#	endif /* PCNFS */
#	ifdef NCSA
#		define tcp_close( s )	do { netclose( s ); netshut() } while(0)
121
122
#		define tcp_read( s, buf, len )	nread( s, buf, len )
#		define tcp_write( s, buf, len )	netwrite( s, buf, len )
123
#	endif /* NCSA */
124
125
126
127

#elif HAVE_CLOSESOCKET
#	define tcp_close( s )		closesocket( s )

Kurt Zeilenga's avatar
Kurt Zeilenga committed
128
129
130
131
132
#	ifdef __BEOS__
#		define tcp_read( s, buf, len )	recv( s, buf, len, 0 )
#		define tcp_write( s, buf, len )	send( s, buf, len, 0 )
#	endif

133
#else
134
135
#	define tcp_read( s, buf, len)	read( s, buf, len )
#	define tcp_write( s, buf, len)	write( s, buf, len )
136

137
#	ifdef SHUT_RDWR
138
#		define tcp_close( s )	(shutdown( s, SHUT_RDWR ), close( s ))
Kurt Zeilenga's avatar
Kurt Zeilenga committed
139
140
141
#	else
#		define tcp_close( s )	close( s )
#	endif
142

143
#ifdef HAVE_PIPE
144
/*
145
 * Only use pipe() on systems where file and socket descriptors
146
147
 * are interchangable
 */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
148
#	define USE_PIPE HAVE_PIPE
149
150
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
151
152
#endif /* MACOS */

153
154
155
156
#ifndef ioctl_t
#	define ioctl_t				int
#endif

157
158
159
#ifndef AC_SOCKET_INVALID
#	define AC_SOCKET_INVALID	(-1)
#endif
160
161
162
#ifndef AC_SOCKET_ERROR
#	define AC_SOCKET_ERROR		(-1)
#endif
163

Kurt Zeilenga's avatar
Kurt Zeilenga committed
164
#if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
Kurt Zeilenga's avatar
Kurt Zeilenga committed
165
#	define inet_aton ldap_pvt_inet_aton
Kurt Zeilenga's avatar
Kurt Zeilenga committed
166
struct in_addr;
167
LDAP_F (int) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
Kurt Zeilenga's avatar
Kurt Zeilenga committed
168
169
#endif

170
171
#if	defined(__WIN32) && defined(_ALPHA)
/* NT on Alpha is hosed. */
172
173
174
175
#	define AC_HTONL( l ) \
        ((((l)&0xffU)<<24) + (((l)&0xff00U)<<8) + \
         (((l)&0xff0000U)>>8) + (((l)&0xff000000U)>>24))
#	define AC_NTOHL(l) AC_HTONL(l)
Kurt Zeilenga's avatar
Kurt Zeilenga committed
176

177
#else
178
179
#	define AC_HTONL( l ) htonl( l )
#	define AC_NTOHL( l ) ntohl( l )
180
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
181

182
183
184
185
/* htons()/ntohs() may be broken much like htonl()/ntohl() */
#define AC_HTONS( s ) htons( s )
#define AC_NTOHS( s ) ntohs( s )

Kurt Zeilenga's avatar
Kurt Zeilenga committed
186
187
188
189
190
191
192
193
#ifdef LDAP_PF_LOCAL
#  if !defined( AF_LOCAL ) && defined( AF_UNIX )
#    define AF_LOCAL	AF_UNIX
#  endif
#  if !defined( PF_LOCAL ) && defined( PF_UNIX )
#    define PF_LOCAL	PF_UNIX
#  endif
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
194

195
196
197
198
199
200
201
#ifndef INET_ADDRSTRLEN
#	define INET_ADDRSTRLEN 16
#endif
#ifndef INET6_ADDRSTRLEN
#	define INET6_ADDRSTRLEN 46
#endif

202
#if defined( HAVE_GETADDRINFO ) || defined( HAVE_GETNAMEINFO )
Kurt Zeilenga's avatar
Kurt Zeilenga committed
203
204
205
206
#	ifdef HAVE_GAI_STRERROR
#		define AC_GAI_STRERROR(x)	(gai_strerror((x)))
#	else
#		define AC_GAI_STRERROR(x)	(ldap_pvt_gai_strerror((x)))
207
		LDAP_F (char *) ldap_pvt_gai_strerror( int );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
208
209
210
#	endif
#endif

211
212
213
214
#ifndef HAVE_GETPEEREID
LDAP_LUTIL_F( int ) getpeereid( int s, uid_t *, gid_t * );
#endif

215
216
217
218
219
/* DNS RFC defines max host name as 255. New systems seem to use 1024 */
#ifndef NI_MAXHOST
#define	NI_MAXHOST	256
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
220
#endif /* _AC_SOCKET_H_ */