📄 tcp.h
字号:
DnsConfigPrimaryDomainName_UTF8, DnsConfigAdapterDomainName_W,
DnsConfigAdapterDomainName_A, DnsConfigAdapterDomainName_UTF8,
DnsConfigDnsServerList, DnsConfigSearchList,
DnsConfigAdapterInfo, DnsConfigPrimaryHostNameRegistrationEnabled,
DnsConfigAdapterHostNameRegistrationEnabled,
DnsConfigAddressRegistrationMaxCount, DnsConfigHostName_W,
DnsConfigHostName_A, DnsConfigHostName_UTF8,
DnsConfigFullHostName_W, DnsConfigFullHostName_A,
DnsConfigFullHostName_UTF8 } DNS_CONFIG_TYPE;
#define DNS_TYPE_A 1
#define DNS_TYPE_PTR 12
#define DNS_TYPE_SRV 33
#define DNS_QUERY_STANDARD 0
#define DNS_QUERY_BYPASS_CACHE 8
#if defined( _MSC_VER )
#pragma warning( disable: 4214 ) /* Non-int bitfields */
#endif /* _MSC_VER */
typedef struct {
DWORD Section : 2;
DWORD Delete : 1;
DWORD CharSet : 2;
DWORD Unused : 3;
DWORD Reserved : 24;
} DNS_RECORD_FLAGS;
typedef struct {
IP4_ADDRESS IpAddress;
} DNS_A_DATA, *PDNS_A_DATA;
typedef struct {
LPTSTR pNameHost;
} DNS_PTR_DATA, *PDNS_PTR_DATA;
typedef struct {
LPTSTR pNameTarget;
WORD wPriority;
WORD wWeight;
WORD wPort;
WORD Pad;
} DNS_SRV_DATA, *PDNS_SRV_DATA;
typedef struct _DnsRecord {
struct _DnsRecord *pNext;
LPTSTR pName;
WORD wType;
WORD wDataLength;
union {
DWORD DW;
DNS_RECORD_FLAGS S;
} Flags;
DWORD dwTtl;
DWORD dwReserved;
union {
DNS_A_DATA A;
DNS_PTR_DATA PTR, Ptr,
NS, Ns,
CNAME, Cname,
MB, Mb,
MD, Md,
MF, Mf,
MG, Mg,
MR, Mr;
#if 0
DNS_MINFO_DATA MINFO, Minfo,
RP, Rp;
DNS_MX_DATA MX, Mx,
AFSDB, Afsdb,
RT, Rt;
DNS_TXT_DATA HINFO, Hinfo,
ISDN, Isdn,
TXT, Txt,
X25;
DNS_NULL_DATA Null;
DNS_WKS_DATA WKS, Wks;
DNS_AAAA_DATA AAAA;
DNS_KEY_DATA KEY, Key;
DNS_SIG_DATA SIG, Sig;
DNS_ATMA_DATA ATMA, Atma;
DNS_NXT_DATA NXT, Nxt;
#endif /* 0 */
DNS_SRV_DATA SRV, Srv;
#if 0
DNS_TKEY_DATA TKEY, Tkey;
DNS_TSIG_DATA TSIG, Tsig;
DNS_WINS_DATA WINS, Wins;
DNS_WINSR_DATA WINSR, WinsR,
NBSTAT, Nbstat;
#endif /* 0 */
} Data;
} DNS_RECORD, *PDNS_RECORD;
#endif /* VC++ 7 and newer vs. older versions */
/* For backwards-compatibility purposes, wspiapi.h overrides the new address/
name-handling functions introduced for IPv6 with complex macros that
substitute inline function calls that try and dynamically load different
libraries depending on the Windows version and call various helper
functions to provide the same service. Since we dynamically load the
required libraries, we don't need any of this complexity, so we undefine
the macros in order to make our own ones work */
#ifdef getaddrinfo
#undef freeaddrinfo
#undef getaddrinfo
#undef getnameinfo
#endif /* getaddrinfo defined as macros in wspiapi.h */
/* Set up the appropriate calling convention for the Winsock API */
#if defined( WSAAPI )
#define SOCKET_API WSAAPI
#elif defined( WINSOCKAPI )
#define SOCKET_API WINSOCKAPI
#else
#define SOCKET_API FAR PASCAL
#endif /* WSAAPI */
/****************************************************************************
* *
* Other Systems *
* *
****************************************************************************/
#else
#error You need to set up OS-specific networking include handling in net_tcp.h
#endif /* OS-specific includes and defines */
/****************************************************************************
* *
* General/Portability Defines *
* *
****************************************************************************/
/* Now that we've included all of the networking headers, try and guess
whether this is an IPv6-enabled system. We can detect this by the
existence of definitions for the EAI_xxx return values from
getaddrinfo(). Note that we can't safely detect it using the more
obvious AF_INET6 since many headers defined this in anticipation of IPv6
long before the remaining code support was present */
#if defined( EAI_BADFLAGS ) && defined( EAI_NONAME )
#define IPv6
#endif /* getaddrinfo() return values defined */
/* BeOS with the BONE network stack has the necessary IPv6 defines but no
actual IPv6 support, so we disable it again */
#if defined( __BEOS__ ) && defined( BONE_VERSION ) && defined( IPv6 )
#undef IPv6
#endif /* BeOS with BONE */
/* The size of a (v4) IP address and the number of IP addresses that we try
to connect to for a given host, used if we're providing an emulated
(IPv4-only) getaddrinfo() */
#define IP_ADDR_SIZE 4
#define IP_ADDR_COUNT 16
/* Test for common socket errors */
#ifndef __WINDOWS__
#define INVALID_SOCKET -1
#endif /* __WINDOWS__ */
#define isBadSocket( socket ) ( ( socket ) == INVALID_SOCKET )
#ifdef __WINDOWS__
#define isSocketError( status ) ( ( status ) == SOCKET_ERROR )
#define isBadAddress( address ) ( ( address ) == INADDR_NONE )
#else
#define isSocketError( status ) ( ( status ) == -1 )
#define isBadAddress( address ) ( ( address ) == ( in_addr_t ) -1 )
#endif /* Windows vs. other systems */
#if defined( __SYMBIAN32__ )
/* Symbian OS doesn't support nonblocking I/O */
#define isNonblockWarning() 0
#elif defined( __BEOS__ )
#if defined( BONE_VERSION )
/* BONE returns "Operation now in progress" */
#define isNonblockWarning() ( errno == EWOULDBLOCK || \
errno == 0x80007024 )
#else
/* BeOS, even though it supposedly doesn't support nonblocking
sockets, can return EWOULDBLOCK */
#define isNonblockWarning() ( errno == EWOULDBLOCK )
#endif /* BeOS with/without BONE */
#elif defined( __WINDOWS__ )
#define isNonblockWarning() ( WSAGetLastError() == WSAEWOULDBLOCK )
#else
#define isNonblockWarning() ( errno == EINPROGRESS )
#endif /* OS-specific socket error handling */
/* Error code handling */
#ifdef __WINDOWS__
#define getErrorCode() WSAGetLastError()
#define getHostErrorCode() WSAGetLastError()
#else
#define getErrorCode() errno
#if ( defined( __MVS__ ) && defined( _OPEN_THREADS ) )
/* MVS converts this into a hidden function in the presence of threads,
but not transparently like other systems */
#define getHostErrorCode() ( *__h_errno() )
#else
#define getHostErrorCode() h_errno
#endif /* MVS */
#endif /* OS-specific error code handling */
/* Windows and BeOS use a distinct socket handle type and require the use of
separate closesocket() and ioctlsocket() functions because socket handles
aren't the same as standard Windows/BeOS handles */
#ifdef SOCKET
/* MP-RAS has already defined this */
#undef SOCKET
#endif /* SOCKET */
#define SOCKET int
#ifndef __WINDOWS__
#if !defined( __BEOS__ ) || \
( defined( __BEOS__ ) && defined( BONE_VERSION ) )
#define closesocket close
#endif /* BeOS without BONE */
#define ioctlsocket ioctl
#endif /* OS-specific portability defines */
/* The generic sockaddr struct used to reserve storage for protocol-specific
sockaddr structs. The IPv4 equivalent is given further down in the IPv6-
mapping definitions */
#ifdef IPv6
#define SOCKADDR_STORAGE struct sockaddr_storage
#endif /* IPv6 */
/* Many systems don't define the in_*_t's */
#if defined( __APPLE__ ) || defined( __BEOS__ ) || \
defined( __bsdi__ ) || defined( _CRAY ) || \
defined( __CYGWIN__ ) || defined( __FreeBSD__ ) || \
defined( __hpux ) || defined( __linux__ ) || \
defined( __NetBSD__ ) || defined( __OpenBSD__ ) || \
defined( __QNX__ ) || ( defined( sun ) && OSVERSION <= 5 ) || \
defined( __WINDOWS__ )
#ifndef in_addr_t
#define in_addr_t u_long
#define in_port_t u_short
#endif /* in_addr_t */
#endif /* Older Unixen without in_*_t's */
/* Some systems use int for size parameters to socket functions and some use
size_t (and just to be difficult some use socklen_t, which we use if we
can get it). The following is required to distinguish the different ones
to avoid compiler warnings on systems that insist on having it one
particular way */
#if defined( socklen_t ) || defined( __socklen_t_defined )
#define SIZE_TYPE socklen_t
#elif defined( __APPLE__ ) || defined( __BEOS__ ) || defined( _CRAY ) || \
defined( __WINDOWS__ )
#define SIZE_TYPE int
#else
#define SIZE_TYPE size_t
#endif /* Different size types */
/* The Bind namespace (via nameser.h) was cleaned up between the old (widely-
used) Bind4 API and the newer (little-used) Bind8/9 one. In order to
handle both, we use the newer definitions, but map them back to the Bind4
forms if required. The only thing this doesn't give us is the HEADER
struct, which seems to have no equivalent in Bind8/9 */
#ifndef NS_PACKETSZ
#define NS_PACKETSZ PACKETSZ
#define NS_HFIXEDSZ HFIXEDSZ
#define NS_RRFIXEDSZ RRFIXEDSZ
#define NS_QFIXEDSZ QFIXEDSZ
#endif /* Bind8 names */
/* Older versions of QNX don't define HFIXEDSZ either */
#if defined( __QNX__ ) && ( OSVERSION <= 4 )
#define HFIXEDSZ 12
#endif /* QNX 4.x */
/* Values defined in some environments but not in others. MSG_NOSIGNAL is
used to avoid SIGPIPEs on writes if the other side closes the connection,
if it's not implemented in this environment we just clear the flag */
#ifndef SHUT_WR
#define SHUT_WR 1
#endif /* SHUT_WR */
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif /* MSG_NOSIGNAL */
/* For some connections that involve long-running sessions we need to be
able to gracefully recover from local errors such as an interrupted system
call, and remote errors such as the remote process or host crashing and
restarting, which we can do by closing and re-opening the connection. The
various situations are:
Local error:
Retry the call on EAGAIN or EINTR
Process crashes and restarts:
Write: Remote host sends a RST in response to an attempt to continue
a TCP session that it doesn't remember, which is reported
locally as the dreaded (if you ssh or NNTP to remote hosts a
lot) connection reset by peer error.
Read: Remote host sends a FIN, we read 0 bytes.
Network problem:
Write: Data is re-sent, if a read is pending it returns ETIMEDOUT,
otherwise write returns EPIPE or SIGPIPE (although we try
and avoid the latter using MSG_NOSIGNAL). Some
implementations may also return ENETUNREACH or EHOSTUNREACH
if they receive the right ICMP information.
Read: See above, without the write sematics.
Host crashes and restarts:
Write: Looks like a network outage until the host is restarted, then
gets an EPIPE/SIGPIPE.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -