' ########################################################################################
' Microsoft Windows
' File: WinSock.inc
' Copyright (c) 2010 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
 '/* WINSOCK.H--definitions to be used with the WINSOCK.DLL
' * Copyright (c) Microsoft Corporation. All rights reserved.
' *
' * This header file corresponds to version 1.1 of the Windows Sockets specification.
' *
' * This file includes parts which are Copyright (c) 1982-1986 Regents
' * of the University of California. All rights reserved. The
' * Berkeley Software License Agreement specifies the terms and
' * conditions for redistribution.
' *
' */
#IF NOT %DEF(PBX_WinSock_PBI)
#DEFINE PBX_WinSock_PBI
%EQUATE `WINSOCK_INC = 1
#IF NOT %DEF(%WINSOCKAPI)
 %WINSOCKAPI = 1
 %WINSOCK2API = 1 ' Prevent inclusion of winsock2.inc
#INCLUDE ONCE "Core/Windows.inc"
'/*
' * Basic system type definitions, taken from the BSD file sys/types.h.
' */
'typedef unsigned char u_char;
'typedef unsigned short u_short;
'typedef unsigned int u_int;
'typedef unsigned long u_long;
'/*
' * The new type to be used in all
' * instances which refer to sockets.
' */
'typedef UINT_PTR SOCKET;
'/*
' * Select uses arrays of SOCKETs. These macros manipulate such
' * arrays. FD_SETSIZE may be defined by the user before including
' * this file, but the default here should be >= 64.
' *
' * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
' * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
' */
'#ifndef FD_SETSIZE
'#define FD_SETSIZE 64
'#endif /* FD_SETSIZE */
#IF NOT %DEF(%FD_SETSIZE)
 %FD_SETSIZE = 64
#ENDIF
' // Size = 260 bytes
TYPE fd_setstruc DWORD
 fd_count AS DWORD ' /* how many are SET? */
 fd_array (%FD_SETSIZE - 1) AS DWORD ' /* an array of SOCKETs */
END TYPE
MACRO FD_SET_STRUCT = fd_setstruc
'extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
DECLARE FUNCTION WSAFDIsSet LIB "wsock32.dll" ALIAS "__WSAFDIsSet" ( BYVAL s AS QUAD ' SOCKET , BYREF pfdset AS fd_setstruc ' fd_set FAR * ) AS LONG ' int
'#ifdef __cplusplus
'}
'#endif
'#define FD_CLR(fd, set) do { \
' u_int __i; \
' for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
' if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
' while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
' ((fd_set FAR *)(set))->fd_array[__i] = \
' ((fd_set FAR *)(set))->fd_array[__i+1]; \
' } \
' ((fd_set FAR *)(set))->fd_count--; \
' break; \
' } \
' } \
'} while(0)
'#define FD_SET(fd, set) do { \
' if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
' ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=(fd);\
'} while(0)
'#define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
'#define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set FAR *)(set))
SUB FD_SET (BYVAL s AS DWORD, BYREF fds AS fd_setstruc)
 IF fds.fd_count < %FD_SETSIZE THEN
 fds.fd_array(fds.fd_count) = s
 INCR fds.fd_count
 END IF
END SUB
SUB FD_ZERO (BYREF fd AS fd_setstruc)
 fd.fd_count = 0
END SUB
FUNCTION FD_ISSET (BYVAL fd AS DWORD, BYREF fds AS fd_setstruc) AS LONG
 FUNCTION = WSAFDIsSet(fd, fds)
END FUNCTION
'/*
' * Structure used in select() call, taken from the BSD file sys/time.h.
' */
'struct timeval {
' long tv_sec; /* seconds */
' long tv_usec; /* and microseconds */
'};
' // Size = 8 bytes
TYPE timeval DWORD
 tv_sec AS LONG ' /* seconds */
 tv_usec AS LONG ' /* and microseconds */
END TYPE
'/*
' * Operations on timevals.
' *
' * NB: timercmp does not work for >= or <=.
' */
'#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
'#define timercmp(tvp, uvp, cmp) \
' ((tvp)->tv_sec cmp (uvp)->tv_sec || \
' (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
'#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
MACRO timerisset (tvp) = (tvp.tv_sec OR tvp.tv_usec)
MACRO timerclear (tvp)
 tvp.tv_sec = 0
 tvp.tv_usec = 0
END MACRO
'/*
' * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
' *
' *
' * Ioctl's have the command encoded in the lower word,
' * and the size of any in or out parameters in the upper
' * word. The high 2 bits of the upper word are used
' * to encode the in/out status of the parameter; for now
' * we restrict parameters to at most 128 bytes.
' */
'#define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
'#define IOC_VOID 0x20000000 /* no parameters */
'#define IOC_OUT 0x40000000 /* copy out parameters */
'#define IOC_IN 0x80000000 /* copy in parameters */
'#define IOC_INOUT (IOC_IN|IOC_OUT)
' /* 0x20000000 distinguishes new &
' old ioctl's */
%EQUATE `IOCPARM_MASK = &H7F ' parameters must be < 128 bytes
%EQUATE `IOC_VOID = &H20000000 ' no parameters
%EQUATE `IOC_OUT = &H40000000 ' copy out parameters
%EQUATE `IOC_IN = &H80000000 ' copy in parameters
%EQUATE `IOC_INOUT = (%IOC_IN OR %IOC_OUT) ' &H20000000 distinguishes new &
 ' old ioctl's
'#define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
MACRO FUNCTION IO_ (x, y)
 MACROTEMP t
 LOCAL t AS DWORD
 t = x
 SHIFT LEFT t, 8
END MACRO = (%IOC_VOID OR t OR y)
'#define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
MACRO FUNCTION IOR_ (x, y, t)
 MACROTEMP t1, t2
 LOCAL t1 AS DWORD
 LOCAL t2 AS DWORD
 t1 = SIZEOF(t) AND %IOCPARM_MASK
 SHIFT LEFT t1, 16
 t2 = x
 SHIFT LEFT t2, 8
END MACRO = (%IOC_OUT OR t1 OR t2 OR y)
'#define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
MACRO FUNCTION IOW_ (x, y, t)
 MACROTEMP t1, t2
 LOCAL t1 AS DWORD
 LOCAL t2 AS DWORD
 t1 = SIZEOF(t) AND %IOCPARM_MASK
 SHIFT LEFT t1, 16
 t2 = x
 SHIFT LEFT t2, 8
