Difference between revisions of "Unit Winsock2"

From Ultibo.org
Jump to: navigation, search
 
(5 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
----
 
----
  
'''Ultibo Winsock2 interface unit'''
+
'''Ultibo Winsock2 Interface unit'''
  
 
''Notes:''
 
''Notes:''
Line 132: Line 132:
 
|  
 
|  
 
|-
 
|-
| <code>INET6_ADDRSTR_INIT = GlobalSock.INET6_ADDRSTR_INIT;</code>
+
| <code>INET6_ADDRSTR_ANY = GlobalSock.INET6_ADDRSTR_ANY;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
Line 176: Line 176:
 
|-
 
|-
 
| <code>IN6ADDR_LOOPBACK:TIn6Addr = (u6_addr8: (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1));</code>
 
| <code>IN6ADDR_LOOPBACK:TIn6Addr = (u6_addr8: (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1));</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>IN6ADDR_NONE:TIn6Addr = (u6_addr16: ($ffff, $ffff, $ffff, $ffff, $ffff, $ffff, $ffff, $ffff));</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
Line 552: Line 557:
 
|-
 
|-
 
| <code>SO_DONTLINGER = GlobalSock.SO_DONTLINGER;</code>
 
| <code>SO_DONTLINGER = GlobalSock.SO_DONTLINGER;</code>
 +
| &nbsp;
 +
|-
 +
| <code>SO_EXCLUSIVEADDRUSE = GlobalSock.SO_EXCLUSIVEADDRUSE;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
Line 2,160: Line 2,168:
 
|}
 
|}
  
'''Datagrams server classes'''
+
'''Datagram server classes'''
  
 
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
Line 2,460: Line 2,468:
 
|-
 
|-
 
! Note
 
! Note
| None documented
+
| Address will be returned in network order
 
|-
 
|-
 
|}
 
|}
Line 2,473: Line 2,481:
 
! Note
 
! Note
 
| As per the Winsock specification, the buffer returned by this function is only guaranteed to be valid until the next Winsock function call is made within the same thread. Therefore, the data should be copied before another Winsock call.
 
| As per the Winsock specification, the buffer returned by this function is only guaranteed to be valid until the next Winsock function call is made within the same thread. Therefore, the data should be copied before another Winsock call.
 +
Address will be in network order
 
|-
 
|-
 
|}
 
|}
Line 2,736: Line 2,745:
 
|-
 
|-
 
! Note
 
! Note
| None documented
+
| Address will be in network order where applicable
 
|-
 
|-
 
|}
 
|}
Line 2,772: Line 2,781:
 
|-
 
|-
 
! Note
 
! Note
| None documented
+
| Port will be in network order
 
|-
 
|-
 
|}
 
|}
Line 2,815: Line 2,824:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function getaddrinfo(pNodeName, pServiceName: PChar; pHints: PAddrInfo; var ppResult: PAddrInfo): LongInt;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function getaddrinfo(pNodeName, pServiceName: PChar; pHints: PAddrInfo; var ppResult: PAddrInfo): LongInt;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' RFC 3493 protocol-independent translation from a host name to an address</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 2,827: Line 2,836:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">procedure freeaddrinfo(ai: PAddrInfo);</pre>
 
<pre style="border: 0; padding-bottom:0px;">procedure freeaddrinfo(ai: PAddrInfo);</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Free address information that GetAddrInfo dynamically allocates in TAddrInfo structures</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 2,839: Line 2,848:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function getnameinfo(sa: PSockAddr; salen: Integer; host: PChar; hostlen: DWORD; serv: PChar; servlen: DWORD; flags: Integer): Integer;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function getnameinfo(sa: PSockAddr; salen: Integer; host: PChar; hostlen: DWORD; serv: PChar; servlen: DWORD; flags: Integer): Integer;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' RFC 3493 protocol-independent name resolution from an address to a host name and a port number to a service name</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function Gai_StrError(ecode: Longint): PChar;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Return an error message for an error code returned by GetAddrInfo or GetNameInfo</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 2,916: Line 2,937:
 
|-
 
