📄 tcp.h
字号:
/****************************************************************************
* *
* cryptlib TCP/IP Interface Header *
* Copyright Peter Gutmann 1998-2004 *
* *
****************************************************************************/
#ifdef USE_TCP
/****************************************************************************
* *
* AMX *
* *
****************************************************************************/
#ifdef __AMX__
#include <kn_sock.h>
/* All KwikNet functions have kn_ prefix, to use the standard sockets API
names we have to redefine them to the usual names */
#define accept kn_accept
#define bind kn_bind
#define closesocket kn_close
#define connect kn_connect
#define getsockopt kn_getsockopt
#define listen kn_listen
#define recv kn_recv
#define select kn_select
#define send kn_send
#define setsockopt kn_setsockopt
#define shutdown kn_shutdown
#define socket kn_socket
#endif /* AMX */
/****************************************************************************
* *
* BeOS *
* *
****************************************************************************/
/* If we're building under BeOS the system may have the new(er) BONE (BeOs
Network Environment) network stack. This didn't quite make it into BeOS
v5 before the demise of Be Inc but was leaked after Be folded, as was the
experimental/developmental Dano release of BeOS, which would have become
BeOS 5.1 and also has a newer network stack. In order to detect this we
have to pull in sys/socket.h before we try anything else */
#ifdef __BEOS__
#include <sys/socket.h>
#endif /* __BEOS__ */
/* If we're using the original (rather minimal) BeOS TCP/IP stack, we have
to provide a customised interface for it rather than using the same one
as the generic Unix/BSD interface */
#if defined( __BEOS__ ) && !defined( BONE_VERSION )
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <socket.h>
/* BeOS doesn't define any of the PF_xxx's, howewever it does defines
some of the AF_xxx equivalents, since these are synonyms we just define
the PF_xxx's ourselves */
#define PF_UNSPEC 0
#define PF_INET AF_INET
/* BeOS doesn't define in_*_t's */
#define in_addr_t u_long
#define in_port_t u_short
/* BeOS doesn't define NO_ADDRESS, but NO_DATA is a synonym for this */
#define NO_ADDRESS NO_DATA
/* BeOS doesn't support checking for anything except readability in select()
and only supports one or two socket options, so we define our own
versions of these functions that no-op out unsupported options */
#define select( sockets, readFD, writeFD, exceptFD, timeout ) \
my_select( sockets, readFD, writeFD, exceptFD, timeout )
#define getsockopt( socket, level, optname, optval, optlen ) \
my_getsockopt( socket, level, optname, optval, optlen )
#define setsockopt( socket, level, optname, optval, optlen ) \
my_setsockopt( socket, level, optname, optval, optlen )
/* The following options would be required, but aren't provided by BeOS. If
you're building under a newer BeOS version that supports these options,
you'll also need to update my_set/setsockopt() to no longer no-op them
out */
#define SO_ERROR -1
#define TCP_NODELAY -1
/****************************************************************************
* *
* uITRON *
* *
****************************************************************************/
#elif defined( __ITRON__ )
/* uITRON has a TCP/IP API but it doesn't seem to be widely used, and the
only available documentation is in Japanese. If you need TCP/IP support
under uITRON and have an implementation available, you can add the
appropriate interface by replacing net_tcp.c and net_dns.c with the
equivalent uITRON API glue code */
#error You need to set up the TCP/IP headers and interface in net_tcp.c/net_dns.c
/****************************************************************************
* *
* Unix and Unix-compatible Systems *
* *
****************************************************************************/
/* Guardian sockets originally couldn't handle nonblocking I/O like standard
BSD sockets, but required the use of a special non-blocking socket type
(nowait sockets) and the use of AWAITIOX() on the I/O tag returned from
the nowait socket call, since the async state was tied to this rather
than to the socket handle. One of the early G06 releases added select()
support, although even the latest documentation still claims that
select() isn't supported. To avoid having to support two completely
different interfaces, we use the more recent (and BSD standard) select()
interface. Anyone running this code on old systems will have to add
wrappers for the necessary socket_nw()/accept_nw()/AWAITIOX() calls */
#elif ( defined( __BEOS__ ) && defined( BONE_VERSION ) ) || \
defined( __ECOS__ ) || defined( __PALMOS__ ) || \
defined( __RTEMS__ ) || defined ( __SYMBIAN32__ ) || \
defined( __TANDEM_NSK__ ) || defined( __TANDEM_OSS__ ) || \
defined( __UNIX__ )
/* C_IN is a cryptlib.h value which is also defined in some versions of
netdb.h, so we have to undefine it before we include any network header
files */
#undef C_IN
/* PHUX and Tandem OSS have broken networking headers that require manually
defining _XOPEN_SOURCE_EXTENDED in order for various function prototypes
to be enabled. The Tandem variant of this problem has all the function
prototypes for the NSK target and a comment by the 'else' that follows
saying that it's for the OSS target, but then an ifdef for
_XOPEN_SOURCE_EXTENDED that prevents it from being enabled unless
_XOPEN_SOURCE_EXTENDED is also defined */
#if ( defined( __hpux ) && ( OSVERSION >= 10 ) ) || defined( _OSS_TARGET )
#define _XOPEN_SOURCE_EXTENDED 1
#endif /* Workaround for inconsistent networking headers */
/* In OS X 10.3 (Panther), Apple broke the bind interface by changing the
BIND_4_COMPAT define to BIND_8_COMPAT ("Apple reinvented the wheel and
made it square" is one of the more polite comments on this change). In
order to get things to work, we have to define BIND_8_COMPAT here, which
forces the inclusion of nameser_compat.h when we include nameser.h. All
(non-Apple) systems automatically define BIND_4_COMPAT to force this
inclusion, since Bind9 support (in the form of anything other than the
installed binaries) is still pretty rare */
#if defined( __APPLE__ ) && !defined( BIND_8_COMPAT )
#define BIND_8_COMPAT
#endif /* Mac OS X without backwards-compatibility bind define */
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#if defined( __APPLE__ ) || defined( __BEOS__ ) || defined( __bsdi__ ) || \
defined( __FreeBSD__ ) || defined( __hpux ) || defined( __MVS__ ) || \
defined( __NetBSD__ ) || defined( __OpenBSD__ ) || defined( __QNX__ ) || \
( defined( sun ) && OSVERSION <= 5 ) || defined( __SYMBIAN32__ ) || \
defined( __VMCMS__ )
#include <netinet/in.h>
#endif /* OS x || BeOS || *BSDs || PHUX || SunOS 4.x/2.5.x || Symbian OS */
#include <arpa/inet.h>
#if !( defined( __CYGWIN__ ) || defined( __PALMOS__ ) || \
defined( __SYMBIAN32__ ) )
#include <arpa/nameser.h>
#endif /* Cygwin || Symbian OS */
#if defined( __MVS__ ) || defined( __VMCMS__ )
/* The following have conflicting definitions in xti.h */
#undef T_NULL
#undef T_UNSPEC
#endif /* MVS || VM */
#if !defined( __MVS__ )
/* netinet/tcp.h is a BSD-ism, but all Unixen seem to use this even if
XPG4 and SUS say it should be in xti.h */
#include <netinet/tcp.h>
#endif /* !MVS */
#if !( defined( __CYGWIN__ ) || defined( __PALMOS__ ) || \
defined( __SYMBIAN32__ ) )
#include <resolv.h>
#endif /* Cygwin || Symbian OS */
#ifndef TCP_NODELAY
#include <xti.h>
#if defined( __MVS__ ) || defined( __VMCMS__ )
/* The following have conflicting definitions in nameser.h */
#undef T_NULL
#undef T_UNSPEC
#endif /* MVS || VM */
#endif /* TCP_NODELAY */
#ifdef __SCO_VERSION__
#include <signal.h>
#ifndef SIGIO
#include <sys/signal.h>
#endif /* SIGIO not defined in signal.h - only from SCO */
#endif /* UnixWare/SCO */
#if defined( _AIX ) || defined( __PALMOS__ ) || defined( __QNX__ )
#include <sys/select.h>
#endif /* Aches || Palm OS || QNX */
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#ifdef __PALMOS__
/* Needed for close(). unistd.h, which contains this, is normally
included by default in Unix environments, but isn't for PalmOS */
#include <unistd.h>
#endif /* Palm OS */
/* AIX and SCO don't define sockaddr_storage in their IPv6 headers so we
define a placeholder equivalent here */
#if defined( IPv6 ) && \
( ( defined( _AIX ) && OSVERSION <= 5 ) || defined( __SCO_VERSION__ ) )
struct sockaddr_storage {
union {
struct sockaddr_in6 bigSockaddrStruct;
char padding[ 128 ];
} dummyMember;
};
#endif /* IPv6 versions without sockaddr_storage */
/* PHUX generally doesn't define h_errno, we have to be careful here since
later versions may use macros to get around threading issues so we check
for the existence of a macro with the given name before defining our own
version */
#if defined( __hpux ) && !defined( h_errno )
/* Usually missing from netdb.h */
extern int h_errno;
#endif /* PHUX && !h_errno */
/****************************************************************************
* *
* VxWorks *
* *
****************************************************************************/
#elif defined( __VXWORKS__ )
/* VxWorks includes a (somewhat minimal) BSD sockets implementation, if
you're using a newer, enhanced implementation or a third-party
alternative with more complete functionality (and less bugs), you can use
the generic Unix headers and defines further down */
#include <socket.h>
#include <selectLib.h>
/****************************************************************************
* *
* Windows *
* *
****************************************************************************/
#elif defined( __WINDOWS__ )
/* Winsock2 wasn't available until eVC++ 4.0, so if we're running an older
version we have to use the Winsock1 interface */
#if defined( __WINCE__ ) && ( _WIN32_WCE < 400 )
#include <winsock.h>
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#endif /* Older WinCE vs. newer WinCE and Win32 */
/* VC++ 7 and newer have IPv6 support included in ws2tcpip.h, VC++ 6 can
have it bolted-on using the IPv6 Technology Preview but it's not present
by default. In addition the Tech.Preview is quite buggy and unstable,
leaking handles and memory and in some cases leading to runaway memory
consumption that locks up the machine if the process isn't killed in
time, so we don't want to encourage its use */
#if defined( _MSC_VER ) && ( _MSC_VER > 1300 )
/* #include <tpipv6.h> */ /* From IPv6 Tech.Preview */
#endif /* VC++ 7 and newer */
/* VC++ 7 and newer have DNS headers, for older versions we have to define
the necessary types and constants ourselves */
#if defined( _MSC_VER ) && ( _MSC_VER > 1300 )
#include <windns.h>
#else
/* windns.h is quite new and many people don't have it yet, not helped by
the fact that it's also changed over time. For example,
DnsRecordListFree() has also been DnsFreeRecordList() and DnsFree() at
various times, with the parameters changing to match. Because of this,
we have to define our own (very cut-down) subset of what's in there
here. We define PIP4_ARRAY as a void * since it's only used to specify
optional DNS servers to query, we never need this so we just set the
parameter to NULL. As with the DnsXXX functions, PIP4_ARRAY has
changed over time. It was known as PIP_ARRAY in the original VC++ .NET
release, but was renamed PIP4_ARRAY for .NET 2003, although some MSDN
entries still refer to PIP_ARRAY even in the 2003 version */
typedef LONG DNS_STATUS;
typedef void *PIP4_ARRAY;
typedef DWORD IP4_ADDRESS;
typedef enum { DnsFreeFlat, DnsFreeRecordList } DNS_FREE_TYPE;
typedef enum { DnsConfigPrimaryDomainName_W, DnsConfigPrimaryDomainName_A,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -