home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ldapsdk.zip / include / ac / socket.h < prev    next >
C/C++ Source or Header  |  2001-05-30  |  5KB  |  207 lines

  1. /* Generic socket.h */
  2. /* $OpenLDAP: pkg/ldap/include/ac/socket.h,v 1.19.2.10 2001/05/30 05:10:45 kurt Exp $ */
  3. /*
  4.  * Copyright 1998-2001 The OpenLDAP Foundation, Redwood City, California, USA
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted only as authorized by the OpenLDAP
  9.  * Public License.  A copy of this license is available at
  10.  * http://www.OpenLDAP.org/license.html or in file LICENSE in the
  11.  * 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_UN_H
  25. #include <sys/un.h>
  26. #endif
  27.  
  28. #ifdef HAVE_SYS_SELECT_H
  29. #include <sys/select.h>
  30. #endif
  31.  
  32. #include <netinet/in.h>
  33.  
  34. #ifdef HAVE_NETINET_TCP_H
  35. #include <netinet/tcp.h>
  36. #endif
  37.  
  38. #ifdef HAVE_ARPA_INET_H
  39. #include <arpa/inet.h>
  40. #endif
  41.  
  42. #ifdef HAVE_ARPA_NAMESER_H
  43. #include <arpa/nameser.h>
  44. #endif
  45.  
  46. #include <netdb.h>
  47.  
  48. #ifdef HAVE_RESOLV_H
  49. #include <resolv.h>
  50. #endif
  51.  
  52. #endif /* HAVE_SYS_SOCKET_H */
  53.  
  54. #ifdef HAVE_WINSOCK2
  55. #include <winsock2.h>
  56. #elif HAVE_WINSOCK
  57. #include <winsock.h>
  58. #else
  59. #define WSACleanup()
  60. #endif
  61.  
  62. #ifdef HAVE_PCNFS
  63. #include <tklib.h>
  64. #endif /* HAVE_PCNFS */
  65.  
  66. #ifndef INADDR_LOOPBACK
  67. #define INADDR_LOOPBACK    (0x7f000001UL)
  68. #endif
  69.  
  70. #ifndef MAXHOSTNAMELEN
  71. #define MAXHOSTNAMELEN  64
  72. #endif
  73.  
  74. #undef    sock_errno
  75. #undef    sock_errstr
  76. #define sock_errno()    errno
  77. #define sock_errstr(e)    STRERROR(e)
  78.  
  79. #ifdef HAVE_WINSOCK
  80. #    define tcp_read( s, buf, len )    recv( s, buf, len, 0 )
  81. #    define tcp_write( s, buf, len )    send( s, buf, len, 0 )
  82. #    define ioctl( s, c, a )        ioctlsocket( (s), (c), (a) )
  83. #    define ioctl_t                u_long
  84. #    define AC_SOCKET_INVALID    ((unsigned int) ~0)
  85.  
  86. #    if SD_BOTH
  87. #        define tcp_close( s )    (shutdown( s, SD_BOTH ), closesocket( s ))
  88. #else
  89. #        define tcp_close( s )        closesocket( s )
  90. #endif
  91.  
  92. #define EWOULDBLOCK WSAEWOULDBLOCK
  93. #define EINPROGRESS WSAEINPROGRESS
  94. #define ETIMEDOUT    WSAETIMEDOUT
  95.  
  96. #undef    sock_errno
  97. #undef    sock_errstr
  98. #define    sock_errno()    WSAGetLastError()
  99. #define    sock_errstr(e)    ber_pvt_wsa_err2string(e)
  100.  
  101. LBER_F( char * ) ber_pvt_wsa_err2string LDAP_P((int));
  102.  
  103. #elif MACOS
  104. #    define tcp_close( s )        tcpclose( s )
  105. #    define tcp_read( s, buf, len )    tcpread( s, buf, len )
  106. #    define tcp_write( s, buf, len )    tcpwrite( s, buf, len )
  107.  
  108. #elif DOS
  109. #    ifdef PCNFS
  110. #        define tcp_close( s )    close( s )
  111. #        define tcp_read( s, buf, len )    recv( s, buf, len, 0 )
  112. #        define tcp_write( s, buf, len )    send( s, buf, len, 0 )
  113. #    endif /* PCNFS */
  114. #    ifdef NCSA
  115. #        define tcp_close( s )    do { netclose( s ); netshut() } while(0)
  116. #        define tcp_read( s, buf, len )    nread( s, buf, len )
  117. #        define tcp_write( s, buf, len )    netwrite( s, buf, len )
  118. #    endif /* NCSA */
  119.  
  120. #elif HAVE_CLOSESOCKET
  121. #    define tcp_close( s )        closesocket( s )
  122.  
  123. #    ifdef __BEOS__
  124. #        define tcp_read( s, buf, len )    recv( s, buf, len, 0 )
  125. #        define tcp_write( s, buf, len )    send( s, buf, len, 0 )
  126. #    endif
  127.  
  128. #else
  129. #    define tcp_read( s, buf, len)    read( s, buf, len )
  130. #    define tcp_write( s, buf, len)    write( s, buf, len )
  131.  
  132. #    if SHUT_RDWR
  133. #        define tcp_close( s )    (shutdown( s, SHUT_RDWR ), close( s ))
  134. #else
  135. #        define tcp_close( s )        close( s )
  136. #endif
  137.  
  138. #ifdef HAVE_PIPE
  139. /*
  140.  * Only use pipe() on systems where file and socket descriptors 
  141.  * are interchangable
  142.  */
  143. #define USE_PIPE HAVE_PIPE
  144. #endif
  145.  
  146. #endif /* MACOS */
  147.  
  148. #ifndef ioctl_t
  149. #    define ioctl_t                int
  150. #endif
  151.  
  152. #ifndef AC_SOCKET_INVALID
  153. #    define AC_SOCKET_INVALID    (-1)
  154. #endif
  155. #ifndef AC_SOCKET_ERROR
  156. #    define AC_SOCKET_ERROR        (-1)
  157. #endif
  158.  
  159. #if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
  160. #define inet_aton ldap_pvt_inet_aton
  161. struct in_addr;
  162. LDAP_F (int) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
  163. #endif
  164.  
  165. #if    defined(__WIN32) && defined(_ALPHA)
  166. /* NT on Alpha is hosed. */
  167. #    define AC_HTONL( l ) \
  168.         ((((l)&0xffU)<<24) + (((l)&0xff00U)<<8) + \
  169.          (((l)&0xff0000U)>>8) + (((l)&0xff000000U)>>24))
  170. #    define AC_NTOHL(l) AC_HTONL(l)
  171.  
  172. #else
  173. #    define AC_HTONL( l ) htonl( l )
  174. #    define AC_NTOHL( l ) ntohl( l )
  175. #endif
  176.  
  177. /* htons()/ntohs() may be broken much like htonl()/ntohl() */
  178. #define AC_HTONS( s ) htons( s )
  179. #define AC_NTOHS( s ) ntohs( s )
  180.  
  181. #ifdef LDAP_PF_LOCAL
  182. #  if !defined( AF_LOCAL ) && defined( AF_UNIX )
  183. #    define AF_LOCAL    AF_UNIX
  184. #  endif
  185. #  if !defined( PF_LOCAL ) && defined( PF_UNIX )
  186. #    define PF_LOCAL    PF_UNIX
  187. #  endif
  188. #endif
  189.  
  190. #ifndef INET_ADDRSTRLEN
  191. #    define INET_ADDRSTRLEN 16
  192. #endif
  193. #ifndef INET6_ADDRSTRLEN
  194. #    define INET6_ADDRSTRLEN 46
  195. #endif
  196.  
  197. #ifdef HAVE_GETADDRINFO
  198. #    ifdef HAVE_GAI_STRERROR
  199. #        define AC_GAI_STRERROR(x)    (gai_strerror((x)))
  200. #    else
  201. #        define AC_GAI_STRERROR(x)    (ldap_pvt_gai_strerror((x)))
  202.         char * ldap_pvt_gai_strerror( int );
  203. #    endif
  204. #endif
  205.  
  206. #endif /* _AC_SOCKET_H_ */
  207.