END MACRO = (%IOC_IN OR t1 OR t2 OR y)
'#define FIONREAD _IOR('f', 127, u_long) /* get # bytes to read */
'#define FIONBIO _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
'#define FIOASYNC _IOW('f', 125, u_long) /* set/clear async i/o */
%EQUATE `FIONREAD = &H4004667F ' get # bytes to read
%EQUATE `FIONBIO = &H8004667E ' set/clear non-blocking i/o
%EQUATE `FIONSYNC = &H8004667D ' set/clear async i/o
'/* Socket I/O Controls */
'#define SIOCSHIWAT _IOW('s', 0, u_long) /* set high watermark */
'#define SIOCGHIWAT _IOR('s', 1, u_long) /* get high watermark */
'#define SIOCSLOWAT _IOW('s', 2, u_long) /* set low watermark */
'#define SIOCGLOWAT _IOR('s', 3, u_long) /* get low watermark */
'#define SIOCATMARK _IOR('s', 7, u_long) /* at oob mark? */
%EQUATE `SIOCSHIWAT = &H80047300 ' set high watermark
%EQUATE `SIOCGHIWAT = &H80047301 ' get high watermark
%EQUATE `SIOCSLOWAT = &H80047302 ' set low watermark
%EQUATE `SIOCGLOWAT = &H80047303 ' get low watermark
%EQUATE `SIOCATMARK = &H80047307 ' at oob mark?
'/*
' * Structures returned by network data base library, taken from the
' * BSD file netdb.h. All addresses are supplied in host order, and
' * returned in network order (suitable for use in system calls).
' */
'struct hostent {
' char FAR * h_name; /* official name of host */
' char FAR * FAR * h_aliases; /* alias list */
' short h_addrtype; /* host address type */
' short h_length; /* length of address */
' char FAR * FAR * h_addr_list; /* list of addresses */
'#define h_addr h_addr_list[0] /* address, for backward compat */
'};
' // Size = 16 bytes
TYPE hostent DWORD FILL
 h_name AS ASCIIZ PTR ' official name of host
 h_alias AS DWORD ' alias list (pointer to ASCIIZ PTR list)
 h_addr AS INTEGER ' host address type
 h_len AS INTEGER ' length of address
 h_list AS DWORD ' list of addresses (pointer to ASCIIZ PTR list)
END TYPE
'/*
' * It is assumed here that a network number
' * fits in 32 bits.
' */
'struct netent {
' char FAR * n_name; /* official name of net */
' char FAR * FAR * n_aliases; /* alias list */
' short n_addrtype; /* net address type */
' u_long n_net; /* network # */
'};
' // Size = 16 bytes
TYPE netent DWORD
 n_name AS ASCIIZ PTR ' official name of net
 n_aliases AS DWORD ' alias list (pointer to ASCIIZ PTR list)
 n_addrtype AS INTEGER ' net address type
 n_net AS DWORD ' network #
END TYPE
'struct servent {
' char FAR * s_name; /* official service name */
' char FAR * FAR * s_aliases; /* alias list */
'#ifdef _WIN64
' char FAR * s_proto; /* protocol to use */
' short s_port; /* port # */
'#else
' short s_port; /* port # */
' char FAR * s_proto; /* protocol to use */
'#endif
'};
' // Size = 16 bytes
TYPE servent DWORD
 s_name AS ASCIIZ PTR ' official service name
 s_aliases AS DWORD ' alias list (pointer to ASCIIZ PTR list)
 s_port AS INTEGER ' port #
 s_proto AS ASCIIZ PTR ' protocol to use
END TYPE
'struct protoent {
' char FAR * p_name; /* official protocol name */
' char FAR * FAR * p_aliases; /* alias list */
' short p_proto; /* protocol # */
'};
' // Size = 12 bytes
TYPE protoent DWORD
 p_name AS ASCIIZ PTR ' official protocol name
 p_aliases AS DWORD ' alias list (pointer to ASCIIZ PTR list)
 p_proto AS INTEGER ' protocol #
END TYPE
'/*
' * Constants and structures defined by the internet system,
' * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
' */
'/*
' * Protocols
' */
%EQUATE `IPPROTO_IP = 0 ' dummy for IP
%EQUATE `IPPROTO_ICMP = 1 ' control message protocol
%EQUATE `IPPROTO_GGP = 2 ' gateway^2 (deprecated)
%EQUATE `IPPROTO_TCP = 6 ' tcp
%EQUATE `IPPROTO_PUP = 12 ' pup
%EQUATE `IPPROTO_UDP = 17 ' user datagram protocol
%EQUATE `IPPROTO_IDP = 22 ' xns idp
%EQUATE `IPPROTO_ND = 77 ' UNOFFICIAL net disk proto
%EQUATE `IPPROTO_RAW = 255 ' raw IP packet
%EQUATE `IPPROTO_MAX = 256
'/*
' * Port/socket numbers: network standard functions
' */
%EQUATE `IPPORT_ECHO = 7
%EQUATE `IPPORT_DISCARD = 9
%EQUATE `IPPORT_SYSTAT = 11
%EQUATE `IPPORT_DAYTIME = 13
%EQUATE `IPPORT_NETSTAT = 15
%EQUATE `IPPORT_FTP = 21
%EQUATE `IPPORT_TELNET = 23
%EQUATE `IPPORT_SMTP = 25
%EQUATE `IPPORT_TIMESERVER = 37
%EQUATE `IPPORT_NAMESERVER = 42
%EQUATE `IPPORT_WHOIS = 43
%EQUATE `IPPORT_MTP = 57
'/*
' * Port/socket numbers: host specific functions
' */
%EQUATE `IPPORT_TFTP = 69
%EQUATE `IPPORT_RJE = 77
%EQUATE `IPPORT_FINGER = 79
%EQUATE `IPPORT_TTYLINK = 87
%EQUATE `IPPORT_SUPDUP = 95
'/*
' * UNIX TCP sockets
' */
%EQUATE `IPPORT_EXECSERVER = 512
%EQUATE `IPPORT_LOGINSERVER = 513
%EQUATE `IPPORT_CMDSERVER = 514
%EQUATE `IPPORT_EFSSERVER = 520
'/*
' * UNIX UDP sockets
' */
%EQUATE `IPPORT_BIFFUDP = 512
%EQUATE `IPPORT_WHOSERVER = 513
%EQUATE `IPPORT_ROUTESERVER = 520
' /* 520+1 also used */
'/*
' * Ports < IPPORT_RESERVED are reserved for
' * privileged processes (e.g. root).
' */
%EQUATE `IPPORT_RESERVED = 1024
'/*
' * Link numbers
' */
%EQUATE `IMPLINK_IP = 155
%EQUATE `IMPLINK_LOWEXPER = 156
%EQUATE `IMPLINK_HIGHEXPER = 158
#INCLUDE ONCE "Legacy/System/inaddr.inc"
'/*
' * Definitions of bits in internet address integers.
' * On subnets, the decomposition of addresses to host and net parts
' * is done according to subnet mask, not the masks here.
' */
'#define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
'#define IN_CLASSA_NET 0xff000000
'#define IN_CLASSA_NSHIFT 24
'#define IN_CLASSA_HOST 0x00ffffff
'#define IN_CLASSA_MAX 128
FUNCTION IN_CLASSA (BYVAL i AS DWORD) AS LONG
 FUNCTION = ((i AND &H80000000) = 0)
END FUNCTION
%EQUATE `IN_CLASSA_NET = &HFF000000
%EQUATE `IN_CLASSA_NSHIFT = 24
%EQUATE `IN_CLASSA_HOST = &H00FFFFFF
%EQUATE `IN_CLASSA_MAX = 128
'#define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
'#define IN_CLASSB_NET 0xffff0000
'#define IN_CLASSB_NSHIFT 16
'#define IN_CLASSB_HOST 0x0000ffff
'#define IN_CLASSB_MAX 65536
FUNCTION IN_CLASSB (BYVAL i AS DWORD) AS LONG
 FUNCTION = ((i AND &HC0000000) = &H80000000)
END FUNCTION
%EQUATE `IN_CLASSB_NET = &HFFFF0000
%EQUATE `IN_CLASSB_NSHIFT = 16
%EQUATE `IN_CLASSB_HOST = &H0000FFFF
%EQUATE `IN_CLASSB_MAX = 65536
'#define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000)
'#define IN_CLASSC_NET 0xffffff00
'#define IN_CLASSC_NSHIFT 8
'#define IN_CLASSC_HOST 0x000000ff
FUNCTION IN_CLASSC (BYVAL i AS DWORD) AS LONG
 FUNCTION = ((i AND &He0000000) = &Hc0000000)
END FUNCTION
%EQUATE `IN_CLASSC_NET = &HFFFFFF00
%EQUATE `IN_CLASSC_NSHIFT = 8
%EQUATE `IN_CLASSC_HOST = &H000000FF
'#define INADDR_ANY (u_long)0x00000000
'#define INADDR_LOOPBACK 0x7f000001
'#define INADDR_BROADCAST (u_long)0xffffffff
'#define INADDR_NONE 0xffffffff
%EQUATE `INADDR_ANY = &H00000000
%EQUATE `INADDR_LOOPBACK = &H7F000001
%EQUATE `INADDR_BROADCAST = &HFFFFFFFF
%EQUATE `INADDR_NONE = &HFFFFFFFF
'/*
' * Socket address, internet style.
' */
' // Size = 16 bytes
TYPE sockaddr_in BYTE
 sin_family AS INTEGER ' short
 sin_port AS WORD ' u_short
 sin_addr AS in_addr ' struct in_addr
 sin_zero AS STRING * 8 ' char[8]
END TYPE
%EQUATE `WSADESCRIPTION_LEN = 256
%EQUATE `WSASYS_STATUS_LEN = 128
' // Size = 400 bytes
TYPE WSADATA DWORD FILL
 wVersion AS WORD ' WORD
 wHighVersion AS WORD ' WORD
'#ifdef _WIN64
' unsigned short iMaxSockets;
' unsigned short iMaxUdpDg;
' char FAR * lpVendorInfo;
' char szDescription[WSADESCRIPTION_LEN+1];
' char szSystemStatus[WSASYS_STATUS_LEN+1];
'#else
 szDescription AS ASCIIZ * %WSADESCRIPTION_LEN + 1 ' char[[WSADESCRIPTION_LEN+1]
 szSystemStatus AS ASCIIZ * %WSASYS_STATUS_LEN + 1 ' char[WSASYS_STATUS_LEN+1]
 iMaxSockets AS WORD ' unsigned short
 iMaxUdpDg AS WORD ' unsigned short
 lpVendorInfo AS ASCIIZ PTR ' char FAR *
'#endif
END TYPE
'typedef WSADATA FAR *LPWSADATA;
'/*
' * Options for use with [gs]etsockopt at the IP level.
' */
%EQUATE `IP_OPTIONS = 1 ' set/get IP per-packet options
%EQUATE `IP_MULTICAST_IF = 2 ' set/get IP multicast interface
%EQUATE `IP_MULTICAST_TTL = 3 ' set/get IP multicast timetolive
%EQUATE `IP_MULTICAST_LOOP = 4 ' set/get IP multicast loopback
%EQUATE `IP_ADD_MEMBERSHIP = 5 ' add an IP group membership
%EQUATE `IP_DROP_MEMBERSHIP = 6 ' drop an IP group membership
%EQUATE `IP_TTL = 7 ' set/get IP Time To Live
%EQUATE `IP_TOS = 8 ' set/get IP Type Of Service
%EQUATE `IP_DONTFRAGMENT = 9 ' set/get IP Don't Fragment flag
%EQUATE `IP_DEFAULT_MULTICAST_TTL = 1 ' normally limit m'casts to 1 hop
%EQUATE `IP_DEFAULT_MULTICAST_LOOP = 1 ' normally hear sends if a member
%EQUATE `IP_MAX_MEMBERSHIPS = 20 ' per socket; must fit in one mbuf
'/*
' * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
' */
' // Size = 8 bytes
TYPE ip_mreq BYTE
 imr_multiaddr AS in_addr ' struct in_addr // IP multicast address of group
 imr_interface AS in_addr ' struct in_addr // local IP address of interface
END TYPE
'/*
' * Definitions related to sockets: types, address families, options,
' * taken from the BSD file sys/socket.h.
' */
'/*
' * This is used instead of -1, since the
' * SOCKET type is unsigned.
' */
%EQUATE `INVALID_SOCKET = &HFFFFFFFF ' (SOCKET)(~0)
%EQUATE `SOCKET_ERROR = -1 ' (-1)
'/*
' * Types
' */
%EQUATE `SOCK_STREAM = 1
%EQUATE `SOCK_DGRAM = 2
%EQUATE `SOCK_RAW = 3
%EQUATE `SOCK_RDM = 4
%EQUATE `SOCK_SEQPACKET = 5
'/*
' * Option flags per-socket.
' */
%EQUATE `SO_DEBUG = &H00001
%EQUATE `SO_ACCEPTCONN = &H00002
%EQUATE `SO_REUSEADDR = &H00004
%EQUATE `SO_KEEPALIVE = &H00008
%EQUATE `SO_DONTROUTE = &H00010
%EQUATE `SO_BROADCAST = &H00020
%EQUATE `SO_USELOOPBACK = &H00040
%EQUATE `SO_LINGER = &H00080
%EQUATE `SO_OOBINLINE = &H00100
'#define SO_DONTLINGER (u_int)(~SO_LINGER)
%EQUATE `SO_DONTLINGER = &H0FF7F ' CDWD(NOT %SO_LINGER)
'/*
' * Additional options.
' */
%EQUATE `SO_SNDBUF = &H01001
%EQUATE `SO_RCVBUF = &H01002
%EQUATE `SO_SNDLOWAT = &H01003
%EQUATE `SO_RCVLOWAT = &H01004
%EQUATE `SO_SNDTIMEO = &H01005
%EQUATE `SO_RCVTIMEO = &H01006
%EQUATE `SO_ERROR = &H01007
%EQUATE `SO_TYPE = &H01008
'/*
' * Options for connect and disconnect data and options. Used only by
' * non-TCP/IP transports such as DECNet, OSI TP4, etc.
' */
%EQUATE `SO_CONNDATA = &H07000
%EQUATE `SO_CONNOPT = &H07001
%EQUATE `SO_DISCDATA = &H07002
%EQUATE `SO_DISCOPT = &H07003
%EQUATE `SO_CONNDATALEN = &H07004
%EQUATE `SO_CONNOPTLEN = &H07005
%EQUATE `SO_DISCDATALEN = &H07006
%EQUATE `SO_DISCOPTLEN = &H07007
'/*
' * Option for opening sockets for synchronous access.
' */
%EQUATE `SO_OPENTYPE = &H07008
%EQUATE `SO_SYNCHRONOUS_ALERT = &H10
%EQUATE `SO_SYNCHRONOUS_NONALERT = &H20
'/*
' * Other NT-specific options.
' */
%EQUATE `SO_MAXDG = &H07009
%EQUATE `SO_MAXPATHDG = &H0700A
%EQUATE `SO_UPDATE_ACCEPT_CONTEXT = &H0700B
%EQUATE `SO_CONNECT_TIME = &H0700C
'/*
' * TCP options.
' */
%EQUATE `TCP_NODELAY = &H00001
%EQUATE `TCP_BSDURGENT = &H07000
'/*
' * Address families.
' */
%EQUATE `AF_UNSPEC = 0 ' unspecified
%EQUATE `AF_UNIX = 1 ' local to host (pipes, portals)
%EQUATE `AF_INET = 2
%EQUATE `AF_IMPLINK = 3 ' arpanet imp addresses
%EQUATE `AF_PUP = 4 ' pup protocols: e.g. BSP
%EQUATE `AF_CHAOS = 5 ' mit CHAOS protocols
%EQUATE `AF_NS = 6 ' XEROX NS protocols
%EQUATE `AF_IPX = 6 ' IPX and SPX
%EQUATE `AF_ISO = 7 ' ISO protocols
%EQUATE `AF_OSI = %AF_ISO ' OSI is ISO
%EQUATE `AF_ECMA = 8 ' european computer manufacturers
%EQUATE `AF_DATAKIT = 9 ' datakit protocols
%EQUATE `AF_CCITT = 10 ' CCITT protocols, X.25 etc
%EQUATE `AF_SNA = 11 ' IBM SNA
%EQUATE `AF_DECnet = 12 ' DECnet
%EQUATE `AF_DLI = 13 ' Direct data link interface
%EQUATE `AF_LAT = 14 ' LAT
%EQUATE `AF_HYLINK = 15 ' NSC Hyperchannel
%EQUATE `AF_APPLETALK = 16 ' AppleTalk
%EQUATE `AF_NETBIOS = 17 ' NetBios-style addresses
%EQUATE `AF_VOICEVIEW = 18 ' VoiceView
%EQUATE `AF_FIREFOX = 19 ' FireFox
%EQUATE `AF_UNKNOWN1 = 20 ' Somebody is using this!
%EQUATE `AF_BAN = 21 ' Banyan
%EQUATE `AF_MAX = 22
'/*
' * Structure used by kernel to store most
' * addresses.
' */
' // Size = 16 bytes
TYPE sockaddr BYTE
 sa_family AS WORD ' u_short // address family
 sa_data AS STRING * 14 ' char[14] // up to 14 bytes of direct address
