23 #define accept kn_accept
25 #define closesocket kn_close
26 #define connect kn_connect
27 #define getsockopt kn_getsockopt
28 #define listen kn_listen
30 #define select kn_select
32 #define setsockopt kn_setsockopt
33 #define shutdown kn_shutdown
34 #define socket kn_socket
52 #include <sys/socket.h>
59 #if defined( __BEOS__ ) && !defined( BONE_VERSION )
71 #define PF_INET AF_INET
75 #define in_addr_t u_long
76 #define in_port_t u_short
80 #define NO_ADDRESS NO_DATA
86 #define select( sockets, readFD, writeFD, exceptFD, timeout ) \
87 my_select( sockets, readFD, writeFD, exceptFD, timeout )
88 #define getsockopt( socket, level, optname, optval, optlen ) \
89 my_getsockopt( socket, level, optname, optval, optlen )
90 #define setsockopt( socket, level, optname, optval, optlen ) \
91 my_setsockopt( socket, level, optname, optval, optlen )
99 #define TCP_NODELAY -1
107 #elif defined( __THREADX__ )
114 #include "r:/temp/trsocket.h"
121 #ifndef NI_NUMERICSERV
122 #define NI_NUMERICSERV 0
130 #define IPV6_V6ONLY 5000
138 #define closesocket tfClose
139 #define ioctlsocket tfIoctl
140 #define getErrorCode() tfGetSocketError( netStream->netSocket )
141 #define getHostErrorCode() tfGetSocketError( netStream->netSocket )
145 #ifndef EADDRNOTAVAIL
146 #define EADDRNOTAVAIL TM_EADDRNOTAVAIL
147 #define EAGAIN TM_EAGAIN
148 #define ECONNABORTED TM_ECONNABORTED
149 #define ECONNREFUSED TM_ECONNREFUSED
150 #define ECONNRESET TM_ECONNRESET
151 #define EINPROGRESS TM_EINPROGRESS
152 #define EINTR TM_EINTR
153 #define EMFILE TM_EMFILE
154 #define EMSGSIZE TM_EMSGSIZE
155 #define ENETUNREACH TM_ENETUNREACH
156 #define ENOBUFS TM_ENOBUFS
157 #define ENOTCONN TM_ENOTCONN
158 #define ETIMEDOUT TM_ETIMEDOUT
159 #define HOST_NOT_FOUND TM_DNS_ENAME_ERROR
160 #define NO_ADDRESS TM_DNS_EANSWER
161 #define NO_DATA TM_DNS_EANSWER
162 #define TRY_AGAIN TM_EAGAIN
171 #elif defined( __ITRON__ )
179 #error You need to set up the TCP/IP headers and interface in net_tcp.c/net_dns.c
198 #elif ( defined( __BEOS__ ) && defined( BONE_VERSION ) ) || \
199 defined( __ECOS__ ) || defined( __MVS__ ) || \
200 defined( __PALMOS__ ) || defined( __RTEMS__ ) || \
201 defined ( __SYMBIAN32__ ) || defined( __TANDEM_NSK__ ) || \
202 defined( __TANDEM_OSS__ ) || defined( __UNIX__ )
218 #if ( defined( __hpux ) && ( OSVERSION >= 10 ) ) || defined( _OSS_TARGET )
219 #define _XOPEN_SOURCE_EXTENDED 1
231 #if defined( __APPLE__ ) && !defined( BIND_8_COMPAT )
232 #define BIND_8_COMPAT
238 #if defined( __APPLE__ ) || defined( __BEOS__ ) || defined( __bsdi__ ) || \
239 defined( __FreeBSD__ ) || defined( __hpux ) || defined( __MVS__ ) || \
240 defined( __NetBSD__ ) || defined( __OpenBSD__ ) || defined( __QNX__ ) || \
241 ( defined( sun ) && OSVERSION <= 5 ) || defined( __SYMBIAN32__ ) || \
243 #include <netinet/in.h>
245 #include <arpa/inet.h>
246 #if !( defined( __CYGWIN__ ) || defined( __PALMOS__ ) || \
247 defined( __SYMBIAN32__ ) || defined( USE_EMBEDDED_OS ) )
248 #include <arpa/nameser.h>
250 #if defined( __MVS__ ) || defined( __VMCMS__ )
255 #if !defined( __MVS__ )
258 #include <netinet/tcp.h>
260 #if !( defined( __CYGWIN__ ) || defined( __PALMOS__ ) || \
261 defined( __SYMBIAN32__ ) || defined( USE_EMBEDDED_OS ) )
264 #if !defined( TCP_NODELAY ) && !defined( USE_EMBEDDED_OS )
266 #if defined( __MVS__ ) || defined( __VMCMS__ )
272 #ifdef __SCO_VERSION__
275 #include <sys/signal.h>
278 #if defined( _AIX ) || defined( __PALMOS__ ) || defined( __QNX__ )
279 #include <sys/select.h>
281 #include <sys/socket.h>
282 #include <sys/time.h>
283 #include <sys/types.h>
293 #if defined( IPv6 ) && \
294 ( ( defined( _AIX ) && OSVERSION <= 5 ) || defined( __SCO_VERSION__ ) )
295 struct sockaddr_storage {
297 struct sockaddr_in6 bigSockaddrStruct;
308 #if defined( __hpux ) && !defined( h_errno )
319 #elif defined( __VXWORKS__ )
327 #include <selectLib.h>
335 #elif defined( __WINDOWS__ )
340 #if defined( _MSC_VER ) && ( _MSC_VER <= 800 ) || \
341 defined( __WINCE__ ) && ( _WIN32_WCE < 400 )
344 #include <winsock2.h>
345 #include <ws2tcpip.h>
355 #if defined( _MSC_VER ) && ( _MSC_VER > 1300 )
363 #if defined( _MSC_VER ) && ( _MSC_VER > 1300 ) && !defined( WIN_DDK )
365 #elif defined( _MSC_VER ) && ( _MSC_VER > 800 )
377 typedef LONG DNS_STATUS;
378 typedef void *PIP4_ARRAY;
379 typedef DWORD IP4_ADDRESS;
380 typedef enum { DnsFreeFlat, DnsFreeRecordList } DNS_FREE_TYPE;
381 typedef enum { DnsConfigPrimaryDomainName_W, DnsConfigPrimaryDomainName_A,
382 DnsConfigPrimaryDomainName_UTF8, DnsConfigAdapterDomainName_W,
383 DnsConfigAdapterDomainName_A, DnsConfigAdapterDomainName_UTF8,
384 DnsConfigDnsServerList, DnsConfigSearchList,
385 DnsConfigAdapterInfo, DnsConfigPrimaryHostNameRegistrationEnabled,
386 DnsConfigAdapterHostNameRegistrationEnabled,
387 DnsConfigAddressRegistrationMaxCount, DnsConfigHostName_W,
388 DnsConfigHostName_A, DnsConfigHostName_UTF8,
389 DnsConfigFullHostName_W, DnsConfigFullHostName_A,
390 DnsConfigFullHostName_UTF8 } DNS_CONFIG_TYPE;
392 #define DNS_TYPE_PTR 12
393 #define DNS_TYPE_SRV 33
394 #define DNS_QUERY_STANDARD 0
395 #define DNS_QUERY_BYPASS_CACHE 8
400 unsigned int Section : 2;
401 unsigned int Delete : 1;
402 unsigned int CharSet : 2;
403 unsigned int Unused : 3;
404 unsigned int Reserved : 24;
407 IP4_ADDRESS IpAddress;
408 } DNS_A_DATA, *PDNS_A_DATA;
411 } DNS_PTR_DATA, *PDNS_PTR_DATA;
418 } DNS_SRV_DATA, *PDNS_SRV_DATA;
419 typedef struct _DnsRecord {
420 struct _DnsRecord *pNext;
432 DNS_PTR_DATA
PTR, Ptr,
441 DNS_MINFO_DATA MINFO, Minfo,
446 DNS_TXT_DATA HINFO, Hinfo,
451 DNS_WKS_DATA WKS, Wks;
453 DNS_KEY_DATA KEY, Key;
454 DNS_SIG_DATA SIG, Sig;
455 DNS_ATMA_DATA ATMA, Atma;
456 DNS_NXT_DATA NXT, Nxt;
458 DNS_SRV_DATA SRV, Srv;
460 DNS_TKEY_DATA TKEY, Tkey;
461 DNS_TSIG_DATA TSIG, Tsig;
462 DNS_WINS_DATA WINS, Wins;
463 DNS_WINSR_DATA WINSR, WinsR,
467 } DNS_RECORD, *PDNS_RECORD;
486 #if defined( WSAAPI )
487 #define SOCKET_API WSAAPI
488 #elif defined( WINSOCKAPI )
489 #define SOCKET_API WINSOCKAPI
491 #define SOCKET_API FAR PASCAL
502 #error You need to set up OS-specific networking include handling in net_tcp.h
519 #if defined( EAI_BADFLAGS ) && defined( EAI_NONAME )
526 #if defined( __BEOS__ ) && defined( BONE_VERSION ) && defined( IPv6 )
534 #define IP_ADDR_SIZE 4
535 #define IP_ADDR_COUNT 16
550 #define INVALID_SOCKET -1
552 #if defined( __WINDOWS__ )
553 #define isBadSocket( socket ) ( ( socket ) <= 0 )
554 #elif defined( STDERR_FILENO )
555 #define isBadSocket( socket ) ( ( socket ) <= STDERR_FILENO || \
556 ( socket ) >= FD_SETSIZE )
558 #define isBadSocket( socket ) ( ( socket ) <= 0 || \
559 ( socket ) >= FD_SETSIZE )
562 #define isSocketError( status ) ( ( status ) == SOCKET_ERROR )
563 #define isBadAddress( address ) ( ( address ) == INADDR_NONE )
565 #define isSocketError( status ) ( ( status ) == -1 )
566 #define isBadAddress( address ) ( ( address ) == ( in_addr_t ) -1 )
568 #if defined( __SYMBIAN32__ )
570 #define isNonblockWarning() 0
571 #elif defined( __BEOS__ )
572 #if defined( BONE_VERSION )
574 #define isNonblockWarning() ( errno == EWOULDBLOCK || \
575 errno == 0x80007024 )
579 #define isNonblockWarning() ( errno == EWOULDBLOCK )
581 #elif defined( __WINDOWS__ )
582 #define isNonblockWarning() ( WSAGetLastError() == WSAEWOULDBLOCK )
584 #define isNonblockWarning() ( errno == EINPROGRESS )
589 #if defined( __WINDOWS__ )
590 #define getErrorCode() WSAGetLastError()
591 #define getHostErrorCode() WSAGetLastError()
592 #elif !defined( getErrorCode )
593 #define getErrorCode() errno
594 #if ( defined( __MVS__ ) && defined( _OPEN_THREADS ) )
597 #define getHostErrorCode() ( *__h_errno() )
599 #define getHostErrorCode() h_errno
612 #if !defined( __WINDOWS__ ) && !defined( closesocket )
613 #if !defined( __BEOS__ ) || \
614 ( defined( __BEOS__ ) && defined( BONE_VERSION ) )
615 #define closesocket close
617 #define ioctlsocket ioctl
625 #define SOCKADDR_STORAGE struct sockaddr_storage
630 #if defined( __APPLE__ ) || defined( __BEOS__ ) || \
631 defined( __bsdi__ ) || defined( _CRAY ) || \
632 defined( __CYGWIN__ ) || defined( __FreeBSD__ ) || \
633 defined( __hpux ) || defined( __linux__ ) || \
634 defined( __NetBSD__ ) || defined( __OpenBSD__ ) || \
635 defined( __QNX__ ) || ( defined( sun ) && OSVERSION <= 5 ) || \
636 defined( __WINDOWS__ )
638 #define in_addr_t u_long
639 #define in_port_t u_short
662 #if defined( socklen_t ) || defined( __socklen_t_defined )
663 #define SIZE_TYPE socklen_t
664 #elif defined( __APPLE__ ) || defined( __BEOS__ ) || defined( _CRAY ) || \
665 defined( __WINDOWS__ )
666 #define SIZE_TYPE int
668 #define SIZE_TYPE size_t
678 #define NS_PACKETSZ PACKETSZ
679 #define NS_HFIXEDSZ HFIXEDSZ
680 #define NS_RRFIXEDSZ RRFIXEDSZ
681 #define NS_QFIXEDSZ QFIXEDSZ
686 #if defined( __QNX__ ) && ( OSVERSION <= 4 )
698 #define MSG_NOSIGNAL 0
742 #define isRecoverableError( status ) ( ( status ) == WSAECONNRESET )
743 #define isRestartableError() ( WSAGetLastError() == WSAEWOULDBLOCK || \
744 WSAGetLastError() == WSAEINPROGRESS )
745 #define isTimeoutError() ( WSAGetLastError() == WSAETIMEDOUT )
747 #define isRecoverableError( status ) ( ( status ) == ECONNRESET )
748 #define isRestartableError() ( errno == EINTR || errno == EAGAIN )
749 #define isTimeoutError() ( errno == ETIMEDOUT )
762 #if defined( __BEOS__ ) && defined( BONE_VERSION )
778 struct sockaddr *ai_addr;
779 struct addrinfo *ai_next;
786 typedef char SOCKADDR_STORAGE[ 128 ];
789 #define AI_PASSIVE 0x1
798 #define NI_NUMERICHOST 0x2
799 #define NI_NUMERICSERV 0x8
801 #define NI_NUMERICHOST 0x1
802 #define NI_NUMERICSERV 0x2
807 #define IPPROTO_IPV6 41
809 #define IPV6_V6ONLY 27
811 #define IPV6_V6ONLY 26
817 #define getaddrinfo my_getaddrinfo
818 #define freeaddrinfo my_freeaddrinfo
819 #define getnameinfo my_getnameinfo
821 static int my_getaddrinfo(
const char *nodename,
const char *servname,
822 const struct addrinfo *hints,
823 struct addrinfo **res );
824 static void my_freeaddrinfo(
struct addrinfo *ai );
825 static int my_getnameinfo(
const struct sockaddr *sa, SIZE_TYPE salen,
826 char *node, SIZE_TYPE nodelen,
827 char *service, SIZE_TYPE servicelen,
841 #if defined( __WINDOWS__ ) && !defined( IPV6_V6ONLY ) && \
842 ( defined( _M_X64 ) || defined( __WINCE__ ) )
843 #define IPV6_V6ONLY 27
850 #if defined( __BEOS__ ) && defined( BONE_VERSION )
853 typedef char SOCKADDR_STORAGE[ 128 ];
855 #define getaddrinfo my_getaddrinfo
856 #define freeaddrinfo my_freeaddrinfo
857 #define getnameinfo my_getnameinfo
859 static int my_getaddrinfo(
const char *nodename,
const char *servname,
860 const struct addrinfo *hints,
861 struct addrinfo **res );
862 static void my_freeaddrinfo(
struct addrinfo *ai );
863 static int my_getnameinfo(
const struct sockaddr *sa, SIZE_TYPE salen,
864 char *node, SIZE_TYPE nodelen,
865 char *service, SIZE_TYPE servicelen,
877 #ifndef NS_SRVFIXEDSZ
878 #define NS_SRVFIXEDSZ ( NS_RRFIXEDSZ + 6 )
880 #ifndef AI_ADDRCONFIG
881 #define AI_ADDRCONFIG 0
883 #ifndef AI_NUMERICSERV
884 #define AI_NUMERICSERV 0
917 #if defined( USE_THREADS ) && defined( __GLIBC__ ) && ( __GLIBC__ >= 2 ) && \
918 ( !defined( __BEOS__ ) || !defined( BONE_VERSION ) )
919 #define gethostbyname_vars() \
920 char hostBuf[ 4096 ]; \
921 struct hostent hostEnt;
922 #define gethostbyname_threadsafe( hostName, hostEntPtr, hostErrno ) \
923 if( gethostbyname_r( hostName, &hostEnt, hostBuf, 4096, &hostEntPtr, &hostErrno ) < 0 ) \
925 #elif defined( USE_THREADS ) && \
926 ( ( defined( sun ) && OSVERSION > 4 ) || \
927 ( defined( __sgi ) && OSVERSION >= 6 ) || defined( __QNX__ ) )
928 #define gethostbyname_vars() \
929 char hostBuf[ 4096 ]; \
930 struct hostent hostEnt;
931 #define gethostbyname_threadsafe( hostName, hostEntPtr, hostErrno ) \
932 hostEntPtr = gethostbyname_r( hostName, &hostEnt, hostBuf, 4096, &hostErrno )
934 #define gethostbyname_vars()
935 #define gethostbyname_threadsafe( hostName, hostEntPtr, hostErrno ) \
936 hostEntPtr = gethostbyname( hostName ); \
989 #if defined( F_GETFL ) && defined( F_SETFL ) && defined( O_NONBLOCK )
990 #define getSocketNonblockingStatus( socket, value ) \
992 value = fcntl( socket, F_GETFL, 0 ); \
993 value = ( isSocketError( value ) || ( value & O_NONBLOCK ) ) ? \
996 #define setSocketNonblocking( socket ) \
998 const int flags = fcntl( socket, F_GETFL, 0 ); \
999 fcntl( socket, F_SETFL, flags | O_NONBLOCK ); \
1001 #define setSocketBlocking( socket ) \
1003 const int flags = fcntl( socket, F_GETFL, 0 ); \
1004 fcntl( socket, F_SETFL, flags & ~O_NONBLOCK ); \
1006 #elif defined( FIONBIO )
1007 #define getSocketNonblockingStatus( socket, value ) \
1009 unsigned long nonBlock = FALSE; \
1010 value = ioctlsocket( socket, FIONBIO, &nonBlock ); \
1011 value = isSocketError( value ) ? TRUE : FALSE; \
1013 #define setSocketNonblocking( socket ) \
1015 unsigned long nonBlock = TRUE; \
1016 ioctlsocket( socket, FIONBIO, &nonBlock ); \
1018 #define setSocketBlocking( socket ) \
1020 unsigned long nonBlock = FALSE; \
1021 ioctlsocket( socket, FIONBIO, &nonBlock ); \
1023 #elif defined( __AMX__ ) || defined( __BEOS__ )
1024 #define getSocketNonblockingStatus( socket, value ) \
1026 int nonBlock = FALSE; \
1027 setsockopt( socket, SOL_SOCKET, SO_NONBLOCK, &nonBlock, sizeof( int ) ); \
1029 #define setSocketNonblocking( socket ) \
1031 int nonBlock = TRUE; \
1032 setsockopt( socket, SOL_SOCKET, SO_NONBLOCK, &nonBlock, sizeof( int ) ); \
1034 #define setSocketBlocking( socket ) \
1036 int nonBlock = FALSE; \
1037 setsockopt( socket, SOL_SOCKET, SO_NONBLOCK, &nonBlock, sizeof( int ) ); \
1039 #elif defined( __SYMBIAN32__ )
1041 #define getSocketNonblockingStatus( socket, value ) value = 0
1042 #define setSocketNonblocking( socket )
1043 #define setSocketBlocking( socket )
1045 #error Need to create macros to handle nonblocking I/O
1058 int initDNS(
const INSTANCE_HANDLE hTCP,
const INSTANCE_HANDLE hAddr );
1059 void endDNS(
const INSTANCE_HANDLE hTCP );
1062 int initDNSSRV(
const INSTANCE_HANDLE hTCP );
1063 void endDNSSRV(
const INSTANCE_HANDLE hTCP );
1065 #define initDNSSRV( hTCP ) CRYPT_ERROR
1066 #define endDNSSRV( hTCP )
1074 OUT_PTR struct addrinfo **addrInfoPtrPtr,
1079 void freeAddressInfo(
struct addrinfo *addrInfoPtr );
1081 void getNameInfo(
IN_BUFFER( sockAddrLen )
const void *sockAddr,
1103 #define findHostInfo( netStream, hostName, hostNameLen, hostPort, name, nameLen ) \
1104 setSocketError( netStream, "DNS SRV services not available", 30, \
1105 CRYPT_ERROR_NOTAVAIL, FALSE ); \
1106 memset( hostName, 0, min( 16, hostNameLen ) ); \
1120 IN_BUFFER( errorMessageLength )
const char *errorMessage,