|-
 
! Note
 
! Note
| None documented
+
| Address will be returned in network order where applicable
 
|-
 
|-
 
|}
 
|}
Line 2,928: Line 2,949:
 
|-
 
|-
 
! Note
 
! Note
| None documented
+
| Address will be returned in network order where applicable
 
|-
 
|-
 
|}
 
|}
Line 2,940: Line 2,961:
 
|-
 
|-
 
! Note
 
! Note
| None documented
+
| Address will be returned in network order where applicable
 
|-
 
|-
 
|}
 
|}
Line 2,952: Line 2,973:
 
|-
 
|-
 
! Note
 
! Note
| None documented
+
| Address will be in network order where applicable
 
|-
 
|-
 
|}
 
|}
Line 2,964: Line 2,985:
 
|-
 
|-
 
! Note
 
! Note
| None documented
+
| Address will be in network order where applicable
 
|-
 
|-
 
|}
 
|}
Line 2,976: Line 2,997:
 
|-
 
|-
 
! Note
 
! Note
| None documented
+
| Address will be in network order where applicable
 
|-
 
|-
 
|}
 
|}
Line 3,171: Line 3,192:
 
|-
 
|-
 
! Note
 
! Note
| None documented
+
| Address will be in network order where applicable
 
|-
 
|-
 
|}
 
|}

Latest revision as of 02:50, 6 March 2025

Return to Unit Reference


Description


Ultibo Winsock2 Interface unit

Notes:

  • All BSD/Winsock functions that accept an Address or Port expect them to be in Network order.
  • All other functions that take an Address or Port expect them to be in Host order.

Constants



[Expand]
Winsock2 specific constants WINSOCK_*


[Expand]
IP protocol IPPROTO_*


[Expand]
IP port IPPORT_*


[Expand]
IP option IP_*


[Expand]
Socket type SOCK_*


[Expand]
Socket option SO_*


[Expand]
TCP option TCP_*


[Expand]
UDP option UDP_*


[Expand]
Address family AF_*


[Expand]
Protocol family PF_*


[Expand]
Message flag MSG_*


[Expand]
FD option FD_*


[Expand]
Socket error WSAE*


[Expand]
Condition function value CF_*


[Expand]
Shutdown option SD_*


[Expand]
Socket group SG_*


[Expand]
Provider flag PFL_*


[Expand]
Service flag XP1_*


[Expand]
Join leaf option JL_*


[Expand]
Socket flag WSA_FLAG_*


[Expand]
Socket IOC option IOC_*


[Expand]
SIO option SIO_*


[Expand]
Name space NS_*


[Expand]
Resolution flag RES_*


[Expand]
Service type value SERVICE_TYPE_*


[Expand]
LUP option LUP_*


[Expand]
Address info flag AI_*


[Expand]
Name info flag NI_*


Type definitions


See globalsock.pas

Class definitions



Base socket classes

TWinsock2Socket = class(TListObject)
TWinsock2SocketThread = class(TThreadEx)
TWinsock2SocketThreads = class(TObject)
TWinsock2SocketBuffer = class(TObject)
TWinsock2SocketBuffers = class(TObject)

Raw socket (SOCK_RAW) classes

TWinsock2RAWSocket = class(TWinsock2Socket)

Stream socket (SOCK_STREAM) classes

TWinsock2TCPSocket = class(TWinsock2Socket)

Datagram socket (SOCK_DGRAM) classes

TWinsock2UDPSocket = class(TWinsock2Socket)

Raw client classes

TWinsock2RAWClient = class(TWinsock2RAWSocket)

Stream client classes

TWinsock2TCPClient = class(TWinsock2TCPSocket)

Datagram client classes

TWinsock2UDPClient = class(TWinsock2UDPSocket)

Stream server classes

TWinsock2TCPServer = class(TWinsock2TCPSocket)
TWinsock2TCPServerThread = class(TWinsock2SocketThread)
TWinsock2TCPListenerThread = class(TWinsock2SocketThread)
TWinsock2TCPServerThreads = class(TWinsock2SocketThreads)
TWinsock2TCPListener = class(TWinsock2TCPSocket)