END TYPE
'/*
' * Structure used by kernel to pass protocol
' * information in raw sockets.
' */
' // Size = 4 bytes
TYPE sockproto WORD
 sp_family AS WORD ' u_short // address family
 sp_protocol AS WORD ' u_short // protocol
END TYPE
'/*
' * Protocol families, same as address families for now.
' */
%EQUATE `PF_UNSPEC = %AF_UNSPEC
%EQUATE `PF_UNIX = %AF_UNIX
%EQUATE `PF_INET = %AF_INET
%EQUATE `PF_IMPLINK = %AF_IMPLINK
%EQUATE `PF_PUP = %AF_PUP
%EQUATE `PF_CHAOS = %AF_CHAOS
%EQUATE `PF_NS = %AF_NS
%EQUATE `PF_IPX = %AF_IPX
%EQUATE `PF_ISO = %AF_ISO
%EQUATE `PF_OSI = %AF_OSI
%EQUATE `PF_ECMA = %AF_ECMA
%EQUATE `PF_DATAKIT = %AF_DATAKIT
%EQUATE `PF_CCITT = %AF_CCITT
%EQUATE `PF_SNA = %AF_SNA
%EQUATE `PF_DECnet = %AF_DECnet
%EQUATE `PF_DLI = %AF_DLI
%EQUATE `PF_LAT = %AF_LAT
%EQUATE `PF_HYLINK = %AF_HYLINK
%EQUATE `PF_APPLETALK = %AF_APPLETALK
%EQUATE `PF_VOICEVIEW = %AF_VOICEVIEW
%EQUATE `PF_FIREFOX = %AF_FIREFOX
%EQUATE `PF_UNKNOWN1 = %AF_UNKNOWN1
%EQUATE `PF_BAN = %AF_BAN
%EQUATE `PF_MAX = %AF_MAX
'/*
' * Structure used for manipulating linger option.
' */
' // Size = 4 bytes
TYPE linger WORD
 l_onoff AS WORD ' u_short // option on/off
 l_linger AS WORD ' u_short // linger time
