Back to index

openldap  2.4.31
socket.h
Go to the documentation of this file.
00001 /* Generic socket.h */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 1998-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 
00017 #ifndef _AC_SOCKET_H_
00018 #define _AC_SOCKET_H_
00019 
00020 #ifdef HAVE_SYS_TYPES_H
00021 #include <sys/types.h>
00022 #endif
00023 
00024 #ifdef HAVE_POLL_H
00025 #include <poll.h>
00026 #elif defined(HAVE_SYS_POLL_H)
00027 #include <sys/poll.h>
00028 #endif
00029 
00030 #ifdef HAVE_SYS_SOCKET_H
00031 #include <sys/socket.h>
00032 
00033 #ifdef HAVE_SYS_UN_H
00034 #include <sys/un.h>
00035 #endif
00036 
00037 #ifdef HAVE_SYS_SELECT_H
00038 #include <sys/select.h>
00039 #endif
00040 
00041 #include <netinet/in.h>
00042 
00043 #ifdef HAVE_NETINET_TCP_H
00044 #include <netinet/tcp.h>
00045 #endif
00046 
00047 #ifdef HAVE_ARPA_INET_H
00048 #include <arpa/inet.h>
00049 #endif
00050 
00051 #ifdef HAVE_ARPA_NAMESER_H
00052 #include <arpa/nameser.h>
00053 #endif
00054 
00055 #include <netdb.h>
00056 
00057 #ifdef HAVE_RESOLV_H
00058 #include <resolv.h>
00059 #endif
00060 
00061 #endif /* HAVE_SYS_SOCKET_H */
00062 
00063 #ifdef HAVE_WINSOCK2
00064 #include <winsock2.h>
00065 #elif HAVE_WINSOCK
00066 #include <winsock.h>
00067 #endif
00068 
00069 #ifdef HAVE_PCNFS
00070 #include <tklib.h>
00071 #endif /* HAVE_PCNFS */
00072 
00073 #ifndef INADDR_LOOPBACK
00074 #define INADDR_LOOPBACK     (0x7f000001UL)
00075 #endif
00076 
00077 #ifndef MAXHOSTNAMELEN
00078 #define MAXHOSTNAMELEN  64
00079 #endif
00080 
00081 #undef sock_errno
00082 #undef sock_errstr
00083 #define sock_errno() errno
00084 #define sock_errstr(e)      STRERROR(e)
00085 #define sock_errset(e)      ((void) (errno = (e)))
00086 
00087 #ifdef HAVE_WINSOCK
00088 #      define tcp_read( s, buf, len )     recv( s, buf, len, 0 )
00089 #      define tcp_write( s, buf, len )    send( s, buf, len, 0 )
00090 #      define ioctl( s, c, a )            ioctlsocket( (s), (c), (a) )
00091 #      define ioctl_t                            u_long
00092 #      define AC_SOCKET_INVALID    ((unsigned int) -1)
00093 
00094 #      ifdef SD_BOTH
00095 #             define tcp_close( s )       (shutdown( s, SD_BOTH ), closesocket( s ))
00096 #      else
00097 #             define tcp_close( s )              closesocket( s )
00098 #      endif
00099 
00100 #define EWOULDBLOCK WSAEWOULDBLOCK
00101 #define EINPROGRESS WSAEINPROGRESS
00102 #define ETIMEDOUT    WSAETIMEDOUT
00103 
00104 #undef sock_errno
00105 #undef sock_errstr
00106 #undef sock_errset
00107 #define       sock_errno()  WSAGetLastError()
00108 #define       sock_errstr(e)       ber_pvt_wsa_err2string(e)
00109 #define       sock_errset(e)       WSASetLastError(e)
00110 
00111 LBER_F( char * ) ber_pvt_wsa_err2string LDAP_P((int));
00112 
00113 #elif MACOS
00114 #      define tcp_close( s )              tcpclose( s )
00115 #      define tcp_read( s, buf, len )     tcpread( s, buf, len )
00116 #      define tcp_write( s, buf, len )    tcpwrite( s, buf, len )
00117 
00118 #elif DOS
00119 #      ifdef PCNFS
00120 #             define tcp_close( s )       close( s )
00121 #             define tcp_read( s, buf, len )     recv( s, buf, len, 0 )
00122 #             define tcp_write( s, buf, len )    send( s, buf, len, 0 )
00123 #      endif /* PCNFS */
00124 #      ifdef NCSA
00125 #             define tcp_close( s )       do { netclose( s ); netshut() } while(0)
00126 #             define tcp_read( s, buf, len )     nread( s, buf, len )
00127 #             define tcp_write( s, buf, len )    netwrite( s, buf, len )
00128 #      endif /* NCSA */
00129 
00130 #elif defined(HAVE_CLOSESOCKET)
00131 #      define tcp_close( s )              closesocket( s )
00132 
00133 #      ifdef __BEOS__
00134 #             define tcp_read( s, buf, len )     recv( s, buf, len, 0 )
00135 #             define tcp_write( s, buf, len )    send( s, buf, len, 0 )
00136 #      endif
00137 
00138 #else
00139 #      define tcp_read( s, buf, len)      read( s, buf, len )
00140 #      define tcp_write( s, buf, len)     write( s, buf, len )
00141 
00142 #      ifdef SHUT_RDWR
00143 #             define tcp_close( s )       (shutdown( s, SHUT_RDWR ), close( s ))
00144 #      else
00145 #             define tcp_close( s )       close( s )
00146 #      endif
00147 
00148 #ifdef HAVE_PIPE
00149 /*
00150  * Only use pipe() on systems where file and socket descriptors
00151  * are interchangable
00152  */
00153 #      define USE_PIPE HAVE_PIPE
00154 #endif
00155 
00156 #endif /* MACOS */
00157 
00158 #ifndef ioctl_t
00159 #      define ioctl_t                            int
00160 #endif
00161 
00162 #ifndef AC_SOCKET_INVALID
00163 #      define AC_SOCKET_INVALID    (-1)
00164 #endif
00165 #ifndef AC_SOCKET_ERROR
00166 #      define AC_SOCKET_ERROR             (-1)
00167 #endif
00168 
00169 #if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
00170 #      define inet_aton ldap_pvt_inet_aton
00171 struct in_addr;
00172 LDAP_F (int) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
00173 #endif
00174 
00175 #if    defined(__WIN32) && defined(_ALPHA)
00176 /* NT on Alpha is hosed. */
00177 #      define AC_HTONL( l ) \
00178         ((((l)&0xffU)<<24) + (((l)&0xff00U)<<8) + \
00179          (((l)&0xff0000U)>>8) + (((l)&0xff000000U)>>24))
00180 #      define AC_NTOHL(l) AC_HTONL(l)
00181 
00182 #else
00183 #      define AC_HTONL( l ) htonl( l )
00184 #      define AC_NTOHL( l ) ntohl( l )
00185 #endif
00186 
00187 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
00188 #define AC_HTONS( s ) htons( s )
00189 #define AC_NTOHS( s ) ntohs( s )
00190 
00191 #ifdef LDAP_PF_LOCAL
00192 #  if !defined( AF_LOCAL ) && defined( AF_UNIX )
00193 #    define AF_LOCAL AF_UNIX
00194 #  endif
00195 #  if !defined( PF_LOCAL ) && defined( PF_UNIX )
00196 #    define PF_LOCAL PF_UNIX
00197 #  endif
00198 #endif
00199 
00200 #ifndef INET_ADDRSTRLEN
00201 #      define INET_ADDRSTRLEN 16
00202 #endif
00203 #ifndef INET6_ADDRSTRLEN
00204 #      define INET6_ADDRSTRLEN 46
00205 #endif
00206 
00207 #if defined( HAVE_GETADDRINFO ) || defined( HAVE_GETNAMEINFO )
00208 #      ifdef HAVE_GAI_STRERROR
00209 #             define AC_GAI_STRERROR(x)   (gai_strerror((x)))
00210 #      else
00211 #             define AC_GAI_STRERROR(x)   (ldap_pvt_gai_strerror((x)))
00212               LDAP_F (char *) ldap_pvt_gai_strerror( int );
00213 #      endif
00214 #endif
00215 
00216 #if defined(LDAP_PF_LOCAL) && \
00217        !defined(HAVE_GETPEEREID) && \
00218        !defined(HAVE_GETPEERUCRED) && \
00219        !defined(SO_PEERCRED) && !defined(LOCAL_PEERCRED) && \
00220        defined(HAVE_SENDMSG) && (defined(HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTSLEN) || \
00221        defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL))
00222 #      define LDAP_PF_LOCAL_SENDMSG 1
00223 #endif
00224 
00225 #ifdef HAVE_GETPEEREID
00226 #define       LUTIL_GETPEEREID( s, uid, gid, bv )       getpeereid( s, uid, gid )
00227 #elif defined(LDAP_PF_LOCAL_SENDMSG)
00228 struct berval;
00229 LDAP_LUTIL_F( int ) lutil_getpeereid( int s, uid_t *, gid_t *, struct berval *bv );
00230 #define       LUTIL_GETPEEREID( s, uid, gid, bv )       lutil_getpeereid( s, uid, gid, bv )
00231 #else
00232 LDAP_LUTIL_F( int ) lutil_getpeereid( int s, uid_t *, gid_t * );
00233 #define       LUTIL_GETPEEREID( s, uid, gid, bv )       lutil_getpeereid( s, uid, gid )
00234 #endif
00235 
00236 /* DNS RFC defines max host name as 255. New systems seem to use 1024 */
00237 #ifndef NI_MAXHOST
00238 #define       NI_MAXHOST    256
00239 #endif
00240 
00241 #ifdef HAVE_POLL
00242 # ifndef INFTIM
00243 #  define INFTIM (-1)
00244 # endif
00245 #undef POLL_OTHER
00246 #define POLL_OTHER   (POLLERR|POLLHUP)
00247 #undef POLL_READ
00248 #define POLL_READ    (POLLIN|POLLPRI|POLL_OTHER)
00249 #undef POLL_WRITE              
00250 #define POLL_WRITE   (POLLOUT|POLL_OTHER)
00251 #endif
00252 
00253 #endif /* _AC_SOCKET_H_ */