Datagram server classes

TWinsock2UDPServer = class(TWinsock2UDPSocket)
TWinsock2UDPServerThread = class(TWinsock2SocketThread)
TWinsock2UDPListenerThread = class(TWinsock2SocketThread)
TWinsock2UDPServerThreads = class(TWinsock2SocketThreads)
TWinsock2UDPServerBuffer = class(TWinsock2SocketBuffer)
TWinsock2UDPServerBuffers = class(TWinsock2SocketBuffers)
TWinsock2UDPListener = class(TWinsock2UDPSocket)


Public variables


None defined

Function declarations



Initialization functions

[Expand]
procedure WS2Init;
Description: To be documented


[Expand]
function WS2Start:Boolean;
Description: To be documented


[Expand]
function WS2Stop:Boolean;
Description: To be documented


[Expand]
procedure WS2AsyncStart(Data:Pointer);
Description: To be documented


Winsock2 functions

[Expand]
function accept( const s: TSocket; addr: PSockAddr; addrlen: PLongint ): TSocket;
Description: To be documented


[Expand]
function accept( const s: TSocket; addr: PSockAddr; var addrlen: Longint ): TSocket;
Description: To be documented


[Expand]
function bind( const s: TSocket; addr: PSockAddr; namelen: Longint ): Longint;
Description: To be documented


[Expand]
function bind( const s: TSocket; var addr: TSockAddr; namelen: Longint ): Longint;
Description: To be documented


[Expand]
function closesocket( const s: TSocket ): Longint;
Description: To be documented


[Expand]
function connect( const s: TSocket; name: PSockAddr; namelen: Longint): Longint;
Description: To be documented


[Expand]
function connect( const s: TSocket; var name: TSockAddr; namelen: Longint): Longint;
Description: To be documented


[Expand]
function ioctlsocket( const s: TSocket; cmd: Longint; var arg: u_long ): Longint;
Description: To be documented


[Expand]
function ioctlsocket( const s: TSocket; cmd: Longint; argp: pu_long ): Longint;
Description: To be documented


[Expand]
function getpeername( const s: TSocket; var name: TSockAddr; var namelen: Longint ): Longint;
Description: To be documented


[Expand]
function getsockname( const s: TSocket; var name: TSockAddr; var namelen: Longint ): Longint;
Description: To be documented


[Expand]
function getsockopt( const s: TSocket; const level, optname: Longint; optval: PChar; var optlen: Longint ): Longint;
Description: To be documented


[Expand]
function getsockopt( const s: TSocket; const level, optname: Longint; optval: Pointer; var optlen: Longint ): Longint;
Description: To be documented


[Expand]
function getsockopt( const s: TSocket; const level, optname: Longint; var optval; var optlen: Longint ): Longint;
Description: To be documented


[Expand]
function htonl(hostlong: u_long): u_long;
Description: To be documented


[Expand]
function htons(hostshort: u_short): u_short;
Description: To be documented


[Expand]
function inet_addr(cp: PChar): u_long;
Description: To be documented


[Expand]
function inet_ntoa(inaddr: TInAddr): PChar;
Description: To be documented


[Expand]
function listen(s: TSocket; backlog: Longint): Longint;
Description: To be documented


[Expand]
function ntohl(netlong: u_long): u_long;
Description: To be documented


[Expand]
function ntohs(netshort: u_short): u_short;
Description: To be documented


[Expand]
function recv(s: TSocket; var Buf; len, flags: Longint): Longint;
Description: To be documented


[Expand]
function recv(s: TSocket; Buf: PChar; len, flags: Longint): Longint;
Description: To be documented


[Expand]
function recv(s: TSocket; Buf: Pointer; len, flags: Longint): Longint;
Description: To be documented


[Expand]
function recvfrom(s: TSocket; Buf: PChar; len, flags: Longint; from: PSockAddr; fromlen: PLongint): Longint;
Description: To be documented


[Expand]
function recvfrom(s: TSocket; Buf: Pointer; len, flags: Longint; from: PSockAddr; fromlen: PLongint): Longint;
Description: To be documented