END TYPE
'/*
' * Level number for (get/set)sockopt() to apply to socket itself.
' */
'#define SOL_SOCKET 0xffff /* options for socket level */
%EQUATE `SOL_SOCKET = &HFFFF ' options for socket level
'/*
' * Maximum queue length specifiable by listen.
' */
'#define SOMAXCONN 5
'#define MSG_OOB 0x1 /* process out-of-band data */
'#define MSG_PEEK 0x2 /* peek at incoming message */
'#define MSG_DONTROUTE 0x4 /* send without using routing tables */
'#define MSG_MAXIOVLEN 16
'#define MSG_PARTIAL 0x8000 /* partial send or recv for message xport */
%EQUATE `SOMAXCONN = 5
%EQUATE `MSG_OOB = &H1 ' process out-of-band data
%EQUATE `MSG_PEEK = &H2 ' peek at incoming message
%EQUATE `MSG_DONTROUTE = &H4 ' send without using routing tables
%EQUATE `MSG_MAXIOVLEN = 16
%EQUATE `MSG_PARTIAL = &H8000 ' partial send or recv for message xport
'/*
' * Define constant based on rfc883, used by gethostbyxxxx() calls.
' */
'#define MAXGETHOSTSTRUCT 1024
%EQUATE `MAXGETHOSTSTRUCT = 1024
'/*
' * Define flags to be used with the WSAAsyncSelect() call.
' */
%EQUATE `FD_READ = &H001
%EQUATE `FD_WRITE = &H002
%EQUATE `FD_OOB = &H004
%EQUATE `FD_ACCEPT = &H008
%EQUATE `FD_CONNECT = &H010
%EQUATE `FD_CLOSE = &H020
'/*
' * WinSock error codes are also defined in winerror.h
' * Hence the IFDEF.
' */
'#ifndef WSABASEERR
#IF NOT %DEF(%WSABASEERR) '----------------------------------------------------
'/*
' * All Windows Sockets error constants are biased by WSABASEERR from
' * the "normal"
' */
'#define WSABASEERR 10000
%EQUATE `WSABASEERR = 10000
'/*
' * Windows Sockets definitions of regular Microsoft C error constants
' */
%EQUATE `WSAEINTR = %WSABASEERR + 4
%EQUATE `WSAEBADF = %WSABASEERR + 9
%EQUATE `WSAEACCES = %WSABASEERR + 13
%EQUATE `WSAEFAULT = %WSABASEERR + 14
%EQUATE `WSAEINVAL = %WSABASEERR + 22
%EQUATE `WSAEMFILE = %WSABASEERR + 24
'/*
' * Windows Sockets definitions of regular Berkeley error constants
' */
%EQUATE `WSAEWOULDBLOCK = %WSABASEERR + 35
%EQUATE `WSAEINPROGRESS = %WSABASEERR + 36
%EQUATE `WSAEALREADY = %WSABASEERR + 37
%EQUATE `WSAENOTSOCK = %WSABASEERR + 38
%EQUATE `WSAEDESTADDRREQ = %WSABASEERR + 39
%EQUATE `WSAEMSGSIZE = %WSABASEERR + 40
%EQUATE `WSAEPROTOTYPE = %WSABASEERR + 41
%EQUATE `WSAENOPROTOOPT = %WSABASEERR + 42
%EQUATE `WSAEPROTONOSUPPORT = %WSABASEERR + 43
%EQUATE `WSAESOCKTNOSUPPORT = %WSABASEERR + 44
%EQUATE `WSAEOPNOTSUPP = %WSABASEERR + 45
%EQUATE `WSAEPFNOSUPPORT = %WSABASEERR + 46
%EQUATE `WSAEAFNOSUPPORT = %WSABASEERR + 47
%EQUATE `WSAEADDRINUSE = %WSABASEERR + 48
%EQUATE `WSAEADDRNOTAVAIL = %WSABASEERR + 49
%EQUATE `WSAENETDOWN = %WSABASEERR + 50
%EQUATE `WSAENETUNREACH = %WSABASEERR + 51
%EQUATE `WSAENETRESET = %WSABASEERR + 52
%EQUATE `WSAECONNABORTED = %WSABASEERR + 53
%EQUATE `WSAECONNRESET = %WSABASEERR + 54
%EQUATE `WSAENOBUFS = %WSABASEERR + 55
%EQUATE `WSAEISCONN = %WSABASEERR + 56
%EQUATE `WSAENOTCONN = %WSABASEERR + 57
%EQUATE `WSAESHUTDOWN = %WSABASEERR + 58
%EQUATE `WSAETOOMANYREFS = %WSABASEERR + 59
%EQUATE `WSAETIMEDOUT = %WSABASEERR + 60
%EQUATE `WSAECONNREFUSED = %WSABASEERR + 61
%EQUATE `WSAELOOP = %WSABASEERR + 62
%EQUATE `WSAENAMETOOLONG = %WSABASEERR + 63
%EQUATE `WSAEHOSTDOWN = %WSABASEERR + 64
%EQUATE `WSAEHOSTUNREACH = %WSABASEERR + 65
%EQUATE `WSAENOTEMPTY = %WSABASEERR + 66
%EQUATE `WSAEPROCLIM = %WSABASEERR + 67
%EQUATE `WSAEUSERS = %WSABASEERR + 68
%EQUATE `WSAEDQUOT = %WSABASEERR + 69
%EQUATE `WSAESTALE = %WSABASEERR + 70
%EQUATE `WSAEREMOTE = %WSABASEERR + 71
%EQUATE `WSAEDISCON = %WSABASEERR + 101
'/*
' * Extended Windows Sockets error constant definitions
' */
%EQUATE `WSASYSNOTREADY = %WSABASEERR + 91
%EQUATE `WSAVERNOTSUPPORTED = %WSABASEERR + 92
%EQUATE `WSANOTINITIALISED = %WSABASEERR + 93
'/*
' * Error return codes from gethostbyname() and gethostbyaddr()
' * (when using the resolver). Note that these errors are
' * retrieved via WSAGetLastError() and must therefore follow
' * the rules for avoiding clashes with error numbers from
' * specific implementations or language run-time systems.
' * For this reason the codes are based at WSABASEERR+1001.
' * Note also that [WSA]NO_ADDRESS is defined only for
' * compatibility purposes.
' */
'/* Authoritative Answer: Host not found */
%EQUATE `WSAHOST_NOT_FOUND = %WSABASEERR + 1001
'/* Non-Authoritative: Host not found, or SERVERFAIL */
%EQUATE `WSATRY_AGAIN = %WSABASEERR + 1002
'/* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
%EQUATE `WSANO_RECOVERY = %WSABASEERR + 1003
'/* Valid name, no data record of requested type */
%EQUATE `WSANO_DATA = %WSABASEERR + 1004
'/* Authoritative Answer: Host not found Securely */
%EQUATE `WSA_SECURE_HOST_NOT_FOUND = %WSABASEERR + 1032
'/* Name based IPSEC policy could not be added*/
%EQUATE `WSA_IPSEC_NAME_POLICY_ERROR = %WSABASEERR + 1033
'/*
' * WinSock error codes are also defined in winerror.h
' * Hence the IFDEF.
' */
'#endif /* ifdef WSABASEERR */
#ENDIF ' #IF %DEF(%WSABASEERR) -----------------------------------------------
'/*
' * Compatibility macros.
' */
'#define h_errno WSAGetLastError()
MACRO h_errno = WSAGetLastError()
%EQUATE `HOST_NOT_FOUND = %WSAHOST_NOT_FOUND
%EQUATE `TRY_AGAIN = %WSATRY_AGAIN
%EQUATE `NO_RECOVERY = %WSANO_RECOVERY
%EQUATE `NO_DATA = %WSANO_DATA
' no address, look for MX record
%EQUATE `WSANO_ADDRESS = %WSANO_DATA
%EQUATE `NO_ADDRESS = %WSANO_ADDRESS
'/*
' * Windows Sockets errors redefined as regular Berkeley error constants.
' * These are commented out in Windows NT to avoid conflicts with errno.h.
' * Use the WSA constants instead.
' */
'#if 0
'#define EWOULDBLOCK WSAEWOULDBLOCK
'#define EINPROGRESS WSAEINPROGRESS
'#define EALREADY WSAEALREADY
'#define ENOTSOCK WSAENOTSOCK
'#define EDESTADDRREQ WSAEDESTADDRREQ
'#define EMSGSIZE WSAEMSGSIZE
'#define EPROTOTYPE WSAEPROTOTYPE
'#define ENOPROTOOPT WSAENOPROTOOPT
'#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
'#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
'#define EOPNOTSUPP WSAEOPNOTSUPP
'#define EPFNOSUPPORT WSAEPFNOSUPPORT
'#define EAFNOSUPPORT WSAEAFNOSUPPORT
'#define EADDRINUSE WSAEADDRINUSE
'#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
'#define ENETDOWN WSAENETDOWN
'#define ENETUNREACH WSAENETUNREACH
'#define ENETRESET WSAENETRESET
'#define ECONNABORTED WSAECONNABORTED
'#define ECONNRESET WSAECONNRESET
'#define ENOBUFS WSAENOBUFS
'#define EISCONN WSAEISCONN
'#define ENOTCONN WSAENOTCONN
'#define ESHUTDOWN WSAESHUTDOWN
'#define ETOOMANYREFS WSAETOOMANYREFS
'#define ETIMEDOUT WSAETIMEDOUT
'#define ECONNREFUSED WSAECONNREFUSED
'#define ELOOP WSAELOOP
'#define ENAMETOOLONG WSAENAMETOOLONG
'#define EHOSTDOWN WSAEHOSTDOWN
'#define EHOSTUNREACH WSAEHOSTUNREACH
'#define ENOTEMPTY WSAENOTEMPTY
'#define EPROCLIM WSAEPROCLIM
'#define EUSERS WSAEUSERS
'#define EDQUOT WSAEDQUOT
'#define ESTALE WSAESTALE
'#define EREMOTE WSAEREMOTE
'#endif
%EQUATE `EWOULDBLOCK = %WSAEWOULDBLOCK
%EQUATE `EINPROGRESS = %WSAEINPROGRESS
%EQUATE `EALREADY = %WSAEALREADY
%EQUATE `ENOTSOCK = %WSAENOTSOCK
%EQUATE `EDESTADDRREQ = %WSAEDESTADDRREQ
%EQUATE `EMSGSIZE = %WSAEMSGSIZE
%EQUATE `EPROTOTYPE = %WSAEPROTOTYPE
%EQUATE `ENOPROTOOPT = %WSAENOPROTOOPT
%EQUATE `EPROTONOSUPPORT = %WSAEPROTONOSUPPORT
%EQUATE `ESOCKTNOSUPPORT = %WSAESOCKTNOSUPPORT
%EQUATE `EOPNOTSUPP = %WSAEOPNOTSUPP
%EQUATE `EPFNOSUPPORT = %WSAEPFNOSUPPORT
%EQUATE `EAFNOSUPPORT = %WSAEAFNOSUPPORT
%EQUATE `EADDRINUSE = %WSAEADDRINUSE
%EQUATE `EADDRNOTAVAIL = %WSAEADDRNOTAVAIL
%EQUATE `ENETDOWN = %WSAENETDOWN
%EQUATE `ENETUNREACH = %WSAENETUNREACH
%EQUATE `ENETRESET = %WSAENETRESET
%EQUATE `ECONNABORTED = %WSAECONNABORTED
%EQUATE `ECONNRESET = %WSAECONNRESET
%EQUATE `ENOBUFS = %WSAENOBUFS
%EQUATE `EISCONN = %WSAEISCONN
%EQUATE `ENOTCONN = %WSAENOTCONN
%EQUATE `ESHUTDOWN = %WSAESHUTDOWN
%EQUATE `ETOOMANYREFS = %WSAETOOMANYREFS
%EQUATE `ETIMEDOUT = %WSAETIMEDOUT
%EQUATE `ECONNREFUSED = %WSAECONNREFUSED
%EQUATE `ELOOP = %WSAELOOP
%EQUATE `ENAMETOOLONG = %WSAENAMETOOLONG
%EQUATE `EHOSTDOWN = %WSAEHOSTDOWN
%EQUATE `EHOSTUNREACH = %WSAEHOSTUNREACH
%EQUATE `ENOTEMPTY = %WSAENOTEMPTY
%EQUATE `EPROCLIM = %WSAEPROCLIM
%EQUATE `EUSERS = %WSAEUSERS
%EQUATE `EDQUOT = %WSAEDQUOT
%EQUATE `ESTALE = %WSAESTALE
%EQUATE `EREMOTE = %WSAEREMOTE
'/* Socket function prototypes */
DECLARE FUNCTION aaccept LIB "wsock32.dll" ALIAS "accept" ( BYVAL s AS QUAD , BYREF addr AS sockaddr_in , BYREF addrlen AS LONG ) AS QUAD ' SOCKET
DECLARE FUNCTION bind LIB "wsock32.dll" ALIAS "bind" ( BYVAL s AS QUAD , BYREF addr AS sockaddr_in , BYVAL namelen AS LONG ) AS LONG ' int
DECLARE FUNCTION closesocket LIB "wsock32.dll" ALIAS "closesocket" ( BYVAL s AS QUAD ) AS LONG ' int
DECLARE FUNCTION cconnect LIB "wsock32.dll" ALIAS "connect" ( BYVAL s AS QUAD , BYREF name AS sockaddr_in , BYVAL namelen AS LONG ) AS LONG ' int
DECLARE FUNCTION ioctlsocket LIB "wsock32.dll" ALIAS "ioctlsocket" ( BYVAL s AS QUAD , BYVAL cmd AS LONG , BYREF argp AS QUAD ) AS LONG ' int
DECLARE FUNCTION getpeername LIB "wsock32.dll" ALIAS "getpeername" ( BYVAL s AS QUAD , BYREF name AS sockaddr_in , BYREF namelen AS LONG ) AS LONG ' int
DECLARE FUNCTION getsockname LIB "wsock32.dll" ALIAS "getsockname" ( BYVAL s AS QUAD , BYREF name AS sockaddr_in , BYREF namelen AS LONG ) AS LONG ' int
DECLARE FUNCTION getsockopt LIB "wsock32.dll" ALIAS "getsockopt" ( BYVAL s AS QUAD , BYVAL level AS LONG , BYVAL optname AS LONG , BYREF optval AS ANY , BYREF optlen AS LONG ) AS LONG ' int
DECLARE FUNCTION htonl LIB "wsock32.dll" ALIAS "htonl" ( BYVAL hostlong AS QUAD ) AS QUAD ' u_long
DECLARE FUNCTION htons LIB "wsock32.dll" ALIAS "htons" ( BYVAL hostshort AS WORD ) AS WORD ' u_short
DECLARE FUNCTION inet_addr LIB "wsock32.dll" ALIAS "inet_addr" ( BYREF cp AS ASCIIZ ) AS QUAD ' unsigned long
DECLARE FUNCTION inet_ntoa LIB "wsock32.dll" ALIAS "inet_ntoa" ( BYVAL in_ AS QUAD ) AS QUAD ' char FAR*
DECLARE FUNCTION listen LIB "wsock32.dll" ALIAS "listen" ( BYVAL s AS QUAD , BYVAL backlog AS LONG ) AS LONG ' int
DECLARE FUNCTION ntohl LIB "wsock32.dll" ALIAS "ntohl" ( BYVAL netlong AS QUAD ) AS QUAD ' u_long
DECLARE FUNCTION ntohs LIB "wsock32.dll" ALIAS "ntohs" ( BYVAL netshort AS WORD ) AS WORD ' u_short
DECLARE FUNCTION rrecv LIB "wsock32.dll" ALIAS "recv" ( BYVAL s AS QUAD , BYREF buf AS ANY , BYVAL len AS LONG , BYVAL flags AS LONG ) AS LONG ' int
DECLARE FUNCTION recvfrom LIB "wsock32.dll" ALIAS "recvfrom" ( BYVAL s AS LONG , BYREF buf AS ANY , BYVAL len AS LONG , BYVAL flags AS LONG , BYREF from AS sockaddr_in , BYREF fromlen AS LONG ) AS LONG ' int
DECLARE FUNCTION sselect LIB "wsock32.dll" ALIAS "select" ( BYVAL nfds AS LONG , BYREF readfds AS fd_setstruc , BYREF writefds AS fd_setstruc , BYREF exceptfds AS fd_setstruc , BYREF timeout AS timeval ) AS LONG ' int
DECLARE FUNCTION ssend LIB "wsock32.dll" ALIAS "send" ( BYVAL s AS QUAD , BYREF buf AS ANY , BYVAL len AS LONG , BYVAL flags AS LONG ) AS LONG ' int
DECLARE FUNCTION sendto LIB "wsock32.dll" ALIAS "sendto" ( BYVAL s AS QUAD , BYREF buf AS ANY , BYVAL len AS LONG , BYVAL flags AS LONG , BYREF to AS sockaddr_in , BYVAL tolen AS LONG ) AS LONG ' int
DECLARE FUNCTION setsockopt LIB "wsock32.dll" ALIAS "setsockopt" ( BYVAL s AS QUAD , BYVAL level AS LONG , BYVAL optname AS LONG , BYREF optval AS ANY , BYVAL optlen AS LONG ) AS LONG ' int
DECLARE FUNCTION shutdown LIB "wsock32.dll" ALIAS "shutdown" ( BYVAL s AS QUAD , BYVAL how AS LONG ) AS LONG ' int
DECLARE FUNCTION socket LIB "wsock32.dll" ALIAS "socket" ( BYVAL af AS QUAD , BYVAL type AS LONG , BYVAL protocol AS LONG ) AS QUAD ' SOCKET
'/* Database function prototypes */
DECLARE FUNCTION gethostbyaddr LIB "wsock32.dll" ALIAS "gethostbyaddr" ( BYREF addr AS ANY , BYVAL len AS LONG , BYVAL type AS LONG ) AS QUAD ' struct hostent FAR *
DECLARE FUNCTION gethostbyname LIB "wsock32.dll" ALIAS "gethostbyname" ( BYREF name AS ASCIIZ ) AS QUAD ' struct hostent FAR *
DECLARE FUNCTION gethostname LIB "wsock32.dll" ALIAS "gethostname" ( BYREF name AS ASCIIZ , BYVAL namelen AS LONG ) AS LONG ' int
DECLARE FUNCTION getservbyport LIB "wsock32.dll" ALIAS "getservbyport" ( BYVAL port AS LONG , BYREF proto AS ASCIIZ ) AS QUAD ' struct servent FAR *
DECLARE FUNCTION getservbyname LIB "wsock32.dll" ALIAS "getservbyname" ( BYREF name AS ASCIIZ , BYREF proto AS ASCIIZ ) AS QUAD ' struct servent FAR *
DECLARE FUNCTION getprotobynumber LIB "wsock32.dll" ALIAS "getprotobynumber" ( BYVAL proto AS LONG ) AS QUAD ' struct protoent FAR *
DECLARE FUNCTION getprotobyname LIB "wsock32.dll" ALIAS "getprotobyname" ( BYREF name AS ASCIIZ ) AS QUAD ' struct protoent FAR *
'/* Microsoft Windows Extension function prototypes */
DECLARE FUNCTION WSAStartup LIB "wsock32.dll" ALIAS "WSAStartup" ( BYVAL wVersionRequired AS WORD , BYREF lpWSAData AS WSADATA ) AS LONG ' int
DECLARE FUNCTION WSACleanup LIB "wsock32.dll" ALIAS "WSACleanup" ( ) AS LONG ' int
DECLARE SUB WSASetLastError LIB "wsock32.dll" ALIAS "WSASetLastError" ( BYVAL iError AS LONG ) ' void
DECLARE FUNCTION WSAGetLastError LIB "wsock32.dll" ALIAS "WSAGetLastError" ( ) AS LONG ' int
DECLARE FUNCTION WSAIsBlocking LIB "wsock32.dll" ALIAS "WSAIsBlocking" ( ) AS LONG
DECLARE FUNCTION WSAUnhookBlockingHook LIB "wsock32.dll" ALIAS "WSAUnhookBlockingHook" ( ) AS LONG ' int
DECLARE FUNCTION WSASetBlockingHook LIB "wsock32.dll" ALIAS "WSASetBlockingHook" ( BYVAL lpBlockFunc AS QUAD ) AS QUAD ' FARPROC
DECLARE FUNCTION WSACancelBlockingCall LIB "wsock32.dll" ALIAS "WSACancelBlockingCall" ( ) AS LONG ' int
DECLARE FUNCTION WSAAsyncGetServByName LIB "wsock32.dll" ALIAS "WSAAsyncGetServByName" ( BYVAL hWnd AS QUAD , BYVAL wMsg AS QUAD , BYREF name AS ASCIIZ , BYREF proto AS ASCIIZ , BYREF buf AS ASCIIZ , BYVAL buflen AS LONG ) AS QUAD
DECLARE FUNCTION WSAAsyncGetServByPort LIB "wsock32.dll" ALIAS "WSAAsyncGetServByPort" ( BYVAL hWnd AS QUAD
 , BYVAL wMsg AS DWORD
 , BYVAL port AS LONG
 , BYREF proto AS ASCIIZ
 , BYREF buf AS ASCIIZ
 , BYVAL buflen AS LONG
 ) AS DWORD
DECLARE FUNCTION WSAAsyncGetProtoByName LIB "wsock32.dll" ALIAS "WSAAsyncGetProtoByName" ( BYVAL hWnd AS DWORD
 , BYVAL wMsg AS DWORD
 , BYREF name AS ASCIIZ
 , BYREF buf AS ASCIIZ
 , BYVAL buflen AS LONG
 ) AS DWORD
DECLARE FUNCTION WSAAsyncGetProtoByNumber LIB "wsock32.dll" ALIAS "WSAAsyncGetProtoByNumber" ( BYVAL hWnd AS DWORD
 , BYVAL wMsg AS DWORD
 , BYVAL number AS LONG
 , BYREF buf AS ASCIIZ
 , BYVAL buflen AS LONG
 ) AS DWORD
DECLARE FUNCTION WSAAsyncGetHostByName LIB "wsock32.dll" ALIAS "WSAAsyncGetHostByName" ( BYVAL hWnd AS DWORD
 , BYVAL wMsg AS DWORD
 , BYREF name AS ASCIIZ
 , BYREF buf AS ASCIIZ
 , BYVAL buflen AS LONG
 ) AS DWORD
DECLARE FUNCTION WSAAsyncGetHostByAddr LIB "wsock32.dll" ALIAS "WSAAsyncGetHostByAddr" ( BYVAL hWnd AS DWORD
 , BYVAL wMsg AS DWORD
 , BYREF addr AS ASCIIZ
 , BYVAL len AS LONG
 , BYVAL type AS LONG
 , BYREF buf AS ASCIIZ
 , BYVAL buflen AS LONG
 ) AS DWORD
DECLARE FUNCTION WSACancelAsyncRequest LIB "wsock32.dll" ALIAS "WSACancelAsyncRequest" ( BYVAL hAsyncTaskHandle AS DWORD
 ) AS LONG ' int
DECLARE FUNCTION WSAAsyncSelect LIB "wsock32.dll" ALIAS "WSAAsyncSelect" ( BYVAL s AS QUAD , BYVAL hWnd AS QUAD , BYVAL wMsg AS QUAD , BYVAL lEvent AS LONG ) AS LONG ' int
DECLARE FUNCTION WSARecvEx LIB "wsock32.dll" ALIAS "WSARecvEx" ( BYVAL s AS QUAD , BYREF buf AS ANY , BYVAL len AS LONG , BYVAL flags AS LONG ) AS LONG ' int
' // Size = 16 bytes
TYPE TRANSMIT_FILE_BUFFERS DWORD
 Head AS DWORD
 HeadLength AS DWORD
 Tail AS DWORD
 TailLength AS DWORD
END TYPE
%EQUATE `TF_DISCONNECT = &H01
%EQUATE `TF_REUSE_SOCKET = &H02
%EQUATE `TF_WRITE_BEHIND = &H04
DECLARE FUNCTION TransmitFile LIB "wsock32.dll" ALIAS "TransmitFile" ( BYVAL hSocket AS QUAD , BYVAL hFile AS QUAD , BYVAL nNumberOfBytesToWrite AS QUAD , BYVAL nNumberOfBytesPerSend AS QUAD , BYREF lpOverlapped AS OVERLAPPED , BYREF lpTransmitBuffers AS TRANSMIT_FILE_BUFFERS , BYVAL dwReserved AS QUAD ) AS LONG
DECLARE FUNCTION AcceptEx LIB "wsock32.dll" ALIAS "AcceptEx" ( BYVAL sListenSocket AS QUAD
 , BYVAL sAcceptSocket AS DWORD
 , BYREF lpOutputBuffer AS ANY
 , BYVAL dwReceiveDataLength AS DWORD
 , BYVAL dwLocalAddressLength AS DWORD
 , BYVAL dwRemoteAddressLength AS DWORD
 , BYREF lpdwBytesReceived AS DWORD
 , BYREF lpOverlapped AS OVERLAPPED
 ) AS LONG
