1999-08-30 07:29:08 +08:00
|
|
|
/* Generic socket.h */
|
|
|
|
/* $Id$ */
|
1998-12-29 03:51:35 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted only
|
|
|
|
* as authorized by the OpenLDAP Public License. A copy of this
|
|
|
|
* license is available at http://www.OpenLDAP.org/license.html or
|
|
|
|
* in file LICENSE in the top-level directory of the distribution.
|
|
|
|
*/
|
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>
|
|
|
|
|
|
|
|
#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
|
|
|
#else
|
1998-11-17 12:07:31 +08:00
|
|
|
#define WSACleanup()
|
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:09:27 +08:00
|
|
|
#define SOCK_ERR(num, str) \
|
|
|
|
num = errno; str = STRERROR(errno)
|
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_close( s ) closesocket( s )
|
|
|
|
# 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
|
|
|
|
|
|
|
#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:09:27 +08:00
|
|
|
#undef SOCK_ERR
|
|
|
|
#define SOCK_ERR(num, str) \
|
|
|
|
num = WSAGetLastError(); str = WSAGetLastErrorString()
|
1999-08-29 09:56:51 +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-03-29 13:15:59 +08:00
|
|
|
#else
|
|
|
|
# define tcp_close( s ) close( s )
|
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 )
|
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-08-04 04:02:44 +08:00
|
|
|
#if !defined( HAVE_INET_ATON ) && !defined( inet_aton )
|
|
|
|
#define inet_aton ldap_pvt_inet_aton
|
|
|
|
struct in_addr;
|
1999-08-05 02:27:15 +08:00
|
|
|
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. */
|
|
|
|
#define AC_HTONL( l ) \
|
|
|
|
((((l)&0xff)<<24) + (((l)&0xff00)<<8) + \
|
|
|
|
(((l)&0xff0000)>>8) + (((l)&0xff000000)>>24))
|
1999-06-19 07:53:05 +08:00
|
|
|
#define AC_NTOHL(l) AC_HTONL(l)
|
1999-06-05 06:27:28 +08:00
|
|
|
|
|
|
|
#elif defined(__alpha) && !defined(VMS)
|
1998-10-25 09:41:42 +08:00
|
|
|
/*
|
|
|
|
* htonl and ntohl on the DEC Alpha under OSF 1 seem to only swap the
|
|
|
|
* lower-order 32-bits of a (64-bit) long, so we define correct versions
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
#define AC_HTONL( l ) (((long)htonl( (l) & 0x00000000FFFFFFFF )) << 32 \
|
|
|
|
| htonl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
|
|
|
|
|
|
|
|
#define AC_NTOHL( l ) (((long)ntohl( (l) & 0x00000000FFFFFFFF )) << 32 \
|
|
|
|
| ntohl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
|
|
|
|
|
1999-06-05 06:27:28 +08:00
|
|
|
#else
|
|
|
|
#define AC_HTONL( l ) htonl( l )
|
|
|
|
#define AC_NTOHL( l ) ntohl( l )
|
|
|
|
#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 )
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif /* _AC_SOCKET_H_ */
|