[Expand]
function recvfrom(s: TSocket; var Buf; len, flags: Longint; var from: TSockAddr; var fromlen: Longint): Longint;
Description: To be documented


[Expand]
function select(nfds: Longint; readfds, writefds, exceptfds: PFDSet; timeout: PTimeVal): Longint;
Description: To be documented


[Expand]
function send(s: TSocket; var Buf; len, flags: Longint): Longint;
Description: To be documented


[Expand]
function send(s: TSocket; Buf: PChar; len, flags: Longint): Longint;
Description: To be documented


[Expand]
function send(s: TSocket; Buf: Pointer; len, flags: Longint): Longint;
Description: To be documented


[Expand]
function sendto(s: TSocket; var Buf; len, flags: Longint; var addrto: TSockAddr; tolen: Longint): Longint;
Description: To be documented


[Expand]
function sendto(s: TSocket; Buf: PChar; len, flags: Longint; addrto: PSockAddr; tolen: Longint): Longint;
Description: To be documented


[Expand]
function sendto(s: TSocket; Buf: Pointer; len, flags: Longint; addrto: PSockAddr; tolen: Longint): Longint;
Description: To be documented


[Expand]
function setsockopt(s: TSocket; level, optname: Longint; const optval; optlen: Longint): Longint;
Description: To be documented


[Expand]
function setsockopt(s: TSocket; level, optname: Longint; optval: PChar; optlen: Longint): Longint;
Description: To be documented


[Expand]
function setsockopt(s: TSocket; level, optname: Longint; optval: Pointer; optlen: Longint): Longint;
Description: To be documented


[Expand]
function shutdown(s: TSocket; how: Longint): Longint;
Description: To be documented


[Expand]
function socket(af, struct, protocol: Longint): TSocket;
Description: To be documented


[Expand]
function gethostbyaddr(addr: Pointer; len, family: Longint): PHostEnt;
Description: To be documented


[Expand]
function gethostbyname(name: PChar): PHostEnt;
Description: To be documented


[Expand]
function gethostname(name: PChar; len: Longint): Longint;
Description: To be documented


[Expand]
function getservbyport(port: Longint; proto: PChar): PServEnt;
Description: To be documented


[Expand]
function getservbyname(name, proto: PChar): PServEnt;
Description: To be documented


[Expand]
function getprotobynumber(proto: Longint): PProtoEnt;
Description: To be documented


[Expand]
function getprotobyname(name: PChar): PProtoEnt;
Description: To be documented


[Expand]
function getaddrinfo(pNodeName, pServiceName: PChar; pHints: PAddrInfo; var ppResult: PAddrInfo): LongInt;
Description: RFC 3493 protocol-independent translation from a host name to an address


[Expand]
procedure freeaddrinfo(ai: PAddrInfo);
Description: Free address information that GetAddrInfo dynamically allocates in TAddrInfo structures


[Expand]
function getnameinfo(sa: PSockAddr; salen: Integer; host: PChar; hostlen: DWORD; serv: PChar; servlen: DWORD; flags: Integer): Integer;
Description: RFC 3493 protocol-independent name resolution from an address to a host name and a port number to a service name


[Expand]
function Gai_StrError(ecode: Longint): PChar;
Description: Return an error message for an error code returned by GetAddrInfo or GetNameInfo


[Expand]
function WSAStartup(wVersionRequired: word; var WSData: TWSAData): Longint;
Description: To be documented


[Expand]
function WSACleanup: Longint;
Description: To be documented


[Expand]
procedure WSASetLastError(iError: Longint); inline;
Description: To be documented


[Expand]
function WSAGetLastError: Longint; inline;
Description: To be documented


[Expand]
function __WSAFDIsSet(s: TSOcket; var FDSet: TFDSet): Bool;
Description: To be documented


[Expand]
function inet_pton(Family: Longint; pszAddrString: PChar; pAddrBuf: Pointer): Longint;
Description: To be documented


[Expand]
function InetPtonA(Family: Longint; pszAddrString: PChar; pAddrBuf: Pointer): Longint;
Description: To be documented


