1999-08-30 07:29:08 +08:00
|
|
|
/* Generic socket.h */
|
1999-08-30 16:08:00 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 12:16:36 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 1998-2004 The OpenLDAP Foundation.
|
1998-12-29 03:51:35 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2001-05-29 11:35:56 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
2003-11-26 07:17:08 +08:00
|
|
|
* 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>.
|
1998-12-29 03:51:35 +08:00
|
|
|
*/
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#ifndef _AC_SOCKET_H_
|
|
|
|
#define _AC_SOCKET_H_
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2000-01-02 09:21:25 +08:00
|
|
|
#ifdef HAVE_SYS_UN_H
|
|
|
|
#include <sys/un.h>
|
|
|
|
#endif
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_SYS_SELECT_H
|
|
|
|
#include <sys/select.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
1999-07-27 08:31:08 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_TCP_H
|
1999-07-23 05:49:35 +08:00
|
|
|
#include <netinet/tcp.h>
|
1999-07-27 08:31:08 +08:00
|
|
|
#endif
|
1999-03-13 09:12:54 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <arpa/inet.h>
|
1999-03-13 09:12:54 +08:00
|
|
|
#endif
|
1999-02-05 05:54:38 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_ARPA_NAMESER_H
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <arpa/nameser.h>
|
1999-02-05 05:54:38 +08:00
|
|
|
#endif
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <netdb.h>
|
1999-02-05 05:54:38 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_RESOLV_H
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <resolv.h>
|
|
|
|
#endif
|
|
|
|
|
1999-02-05 05:54:38 +08:00
|
|
|
#endif /* HAVE_SYS_SOCKET_H */
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_WINSOCK2
|
1998-11-17 12:07:31 +08:00
|
|
|
#include <winsock2.h>
|
|
|
|
#elif HAVE_WINSOCK
|
|
|
|
#include <winsock.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_PCNFS
|
|
|
|
#include <tklib.h>
|
|
|
|
#endif /* HAVE_PCNFS */
|
|
|
|
|
|
|
|
#ifndef INADDR_LOOPBACK
|
1999-06-08 02:35:30 +08:00
|
|
|
#define INADDR_LOOPBACK (0x7f000001UL)
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MAXHOSTNAMELEN
|
|
|
|
#define MAXHOSTNAMELEN 64
|
|
|
|
#endif
|
|
|
|
|
1999-08-30 07:33:35 +08:00
|
|
|
#undef sock_errno
|
|
|
|
#undef sock_errstr
|
|
|
|
#define sock_errno() errno
|
|
|
|
#define sock_errstr(e) STRERROR(e)
|
1999-08-29 12:01:16 +08:00
|
|
|
|
1999-03-29 13:15:59 +08:00
|
|
|
#ifdef HAVE_WINSOCK
|
1999-08-29 12:01:16 +08:00
|
|
|
# define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
|
|
|
|
# define tcp_write( s, buf, len ) send( s, buf, len, 0 )
|
1999-03-29 13:15:59 +08:00
|
|
|
# define ioctl( s, c, a ) ioctlsocket( (s), (c), (a) )
|
1999-03-29 13:28:29 +08:00
|
|
|
# define ioctl_t u_long
|
1999-06-19 07:53:05 +08:00
|
|
|
# define AC_SOCKET_INVALID ((unsigned int) ~0)
|
1999-05-19 04:52:36 +08:00
|
|
|
|
2002-06-20 02:15:20 +08:00
|
|
|
# ifdef SD_BOTH
|
2000-08-29 06:24:01 +08:00
|
|
|
# define tcp_close( s ) (shutdown( s, SD_BOTH ), closesocket( s ))
|
2001-05-20 07:08:11 +08:00
|
|
|
# else
|
2000-08-29 06:24:01 +08:00
|
|
|
# define tcp_close( s ) closesocket( s )
|
2001-05-20 07:08:11 +08:00
|
|
|
# endif
|
2000-08-29 06:24:01 +08:00
|
|
|
|
1999-05-19 04:52:36 +08:00
|
|
|
#define EWOULDBLOCK WSAEWOULDBLOCK
|
1999-08-04 08:40:03 +08:00
|
|
|
#define EINPROGRESS WSAEINPROGRESS
|
|
|
|
#define ETIMEDOUT WSAETIMEDOUT
|
1999-05-19 04:52:36 +08:00
|
|
|
|
1999-08-30 07:33:35 +08:00
|
|
|
#undef sock_errno
|
|
|
|
#undef sock_errstr
|
|
|
|
#define sock_errno() WSAGetLastError()
|
2000-05-13 05:16:15 +08:00
|
|
|
#define sock_errstr(e) ber_pvt_wsa_err2string(e)
|
1999-08-29 09:56:51 +08:00
|
|
|
|
2000-06-20 06:40:42 +08:00
|
|
|
LBER_F( char * ) ber_pvt_wsa_err2string LDAP_P((int));
|
1999-09-01 00:47:42 +08:00
|
|
|
|
1999-03-29 13:15:59 +08:00
|
|
|
#elif MACOS
|
|
|
|
# define tcp_close( s ) tcpclose( s )
|
1999-08-29 12:01:16 +08:00
|
|
|
# define tcp_read( s, buf, len ) tcpread( s, buf, len )
|
|
|
|
# define tcp_write( s, buf, len ) tcpwrite( s, buf, len )
|
1999-06-09 08:10:26 +08:00
|
|
|
|
1999-03-29 13:15:59 +08:00
|
|
|
#elif DOS
|
|
|
|
# ifdef PCNFS
|
|
|
|
# define tcp_close( s ) close( s )
|
1999-08-29 12:01:16 +08:00
|
|
|
# define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
|
|
|
|
# define tcp_write( s, buf, len ) send( s, buf, len, 0 )
|
1999-03-29 13:15:59 +08:00
|
|
|
# endif /* PCNFS */
|
|
|
|
# ifdef NCSA
|
|
|
|
# define tcp_close( s ) do { netclose( s ); netshut() } while(0)
|
1999-08-29 12:01:16 +08:00
|
|
|
# define tcp_read( s, buf, len ) nread( s, buf, len )
|
|
|
|
# define tcp_write( s, buf, len ) netwrite( s, buf, len )
|
1999-03-29 13:15:59 +08:00
|
|
|
# endif /* NCSA */
|
1999-06-09 08:10:26 +08:00
|
|
|
|
|
|
|
#elif HAVE_CLOSESOCKET
|
|
|
|
# define tcp_close( s ) closesocket( s )
|
|
|
|
|
1999-12-18 05:31:44 +08:00
|
|
|
# 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
|
|
|
|
|
1999-03-29 13:15:59 +08:00
|
|
|
#else
|
1999-08-29 12:01:16 +08:00
|
|
|
# define tcp_read( s, buf, len) read( s, buf, len )
|
|
|
|
# define tcp_write( s, buf, len) write( s, buf, len )
|
1999-09-01 00:47:42 +08:00
|
|
|
|
2002-06-20 02:15:20 +08:00
|
|
|
# ifdef SHUT_RDWR
|
2000-08-29 06:24:01 +08:00
|
|
|
# define tcp_close( s ) (shutdown( s, SHUT_RDWR ), close( s ))
|
2001-05-20 07:08:11 +08:00
|
|
|
# else
|
|
|
|
# define tcp_close( s ) close( s )
|
|
|
|
# endif
|
2000-08-29 06:24:01 +08:00
|
|
|
|
1999-09-01 01:01:10 +08:00
|
|
|
#ifdef HAVE_PIPE
|
1999-09-01 01:24:32 +08:00
|
|
|
/*
|
2001-12-24 11:49:54 +08:00
|
|
|
* Only use pipe() on systems where file and socket descriptors
|
1999-09-01 01:24:32 +08:00
|
|
|
* are interchangable
|
|
|
|
*/
|
2001-05-20 07:08:11 +08:00
|
|
|
# define USE_PIPE HAVE_PIPE
|
1999-09-01 00:47:42 +08:00
|
|
|
#endif
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif /* MACOS */
|
|
|
|
|
1999-03-29 13:28:29 +08:00
|
|
|
#ifndef ioctl_t
|
|
|
|
# define ioctl_t int
|
|
|
|
#endif
|
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
#ifndef AC_SOCKET_INVALID
|
|
|
|
# define AC_SOCKET_INVALID (-1)
|
|
|
|
#endif
|
1999-09-01 00:47:42 +08:00
|
|
|
#ifndef AC_SOCKET_ERROR
|
|
|
|
# define AC_SOCKET_ERROR (-1)
|
|
|
|
#endif
|
1999-06-19 07:53:05 +08:00
|
|
|
|
1999-08-04 04:02:44 +08:00
|
|
|
#if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
|
2001-05-20 07:08:11 +08:00
|
|
|
# define inet_aton ldap_pvt_inet_aton
|
1999-08-04 04:02:44 +08:00
|
|
|
struct in_addr;
|
2000-06-19 03:48:07 +08:00
|
|
|
LDAP_F (int) ldap_pvt_inet_aton LDAP_P(( const char *, struct in_addr * ));
|
1999-08-04 04:02:44 +08:00
|
|
|
#endif
|
|
|
|
|
1999-06-05 06:27:28 +08:00
|
|
|
#if defined(__WIN32) && defined(_ALPHA)
|
|
|
|
/* NT on Alpha is hosed. */
|
1999-11-27 07:32:18 +08:00
|
|
|
# define AC_HTONL( l ) \
|
|
|
|
((((l)&0xffU)<<24) + (((l)&0xff00U)<<8) + \
|
|
|
|
(((l)&0xff0000U)>>8) + (((l)&0xff000000U)>>24))
|
|
|
|
# define AC_NTOHL(l) AC_HTONL(l)
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1999-06-05 06:27:28 +08:00
|
|
|
#else
|
1999-11-27 07:32:18 +08:00
|
|
|
# define AC_HTONL( l ) htonl( l )
|
|
|
|
# define AC_NTOHL( l ) ntohl( l )
|
1999-06-05 06:27:28 +08:00
|
|
|
#endif
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
/* htons()/ntohs() may be broken much like htonl()/ntohl() */
|
|
|
|
#define AC_HTONS( s ) htons( s )
|
|
|
|
#define AC_NTOHS( s ) ntohs( s )
|
|
|
|
|
2000-07-10 05:49:36 +08:00
|
|
|
#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
|
1999-05-19 09:12:33 +08:00
|
|
|
|
2000-09-25 09:24:37 +08:00
|
|
|
#ifndef INET_ADDRSTRLEN
|
|
|
|
# define INET_ADDRSTRLEN 16
|
|
|
|
#endif
|
|
|
|
#ifndef INET6_ADDRSTRLEN
|
|
|
|
# define INET6_ADDRSTRLEN 46
|
|
|
|
#endif
|
|
|
|
|
2003-04-22 02:28:08 +08:00
|
|
|
#if defined( HAVE_GETADDRINFO ) || defined( HAVE_GETNAMEINFO )
|
2000-10-19 01:25:30 +08:00
|
|
|
# ifdef HAVE_GAI_STRERROR
|
|
|
|
# define AC_GAI_STRERROR(x) (gai_strerror((x)))
|
|
|
|
# else
|
|
|
|
# define AC_GAI_STRERROR(x) (ldap_pvt_gai_strerror((x)))
|
2002-12-04 14:17:32 +08:00
|
|
|
LDAP_F (char *) ldap_pvt_gai_strerror( int );
|
2000-10-19 01:25:30 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2002-12-04 14:17:32 +08:00
|
|
|
#ifndef HAVE_GETPEEREID
|
|
|
|
LDAP_LUTIL_F( int ) getpeereid( int s, uid_t *, gid_t * );
|
|
|
|
#endif
|
|
|
|
|
2003-03-05 09:33:36 +08:00
|
|
|
/* DNS RFC defines max host name as 255. New systems seem to use 1024 */
|
|
|
|
#ifndef NI_MAXHOST
|
|
|
|
#define NI_MAXHOST 256
|
|
|
|
#endif
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif /* _AC_SOCKET_H_ */
|