DECLARE SUB GetAcceptExSockaddrs LIB "wsock32.dll" ALIAS "GetAcceptExSockaddrs" ( BYREF lpOutputBuffer AS ANY
 , BYVAL dwReceiveDataLength AS DWORD
 , BYVAL dwLocalAddressLength AS DWORD
 , BYVAL dwRemoteAddressLength AS DWORD
 , BYREF LocalSockaddr AS DWORD
 , BYREF LocalSockaddrLength AS LONG
 , BYREF RemoteSockaddr AS DWORD
 , BYREF RemoteSockaddrLength AS LONG
 ) ' void
'/* Microsoft Windows Extended data types */
'typedef struct sockaddr SOCKADDR;
'typedef struct sockaddr *PSOCKADDR;
'typedef struct sockaddr FAR *LPSOCKADDR;
'typedef struct sockaddr_in SOCKADDR_IN;
'typedef struct sockaddr_in *PSOCKADDR_IN;
'typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
'typedef struct linger LINGER;
'typedef struct linger *PLINGER;
'typedef struct linger FAR *LPLINGER;
'typedef struct in_addr IN_ADDR;
'typedef struct in_addr *PIN_ADDR;
'typedef struct in_addr FAR *LPIN_ADDR;
'typedef struct fd_set FD_SET;
'typedef struct fd_set *PFD_SET;
'typedef struct fd_set FAR *LPFD_SET;
'typedef struct hostent HOSTENT;
'typedef struct hostent *PHOSTENT;
'typedef struct hostent FAR *LPHOSTENT;
'typedef struct servent SERVENT;
'typedef struct servent *PSERVENT;
'typedef struct servent FAR *LPSERVENT;
'typedef struct protoent PROTOENT;
'typedef struct protoent *PPROTOENT;
'typedef struct protoent FAR *LPPROTOENT;
'typedef struct timeval TIMEVAL;
'typedef struct timeval *PTIMEVAL;
'typedef struct timeval FAR *LPTIMEVAL;
'/*
' * Windows message parameter composition and decomposition
' * macros.
' *
' * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
' * when constructing the response to a WSAAsyncGetXByY() routine.
' */
MACRO WSAMAKEASYNCREPLY (buflen, errorno) = MAK(LONG, buflen, errorno)
'/*
' * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
' * when constructing the response to WSAAsyncSelect().
' */
MACRO WSAMAKESELECTREPLY(xevent, errorno) = MAK(LONG, xevent, errorno)
'/*
' * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
' * to extract the buffer length from the lParam in the response
' * to a WSAGetXByY().
' */
MACRO WSAGETASYNCBUFLEN(lParam) = LO(WORD, lParam)
'/*
' * WSAGETASYNCERROR is intended for use by the Windows Sockets application
' * to extract the error code from the lParam in the response
' * to a WSAGetXByY().
' */
MACRO WSAGETASYNCERROR(lParam) = HI(WORD, lParam)
'/*
' * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
' * to extract the event code from the lParam in the response
' * to a WSAAsyncSelect().
' */
'#define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
MACRO WSAGETSELECTEVENT(lParam) = LO(WORD, lParam)
'/*
' * WSAGETSELECTERROR is intended for use by the Windows Sockets application
' * to extract the error code from the lParam in the response
' * to a WSAAsyncSelect().
' */
'#define WSAGETSELECTERROR(lParam) HIWORD(lParam)
MACRO WSAGETSELECTERROR(lParam) = HI(WORD, lParam)
' Return a pointer to all of the host IP addresses
FUNCTION GetHostAddr () AS DWORD
 LOCAL phostent AS hostent PTR
 LOCAL hostname AS ASCIIZ * 256
 IF gethostname(hostname, SIZEOF(hostname)) = 0 THEN
 IF LEN(hostname) THEN
 phostent = gethostbyname(hostname)
 IF phostent THEN
 FUNCTION = @phostent.h_list
 END IF
 END IF
 END IF
END FUNCTION
'#ifdef IPV6STRICT
'#error WINSOCK2 required.
'#endif // IPV6STRICT
#ENDIF ' #IF NOT %DEF(%WINSOCKAPI)
#ENDIF