[Expand]
function InetPtonW(Family: Longint; pszAddrString: PWideChar; pAddrBuf: Pointer): Longint;
Description: To be documented


[Expand]
function inet_ntop(Family: Longint; pAddr: Pointer; pStringBuf: PChar; StringBufSize: Longint): PChar;
Description: To be documented


[Expand]
function InetNtopA(Family: Longint; pAddr: Pointer; pStringBuf: PChar; StringBufSize: Longint): PChar;
Description: To be documented


[Expand]
function InetNtopW(Family: Longint; pAddr: Pointer; pStringBuf: PWideChar; StringBufSize: Longint): PWideChar;
Description: To be documented


[Expand]
function WSAhtonl( s : TSocket; hostlong : u_long; var lpnetlong : DWORD ): Longint;
Description: To be documented


[Expand]
function WSAhtons( s : TSocket; hostshort : u_short; var lpnetshort : WORD ): Longint;
Description: To be documented


[Expand]
function WSANtohl( s : TSocket; netlong : u_long; var lphostlong : DWORD ): Longint;
Description: To be documented


[Expand]
function WSANtohs( s : TSocket; netshort : u_short; var lphostshort : WORD ): Longint;
Description: To be documented


[Expand]
function WSAMakeSyncReply(Buflen, Error: Word): Longint;
Description: To be documented


[Expand]
function WSAMakeSelectReply(Event, Error: Word): Longint;
Description: To be documented


[Expand]
function WSAGetAsyncBuflen(Param: Longint): Word;
Description: To be documented


[Expand]
function WSAGetAsyncError(Param: Longint): Word;
Description: To be documented


[Expand]
function WSAGetSelectEvent(Param: Longint): Word;
Description: To be documented


[Expand]
function WSAGetSelectError(Param: Longint): Word;
Description: To be documented


[Expand]
procedure FD_CLR(Socket: TSocket; var FDSet: TFDSet);
Description: To be documented


[Expand]
function FD_ISSET(Socket: TSocket; var FDSet: TFDSet): Boolean;
Description: To be documented


[Expand]
procedure FD_SET(Socket: TSocket; var FDSet: TFDSet);
Description: To be documented


[Expand]
procedure FD_ZERO(var FDSet: TFDSet);
Description: To be documented


Winsock2 undocumented functions

[Expand]
function WsControl(Proto:DWORD; Action:DWORD; pRequestInfo:Pointer; var pcbRequestInfoLen:DWORD; pResponseInfo:Pointer; var pcbResponseInfoLen:DWORD):Integer;
Description: To be documented


[Expand]
function getnetbyaddr(addr: Pointer; len, Struct: Integer): PNetEnt;
Description: To be documented


[Expand]
function getnetbyname(name: PChar): PNetEnt;
Description: To be documented


Winsock2 enhanced functions

[Expand]
function WsControlEx(Proto:DWORD; Action:DWORD; pRequestInfo:Pointer; var pcbRequestInfoLen:DWORD; pResponseInfo:Pointer; var pcbResponseInfoLen:DWORD):Integer;
Description: To be documented


RTL text IO functions

[Expand]
function SysTextIOReadChar(var ACh:Char; AUserData:Pointer):Boolean;
Description: Handler for platform TextIOReadChar function


[Expand]
function SysTextIOWriteChar(ACh:Char; AUserData:Pointer):Boolean;
Description: Handler for platform TextIOWriteChar function


[Expand]
function SysTextIOWriteBuffer(ABuffer:PChar; ACount:LongInt; AUserData:Pointer):LongInt;
Description: Handler for platform TextIOWriteBuffer function


Winsock2 helper functions

[Expand]
function Winsock2RedirectInput(s:TSocket):Boolean;
Description: Redirect standard input to the socket specified by s


[Expand]
function Winsock2RedirectOutput(s:TSocket):Boolean;
Description: Redirect standard output to the socket specified by s


[Expand]
function Winsock2ErrorToString(AError:LongInt):String;
Description: To be documented


Return to Unit Reference