]> git.sur5r.net Git - openldap/blob - include/ac/socket.h
Add prototypes for strerror/strerror_r.
[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_ARPA_INET_H
31 #include <arpa/inet.h>
32 #endif
33
34 #ifdef HAVE_ARPA_NAMESER_H
35 #include <arpa/nameser.h>
36 #endif
37
38 #include <netdb.h>
39
40 #ifdef HAVE_RESOLV_H
41 #include <resolv.h>
42 #endif
43
44 #endif /* HAVE_SYS_SOCKET_H */
45
46 #ifdef HAVE_WINSOCK2
47 #include <winsock2.h>
48 #elif HAVE_WINSOCK
49 #include <winsock.h>
50 #else
51 #define WSACleanup()
52 #endif
53
54 #ifdef HAVE_PCNFS
55 #include <tklib.h>
56 #endif /* HAVE_PCNFS */
57
58 #ifndef INADDR_LOOPBACK
59 #define INADDR_LOOPBACK (0x7f000001UL)
60 #endif
61
62 #ifndef MAXHOSTNAMELEN
63 #define MAXHOSTNAMELEN  64
64 #endif
65
66 #ifdef HAVE_WINSOCK
67 #       define tcp_close( s )           closesocket( s );
68 #       define ioctl( s, c, a )         ioctlsocket( (s), (c), (a) )
69 #       define ioctl_t                          u_long
70 #       define AC_SOCKET_INVALID        ((unsigned int) ~0)
71
72 #define EWOULDBLOCK WSAEWOULDBLOCK
73
74 #elif MACOS
75 #       define tcp_close( s )           tcpclose( s )
76
77 #elif DOS
78 #       ifdef PCNFS
79 #               define tcp_close( s )   close( s )
80 #       endif /* PCNFS */
81 #       ifdef NCSA
82 #               define tcp_close( s )   do { netclose( s ); netshut() } while(0)
83 #       endif /* NCSA */
84
85 #elif HAVE_CLOSESOCKET
86 #       define tcp_close( s )           closesocket( s )
87
88 #else
89 #       define tcp_close( s )           close( s )
90 #endif /* MACOS */
91
92 #ifndef ioctl_t
93 #       define ioctl_t                          int
94 #endif
95
96 #ifndef AC_SOCKET_INVALID
97 #       define AC_SOCKET_INVALID        (-1)
98 #endif
99
100 #if     defined(__WIN32) && defined(_ALPHA)
101 /* NT on Alpha is hosed. */
102 #define AC_HTONL( l ) \
103         ((((l)&0xff)<<24) + (((l)&0xff00)<<8) + \
104          (((l)&0xff0000)>>8) + (((l)&0xff000000)>>24))
105 #define AC_NTOHL(l) AC_HTONL(l)
106
107 #elif defined(__alpha) && !defined(VMS)
108 /*
109  * htonl and ntohl on the DEC Alpha under OSF 1 seem to only swap the
110  * lower-order 32-bits of a (64-bit) long, so we define correct versions
111  * here.
112  */ 
113 #define AC_HTONL( l )   (((long)htonl( (l) & 0x00000000FFFFFFFF )) << 32 \
114         | htonl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
115
116 #define AC_NTOHL( l ) (((long)ntohl( (l) & 0x00000000FFFFFFFF )) << 32 \
117         | ntohl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
118
119 #else
120 #define AC_HTONL( l ) htonl( l )
121 #define AC_NTOHL( l ) ntohl( l )
122 #endif
123
124 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
125 #define AC_HTONS( s ) htons( s )
126 #define AC_NTOHS( s ) ntohs( s )
127
128
129 #endif /* _AC_SOCKET_H_ */