diff options
author | marco <marco@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2014-01-11 19:45:37 +0000 |
---|---|---|
committer | marco <marco@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2014-01-11 19:45:37 +0000 |
commit | f6bd2d2139abdac7ca1f826380dbe7f8e2b9a1c7 (patch) | |
tree | 5dc2e9b22f463b816e47192ee89cb82bf169f997 /packages/rtl-extra | |
parent | ac072b0df8051da591f0079378a7299d8ce4aa43 (diff) | |
download | fpc-f6bd2d2139abdac7ca1f826380dbe7f8e2b9a1c7.tar.gz |
* winsock(and -2), sockets and gpm to rtl-extra.
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@26426 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/rtl-extra')
34 files changed, 13193 insertions, 0 deletions
diff --git a/packages/rtl-extra/fpmake.pp b/packages/rtl-extra/fpmake.pp index 09691c586a..aa67ed474b 100644 --- a/packages/rtl-extra/fpmake.pp +++ b/packages/rtl-extra/fpmake.pp @@ -15,6 +15,11 @@ Const UComplexOSes = [amiga,emx,gba,go32v2,morphos,msdos,nativent,nds,netware,netwlibc,os2,watcom,wii,wince,win32,win64]+UnixLikes; MatrixOSes = [amiga,emx,gba,go32v2,morphos,msdos,nativent,nds,netware,netwlibc,os2,wii,win32,win64,wince]+UnixLikes; ObjectsOSes = [amiga,emx,gba,go32v2,morphos,msdos,netware,netwlibc,os2,win32,win64,wince]+UnixLikes; + WinsockOSes = [win32,win64,wince,os2,emx,netware,netwlibc]; + WinSock2OSes = [win32,win64,wince]; + // sockets of morphos is implemented, but not active + SocketsOSes = UnixLikes+[netware,netwlibc,os2,wince,win32,win64]; + gpmOSes = [Linux,Android]; AllTargetsextra = ObjectsOSes + UComplexOSes + MatrixOSes; Var @@ -40,6 +45,7 @@ begin P.SourcePath.Add('src/darwin',[iphonesim]); P.SourcePath.Add('src/unix',AllUnixOSes); P.SourcePath.Add('src/os2commn',[os2,emx]); + P.SourcePath.Add('src/netwcomn',[netware,netwlibc]); P.SourcePath.Add('src/win',[win32,win64]); P.IncludePath.Add('src/inc'); @@ -57,6 +63,22 @@ begin AddInclude('mvecimp.inc'); AddInclude('mmatimp.inc'); end; + T:=P.Targets.AddUnit('winsock.pp',WinSockOSes); + with T.Dependencies do + begin + AddInclude('qos.inc',[netware,netwlibc]); + AddInclude('netwsockh.inc',[netware,netwlibc]); + end; + T:=P.Targets.AddUnit('gpm.pp',gpmOSes); + with T.Dependencies do + AddUnit('sockets'); + T:=P.Targets.AddUnit('sockets.pp',SocketsOSes); + with T.Dependencies do + begin + addinclude('socketsh.inc'); + addinclude('sockets.inc'); + addinclude('sockovl.inc'); + end; end end; diff --git a/packages/rtl-extra/src/aix/osdefs.inc b/packages/rtl-extra/src/aix/osdefs.inc new file mode 100644 index 0000000000..a981f7d408 --- /dev/null +++ b/packages/rtl-extra/src/aix/osdefs.inc @@ -0,0 +1,24 @@ +{ + Copyright (c) 2000-2002 by Marco van de Voort + + Target dependent defines used when compileing the baseunix unit + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + ****************************************************************************} + +{define usedomain} // Allow uname with "domain" entry. + // (which is a GNU extension) + diff --git a/packages/rtl-extra/src/beos/osdefs.inc b/packages/rtl-extra/src/beos/osdefs.inc new file mode 100644 index 0000000000..929da7cfa5 --- /dev/null +++ b/packages/rtl-extra/src/beos/osdefs.inc @@ -0,0 +1,24 @@ +{ + Copyright (c) 2000-2002 by Marco van de Voort + + Target dependent defines used when compileing the baseunix unit + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA. + + ****************************************************************************} + +{$define usedomain} // Allow uname with "domain" entry. + // (which is a GNU extension) diff --git a/packages/rtl-extra/src/bsd b/packages/rtl-extra/src/bsd new file mode 100644 index 0000000000..5f82f9cb0b --- /dev/null +++ b/packages/rtl-extra/src/bsd @@ -0,0 +1,26 @@ +{ + Copyright (c) 2000-2002 by Marco van de Voort + + Target dependent defines used when compileing the baseunix unit + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + ****************************************************************************} + +{$define usedomain} // Allow uname with "domain" entry. + // (which is a GNU extension) +{$define hassysctl} // Use sysctl unit + diff --git a/packages/rtl-extra/src/haiku/osdefs.inc b/packages/rtl-extra/src/haiku/osdefs.inc new file mode 100644 index 0000000000..4bfda4a360 --- /dev/null +++ b/packages/rtl-extra/src/haiku/osdefs.inc @@ -0,0 +1,24 @@ +{ + Copyright (c) 2000-2002 by Marco van de Voort + + Target dependent defines used when compileing the baseunix unit + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + ****************************************************************************} + +{$define usedomain} // Allow uname with "domain" entry. + // (which is a GNU extension) diff --git a/packages/rtl-extra/src/inc/sockets.inc b/packages/rtl-extra/src/inc/sockets.inc new file mode 100644 index 0000000000..5f0eb19dd6 --- /dev/null +++ b/packages/rtl-extra/src/inc/sockets.inc @@ -0,0 +1,518 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2000 by the Free Pascal development team + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +{****************************************************************************** + Text File Writeln/ReadLn Support +******************************************************************************} + + +Procedure OpenSock(var F:Text); +begin + if textrec(f).handle=UnusedHandle then + textrec(f).mode:=fmclosed + else + case textrec(f).userdata[1] of + S_OUT : textrec(f).mode:=fmoutput; + S_IN : textrec(f).mode:=fminput; + else + textrec(f).mode:=fmclosed; + end; +end; + + + +procedure iosock(var f:text); + +var r:sizeint; + def_error:word; + +begin + with textrec(f) do + begin + case mode of + fmoutput: + begin + repeat +{$ifdef use_readwrite} + r:=fpwrite(handle,bufptr^,bufpos); +{$else} + r:=fpsend(handle,bufptr,bufpos,0); +{$endif} + until (r<>-1) or (SocketError <> EsockEINTR); + bufend:=r; + def_error:=101; {File write error.} + end; + fminput: + begin + repeat +{$ifdef use_readwrite} + r:=fpread(handle,bufptr^,bufsize); +{$else} + r:=fprecv(handle,bufptr,bufsize,0); +{$endif} + until (r<>-1) or (SocketError <> EsockEINTR); + bufend:=r; + def_error:=100; {File read error.} + end; + end; + if r=-1 then + case SocketError of + EsockEBADF: +{ EsysENOTSOCK:} {Why is this constant not defined? (DM)} + inoutres:=6; {Invalid file handle.} + EsockEFAULT: + inoutres:=217; + EsockEINVAL: + inoutres:=218; + else + inoutres:=def_error; + end; + bufpos:=0; + end; +end; + + + +Procedure FlushSock(var F:Text); +begin + if (textrec(f).mode=fmoutput) and (textrec(f).bufpos<>0) then + begin + IOSock(f); + textrec(f).bufpos:=0; + end; +end; + + + +Procedure CloseSock(var F:text); +begin + { Nothing special has to be done here } +end; + + + +Procedure Sock2Text(Sock:Longint;Var SockIn,SockOut:Text); +{ + Set up two Pascal Text file descriptors for reading and writing) +} +begin +{ First the reading part.} + Assign(SockIn,'.'); + Textrec(SockIn).Handle:=Sock; + Textrec(Sockin).userdata[1]:=S_IN; + TextRec(SockIn).OpenFunc:=@OpenSock; + TextRec(SockIn).InOutFunc:=@IOSock; + TextRec(SockIn).FlushFunc:=@FlushSock; + TextRec(SockIn).CloseFunc:=@CloseSock; + TextRec(SockIn).Mode := fmInput; + Case DefaultTextLineBreakStyle Of + tlbsLF: TextRec(sockin).LineEnd := #10; + tlbsCRLF: TextRec(sockin).LineEnd := #13#10; + tlbsCR: TextRec(sockin).LineEnd := #13; + End; +{ Now the writing part. } + Assign(SockOut,'.'); + Textrec(SockOut).Handle:=Sock; + Textrec(SockOut).userdata[1]:=S_OUT; + TextRec(SockOut).OpenFunc:=@OpenSock; + TextRec(SockOut).InOutFunc:=@IOSock; + TextRec(SockOut).FlushFunc:=@FlushSock; + TextRec(SockOut).CloseFunc:=@CloseSock; + TextRec(SockOut).Mode := fmOutput; + + Case DefaultTextLineBreakStyle Of + tlbsLF: TextRec(sockout).LineEnd := #10; + tlbsCRLF: TextRec(sockout).LineEnd := #13#10; + tlbsCR: TextRec(sockout).LineEnd := #13; + End; +end; + + +{****************************************************************************** + Untyped File +******************************************************************************} + +Procedure Sock2File(Sock:Longint;Var SockIn,SockOut:File); +begin +{Input} + Assign(SockIn,'.'); + FileRec(SockIn).Handle:=Sock; + FileRec(SockIn).RecSize:=1; + FileRec(Sockin).userdata[1]:=S_IN; + FileRec(SockIn).Mode := fmInput; + +{Output} + Assign(SockOut,'.'); + FileRec(SockOut).Handle:=Sock; + FileRec(SockOut).RecSize:=1; + FileRec(SockOut).userdata[1]:=S_OUT; + FileRec(SockOut).Mode := fmOutput; +end; + +{****************************************************************************** + InetSock +******************************************************************************} + +Function DoAccept(Sock:longint;Var addr:TInetSockAddr):longint; + +Var AddrLen : Longint; + +begin + AddrLEn:=SizeOf(Addr); + repeat + DoAccept:=fpaccept(Sock,@Addr,@AddrLen); + until (DoAccept<>-1) or (SocketError <> EsockEINTR); +end; + +Function DoConnect(Sock:longint;const addr: TInetSockAddr): Boolean; + +var + res: longint; +begin + repeat + res:=fpconnect(Sock,@Addr,SizeOF(TInetSockAddr)); + until (res<>-1) or (SocketError <> EsockEINTR); + DoConnect:= res = 0; +end; + +{$warnings off} + +Function Connect(Sock:longint;const addr: TInetSockAddr;var SockIn,SockOut:text):Boolean; + +begin + Connect:=DoConnect(Sock,addr); + If Connect then + Sock2Text(Sock,SockIn,SockOut); +end; + +Function Connect(Sock:longint;const addr:TInetSockAddr;var SockIn,SockOut:file):Boolean; + +begin + Connect:=DoConnect(Sock,addr); + If Connect then + Sock2File(Sock,SockIn,SockOut); +end; + +Function Accept(Sock:longint;var addr:TInetSockAddr;var SockIn,SockOut:text):Boolean; +var + s : longint; +begin + S:=DoAccept(Sock,addr); + if S>0 then + begin + Sock2Text(S,SockIn,SockOut); + Accept:=true; + end + else + Accept:=false; +end; + +Function Accept(Sock:longint;var addr:TInetSockAddr;var SockIn,SockOut:File):Boolean; +var + s : longint; +begin + S:=DoAccept(Sock,addr); + if S>0 then + begin + Sock2File(S,SockIn,SockOut); + Accept:=true; + end + else + Accept:=false; +end; + +{$warnings on} + +type thostaddr= packed array[1..4] of byte; + +function htonl( host : longint):longint; inline;overload;deprecated; +begin +{$ifdef FPC_BIG_ENDIAN} + htonl:=host; +{$else} + htonl:=SwapEndian(host); +{$endif} +end; + +function htonl( host : cardinal):cardinal; inline;overload; +begin +{$ifdef FPC_BIG_ENDIAN} + htonl:=host; +{$else} + htonl:=SwapEndian(host); +{$endif} +end; + +Function NToHl (Net : longint) : longint; inline;overload;deprecated; +begin +{$ifdef FPC_BIG_ENDIAN} + ntohl:=net; +{$else} + ntohl:=SwapEndian(net); +{$endif} +end; + +Function NToHl (Net : cardinal) : cardinal; inline;overload; +begin +{$ifdef FPC_BIG_ENDIAN} + ntohl:=net; +{$else} + ntohl:=SwapEndian(net); +{$endif} +end; + +function htons( host : word):word; inline; + +begin +{$ifdef FPC_BIG_ENDIAN} + htons:=host; +{$else} + htons:=SwapEndian(host); +{$endif} +end; + +Function NToHs (Net : word):word; inline; + +begin +{$ifdef FPC_BIG_ENDIAN} + ntohs:=net; +{$else} + ntohs:=SwapEndian(net); +{$endif} +end; + +Type array4int = array[1..4] of byte; + +function NetAddrToStr (Entry : in_addr) : AnsiString; + +Var Dummy : Ansistring; + i,j : Longint; + +begin + NetAddrToStr:=''; + j:=entry.s_addr; + For I:=1 to 4 do + begin + Str(array4int(j)[i],Dummy); + NetAddrToStr:=NetAddrToStr+Dummy; + If I<4 Then + NetAddrToStr:=NetAddrToStr+'.'; + end; +end; + +function HostAddrToStr (Entry : in_addr) : AnsiString; + +Var x: in_addr; + +begin + x.s_addr:=htonl(entry.s_addr); + HostAddrToStr:=NetAddrToStr(x); +end; + +function StrToHostAddr(IP : AnsiString) : in_addr ; + +Var + Dummy : AnsiString; + I,j,k : Longint; + Temp : in_addr; + +begin + strtohostaddr.s_addr:=0; //:=NoAddress; + For I:=1 to 4 do + begin + If I<4 Then + begin + J:=Pos('.',IP); + If J=0 then + exit; + Dummy:=Copy(IP,1,J-1); + Delete (IP,1,J); + end + else + Dummy:=IP; + Val (Dummy,k,J); + array4int(temp.s_addr)[i]:=k; + If J<>0 then Exit; + end; + strtohostaddr.s_addr:=ntohl(Temp.s_addr); +end; + +function StrToNetAddr(IP : AnsiString) : in_addr; + +begin + StrToNetAddr.s_addr:=htonl(StrToHostAddr(IP).s_addr); +end; + +Function HostToNet (Host : in_addr):in_addr; + +begin + HostToNet.s_addr:=htonl(host.s_addr); +end; + +Function NetToHost (Net : in_addr) : in_addr; + +begin + NetToHost.s_addr:=ntohl(net.s_addr); +end; + +Function HostToNet (Host : Longint) : Longint; + +begin + HostToNet:=htonl(host); +end; + +Function NetToHost (Net : Longint) : Longint; + +begin + NetToHost:=ntohl(net); +end; + +Function ShortHostToNet (Host : Word) : Word; + +begin + ShortHostToNet:=htons(host); +end; + +Function ShortNetToHost (Net : Word) : Word; + +begin + ShortNEtToHost:=ntohs(net); +end; + +const digittab : shortstring = ('0123456789ABCDEF'); + +function lclinttohex (i:integer;digits:longint): ansistring; + +begin + SetLength(lclinttohex,4); + lclinttohex[4]:=digittab[1+(i and 15)]; + lclinttohex[3]:=digittab[1+((i shr 4) and 15)]; + lclinttohex[2]:=digittab[1+((i shr 8) and 15)]; + lclinttohex[1]:=digittab[1+((i shr 12) and 15)];; +end; + +function HostAddrToStr6 (Entry : TIn6_Addr) :ansiString; +var + i: byte; + zr1,zr2: set of byte; + zc1,zc2: byte; + have_skipped: boolean; +begin + zr1 := []; + zr2 := []; + zc1 := 0; + zc2 := 0; + for i := 0 to 7 do begin + if Entry.u6_addr16[i] = 0 then begin + include(zr2, i); + inc(zc2); + end else begin + if zc1 < zc2 then begin + zc1 := zc2; + zr1 := zr2; + zc2 := 0; zr2 := []; + end; + end; + end; + if zc1 < zc2 then begin + zc1 := zc2; + zr1 := zr2; + end; + SetLength(HostAddrToStr6, 8*5-1); + SetLength(HostAddrToStr6, 0); + have_skipped := false; + for i := 0 to 7 do begin + if not (i in zr1) then begin + if have_skipped then begin + if HostAddrToStr6 = '' + then HostAddrToStr6 := '::' + else HostAddrToStr6 := HostAddrToStr6 + ':'; + have_skipped := false; + end; + // FIXME: is that shortnettohost really proper there? I wouldn't be too sure... + HostAddrToStr6 := HostAddrToStr6 +lclIntToHex(ShortNetToHost(Entry.u6_addr16[i]), 1) + ':'; + end else begin + have_skipped := true; + end; + end; + if have_skipped then + if HostAddrToStr6 = '' + then HostAddrToStr6 := '::' + else HostAddrToStr6 := HostAddrToStr6 + ':'; + + if HostAddrToStr6 = '' then HostAddrToStr6 := '::'; + if not (7 in zr1) then + SetLength(HostAddrToStr6, Length(HostAddrToStr6)-1); +end; + + +function StrToHostAddr6(IP : String) : TIn6_addr; +Var Part : String; + IPv6 : TIn6_addr; + P,J : Integer; + W : Word; + Index : Integer; + ZeroAt : Integer; +Begin + FillChar(IPv6,SizeOf(IPv6),0); + { Every 16-bit block is converted at its own and stored into Result. When } + { the '::' zero-spacer is found, its location is stored. Afterwards the } + { address is shifted and zero-filled. } + Index := 0; ZeroAt := -1; + J := 0; + P := Pos(':',IP); + While (P > 0) and (Length(IP) > 0) and (Index < 8) do + Begin + Part := '$'+Copy(IP,1,P-1); + Delete(IP,1,P); + if Length(Part) > 1 then { is there a digit after the '$'? } + Val(Part,W,J) + else W := 0; + IPv6.u6_addr16[Index] := HtoNS(W); + if J <> 0 then + Begin + FillChar(IPv6,SizeOf(IPv6),0); + Exit; + End; + if IP[1] = ':' then + Begin + ZeroAt := Index; + Delete(IP,1,1); + End; + Inc(Index); + P := Pos(':',IP); if P = 0 then P := Length(IP)+1; + End; + { address a:b:c::f:g:h } + { Result now a : b : c : f : g : h : 0 : 0, ZeroAt = 2, Index = 6 } + { Result after a : b : c : 0 : 0 : f : g : h } + if ZeroAt >= 0 then + Begin + Move(IPv6.u6_addr16[ZeroAt+1],IPv6.u6_addr16[(8-Index)+ZeroAt+1],2*(Index-ZeroAt-1)); + FillChar(IPv6.u6_addr16[ZeroAt+1],2*(8-Index),0); + End; + + StrToHostAddr6:=IPv6; +End; + + +function NetAddrToStr6 (Entry : TIn6_Addr) : ansiString; +begin + netaddrtostr6 := HostAddrToStr6((Entry)); +end; + +function StrToNetAddr6(IP : ansiString) : TIn6_Addr; +begin + StrToNetAddr6 := StrToHostAddr6(IP); +end; + + diff --git a/packages/rtl-extra/src/inc/socketsh.inc b/packages/rtl-extra/src/inc/socketsh.inc new file mode 100644 index 0000000000..e7949b56d8 --- /dev/null +++ b/packages/rtl-extra/src/inc/socketsh.inc @@ -0,0 +1,245 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2000 by the Free Pascal development team + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +{$INLINE ON} + +type +{$ifdef SOCK_HAS_SINLEN} + sa_family_t = cuchar; +{$else} + sa_family_t = cushort; +{$endif} + +const + { Socket types } +{$ifdef sunos} + SOCK_STREAM = 2; { stream socket } + SOCK_DGRAM = 1; { datagram socket } + SOCK_RAW = 4; { raw-protocol interface } + SOCK_RDM = 5; { reliably-delivered message } + SOCK_SEQPACKET = 6; { sequenced packet stream } +{$else} + {$if defined(cpumips) and defined(linux)} + { mips-linux has these two swapped for some reason } + SOCK_STREAM = 2; + SOCK_DGRAM = 1; + {$else cpumips and linux} + SOCK_STREAM = 1; { stream (connection) socket } + SOCK_DGRAM = 2; { datagram (conn.less) socket } + {$endif cpumips and linux} + SOCK_RAW = 3; { raw socket } + SOCK_RDM = 4; { reliably-delivered message } + SOCK_SEQPACKET = 5; { sequential packet socket } +{$endif} + + INADDR_ANY = CARDINAL(0); + INADDR_NONE = CARDINAL($FFFFFFFF); + +const + { Two constants to determine whether part of soket is for in or output } + S_IN = 0; + S_OUT = 1; + +type + pin_addr = ^in_addr; + in_addr = packed record + case boolean of + true: (s_addr : cuint32); // inaddr_t=cuint32 + false: (s_bytes : packed array[1..4] of byte); + end; + + TIn_addr = in_addr; + + TInAddr = in_addr; + PInAddr = pin_addr; + + {pin_addrbytes = ^in_addrbytes; + in_addrbytes = packed array [1..4] of byte;} + + psockaddr_in = ^sockaddr_in; + sockaddr_in = packed record + case boolean of + false : ( + {$ifdef SOCK_HAS_SINLEN} + sin_len : cuchar; + {$endif} + sin_family : sa_family_t; + sin_port : cushort; + sin_addr : in_addr; + xpad : array [0..7] of char; { to get to the size of sockaddr... } + ); + true: ( + {$ifdef SOCK_HAS_SINLEN} + len : cuchar deprecated; + {$endif} + family : sa_family_t deprecated; + port : cushort deprecated; + addr : cardinal deprecated; + pad : array [0..7] of char deprecated; { to get to the size of sockaddr... } + ); + end; + + TInetSockAddr = sockaddr_in; + PInetSockAddr = psockaddr_in; + + psockaddr = ^sockaddr; + sockaddr = packed record // if sa_len is defined, sa_family_t is smaller + {$ifdef SOCK_HAS_SINLEN} + sa_len : cuchar; + {$endif} + case integer of + 0: (sa_family: sa_family_t; + sa_data: packed array[0..13] of cuint8); + 1: (sin_family: sa_family_t; + sin_port: cushort; + sin_addr: in_addr; + sin_zero: packed array[0..7] of cuint8); + end; + + TSockAddr = sockaddr; + + plinger = ^linger; + linger = packed record + l_onoff : cint; (* Linger active *) + l_linger : cint; (* How long to linger for *) + end; + + TLinger = linger; + + pin6_addr = ^in6_addr; + in6_addr = packed record + case byte of + 0: (u6_addr8 : array[0..15] of byte); + 1: (u6_addr16 : array[0..7] of Word); + 2: (u6_addr32 : array[0..3] of Cardinal); + 3: (s6_addr8 : array[0..15] of shortint); + 4: (s6_addr : array[0..15] of shortint); + 5: (s6_addr16 : array[0..7] of smallint); + 6: (s6_addr32 : array[0..3] of LongInt); + end; + + Tin6_addr = in6_addr; + + TIn6Addr = in6_addr; + PIn6Addr = pin6_addr; + + psockaddr_in6 = ^sockaddr_in6; + sockaddr_in6 = packed Record + {$ifdef SOCK_HAS_SINLEN} // as per RFC 2553 + sin6_len : cuint8; + {$endif} + sin6_family : sa_family_t; + sin6_port : cuint16; + sin6_flowinfo : cuint32; + sin6_addr : in6_addr; + sin6_scope_id : cuint32; + end; + + TInetSockAddr6 = sockaddr_in6; + PInetSockAddr6 = psockaddr_in6; + + TSockPairArray = Array[0..1] of Longint; + TSockArray = Array[1..2] of Longint; //legacy + + psockaddr_un = ^sockaddr_un; + sockaddr_un = packed record + {$ifdef SOCK_HAS_SINLEN} + sun_len : cuint8; + {$endif} + sun_family : sa_family_t; + sun_path : array[0..107] of char; + end; + + Tsocket=longint; {To easy porting code from Kylix libc unit to sockets unit.} + +function socketerror : cint; + +function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; +function fprecv (s:cint; buf: pointer; len: size_t; flags: cint):ssize_t; +function fprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t; +function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t; +function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t; +function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; +function fplisten (s:cint; backlog : cint):cint; +function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; +function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; +function fpshutdown (s:cint; how:cint):cint; +function fpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint; +function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint; +function fpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint; +function fpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : tsocklen):cint; +function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; + +Function CloseSocket(Sock:Longint):Longint; + +{Basic Socket Functions} +{$ifdef legacysocket} +Function Socket(Domain,SocketType,Protocol:Longint):Longint; deprecated; +Function Send(Sock:Longint;Const Buf;BufLen,Flags:Longint):Longint; deprecated; +Function SendTo(Sock:Longint;Const Buf;BufLen,Flags:Longint;Var Addr; AddrLen : Longint):Longint; deprecated; +Function Recv(Sock:Longint;Var Buf;BufLen,Flags:Longint):Longint; deprecated; +Function RecvFrom(Sock : Longint; Var Buf; Buflen,Flags : Longint; Var Addr; var AddrLen : longInt) : longint;deprecated; +Function Bind(Sock:Longint;Const Addr;AddrLen:Longint):Boolean;deprecated; +Function Listen (Sock,MaxConnect:Longint):Boolean;deprecated; +Function Accept(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;deprecated; +Function Connect(Sock:Longint;Const Addr;Addrlen:Longint):boolean;deprecated; +Function Shutdown(Sock:Longint;How:Longint):Longint;deprecated; +Function GetSocketName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;deprecated; +Function GetPeerName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;deprecated; +Function SetSocketOptions(Sock,Level,OptName:Longint;const OptVal;optlen:longint):Longint;deprecated; +Function GetSocketOptions(Sock,Level,OptName:Longint;Var OptVal;Var optlen:longint):Longint;deprecated; +Function SocketPair(Domain,SocketType,Protocol:Longint;var Pair:TSockArray):Longint;deprecated; +{$endif} + +{ untyped/text filetype support } + +Procedure Sock2Text(Sock:Longint;Var SockIn,SockOut:Text);deprecated; +Function Accept(Sock:longint;var addr:TInetSockAddr;var SockIn,SockOut:File):Boolean; deprecated; +Function Accept(Sock:longint;var addr:TInetSockAddr;var SockIn,SockOut:text):Boolean;deprecated; +Function Connect(Sock:longint;const addr:TInetSockAddr;var SockIn,SockOut:text):Boolean; deprecated; +Function Connect(Sock:longint;const addr:TInetSockAddr;var SockIn,SockOut:file):Boolean;deprecated; +Procedure Sock2File(Sock:Longint;Var SockIn,SockOut:File);deprecated; + +{ Utility routines} +function htonl( host : longint):longint; inline; overload;deprecated; +Function NToHl( Net : longint):longint; inline; overload;deprecated; +function htonl( host : cardinal):cardinal; inline; overload; +Function NToHl( Net : cardinal):cardinal; inline; overload; +function htons( host : word):word; inline; +Function NToHs( Net : word):word; inline; + +function NetAddrToStr (Entry : in_addr) : AnsiString; +function HostAddrToStr(Entry : in_addr) : AnsiString; +function StrToHostAddr(IP : AnsiString) : in_addr ; +function StrToNetAddr (IP : AnsiString) : in_addr; + +{ these for are for netdb legacy compat} +Function HostToNet (Host : in_addr) : in_addr; +Function NetToHost (Net : in_addr) : in_addr; +Function HostToNet (Host : Longint) : Longint; +Function NetToHost (Net : Longint) : Longint; +Function ShortHostToNet(Host : Word) : Word; +Function ShortNetToHost(Net : Word) : Word; + +// ipv6 +function HostAddrToStr6(Entry : Tin6_addr) : AnsiString; +function StrToHostAddr6(IP : String) : Tin6_addr; // not implemented?!? +function NetAddrToStr6 (Entry: Tin6_addr) : AnsiString; +function StrToNetAddr6 (IP : AnsiString) : TIn6_Addr; + +CONST + NoAddress : in_addr = (s_addr:0); + NoNet : in_addr = (s_addr:0); + NoAddress6: in6_addr = (u6_addr16:(0,0,0,0,0,0,0,0)); + NoNet6 : in6_addr = (u6_addr16:(0,0,0,0,0,0,0,0)); + diff --git a/packages/rtl-extra/src/inc/sockovl.inc b/packages/rtl-extra/src/inc/sockovl.inc new file mode 100644 index 0000000000..b0040101cc --- /dev/null +++ b/packages/rtl-extra/src/inc/sockovl.inc @@ -0,0 +1,195 @@ +{ + This file is part of the Free Pascal run time library. + (c) 2000-2003 by Marco van de Voort + member of the Free Pascal development team. + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + socket call implementations for FreeBSD + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY;without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +} + + +{****************************************************************************** + Basic Socket Functions +******************************************************************************} + +{$ifdef legacysocket} +Function socket(Domain,SocketType,Protocol:Longint):Longint; +begin + Socket:=fpsocket(domain,sockettype,protocol); +end; + + +Function Send(Sock:Longint;Const Buf;BufLen,Flags:Longint):Longint; +begin + Send:=fpsend(sock,@buf,buflen,flags); +end; + +Function SendTo(Sock:Longint;Const Buf;BufLen,Flags:Longint;Var Addr; AddrLen : Longint):Longint; +begin + Sendto:=fpsendto(sock,@buf,buflen,flags,@addr,addrlen); +end; + +Function Recv(Sock:Longint;Var Buf;BufLen,Flags:Longint):Longint; +begin + Recv:=fprecv(sock,@buf,buflen,flags); +end; + +Function RecvFrom(Sock : Longint; Var Buf; Buflen,Flags : Longint; Var Addr ; var AddrLen :longint) : longint; + +begin + RecvFrom:=fprecvfrom(Sock,@buf,buflen,flags,@Addr,psocklen(@AddrLen)); +end; + +Function Bind(Sock:Longint;Const Addr;AddrLen:Longint):Boolean; +begin + Bind:=fpbind(Sock,@Addr,AddrLen)=0; +end; + +Function Listen(Sock,MaxConnect:Longint):Boolean; +begin + Listen:=fplisten(sock,maxconnect)=0; +end; + +Function Accept(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + Accept:=fpaccept(sock,@addr,psocklen(@addrlen)); +end; + +Function Connect(Sock:Longint;Const Addr;Addrlen:Longint): boolean; + +begin + Connect:=fpConnect(sock,@addr,addrlen)=0; +end; + +Function Shutdown(Sock:Longint;How:Longint):Longint; +begin + ShutDown:=fpshutdown(sock,how); +end; + +Function GetSocketName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + GetSocketName:=fpgetsockname(sock,@addr,psocklen(@addrlen)); +end; + +Function GetPeerName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + GetPeerName:=fpgetPeerName(sock,@addr,psocklen(@addrlen)); +end; + +Function SetSocketOptions(Sock,Level,OptName:Longint;const OptVal;optlen:longint):Longint; +begin + SetSocketOptions:=fpsetsockopt(Sock,Level,OptName,pointer(@OptVal),optlen); +end; + +Function GetSocketOptions(Sock,Level,OptName:Longint;Var OptVal;Var optlen:longint):Longint; +begin + GetSocketOptions:=fpgetsockopt(Sock,Level,OptName,@OptVal,psocklen(@OptLen)); +end; + +Function SocketPair(Domain,SocketType,Protocol:Longint;var Pair:TSockArray):Longint; +begin + SocketPair:=fpsocketpair(domain,sockettype,protocol,@pair[1]); +end; +{$endif} + +{****************************************************************************** + UnixSock +******************************************************************************} + +Procedure Str2UnixSockAddr(const addr:string;var t:TUnixSockAddr;var len:longint); +begin + Move(Addr[1],t.Path,length(Addr)); + t.Family:=AF_UNIX; + t.Path[length(Addr)]:=#0; + Len:=Length(Addr)+3; +end; + + +Function Bind(Sock:longint;const addr:string):boolean; +var + UnixAddr : TUnixSockAddr; + AddrLen : longint; +begin + Str2UnixSockAddr(addr,UnixAddr,AddrLen); + Bind := fpBind(Sock, @UnixAddr, AddrLen)=0; // what the flying fuck were you thinking? +end; + + +Function DoAccept(Sock:longint;var addr:string):longint; +var + UnixAddr : TUnixSockAddr; + AddrLen : longint; +begin + AddrLen:=length(addr)+3; + DoAccept:=fpAccept(Sock,@UnixAddr,@AddrLen); + Move(UnixAddr.Path,Addr[1],AddrLen); + SetLength(Addr,AddrLen); +end; + + + +Function DoConnect(Sock:longint;const addr:string):Boolean; +var + UnixAddr : TUnixSockAddr; + AddrLen : longint; +begin + Str2UnixSockAddr(addr,UnixAddr,AddrLen); + DoConnect:=fpConnect(Sock,@UnixAddr,AddrLen)=0; +end; + +Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:text):Boolean; +var + s : longint; +begin + S:=DoAccept(Sock,addr); + if S>0 then + begin + Sock2Text(S,SockIn,SockOut); + Accept:=true; + end + else + Accept:=false; +end; + +Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:File):Boolean; +var + s : longint; +begin + S:=DoAccept(Sock,addr); + if S>0 then + begin + Sock2File(S,SockIn,SockOut); + Accept:=true; + end + else + Accept:=false; +end; + +Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:text):Boolean; +begin + Connect:=DoConnect(Sock,addr); + If Connect then + Sock2Text(Sock,SockIn,SockOut); +end; + +Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:file):Boolean; +begin + Connect:=DoConnect(Sock,addr); + if Connect then + Sock2File(Sock,SockIn,SockOut); +end; + +Function CloseSocket (Sock:Longint):Longint; +begin + if fpclose(Sock)=0 then + CloseSocket := 0 else + CloseSocket := -1; +end; + + diff --git a/packages/rtl-extra/src/inc/stdsock.inc b/packages/rtl-extra/src/inc/stdsock.inc new file mode 100644 index 0000000000..e0df429134 --- /dev/null +++ b/packages/rtl-extra/src/inc/stdsock.inc @@ -0,0 +1,149 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 2004 by the Free Pascal development team + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + + +{$define uselibc:=cdecl; external;} + +const + {$ifdef BEOS} + {$ifdef HAIKU} + libname = 'network'; + {$else} + libname = 'net'; + {$endif} + {$else} + libname='c'; + {$endif} + +function cfpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; cdecl; external libname name 'accept'; +function cfpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; cdecl; external libname name 'bind'; +function cfpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; cdecl; external libname name 'connect'; +function cfpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint; cdecl; external libname name 'getpeername'; +function cfpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint; cdecl; external libname name 'getsockname'; +function cfpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint; cdecl; external libname name 'getsockopt'; +function cfplisten (s:cint; backlog : cint):cint; cdecl; external libname name 'listen'; +function cfprecv (s:cint; buf: pointer; len: size_t; flags: cint):ssize_t; cdecl; external libname name 'recv'; +function cfprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t; cdecl; external libname name 'recvfrom'; +//function cfprecvmsg (s:cint; msg: pmsghdr; flags:cint):ssize_t; cdecl; external libname name ''; +function cfpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t; cdecl; external libname name 'send'; +function cfpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t; cdecl; external libname name 'sendto'; +//function cfpsendmsg (s:cint; hdr: pmsghdr; flags:cint):ssize; cdecl; external libname name ''; +function cfpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen :tsocklen):cint; cdecl; external libname name 'setsockopt'; +function cfpshutdown (s:cint; how:cint):cint; cdecl; external libname name 'shutdown'; +function cfpsocket (domain:cint; xtype:cint; protocol: cint):cint; cdecl; external libname name 'socket'; + +{$if defined(BEOS) and not defined(HAIKU)} +// function unavailable under BeOS +{$else} +function cfpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; cdecl; external libname name 'socketpair'; +{$endif} + + +function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; + +begin + fpaccept:=cfpaccept(s,addrx,addrlen); + internal_socketerror:=fpgeterrno; +end; + +function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; +begin + fpbind:=cfpbind (s,addrx,addrlen); + internal_socketerror:=fpgeterrno; +end; + +function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; +begin + fpconnect:=cfpconnect (s,name,namelen); + internal_socketerror:=fpgeterrno; +end; + +function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpgetpeername:=cfpgetpeername (s,name,namelen); + internal_socketerror:=fpgeterrno; +end; + +function fpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpgetsockname:=cfpgetsockname(s,name,namelen); + internal_socketerror:=fpgeterrno; +end; + +function fpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint; +begin + fpgetsockopt:=cfpgetsockopt(s,level,optname,optval,optlen); + internal_socketerror:=fpgeterrno; +end; + +function fplisten (s:cint; backlog : cint):cint; +begin + fplisten:=cfplisten(s,backlog); + internal_socketerror:=fpgeterrno; +end; + +function fprecv (s:cint; buf: pointer; len: size_t; flags:cint):ssize_t; +begin + fprecv:= cfprecv (s,buf,len,flags); + internal_socketerror:=fpgeterrno; +end; + +function fprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t; +begin + fprecvfrom:= cfprecvfrom (s,buf,len,flags,from,fromlen); + internal_socketerror:=fpgeterrno; +end; + +function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t; +begin + fpsend:=cfpsend (s,msg,len,flags); + internal_socketerror:=fpgeterrno; +end; + +function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t; +begin + fpsendto:=cfpsendto (s,msg,len,flags,tox,tolen); + internal_socketerror:=fpgeterrno; +end; + +function fpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen :tsocklen):cint; +begin + fpsetsockopt:=cfpsetsockopt(s,level,optname,optval,optlen); + internal_socketerror:=fpgeterrno; +end; + +function fpshutdown (s:cint; how:cint):cint; +begin + fpshutdown:=cfpshutdown(s,how); + internal_socketerror:=fpgeterrno; +end; + +function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; +begin + fpsocket:=cfpsocket(domain,xtype,protocol); + internal_socketerror:=fpgeterrno; +end; + +{$if defined(BEOS) and not defined(HAIKU)} +// function unavailable under BeOS +function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; +begin + internal_socketerror:= -1; // TODO : check if it is an error +end; +{$else} +function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; +begin + fpsocketpair:=cfpsocketpair(d,xtype,protocol,sv); + internal_socketerror:=fpgeterrno; +end; +{$endif}
\ No newline at end of file diff --git a/packages/rtl-extra/src/linux/osdefs.inc b/packages/rtl-extra/src/linux/osdefs.inc new file mode 100644 index 0000000000..cfb86faec4 --- /dev/null +++ b/packages/rtl-extra/src/linux/osdefs.inc @@ -0,0 +1,87 @@ +{ + Copyright (c) 2000-2002 by Marco van de Voort + + Target dependent defines used when compileing the baseunix unit + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + ****************************************************************************} + +{$ifndef cpux86_64} + {$define usestime} // Use stime() syscall instead of settimeofday +{$endif} +{$define oldreaddir} // Keep using readdir system call instead + // of userland getdents stuff. +{$define usedomain} // Allow uname with "domain" entry. + // (which is a GNU extension) +{$ifdef FPC_USE_LIBC} + {$define usegetcwd} + {$if not defined(cpux86) and not defined(cpux86_64)} + {$linklib m} + {$endif} +{$endif} + +{$if defined(cpupowerpc) or defined(cpupowerpc64) or defined(cpui386) or + (defined(cpuarm) and defined(FPC_ABI_EABI))} + {$DEFINE has_ugetrlimit} +{$endif} + +{$if (defined(cpuarm) and defined(FPC_ABI_EABI))} + {$define FPC_USEGETTIMEOFDAY} + {$undef usestime} + + {$define NO_SYSCALL_TIME} + {$define NO_SYSCALL_UMOUNT} + {$define NO_SYSCALL_STIME} + {$define NO_SYSCALL_ALARM} + {$define NO_SYSCALL_UTIME} + {$define NO_SYSCALL_GETRLIMIT} + {$define NO_SYSCALL_SELECT} + {$define NO_SYSCALL_READDIR} + {$define NO_SYSCALL_MMAP} + {$define NO_SYSCALL_SOCKETCALL} + {$define NO_SYSCALL_SYSCALL} + {$define NO_SYSCALL_IPC} +{$endif} + + {$ifdef CPUARM} +{$define WAIT4} +{$endif CPUARM} + +{$ifdef CPUx86_64} +{$define WAIT4} +{$endif CPUx86_64} + +{$ifdef CPUSPARC} +{$define WAIT4} +{$endif CPUSPARC} + +{$ifdef cpui386} +{$define OLDMMAP} +{$endif cpui386} + +{$ifdef cpum68k} +{$define OLDMMAP} +{$endif cpum68k} + +{$ifdef cpuarm} + {$ifdef FPC_ABI_EABI} + {$define MMAP2} + {$else FPC_ABI_EABI} + {$define OLDMMAP} + {$endif FPC_ABI_EABI} +{$endif cpuarm} + diff --git a/packages/rtl-extra/src/linux/unixsock.inc b/packages/rtl-extra/src/linux/unixsock.inc new file mode 100644 index 0000000000..32fb02b303 --- /dev/null +++ b/packages/rtl-extra/src/linux/unixsock.inc @@ -0,0 +1,239 @@ +{ + This file is part of the Free Pascal run time library. + (c) 2004 by Marco van de Voort + member of the Free Pascal development team. + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + socket call implementations for Linux + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY;without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +} + +{$if not defined(cpux86_64) and not defined(NO_SYSCALL_SOCKETCALL)} + {$define NEED_SOCKETCALL} +{$endif} + +{****************************************************************************** + Basic Socket Functions +******************************************************************************} + +{$ifdef NEED_SOCKETCALL} + +Const + { + Arguments to the Linux Kernel system call for sockets. All + Socket Connected calls go through the same system call, + with an extra argument to determine what action to take. + } + Socket_Sys_SOCKET = 1; + Socket_Sys_BIND = 2; + Socket_Sys_CONNECT = 3; + Socket_Sys_LISTEN = 4; + Socket_Sys_ACCEPT = 5; + Socket_Sys_GETSOCKNAME = 6; + Socket_Sys_GETPEERNAME = 7; + Socket_Sys_SOCKETPAIR = 8; + Socket_Sys_SEND = 9; + Socket_Sys_RECV = 10; + Socket_Sys_SENDTO = 11; + Socket_Sys_RECVFROM = 12; + Socket_Sys_SHUTDOWN = 13; + Socket_Sys_SETSOCKOPT = 14; + Socket_Sys_GETSOCKOPT = 15; + Socket_Sys_SENDMSG = 16; + Socket_Sys_RECVMSG = 17; + + +Function SocketCall(SockCallNr,a1,a2,a3,a4,a5,a6:TSysParam):cint; inline; +var + Args:array[1..6] of TSysParam; +begin + args[1]:=a1; + args[2]:=a2; + args[3]:=a3; + args[4]:=a4; + args[5]:=a5; + args[6]:=a6; + SocketCall:=do_Syscall(syscall_nr_socketcall,sockcallnr,TSysParam(@args)); + internal_socketerror:=fpgeterrno; +end; + + +function SocketCall(SockCallNr,a1,a2,a3:TSysParam):cint;inline; +begin + SocketCall:=SocketCall(SockCallNr,a1,a2,a3,0,0,0); +end; + +function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; +begin + fpSocket:=SocketCall(Socket_Sys_socket,Domain,xtype,Protocol); +end; + +function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t; +begin + fpSend:=SocketCall(Socket_Sys_sendto,S,TSysParam(msg),Len,Flags,0,0); +end; + +function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t; +begin + fpSendto:=SocketCall(Socket_Sys_sendto,S,TSysParam(msg),Len,Flags,TSysParam(tox),tolen); +end; + +function fprecv (s:cint; buf: pointer; len: size_t; flags:cint):ssize_t; +begin + fpRecv:=SocketCall(Socket_Sys_Recvfrom,S,tsysparam(buf),len,flags,0,0); +end; + +function fprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t; +begin + fpRecvFrom:=SocketCall(Socket_Sys_Recvfrom,S,TSysParam(buf),len,flags,TSysParam(from),TSysParam(fromlen)); +end; + +function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; +begin + fpBind:=SocketCall(Socket_Sys_Bind,S,TSysParam(addrx),addrlen); +end; + +function fplisten (s:cint; backlog : cint):cint; +begin + fpListen:=SocketCall(Socket_Sys_Listen,S,backlog,0); +end; + +function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; +begin + fpAccept:=SocketCall(Socket_Sys_accept,S,TSysParam(addrx),TSysParam(addrlen)); +end; + +function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; +begin + fpConnect:=SocketCall(Socket_Sys_connect,S,TSysParam(name),namelen); +end; + +function fpshutdown (s:cint; how:cint):cint; +begin + fpShutDown:=SocketCall(Socket_Sys_shutdown,S,how,0); +end; + +function fpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpGetSockName:=SocketCall(Socket_Sys_GetSockName,S,TSysParam(name),TSysParam(namelen)); +end; + +function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpGetPeerName:=SocketCall(Socket_Sys_GetPeerName,S,TSysParam(name),TSysParam(namelen)); +end; + +function fpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : tsocklen):cint; +begin + fpSetSockOpt:=SocketCall(Socket_Sys_SetSockOpt,S,level,optname,TSysParam(optval),optlen,0); +end; + +function fpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint; +begin + fpGetSockOpt:=SocketCall(Socket_Sys_GetSockOpt,S,level,TSysParam(optname),TSysParam(optval),TSysParam(optlen),0); +end; + +function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; +begin + fpSocketPair:=SocketCall(Socket_Sys_SocketPair,d,xtype,protocol,TSysParam(sv),0,0); +end; + +{$else NEED_SOCKETCALL} + +function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; +begin + fpSocket:=do_syscall(syscall_nr_socket,Domain,xtype,Protocol); + internal_socketerror:=fpgeterrno; +end; + +function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t; +begin + fpSend:=do_syscall(syscall_nr_sendto,S,TSysParam(msg),Len,Flags,0,0); + internal_socketerror:=fpgeterrno; +end; + +function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t; +begin + fpSendto:=do_syscall(syscall_nr_sendto,S,TSysParam(msg),Len,Flags,TSysParam(tox),tolen); + internal_socketerror:=fpgeterrno; +end; + +function fprecv (s:cint; buf: pointer; len: size_t; flags:cint):ssize_t; +begin + fpRecv:=do_syscall(syscall_nr_Recvfrom,S,tsysparam(buf),len,flags,0,0); + internal_socketerror:=fpgeterrno; +end; + +function fprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t; +begin + fpRecvFrom:=do_syscall(syscall_nr_Recvfrom,S,TSysParam(buf),len,flags,TSysParam(from),TSysParam(fromlen)); + internal_socketerror:=fpgeterrno; +end; + +function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; +begin + fpBind:=do_syscall(syscall_nr_Bind,S,TSysParam(addrx),addrlen); + internal_socketerror:=fpgeterrno; +end; + +function fplisten (s:cint; backlog : cint):cint; +begin + fpListen:=do_syscall(syscall_nr_Listen,S,backlog); + internal_socketerror:=fpgeterrno; +end; + +function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; +begin + fpAccept:=do_syscall(syscall_nr_accept,S,TSysParam(addrx),TSysParam(addrlen)); + internal_socketerror:=fpgeterrno; +end; + +function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; +begin + fpConnect:=do_syscall(syscall_nr_connect,S,TSysParam(name),namelen); + internal_socketerror:=fpgeterrno; +end; + +function fpshutdown (s:cint; how:cint):cint; +begin + fpShutDown:=do_syscall(syscall_nr_shutdown,S,how); + internal_socketerror:=fpgeterrno; +end; + +function fpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpGetSockName:=do_syscall(syscall_nr_GetSockName,S,TSysParam(name),TSysParam(namelen)); + internal_socketerror:=fpgeterrno; +end; + +function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpGetPeerName:=do_syscall(syscall_nr_GetPeerName,S,TSysParam(name),TSysParam(namelen)); + internal_socketerror:=fpgeterrno; +end; + +function fpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : tsocklen):cint; +begin + fpSetSockOpt:=do_syscall(syscall_nr_SetSockOpt,S,level,optname,TSysParam(optval),optlen); + internal_socketerror:=fpgeterrno; +end; + +function fpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint; +begin + fpGetSockOpt:=do_syscall(syscall_nr_GetSockOpt,S,level,TSysParam(optname),TSysParam(optval),TSysParam(optlen)); + internal_socketerror:=fpgeterrno; +end; + +function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; +begin + fpSocketPair:=do_syscall(syscall_nr_SocketPair,d,xtype,protocol,TSysParam(sv)); + internal_socketerror:=fpgeterrno; +end; + +{$endif NEED_do_syscall} + diff --git a/packages/rtl-extra/src/linux/unixsockets.inc b/packages/rtl-extra/src/linux/unixsockets.inc new file mode 100644 index 0000000000..1d5eeaf7f0 --- /dev/null +++ b/packages/rtl-extra/src/linux/unixsockets.inc @@ -0,0 +1,34 @@ + +function CMSG_FIRSTHDR(mhdr: Pmsghdr): Pcmsghdr; +begin + if mhdr^.msg_controllen >= SizeOf(cmsghdr) then + Result:=mhdr^.msg_control + else + Result:=nil; +end; + +function CMSG_NXTHDR(mhdr: Pmsghdr; cmsg: Pcmsghdr): Pcmsghdr; +begin + Result:=__cmsg_nxthdr(mhdr, cmsg); +end; + +function CMSG_ALIGN(len: size_t): size_t; +begin + Result:=(len+SizeOf(size_t)-1) and (not(SizeOf(size_t)-1)); +end; + +function CMSG_SPACE(len: size_t): size_t; +begin + Result:=CMSG_ALIGN(len)+CMSG_ALIGN(SizeOf(cmsghdr)); +end; + +function CMSG_LEN(len: size_t): size_t; +begin + Result:=CMSG_ALIGN(SizeOf(cmsghdr))+len; +end; + +function CMSG_DATA(cmsg: Pointer): PByte; +begin + Result:=PByte(Cardinal(cmsg) + SizeOf(Pcmsghdr)); +end; + diff --git a/packages/rtl-extra/src/linux/unixsocketsh.inc b/packages/rtl-extra/src/linux/unixsocketsh.inc new file mode 100644 index 0000000000..4b492654b5 --- /dev/null +++ b/packages/rtl-extra/src/linux/unixsocketsh.inc @@ -0,0 +1,33 @@ +const + clib = 'c'; + +type + Pmsghdr = ^msghdr; + msghdr = record + msg_name : pointer; + msg_namelen : socklen_t; + msg_iov : piovec; + msg_iovlen : size_t; + msg_control : pointer; + msg_controllen : socklen_t; + msg_flags : cInt; + end; + + Pcmsghdr = ^cmsghdr; + cmsghdr = record + cmsg_len : socklen_t; + cmsg_level : cInt; + cmsg_type : cInt; + end; + + function sendmsg(__fd: cInt; __message: pmsghdr; __flags: cInt): ssize_t; cdecl; external clib name 'sendmsg'; + function recvmsg(__fd: cInt; __message: pmsghdr; __flags: cInt): ssize_t; cdecl; external clib name 'recvmsg'; + + function CMSG_FIRSTHDR(mhdr: Pmsghdr): Pcmsghdr; + function CMSG_NXTHDR(mhdr: Pmsghdr; cmsg: Pcmsghdr): Pcmsghdr; + function CMSG_ALIGN(len: size_t): size_t; + function CMSG_SPACE(len: size_t): size_t; + function CMSG_LEN(len: size_t): size_t; + function CMSG_DATA(cmsg : pcmsghdr) : Pbyte; + + diff --git a/packages/rtl-extra/src/linux/unxsockh.inc b/packages/rtl-extra/src/linux/unxsockh.inc new file mode 100644 index 0000000000..ccbad9a18d --- /dev/null +++ b/packages/rtl-extra/src/linux/unxsockh.inc @@ -0,0 +1,345 @@ +{ + This file is part of the Free Pascal run time library. + (c) 2000-2003 by Marco van de Voort + member of the Free Pascal development team. + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + socket call implementations for FreeBSD + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY;without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +} + +Const +{* Supported address families. *} + AF_UNSPEC = 0; + AF_UNIX = 1; { Unix domain sockets } + AF_LOCAL = 1; { POSIX name for AF_UNIX } + AF_INET = 2; { Internet IP Protocol } + AF_AX25 = 3; { Amateur Radio AX.25 } + AF_IPX = 4; { Novell IPX } + AF_APPLETALK = 5; { AppleTalk DDP } + AF_NETROM = 6; { Amateur Radio NET/ROM } + AF_BRIDGE = 7; { Multiprotocol bridge } + AF_ATMPVC = 8; { ATM PVCs } + AF_X25 = 9; { Reserved for X.25 project } + AF_INET6 = 10; { IP version 6 } + AF_ROSE = 11; { Amateur Radio X.25 PLP } + AF_DECnet = 12; { Reserved for DECnet project } + AF_NETBEUI = 13; { Reserved for 802.2LLC project} + AF_SECURITY = 14; { Security callback pseudo AF } + AF_KEY = 15; { PF_KEY key management API } + AF_NETLINK = 16; + AF_ROUTE = AF_NETLINK; { Alias to emulate 4.4BSD } + AF_PACKET = 17; { Packet family } + AF_ASH = 18; { Ash } + AF_ECONET = 19; { Acorn Econet } + AF_ATMSVC = 20; { ATM SVCs } + AF_SNA = 22; { Linux SNA Project (nutters!) } + AF_IRDA = 23; { IRDA sockets } + AF_PPPOX = 24; { PPPoX sockets } + AF_WANPIPE = 25; { Wanpipe API Sockets } + AF_LLC = 26; { Linux LLC } + AF_TIPC = 30; { TIPC sockets } + AF_BLUETOOTH = 31; { Bluetooth sockets } + AF_MAX = 32; { For now.. } + + SOCK_MAXADDRLEN = 255; { longest possible addresses } + +{ +* Protocol families, same as address families for now. +} + + PF_UNSPEC = AF_UNSPEC; + PF_UNIX = AF_UNIX; + PF_LOCAL = AF_LOCAL; + PF_INET = AF_INET; + PF_AX25 = AF_AX25; + PF_IPX = AF_IPX; + PF_APPLETALK = AF_APPLETALK; + PF_NETROM = AF_NETROM; + PF_BRIDGE = AF_BRIDGE; + PF_ATMPVC = AF_ATMPVC; + PF_X25 = AF_X25; + PF_INET6 = AF_INET6; + PF_ROSE = AF_ROSE; + PF_DECnet = AF_DECnet; + PF_NETBEUI = AF_NETBEUI; + PF_SECURITY = AF_SECURITY; + PF_KEY = AF_KEY; + PF_NETLINK = AF_NETLINK; + PF_ROUTE = AF_ROUTE; + PF_PACKET = AF_PACKET; + PF_ASH = AF_ASH; + PF_ECONET = AF_ECONET; + PF_ATMSVC = AF_ATMSVC; + PF_SNA = AF_SNA; + PF_IRDA = AF_IRDA; + PF_PPPOX = AF_PPPOX; + PF_WANPIPE = AF_WANPIPE; + PF_LLC = AF_LLC; + PF_TIPC = AF_TIPC; + PF_BLUETOOTH = AF_BLUETOOTH; + PF_MAX = AF_MAX; + + +{ Maximum queue length specifiable by listen. } + SOMAXCONN = 128; + +{ For setsockoptions(2) } + SOL_SOCKET = 1; + SO_DEBUG = 1; + SO_REUSEADDR= 2; + SO_TYPE = 3; + SO_ERROR = 4; + SO_DONTROUTE= 5; + SO_BROADCAST= 6; + SO_SNDBUF = 7; + SO_RCVBUF = 8; + SO_KEEPALIVE= 9; + SO_OOBINLINE= 10; + SO_NO_CHECK = 11; + SO_PRIORITY = 12; + SO_LINGER = 13; + SO_BSDCOMPAT= 14; +{ To add : SO_REUSEPORT 15 } + SO_PASSCRED= 16; + SO_PEERCRED= 17; + SO_RCVLOWAT= 18; + SO_SNDLOWAT= 19; + SO_RCVTIMEO= 20; + SO_SNDTIMEO= 21; + +{ Security levels - as per NRL IPv6 - don't actually do anything } + + SO_SECURITY_AUTHENTICATION = 22; + SO_SECURITY_ENCRYPTION_TRANSPORT= 23; + SO_SECURITY_ENCRYPTION_NETWORK = 24; + + SO_BINDTODEVICE= 25; + +{ Socket filtering } + + SO_ATTACH_FILTER= 26; + SO_DETACH_FILTER= 27; + SO_PEERNAME = 28; + SO_TIMESTAMP = 29; + SCM_TIMESTAMP = SO_TIMESTAMP; + SO_ACCEPTCONN = 30; + +// Following from kernel 2.6.14-1.1637_FC4 + + SHUT_RD = 0; { shut down the reading side } + SHUT_WR = 1; { shut down the writing side } + SHUT_RDWR = 2; { shut down both sides } + +//from /usr/include/netinet/in.h + + IPPROTO_IP = 0; { Dummy protocol for TCP. } + IPPROTO_HOPOPTS = 0; { IPv6 Hop-by-Hop options. } + + IPPROTO_ICMP = 1; { Internet Control Message Protocol. } + IPPROTO_IGMP = 2; { Internet Group Management Protocol. } + IPPROTO_IPIP = 4; { IPIP tunnels (older KA9Q tunnels use 94). } + IPPROTO_TCP = 6; { Transmission Control Protocol. } + IPPROTO_EGP = 8; { Exterior Gateway Protocol. } + + IPPROTO_PUP = 12; { PUP protocol. } + IPPROTO_UDP = 17; { User Datagram Protocol. } + IPPROTO_IDP = 22; { XNS IDP protocol. } + IPPROTO_TP = 29; { SO Transport Protocol Class 4. } + IPPROTO_IPV6 = 41; { IPv6 header. } + + IPPROTO_ROUTING = 43; { IPv6 routing header. } + IPPROTO_FRAGMENT = 44; { IPv6 fragmentation header. } + IPPROTO_RSVP = 46; { Reservation Protocol. } + IPPROTO_GRE = 47; { General Routing Encapsulation. } + IPPROTO_ESP = 50; { encapsulating security payload. } + IPPROTO_AH = 51; { authentication header. } + IPPROTO_ICMPV6 = 58; { ICMPv6. } + IPPROTO_NONE = 59; { IPv6 no next header. } + IPPROTO_DSTOPTS = 60; { IPv6 destination options. } + IPPROTO_MTP = 92; { Multicast Transport Protocol. } + IPPROTO_ENCAP = 98; { Encapsulation Header. } + IPPROTO_PIM = 103; { Protocol Independent Multicast. } + IPPROTO_COMP = 108; { Compression Header Protocol. } + IPPROTO_SCTP = 132; { Stream Control Transmission Protocol. } + IPPROTO_RAW = 255; { Raw IP packets. } + IPPROTO_MAX = 255; +//from /usr/include/bits/in.h +{ Options for use with getsockopt' and setsockopt' at the IP level. + The first word in the comment at the right is the data type used; + "bool" means a boolean value stored in an int'. } + + IP_OPTIONS = 4; { ip_opts; IP per-packet options. } + IP_HDRINCL = 3; { int; Header is included with data. } + IP_TOS = 1; { int; IP type of service and precedence. } + IP_TTL = 2; { int; IP time to live. } + IP_RECVOPTS = 6; { bool; Receive all IP options w/datagram. } +{ For BSD compatibility. } + IP_RETOPTS = 7; { ip_opts; Set/get IP per-packet options. } + IP_RECVRETOPTS = IP_RETOPTS; { bool; Receive IP options for response. } + + IP_MULTICAST_IF = 32; { in_addr; set/get IP multicast i/f } + IP_MULTICAST_TTL = 33; { u_char; set/get IP multicast ttl } + IP_MULTICAST_LOOP = 34; { i_char; set/get IP multicast loopback } + IP_ADD_MEMBERSHIP = 35; { ip_mreq; add an IP group membership } + IP_DROP_MEMBERSHIP = 36; { ip_mreq; drop an IP group membership } + IP_UNBLOCK_SOURCE = 37; { ip_mreq_source: unblock data from source } + IP_BLOCK_SOURCE = 38; { ip_mreq_source: block data from source } + IP_ADD_SOURCE_MEMBERSHIP = 39; { ip_mreq_source: join source group } + IP_DROP_SOURCE_MEMBERSHIP = 40; { ip_mreq_source: leave source group } + IP_MSFILTER = 41; + MCAST_JOIN_GROUP = 42; { group_req: join any-source group } + MCAST_BLOCK_SOURCE = 43; { group_source_req: block from given group } + MCAST_UNBLOCK_SOURCE = 44; { group_source_req: unblock from given group} + MCAST_LEAVE_GROUP = 45; { group_req: leave any-source group } + MCAST_JOIN_SOURCE_GROUP = 46; { group_source_req: join source-spec gr } + MCAST_LEAVE_SOURCE_GROUP = 47; { group_source_req: leave source-spec gr} + MCAST_MSFILTER = 48; + + MCAST_EXCLUDE = 0; + MCAST_INCLUDE = 1; + + IP_ROUTER_ALERT = 5; { bool } + IP_PKTINFO = 8; { bool } + IP_PKTOPTIONS = 9; + IP_PMTUDISC = 10; { obsolete name? } + IP_MTU_DISCOVER = 10; { int; see below } + IP_RECVERR = 11; { bool } + IP_RECVTTL = 12; { bool } + IP_RECVTOS = 13; { bool } + + +{ IP_MTU_DISCOVER arguments. } + IP_PMTUDISC_DONT = 0; { Never send DF frames. } + IP_PMTUDISC_WANT = 1; { Use per route hints. } + IP_PMTUDISC_DO = 2; { Always DF. } + +{ To select the IP level. } + SOL_IP = 0; + + IP_DEFAULT_MULTICAST_TTL = 1; + IP_DEFAULT_MULTICAST_LOOP = 1; + IP_MAX_MEMBERSHIPS = 20; + + +{ Options for use with getsockopt' and setsockopt' at the IPv6 level. + The first word in the comment at the right is the data type used; + "bool" means a boolean value stored in an int'. } + IPV6_ADDRFORM = 1; + IPV6_PKTINFO = 2; + IPV6_HOPOPTS = 3; + IPV6_DSTOPTS = 4; + IPV6_RTHDR = 5; + IPV6_RXSRCRT = IPV6_RTHDR; + //this may be an old name, I couldn't find it in my include files but + //I found it with google. It may have been depreciated because I only + //saw it in earlier files. + IPV6_PKTOPTIONS = 6; + IPV6_CHECKSUM = 7; + IPV6_HOPLIMIT = 8; + + SCM_SRCRT = IPV6_RXSRCRT; + + IPV6_NEXTHOP = 9; + IPV6_AUTHHDR = 10; + IPV6_UNICAST_HOPS = 16; + IPV6_MULTICAST_IF = 17; + IPV6_MULTICAST_HOPS = 18; + IPV6_MULTICAST_LOOP = 19; + IPV6_JOIN_GROUP = 20; + IPV6_LEAVE_GROUP = 21; + IPV6_ROUTER_ALERT = 22; + IPV6_MTU_DISCOVER = 23; + IPV6_MTU = 24; + IPV6_RECVERR = 25; + IPV6_V6ONLY = 26; + IPV6_JOIN_ANYCAST = 27; + IPV6_LEAVE_ANYCAST = 28; + IPV6_IPSEC_POLICY = 34; + IPV6_XFRM_POLICY = 35; + +{ Obsolete synonyms for the above. } + IPV6_ADD_MEMBERSHIP = IPV6_JOIN_GROUP; + IPV6_DROP_MEMBERSHIP = IPV6_LEAVE_GROUP; + IPV6_RXHOPOPTS = IPV6_HOPOPTS; + IPV6_RXDSTOPTS = IPV6_DSTOPTS; + +{ IPV6_MTU_DISCOVER values. } + IPV6_PMTUDISC_DONT = 0; { Never send DF frames. } + IPV6_PMTUDISC_WANT = 1; { Use per route hints. } + IPV6_PMTUDISC_DO = 2; { Always DF. } + +{ Socket level values for IPv6. } + SOL_IPV6 = 41; + SOL_ICMPV6 = 58; + +{ Routing header options for IPv6. } + IPV6_RTHDR_LOOSE = 0; { Hop doesn't need to be neighbour. } + IPV6_RTHDR_STRICT = 1; { Hop must be a neighbour. } + + IPV6_RTHDR_TYPE_0 = 0; { IPv6 Routing header type 0. } + + { Flags for send, recv etc. } + MSG_OOB = $0001; { Process out-of-band data} + MSG_PEEK = $0002; { Peek at incoming messages } + MSG_DONTROUTE= $0004; { Don't use local routing } + MSG_TRYHARD = MSG_DONTROUTE; + MSG_CTRUNC = $0008; { Control data lost before delivery } + MSG_PROXY = $0010; { Supply or ask second address } + MSG_TRUNC = $0020; + MSG_DONTWAIT = $0040; { Non-blocking I/O } + MSG_EOR = $0080; { End of record } + MSG_WAITALL = $0100; { Wait for a full request } + MSG_FIN = $0200; + MSG_SYN = $0400; + MSG_CONFIRM = $0800; { Confirm path validity } + MSG_RST = $1000; + MSG_ERRQUERE = $2000; { Fetch message from error queue } + MSG_NOSIGNAL = $4000; { Do not generate SIGPIPE } + MSG_MORE = $8000; { Sender will send more } + MSG_EOF = MSG_FIN; + + TCP_NODELAY = 1; + { Limit MSS } + TCP_MAXSEG = 2; + { Never send partially complete segments } + TCP_CORK = 3; + { Start keeplives after this period } + TCP_KEEPIDLE = 4; + { Interval between keepalives } + TCP_KEEPINTVL = 5; + { Number of keepalives before death } + TCP_KEEPCNT = 6; + { Number of SYN retransmits } + TCP_SYNCNT = 7; + { Life time of orphaned FIN-WAIT-2 state } + TCP_LINGER2 = 8; + { Wake up listener only when data arrive } + TCP_DEFER_ACCEPT = 9; + { Bound advertised window } + TCP_WINDOW_CLAMP = 10; + { Information about this connection. } + TCP_INFO = 11; + { Block/reenable quick acks } + TCP_QUICKACK = 12; + { Congestion control algorithm } + TCP_CONGESTION = 13; + { TCP MD5 Signature (RFC2385) } + TCP_MD5SIG = 14; + + UDP_CORK = 1; + { Set the socket to accept encapsulated packets } + UDP_ENCAP = 100; + { UDP encapsulation types } + { draft-ietf-ipsec-nat-t-ike-00/01 } + UDP_ENCAP_ESPINUDP_NON_IKE = 1; + { draft-ietf-ipsec-udp-encaps-06 } + UDP_ENCAP_ESPINUDP = 2; + { rfc2661 } + UDP_ENCAP_L2TPINUDP = 3; + diff --git a/packages/rtl-extra/src/morphos/sockets.pp b/packages/rtl-extra/src/morphos/sockets.pp new file mode 100644 index 0000000000..d0c99e29c7 --- /dev/null +++ b/packages/rtl-extra/src/morphos/sockets.pp @@ -0,0 +1,308 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2007 by the Free Pascal development team + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} +{$PACKRECORDS 2} +unit Sockets; +Interface + +Uses ctypes,exec; + +type + size_t = cuint32; { as definied in the C standard} + ssize_t = cint32; { used by function for returning number of bytes} + + socklen_t= cuint32; + TSocklen = socklen_t; + pSocklen = ^socklen_t; + + +//{ $i unxsockh.inc} +{$define BSD} +{$define SOCK_HAS_SINLEN} +{$i socketsh.inc} + +type + TUnixSockAddr = packed Record + sa_len : cuchar; + family : sa_family_t; + path:array[0..107] of char; //104 total for freebsd. + end; + +type + hostent = record + h_name : PChar; + h_aliases : PPChar; + h_addrtype : LongInt; + h_Length : LongInt; + h_addr_list: ^PDWord; + end; + THostEnt = hostent; + PHostEnt = ^THostEnt; + + +const + AF_UNSPEC = 0; {* unspecified *} + AF_LOCAL = 1; {* local to host (pipes, portals) *} + AF_UNIX = AF_LOCAL; {* backward compatibility *} + AF_INET = 2; {* internetwork: UDP, TCP, etc. *} + AF_IMPLINK = 3; {* arpanet imp addresses *} + AF_PUP = 4; {* pup protocols: e.g. BSP *} + AF_CHAOS = 5; {* mit CHAOS protocols *} + AF_NS = 6; {* XEROX NS protocols *} + AF_ISO = 7; {* ISO protocols *} + AF_OSI = AF_ISO; + AF_ECMA = 8; {* european computer manufacturers *} + AF_DATAKIT = 9; {* datakit protocols *} + AF_CCITT = 10; {* CCITT protocols, X.25 etc *} + AF_SNA = 11; {* IBM SNA *} + AF_DECnet = 12; {* DECnet *} + AF_DLI = 13; {* DEC Direct data link interface *} + AF_LAT = 14; {* LAT *} + AF_HYLINK = 15; {* NSC Hyperchannel *} + AF_APPLETALK = 16; {* Apple Talk *} + AF_ROUTE = 17; {* Internal Routing Protocol *} + AF_LINK = 18; {* Link layer interface *} + pseudo_AF_XTP = 19; {* eXpress Transfer Protocol (no AF) *} + AF_COIP = 20; {* connection-oriented IP, aka ST II *} + AF_CNT = 21; {* Computer Network Technology *} + pseudo_AF_RTIP = 22; {* Help Identify RTIP packets *} + AF_IPX = 23; {* Novell Internet Protocol *} + AF_SIP = 24; {* Simple Internet Protocol *} + pseudo_AF_PIP = 25; {* Help Identify PIP packets *} + + AF_MAX = 26; + + +const + EsockEINTR = 4; // EsysEINTR; + EsockEBADF = 9; // EsysEBADF; + EsockEFAULT = 14; // EsysEFAULT; + EsockEINVAL = 22; //EsysEINVAL; + EsockEACCESS = 13; //ESysEAcces; + EsockEMFILE = 24; //ESysEmfile; + EsockENOBUFS = 55; //ESysENoBufs; + EsockENOTCONN = 57; //ESysENotConn; + EsockEPROTONOSUPPORT = 43; //ESysEProtoNoSupport; + EsockEWOULDBLOCK = 35; //ESysEWouldBlock; // same as eagain on morphos + +{ unix socket specific functions } +{* +Procedure Str2UnixSockAddr(const addr:string;var t:TUnixSockAddr;var len:longint); deprecated; +Function Bind(Sock:longint;const addr:string):boolean; deprecated; +Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:text):Boolean; deprecated; +Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:file):Boolean; deprecated; +Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:text):Boolean; deprecated; +Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:File):Boolean; deprecated; +*} +//function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; maybelibc +//function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; maybelibc +//function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; maybelibc + +var SocketBase : pLibrary; + +function bsd_socket(domain : LongInt location 'd0'; type_ : LongInt location 'd1'; protocol : LongInt location 'd2') : LongInt; syscall legacy SocketBase 030; +function bsd_bind(s : LongInt location 'd0'; const name : psockaddr location 'a0'; namelen : LongInt location 'd1') : LongInt; syscall legacy SocketBase 036; +function bsd_listen(s : LongInt location 'd0'; backlog : LongInt location 'd1') : LongInt; syscall legacy SocketBase 042; +function bsd_accept(s : LongInt location 'd0'; addr : psockaddr location 'a0'; var addrlen : LongInt location 'a1') : LongInt; syscall legacy SocketBase 048; +function bsd_connect(s : LongInt location 'd0'; const name : psockaddr location 'a0'; namelen : LongInt location 'd1') : LongInt; syscall legacy SocketBase 054; +function bsd_sendto(s : LongInt location 'd0'; const msg : pChar location 'a0'; len : LongInt location 'd1'; flags : LongInt location 'd2'; const to_ : psockaddr location 'a1'; tolen : LongInt location 'd3') : LongInt; syscall legacy SocketBase 060; +function bsd_send(s : LongInt location 'd0'; const msg : pChar location 'a0'; len : LongInt location 'd1'; flags : LongInt location 'd2') : LongInt; syscall legacy SocketBase 066; +function bsd_recvfrom(s : LongInt location 'd0'; buf : pChar location 'a0'; len : LongInt location 'd1'; flags : LongInt location 'd2'; from : psockaddr location 'a1'; var fromlen : LongInt location 'a2') : LongInt; syscall legacy SocketBase 072; +function bsd_recv(s : LongInt location 'd0'; buf : pChar location 'a0'; len : LongInt location 'd1'; flags : LongInt location 'd2') : LongInt; syscall legacy SocketBase 078; +function bsd_shutdown(s : LongInt location 'd0'; how : LongInt location 'd1') : LongInt; syscall legacy SocketBase 084; +function bsd_closesocket(d : LongInt location 'd0') : LongInt; syscall legacy SocketBase 120; +function bsd_inet_ntoa(in_ : DWord location 'd0') : pChar; syscall legacy SocketBase 174; +function bsd_inet_addr(const cp : pChar location 'a0') : DWord; syscall legacy SocketBase 180; +function bsd_gethostbyname(const name : pChar location 'a0') : phostent; syscall legacy SocketBase 210; +function bsd_gethostbyaddr(const addr : pChar location 'a0'; len : LongInt location 'd0'; type_ : LongInt location 'd1') : phostent; syscall legacy SocketBase 216; + + +Implementation + +//Uses {$ifndef FPC_USE_LIBC}SysCall{$else}initc{$endif}; + +threadvar internal_socketerror : cint; + +{****************************************************************************** + Kernel Socket Callings +******************************************************************************} + +function socketerror:cint; + +begin + socketerror:=internal_socketerror; +end; + +//{$define uselibc:=cdecl; external;} + +//const libname='c'; +{ +function cfpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; cdecl; external libname name 'accept'; +function cfpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; cdecl; external libname name 'bind'; +function cfpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; cdecl; external libname name 'connect'; +function cfpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint; cdecl; external libname name 'getpeername'; +function cfpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint; cdecl; external libname name 'getsockname'; +function cfpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint; cdecl; external libname name 'getsockopt'; +function cfplisten (s:cint; backlog : cint):cint; cdecl; external libname name 'listen'; +function cfprecv (s:cint; buf: pointer; len: size_t; flags: cint):ssize_t; cdecl; external libname name 'recv'; +function cfprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t; cdecl; external libname name 'recvfrom'; +//function cfprecvmsg (s:cint; msg: pmsghdr; flags:cint):ssize_t; cdecl; external libname name ''; +function cfpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t; cdecl; external libname name 'send'; +function cfpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t; cdecl; external libname name 'sendto'; +//function cfpsendmsg (s:cint; hdr: pmsghdr; flags:cint):ssize; cdecl; external libname name ''; +function cfpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen :tsocklen):cint; cdecl; external libname name 'setsockopt'; +function cfpshutdown (s:cint; how:cint):cint; cdecl; external libname name 'shutdown'; +function cfpsocket (domain:cint; xtype:cint; protocol: cint):cint; cdecl; external libname name 'socket'; +function cfpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; cdecl; external libname name 'socketpair'; +} + +function cfpaccept(s : LongInt location 'd0'; addr : psockaddr location 'a0'; addrlen : pSocklen location 'a1') : LongInt; syscall legacy SocketBase 048; +function cfpbind(s : LongInt location 'd0'; const name : psockaddr location 'a0'; namelen : LongInt location 'd1') : LongInt; syscall legacy SocketBase 036; +function cfpconnect(s : LongInt location 'd0'; const name : psockaddr location 'a0'; namelen : LongInt location 'd1') : LongInt; syscall legacy SocketBase 054; +function cfpsendto(s : LongInt location 'd0'; const msg : pChar location 'a0'; len : LongInt location 'd1'; flags : LongInt location 'd2'; const to_ : psockaddr location 'a1'; tolen : LongInt location 'd3') : LongInt; syscall legacy SocketBase 060; +function cfpsend(s : LongInt location 'd0'; const msg : pChar location 'a0'; len : LongInt location 'd1'; flags : LongInt location 'd2') : LongInt; syscall legacy SocketBase 066; +function cfprecvfrom(s : LongInt location 'd0'; buf : pChar location 'a0'; len : LongInt location 'd1'; flags : LongInt location 'd2'; from : psockaddr location 'a1'; fromlen : pSockLen location 'a2') : LongInt; syscall legacy SocketBase 072; +function cfprecv(s : LongInt location 'd0'; buf : pChar location 'a0'; len : LongInt location 'd1'; flags : LongInt location 'd2') : LongInt; syscall legacy SocketBase 078; +function cfpgetsockopt(s : LongInt location 'd0'; level : LongInt location 'd1'; optname : LongInt location 'd2'; optval : Pointer location 'a0'; optlen : pSockLen location 'a1') : LongInt; syscall legacy SocketBase 096; +function cfpgetsockname(s : LongInt location 'd0'; hostname : psockaddr location 'a0'; namelen : pSockLen location 'a1') : LongInt; syscall legacy SocketBase 102; +function cfpgetpeername(s : LongInt location 'd0'; hostname : psockaddr location 'a0'; namelen : pSockLen location 'a1') : LongInt; syscall legacy SocketBase 108; +function cfpsetsockopt(s : LongInt location 'd0'; level : LongInt location 'd1'; optname : LongInt location 'd2'; const optval : Pointer location 'a0'; optlen : LongInt location 'd3') : LongInt; syscall legacy SocketBase 090; +function cfplisten(s : LongInt location 'd0'; backlog : LongInt location 'd1') : LongInt; syscall legacy SocketBase 042; +function cfpsocket(domain : LongInt location 'd0'; type_ : LongInt location 'd1'; protocol : LongInt location 'd2') : LongInt; syscall legacy SocketBase 030; +function cfpshutdown(s : LongInt location 'd0'; how : LongInt location 'd1') : LongInt; syscall legacy SocketBase 084; +function cfpCloseSocket(d : LongInt location 'd0') : LongInt; syscall legacy SocketBase 120; + +function cfpErrno : LongInt; syscall legacy SocketBase 162; + +function fpgeterrno: longint; inline; +begin + fpgeterrno:=cfpErrno; +end; + +function fpClose(d: LongInt): LongInt; inline; +begin + fpClose:=cfpCloseSocket(d); +end; + +function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; + +begin + fpaccept:=cfpaccept(s,addrx,addrlen); + internal_socketerror:=fpgeterrno; +end; + +function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; +begin + fpbind:=cfpbind (s,addrx,addrlen); + internal_socketerror:=fpgeterrno; +end; + +function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; +begin + fpconnect:=cfpconnect (s,name,namelen); + internal_socketerror:=fpgeterrno; +end; + +function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpgetpeername:=cfpgetpeername (s,name,namelen); + internal_socketerror:=fpgeterrno; +end; + +function fpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpgetsockname:=cfpgetsockname(s,name,namelen); + internal_socketerror:=fpgeterrno; +end; + +function fpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint; +begin + fpgetsockopt:=cfpgetsockopt(s,level,optname,optval,optlen); + internal_socketerror:=fpgeterrno; +end; + +function fplisten (s:cint; backlog : cint):cint; +begin + fplisten:=cfplisten(s,backlog); + internal_socketerror:=fpgeterrno; +end; + +function fprecv (s:cint; buf: pointer; len: size_t; flags:cint):ssize_t; +begin + fprecv:= cfprecv (s,buf,len,flags); + internal_socketerror:=fpgeterrno; +end; + +function fprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t; +begin + fprecvfrom:= cfprecvfrom (s,buf,len,flags,from,fromlen); + internal_socketerror:=fpgeterrno; +end; + +function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t; +begin + fpsend:=cfpsend (s,msg,len,flags); + internal_socketerror:=fpgeterrno; +end; + +function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t; +begin + fpsendto:=cfpsendto (s,msg,len,flags,tox,tolen); + internal_socketerror:=fpgeterrno; +end; + +function fpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen :tsocklen):cint; +begin + fpsetsockopt:=cfpsetsockopt(s,level,optname,optval,optlen); + internal_socketerror:=fpgeterrno; +end; + +function fpshutdown (s:cint; how:cint):cint; +begin + fpshutdown:=cfpshutdown(s,how); + internal_socketerror:=fpgeterrno; +end; + +function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; +begin + fpsocket:=cfpsocket(domain,xtype,protocol); + internal_socketerror:=fpgeterrno; +end; + + +function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; +begin +{ + fpsocketpair:=cfpsocketpair(d,xtype,protocol,sv); + internal_socketerror:=fpgeterrno; +} + fpsocketpair:=-1; +end; + + +{$i sockovl.inc} +{$i sockets.inc} + +// FIXME: this doesn't make any sense here, because SocketBase should be task-specific +// but FPC doesn't support that yet (TODO) +{$WARNING FIX ME, TODO} + +initialization + + SocketBase:=NIL; + SocketBase:=OpenLibrary('bsdsocket.library',4); + +finalization + + if (SocketBase<>NIL) then CloseLibrary(SocketBase); + +end. diff --git a/packages/rtl-extra/src/netware/netwsockh.inc b/packages/rtl-extra/src/netware/netwsockh.inc new file mode 100644 index 0000000000..7a43a3f7ce --- /dev/null +++ b/packages/rtl-extra/src/netware/netwsockh.inc @@ -0,0 +1,58 @@ +const + AF_UNSPEC = winsock.AF_UNSPEC; + AF_UNIX = winsock.AF_UNIX; + AF_INET = winsock.AF_INET; + AF_IMPLINK = winsock.AF_IMPLINK; + AF_PUP = winsock.AF_PUP; + AF_CHAOS = winsock.AF_CHAOS; + AF_NS = winsock.AF_NS; + AF_IPX = winsock.AF_IPX; + AF_ISO = winsock.AF_ISO; + AF_OSI = winsock.AF_OSI; + AF_ECMA = winsock.AF_ECMA; + AF_DATAKIT = winsock.AF_DATAKIT; + AF_CCITT = winsock.AF_CCITT; + AF_SNA = winsock.AF_SNA; + AF_DECnet = winsock.AF_DECnet; + AF_DLI = winsock.AF_DLI; + AF_LAT = winsock.AF_LAT; + AF_HYLINK = winsock.AF_HYLINK; + AF_APPLETALK = winsock.AF_APPLETALK; + AF_VOICEVIEW = winsock.AF_VOICEVIEW; + AF_FIREFOX = winsock.AF_FIREFOX; + AF_UNKNOWN1 = winsock.AF_UNKNOWN1; + AF_BAN = winsock.AF_BAN; + AF_ATM = winsock.AF_ATM; + AF_INET6 = winsock.AF_INET6; + AF_MAX = winsock.AF_MAX; + + PF_UNSPEC = AF_UNSPEC; + PF_UNIX = AF_UNIX; + PF_INET = AF_INET; + PF_IMPLINK = AF_IMPLINK; + PF_PUP = AF_PUP; + PF_CHAOS = AF_CHAOS; + PF_NS = AF_NS; + PF_IPX = AF_IPX; + PF_ISO = AF_ISO; + PF_OSI = AF_OSI; + PF_ECMA = AF_ECMA; + PF_DATAKIT = AF_DATAKIT; + PF_CCITT = AF_CCITT; + PF_SNA = AF_SNA; + PF_DECnet = AF_DECnet; + PF_DLI = AF_DLI; + PF_LAT = AF_LAT; + PF_HYLINK = AF_HYLINK; + PF_APPLETALK = AF_APPLETALK; + PF_VOICEVIEW = AF_VOICEVIEW; + PF_FIREFOX = AF_FIREFOX; + PF_UNKNOWN1 = AF_UNKNOWN1; + PF_BAN = AF_BAN; + PF_ATM = AF_ATM; + PF_INET6 = AF_INET6; + PF_MAX = AF_MAX; + + INVALID_SOCKET = -1; + SOCKET_ERROR = -1; + diff --git a/packages/rtl-extra/src/netware/sockets.pp b/packages/rtl-extra/src/netware/sockets.pp new file mode 100644 index 0000000000..640135c0a4 --- /dev/null +++ b/packages/rtl-extra/src/netware/sockets.pp @@ -0,0 +1,299 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2000 by the Free Pascal development team + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +{$mode objfpc} +unit Sockets; + +Interface + +{$macro on} +{$define maybelibc:=} + +{$R-} + +Uses + winsock; + +Type + cushort=word; + cuint8 =byte; + cuint16=word; + cuint32=cardinal; + size_t =cuint32; + ssize_t=cuint16; + cint =longint; + pcint =^cint; + tsocklen=cint; + psocklen=^tsocklen; + +const + EsockEINTR = WSAEINTR; + EsockEBADF = WSAEBADF; + EsockEFAULT = WSAEFAULT; + EsockEINVAL = WSAEINVAL; + EsockEACCESS = WSAEACCES; + EsockEMFILE = WSAEMFILE; + EsockEMSGSIZE = WSAEMSGSIZE; + EsockENOBUFS = WSAENOBUFS; + EsockENOTCONN = WSAENOTCONN; + EsockENOTSOCK = WSAENOTSOCK; + EsockEPROTONOSUPPORT = WSAEPROTONOSUPPORT; + EsockEWOULDBLOCK = WSAEWOULDBLOCK; + +{$i netwsockh.inc} +{$i socketsh.inc} + +Implementation + +{****************************************************************************** + Basic Socket Functions +******************************************************************************} + + + +//function fprecvmsg (s:cint; msg: pmsghdr; flags:cint):ssize_t; +//function fpsendmsg (s:cint; hdr: pmsghdr; flags:cint):ssize; + +//function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; + + +function SocketError: cint; +begin + SocketError := WSAGetLastError; +end; + +function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; +begin + fpSocket:=WinSock.Socket(Domain,xtype,ProtoCol); +end; + +function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t; +begin + fpSend:=WinSock.Send(S,msg,len,flags); +end; + +function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t; +begin + // Dubious construct, this should be checked. (IPV6 fails ?) + fpSendTo:=WinSock.SendTo(S,msg,Len,Flags,Winsock.TSockAddr(tox^),toLen); +end; + +function fprecv (s:cint; buf: pointer; len: size_t; flags: cint):ssize_t; +begin + fpRecv:=WinSock.Recv(S,Buf,Len,Flags); +end; + +function fprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t; +begin + fpRecvFrom:=WinSock.RecvFrom(S,Buf,Len,Flags,Winsock.TSockAddr(from^),FromLen^); +end; + +function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; +begin + fpConnect:=WinSock.Connect(S,WinSock.TSockAddr(name^),nameLen); +end; + +function fpshutdown (s:cint; how:cint):cint; +begin + fpShutDown:=WinSock.ShutDown(S,How); +end; + +Function socket(Domain,SocketType,Protocol:Longint):Longint; +begin + socket:=fpsocket(Domain,sockettype,protocol); +end; + +Function Send(Sock:Longint;Const Buf;BufLen,Flags:Longint):Longint; +begin + send:=fpsend(sock,@buf,buflen,flags); +end; + +Function SendTo(Sock:Longint;Const Buf;BufLen,Flags:Longint;Var Addr; AddrLen : Longint):Longint; +begin + sendto:=fpsendto(sock,@buf,buflen,flags,@addr,addrlen); +end; + +Function Recv(Sock:Longint;Var Buf;BufLen,Flags:Longint):Longint; +begin + Recv:=fpRecv(Sock,@Buf,BufLen,Flags); +end; + +Function RecvFrom(Sock : Longint; Var Buf; Buflen,Flags : Longint; Var Addr; var AddrLen : longint) : longint; +begin + RecvFrom:=fpRecvFrom(Sock,@Buf,BufLen,Flags,@Addr,@AddrLen); +end; + +function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; +begin + fpbind:=WinSock.Bind(S,WinSock.PSockAddr(Addrx),AddrLen); +end; + +function fplisten (s:cint; backlog : cint):cint; +begin + fplisten:=WinSock.Listen(S,backlog); +end; + +function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; +begin + fpAccept:=WinSock.Accept(S,WinSock.PSockAddr(Addrx),plongint(AddrLen)); +end; + +function fpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpGetSockName:=WinSock.GetSockName(S,WinSock.TSockAddr(name^),nameLen^); +end; + +function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpGetPeerName:=WinSock.GetPeerName(S,WinSock.TSockAddr(name^),NameLen^); +end; + +function fpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint; +begin + fpGetSockOpt:=WinSock.GetSockOpt(S,Level,OptName,OptVal,OptLen^); +end; + +function fpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen :tsocklen):cint; +begin + fpSetSockOpt:=WinSock.SetSockOpt(S,Level,OptName,OptVal,OptLen); +end; + +function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; +begin + fpSocketPair := -1; +end; + +Function CloseSocket(Sock:Longint):Longint; +begin + CloseSocket := Winsock.CloseSocket (Sock); +end; + +Function Bind(Sock:Longint;Const Addr;AddrLen:Longint):Boolean; +begin + Bind:=fpBind(Sock,@Addr,AddrLen)=0; +end; + +Function Listen(Sock,MaxConnect:Longint):Boolean; +begin + Listen:=fplisten(Sock,MaxConnect)=0; +end; + +Function Accept(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + Accept:=FPAccept(sock,@addr,@addrlen); +end; + +Function Shutdown(Sock:Longint;How:Longint):Longint; +begin + Shutdown:=fpshutdown(sock,how); +end; + +Function Connect(Sock:Longint;Const Addr;Addrlen:Longint):Boolean; +begin + Connect:=fpconnect(sock,@addr,addrlen)=0; +end; + +Function GetSocketName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + GetSocketName:=fpGetSockName(sock,@addr,@addrlen); +end; + +Function GetPeerName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + GetPeerName:=fpGetPeerName(Sock,@addr,@addrlen); +end; + +Function GetSocketOptions(Sock,Level,OptName:Longint;Var OptVal;Var optlen:longint):Longint; +begin + GetSocketOptions:=fpGetSockOpt(sock,level,optname,@optval,@optlen); +end; + +Function SetSocketOptions(Sock,Level,OptName:Longint;Const OptVal;optlen:longint):Longint; +begin + SetSocketOptions:=fpsetsockopt(sock,level,optname,@optval,optlen); +end; + +Function SocketPair(Domain,SocketType,Protocol:Longint;var Pair:TSockArray):Longint; +begin + // SocketPair:=SocketCall(Socket_Sys_SocketPair,Domain,SocketType,Protocol,longint(@Pair),0,0); + SocketPair := -1; +end; + + +{$ifdef unix} +{ mimic the linux fpWrite/fpRead calls for the file/text socket wrapper } +function fpWrite(handle : longint;Const bufptr;size : dword) : dword; +begin + fpWrite := dword(WinSock.send(handle, bufptr, size, 0)); + if fpWrite = dword(SOCKET_ERROR) then + fpWrite := 0; +end; + +function fpRead(handle : longint;var bufptr;size : dword) : dword; +var + d : dword; +begin + if ioctlsocket(handle,FIONREAD,@d) = SOCKET_ERROR then + begin + fpRead:=0; + exit; + end; + if d>0 then + begin + if size>d then + size:=d; + fpRead := dword(WinSock.recv(handle, bufptr, size, 0)); + if fpRead = dword(SOCKET_ERROR) then + fpRead := 0; + end; +end; +{$else} +{ mimic the linux fpWrite/fpRead calls for the file/text socket wrapper } +function fpWrite(handle : longint;Const bufptr;size : dword) : dword; +begin + fpWrite := dword(WinSock.send(handle, bufptr, size, 0)); + if fpWrite = dword(SOCKET_ERROR) then + fpWrite := 0; +end; + +function fpRead(handle : longint;var bufptr;size : dword) : dword; +var + d : dword; +begin + if ioctlsocket(handle,FIONREAD,@d) = SOCKET_ERROR then + begin + fpRead:=0; + exit; + end; + if d>0 then + begin + if size>d then + size:=d; + fpRead := dword(WinSock.recv(handle, bufptr, size, 0)); + if fpRead = dword(SOCKET_ERROR) then + fpRead := 0; + end; +end; +{$endif} + +{$i sockets.inc} + +{ winsocket stack needs an init. and cleanup code } +var + wsadata : twsadata; + +initialization + WSAStartUp($2,wsadata); +finalization + WSACleanUp; +end. diff --git a/packages/rtl-extra/src/netwcomn/qos.inc b/packages/rtl-extra/src/netwcomn/qos.inc new file mode 100644 index 0000000000..ac8a8b031f --- /dev/null +++ b/packages/rtl-extra/src/netwcomn/qos.inc @@ -0,0 +1,288 @@ +{ + This file is part of the Free Pascal run time library. + This unit contains the declarations for the WinSock2 + Socket Library for Netware and Win32 + + Copyright (c) 1999-2002 by the Free Pascal development team + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + + { This module defines the Quality of Service structures and types used + by Winsock applications. } + + { + Definitions for valued-based Service Type for each direction of data flow. + } + + type + + SERVICETYPE = u_long; + { No data in this direction } + + const + SERVICETYPE_NOTRAFFIC = $00000000; + { Best Effort } + SERVICETYPE_BESTEFFORT = $00000001; + { Controlled Load } + SERVICETYPE_CONTROLLEDLOAD = $00000002; + { Guaranteed } + SERVICETYPE_GUARANTEED = $00000003; + { Used to notify + change to user } + SERVICETYPE_NETWORK_UNAVAILABLE = $00000004; + { corresponds to + "General Parameters" + defined by IntServ } + SERVICETYPE_GENERAL_INFORMATION = $00000005; + { used to indicate + that the flow spec + contains no change + from any previous + one } + SERVICETYPE_NOCHANGE = $00000006; + { Non-Conforming Traffic } + SERVICETYPE_NONCONFORMING = $00000009; + { Custom ServiceType 1 } + SERVICETYPE_CUSTOM1 = $0000000A; + { Custom ServiceType 2 } + SERVICETYPE_CUSTOM2 = $0000000B; + { Custom ServiceType 3 } + SERVICETYPE_CUSTOM3 = $0000000C; + { Custom ServiceType 4 } + SERVICETYPE_CUSTOM4 = $0000000D; + { + Definitions for bitmap-based Service Type for each direction of data flow. + } + SERVICE_BESTEFFORT = $80020000; + SERVICE_CONTROLLEDLOAD = $80040000; + SERVICE_GUARANTEED = $80080000; + SERVICE_CUSTOM1 = $80100000; + SERVICE_CUSTOM2 = $80200000; + SERVICE_CUSTOM3 = $80400000; + SERVICE_CUSTOM4 = $80800000; + { + Number of available Service Types. + } + NUM_SERVICETYPES = 8; + { + to turn on immediate traffic control, OR ( | ) this flag with the + ServiceType field in the FLOWSPEC + } + { #define SERVICE_IMMEDIATE_TRAFFIC_CONTROL 0x80000000 // obsolete } + SERVICE_NO_TRAFFIC_CONTROL = $81000000; + { + this flag can be used with the immediate traffic control flag above to + prevent any rsvp signaling messages from being sent. Local traffic + control will be invoked, but no RSVP Path messages will be sent.This flag + can also be used in conjunction with a receiving flowspec to suppress + the automatic generation of a Reserve message. The application would + receive notification that a Path message had arrived and would then need + to alter the QOS by issuing WSAIoctl( SIO_SET_QOS ), to unset this flag + and thereby cause Reserve messages to go out. + } + SERVICE_NO_QOS_SIGNALING = $40000000; + { rsvp status code } + STATUS_QOS_RELEASED = $10101010; + { + Flow Specifications for each direction of data flow. + } + { In Bytes/sec } + { In Bytes } + { In Bytes/sec } + { In microseconds } + { In microseconds } + { In Bytes } + { In Bytes } + + type + + Tflowspec = record + TokenRate : u_long; + TokenBucketSize : u_long; + PeakBandwidth : u_long; + Latency : u_long; + DelayVariation : u_long; + ServiceType : SERVICETYPE; + MaxSduSize : u_long; + MinimumPolicedSize : u_long; + end; + PFLOWSPEC = ^Tflowspec; + LPFLOWSPEC = ^Tflowspec; + { + this value can be used in the FLOWSPEC structure to instruct the Rsvp Service + provider to derive the appropriate default value for the parameter. Note + that not all values in the FLOWSPEC structure can be defaults. In the + ReceivingFlowspec, all parameters can be defaulted except the ServiceType. + In the SendingFlowspec, the MaxSduSize and MinimumPolicedSize can be + defaulted. Other defaults may be possible. Refer to the appropriate + documentation. + } + + const + QOS_NOT_SPECIFIED = $FFFFFFFF; + NULL_QOS_TYPE = $FFFFFFFD; + { + define a value that can be used for the PeakBandwidth, which will map into + positive infinity when the FLOWSPEC is converted into IntServ floating point + format. We can't use (-1) because that value was previously defined to mean + "select the default". + } + POSITIVE_INFINITY_RATE = $FFFFFFFE; + { + the provider specific structure can have a number of objects in it. + Each next structure in the + ProviderSpecific will be the QOS_OBJECT_HDR struct that prefaces the actual + data with a type and length for that object. This QOS_OBJECT struct can + repeat several times if there are several objects. This list of objects + terminates either when the buffer length has been reached ( WSABUF ) or + an object of type QOS_END_OF_LIST is encountered. + } + { the length of object buffer INCLUDING + this header } + + type + + TQOS_OBJECT_HDR = record + ObjectType : u_long; + ObjectLength : u_long; + end; + LPQOS_OBJECT_HDR = ^TQOS_OBJECT_HDR; + PQOS_OBJECT_HDR = ^TQOS_OBJECT_HDR; + { + general QOS objects start at this offset from the base and have a range + of 1000 + } + + const + QOS_GENERAL_ID_BASE = 2000; + QOS_OBJECT_PRIORITY = $00000000 + QOS_GENERAL_ID_BASE; + { QOS_PRIORITY structure passed } + QOS_OBJECT_END_OF_LIST = $00000001 + QOS_GENERAL_ID_BASE; + { QOS_End_of_list structure passed } + QOS_OBJECT_SD_MODE = $00000002 + QOS_GENERAL_ID_BASE; + { QOS_ShapeDiscard structure passed } + QOS_OBJECT_TRAFFIC_CLASS = $00000003 + QOS_GENERAL_ID_BASE; + { QOS_Traffic class structure passed } + QOS_OBJECT_DESTADDR = $00000004 + QOS_GENERAL_ID_BASE; + { QOS_DestAddr structure } + QOS_OBJECT_SHAPER_QUEUE_DROP_MODE = $00000005 + QOS_GENERAL_ID_BASE; + { QOS_ShaperQueueDropMode structure } + QOS_OBJECT_SHAPER_QUEUE_LIMIT = $00000006 + QOS_GENERAL_ID_BASE; + { QOS_ShaperQueueLimit structure } + { + This structure defines the absolute priorty of the flow. Priorities in the + range of 0-7 are currently defined. Receive Priority is not currently used, + but may at some point in the future. + } + { this gets mapped to layer 2 priority. } + { there are none currently defined. } + { this could be used to decide who + gets forwarded up the stack first + - not used now } + + type + + TQOS_PRIORITY = record + ObjectHdr : TQOS_OBJECT_HDR; + SendPriority : u_char; + SendFlags : u_char; + ReceivePriority : u_char; + Unused : u_char; + end; + LPQOS_PRIORITY = ^TQOS_PRIORITY; + PQOS_PRIORITY = ^TQOS_PRIORITY; + { + This structure is used to define the behaviour that the traffic + control packet shaper will apply to the flow. + + PS_NONCONF_BORROW - the flow will receive resources remaining + after all higher priority flows have been serviced. If a + TokenRate is specified, packets may be non-conforming and + will be demoted to less than best-effort priority. + + PS_NONCONF_SHAPE - TokenRate must be specified. Non-conforming + packets will be retianed in the packet shaper until they become + conforming. + + PS_NONCONF_DISCARD - TokenRate must be specified. Non-conforming + packets will be discarded. + + } + + TQOS_SD_MODE = record + ObjectHdr : TQOS_OBJECT_HDR; + ShapeDiscardMode : u_long; + end; + LPQOS_SD_MODE = ^TQOS_SD_MODE; + PQOS_SD_MODE = ^TQOS_SD_MODE; + + const + TC_NONCONF_BORROW = 0; + TC_NONCONF_SHAPE = 1; + TC_NONCONF_DISCARD = 2; + TC_NONCONF_BORROW_PLUS = 3; + { + This structure may carry an 802.1 TrafficClass parameter which + has been provided to the host by a layer 2 network, for example, + in an 802.1 extended RSVP RESV message. If this object is obtained + from the network, hosts will stamp the MAC headers of corresponding + transmitted packets, with the value in the object. Otherwise, hosts + may select a value based on the standard Intserv mapping of + ServiceType to 802.1 TrafficClass. + + } + + type + + TQOS_TRAFFIC_CLASS = record + ObjectHdr : TQOS_OBJECT_HDR; + TrafficClass : u_long; + end; + LPQOS_TRAFFIC_CLASS = ^TQOS_TRAFFIC_CLASS; + PQOS_TRAFFIC_CLASS = ^TQOS_TRAFFIC_CLASS; + { + This structure allows overriding of the default schema used to drop + packets when a flow's shaper queue limit is reached. + + DropMethod - + QOS_SHAPER_DROP_FROM_HEAD - Drop packets from + the head of the queue until the new packet can be + accepted into the shaper under the current limit. This + behavior is the default. + QOS_SHAPER_DROP_INCOMING - Drop the incoming, + limit-offending packet. + + } + + TQOS_SHAPER_QUEUE_LIMIT_DROP_MODE = record + ObjectHdr : TQOS_OBJECT_HDR; + DropMode : u_long; + end; + LPQOS_SHAPER_QUEUE_LIMIT_DROP_MODE = ^TQOS_SHAPER_QUEUE_LIMIT_DROP_MODE; + PQOS_SHAPER_QUEUE_LIMIT_DROP_MODE = ^TQOS_SHAPER_QUEUE_LIMIT_DROP_MODE; + + const + QOS_SHAPER_DROP_INCOMING = 0; + QOS_SHAPER_DROP_FROM_HEAD = 1; + + { This structure allows the default per-flow limit on the shaper queue + size to be overridden. + + QueueSizeLimit - Limit, in bytes, of the size of the shaper queue } + + type + + TQOS_SHAPER_QUEUE_LIMIT = record + ObjectHdr : TQOS_OBJECT_HDR; + QueueSizeLimit : u_long; + end; + LPQOS_SHAPER_QUEUE_LIMIT = ^TQOS_SHAPER_QUEUE_LIMIT; + PQOS_SHAPER_QUEUE_LIMIT = ^TQOS_SHAPER_QUEUE_LIMIT; + diff --git a/packages/rtl-extra/src/netwcomn/winsock.pp b/packages/rtl-extra/src/netwcomn/winsock.pp new file mode 100644 index 0000000000..e1e2256f82 --- /dev/null +++ b/packages/rtl-extra/src/netwcomn/winsock.pp @@ -0,0 +1,2442 @@ +{ + This file is part of the Free Pascal run time library. + This unit contains the declarations for the WinSock2 + Socket Library for Netware and Win32 + + Copyright (c) 1999-2003 by the Free Pascal development team + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + ************************************************************************ + For NetWare 4.11 you have to install winsock-support (i.e. nw4wsock.exe) + NetWare >= 5.0 contains winsock support by default + ************************************************************************} + +{$PACKRECORDS 1} +{$R-} + +unit winsock; + +{$mode objfpc} + + interface + + {$ifdef netwlibc} + {$define netware} + {$endif} + const + { + Default maximium number of sockets. + this does not mean that the underlying netware + Sockets implementation has to support that many! + } + FD_SETSIZE = 64; + + type + tOS_INT = LongInt; + tOS_UINT = DWord; + ptOS_INT = ^tOS_INT; + ptOS_UINT = ^tOS_UINT; + + u_char = char; + u_short = word; + u_int = tOS_UINT; + u_long = dword; + pu_long = ^u_long; + pu_short = ^u_short; + plongint = ^longint; + TSocket = longint; + BOOL = boolean; + LPINT = ^integer; + LPDWORD = ^dword; + {$ifdef netware} + OVERLAPPED = record + Internal : DWORD; + InternalHigh: DWORD; + Offset : DWORD; + OffsetHigh : DWORD; + hEvent : THandle; + end; + LPOVERLAPPED = ^OVERLAPPED; + TOVERLAPPED = OVERLAPPED; + POVERLAPPED = ^OVERLAPPED; + {$endif} + PHandle = ^THandle; + TWSAOVERLAPPED= OVERLAPPED; + PWSAOVERLAPPED= ^OVERLAPPED; + TWSAEVENT = THandle; + PWSAEVENT = ^THandle; + + { there is already a procedure called FD_SET, so this + record was renamed (FK) } + fdset = record + fd_count : u_int; + fd_array : array[0..(FD_SETSIZE)-1] of TSocket; + end; + + TFDSet = fdset; + PFDSet = ^fdset; + + timeval = record + tv_sec : longint; + tv_usec : longint; + end; + + TTimeVal = timeval; + PTimeVal = ^TTimeVal; + + const + IOCPARM_MASK = $7f; + IOC_VOID = $20000000; + IOC_OUT = $40000000; + IOC_IN = $80000000; + IOC_INOUT = IOC_IN or IOC_OUT; + FIONREAD = IOC_OUT or + ((4 and IOCPARM_MASK) shl 16) or + (102 shl 8) or 127; + FIONBIO = IOC_IN or + ((4 and IOCPARM_MASK) shl 16) or + (102 shl 8) or 126; + FIOASYNC = IOC_IN or + ((4 and IOCPARM_MASK) shl 16) or + (102 shl 8) or 125; + { + 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). + Slight modifications for differences between Linux and winsock.h + } + type + hostent = record + { official name of host } + h_name: pchar; + { alias list } + h_aliases: ^pchar; + { host address type } + h_addrtype: SmallInt; + { length of address } + h_length: SmallInt; + { list of addresses } + case byte of + 0: (h_addr_list: ^pchar); + 1: (h_addr: ^pchar) + end; + THostEnt = hostent; + PHostEnt = ^THostEnt; + + { + Assumption here is that a network number + fits in an unsigned long -- someday that won't be true! + } + netent = record + n_name : ^char; // official name of net + n_aliases : ^pchar; // alias list + n_addrtype : SmallInt; // net address type + n_pad1 : SmallInt; // ensure right packaging + n_net : u_long; // network # + end; + TNetEnt = netent; + PNetEnt = ^TNetEnt; + + servent = record + { official service name } + s_name : ^char; + { alias list } + s_aliases : ^pchar; + { port # } + s_port : SmallInt; + n_pad1 : SmallInt; { ensure right packaging } + { protocol to use } + s_proto : ^char; + end; + TServEnt = servent; + PServEnt = ^TServEnt; + + protoent = record + { official protocol name } + p_name : ^char; + { alias list } + p_aliases : ^pchar; + { protocol # } + p_proto : SmallInt; + p_pad1 : SmallInt; { ensure packaging } + end; + TProtoEnt = protoent; + PProtoEnt = ^TProtoEnt; + + const + { + Standard well-known IP protocols. + For some reason there are differences between Linx and winsock.h + } + IPPROTO_IP = 0; + IPPROTO_ICMP = 1; + IPPROTO_IGMP = 2; + IPPROTO_GGP = 3; + IPPROTO_TCP = 6; + IPPORT_ECHO = 7; + IPPORT_DISCARD = 9; + IPPORT_SYSTAT = 11; + IPPROTO_PUP = 12; + IPPORT_DAYTIME = 13; + IPPORT_NETSTAT = 15; + IPPROTO_UDP = 17; + IPPROTO_IDP = 22; + IPPROTO_ND = 77; + IPPROTO_RAW = 255; + IPPROTO_MAX = 256; + IPPORT_FTP = 21; + IPPORT_TELNET = 23; + IPPORT_SMTP = 25; + IPPORT_TIMESERVER = 37; + IPPORT_NAMESERVER = 42; + IPPORT_WHOIS = 43; + IPPORT_MTP = 57; + IPPORT_TFTP = 69; + IPPORT_RJE = 77; + IPPORT_FINGER = 79; + IPPORT_TTYLINK = 87; + IPPORT_SUPDUP = 95; + IPPORT_EXECSERVER = 512; + IPPORT_LOGINSERVER = 513; + IPPORT_CMDSERVER = 514; + IPPORT_EFSSERVER = 520; + IPPORT_BIFFUDP = 512; + IPPORT_WHOSERVER = 513; + IPPORT_ROUTESERVER = 520; + IPPORT_RESERVED = 1024; + + const + IMPLINK_IP = 155; + IMPLINK_LOWEXPER = 156; + IMPLINK_HIGHEXPER = 158; + + type + SunB = packed record + s_b1,s_b2,s_b3,s_b4 : u_char; + end; + + SunW = packed record + s_w1,s_w2 : u_short; + end; + + in_addr = record + case integer of + 0 : (S_un_b : SunB); + 1 : (S_un_w : SunW); + 2 : (S_addr : u_long); + end; + TInAddr = in_addr; + PInAddr = ^TInAddr; + + sockaddr_in = record + case integer of + 0 : ( (* equals to sockaddr_in, size is 16 byte *) + sin_family : SmallInt; (* 2 byte *) + sin_port : u_short; (* 2 byte *) + sin_addr : TInAddr; (* 4 byte *) + sin_zero : array[0..7] of char; (* 8 byte *) + ); + 1 : ( (* equals to sockaddr, size is 16 byte *) + sa_family : SmallInt; (* 2 byte *) + sa_data : array[0..13] of char; (* 14 byte *) + ); + + end; + + TSockAddrIn = sockaddr_in; + PSockAddrIn = ^TSockAddrIn; + TSockAddr = sockaddr_in; + PSockAddr = ^TSockAddr; + + const + INADDR_ANY = $00000000; + INADDR_LOOPBACK = $7F000001; + INADDR_BROADCAST = $FFFFFFFF; + + IN_CLASSA_NET = $ff000000; + IN_CLASSA_NSHIFT = 24; + IN_CLASSA_HOST = $00ffffff; + IN_CLASSA_MAX = 128; + IN_CLASSB_NET = $ffff0000; + IN_CLASSB_NSHIFT = 16; + IN_CLASSB_HOST = $0000ffff; + IN_CLASSB_MAX = 65536; + IN_CLASSC_NET = $ffffff00; + IN_CLASSC_NSHIFT = 8; + IN_CLASSC_HOST = $000000ff; + INADDR_NONE = $ffffffff; + + WSADESCRIPTION_LEN = 256; + WSASYS_STATUS_LEN = 128; + + type + WSADATA = record + wVersion : WORD; { 2 byte, ofs 0 } + wHighVersion : WORD; { 2 byte, ofs 2 } + szDescription : array[0..(WSADESCRIPTION_LEN+1)-1] of char; { 257 byte, ofs 4 } + szSystemStatus : array[0..(WSASYS_STATUS_LEN+1)-1] of char; { 129 byte, ofs 261 } + iMaxSockets : word; { 2 byte, ofs 390 } + iMaxUdpDg : word; { 2 byte, ofs 392 } + pad1 : SmallInt; { 2 byte, ofs 394 } { ensure right packaging } + lpVendorInfo : pchar; { 4 byte, ofs 396 } + end; { total size 400 } + TWSAData = WSADATA; + PWSAData = TWSAData; + + const + IP_OPTIONS = 1; + IP_MULTICAST_IF = 2; + IP_MULTICAST_TTL = 3; + IP_MULTICAST_LOOP = 4; + IP_ADD_MEMBERSHIP = 5; + IP_DROP_MEMBERSHIP = 6; + IP_DEFAULT_MULTICAST_TTL = 1; + IP_DEFAULT_MULTICAST_LOOP = 1; + IP_MAX_MEMBERSHIPS = 20; + + type + ip_mreq = record + imr_multiaddr : in_addr; + imr_interface : in_addr; + end; + + { + Definitions related to sockets: types, address families, options, + taken from the BSD file sys/socket.h. + } + const + INVALID_SOCKET = longint(not(1)); + SOCKET_ERROR = -1; + SOCK_STREAM = 1; + SOCK_DGRAM = 2; + SOCK_RAW = 3; + SOCK_RDM = 4; + SOCK_SEQPACKET = 5; + + { For setsockoptions(2) } + SO_DEBUG = $0001; + SO_ACCEPTCONN = $0002; + SO_REUSEADDR = $0004; + SO_KEEPALIVE = $0008; + SO_DONTROUTE = $0010; + SO_BROADCAST = $0020; + SO_USELOOPBACK = $0040; + SO_LINGER = $0080; + SO_OOBINLINE = $0100; + { + Additional options. + } + { send buffer size } + SO_SNDBUF = $1001; + { receive buffer size } + SO_RCVBUF = $1002; + { send low-water mark } + SO_SNDLOWAT = $1003; + { receive low-water mark } + SO_RCVLOWAT = $1004; + { send timeout } + SO_SNDTIMEO = $1005; + { receive timeout } + SO_RCVTIMEO = $1006; + { get error status and clear } + SO_ERROR = $1007; + { get socket type } + SO_TYPE = $1008; + + { WinSock 2 extension -- new option } + SO_GROUP_ID = $2001; { ID of a socket group } + SO_GROUP_PRIORITY = $2002; { the relative priority within a group } + SO_MAX_MSG_SIZE = $2003; { maximum message size } + SO_PROTOCOL_INFOA = $2004; { WSAPROTOCOL_INFOA structure } + SO_PROTOCOL_INFOW = $2005; { WSAPROTOCOL_INFOW structure } + SO_PROTOCOL_INFO = SO_PROTOCOL_INFOW; + PVD_CONFIG = $3001; { configuration info for service provider } + + + { + Options for connect and disconnect data and options. Used only by + non-TCP/IP transports such as DECNet, OSI TP4, etc. + } + SO_CONNDATA = $7000; + SO_CONNOPT = $7001; + SO_DISCDATA = $7002; + SO_DISCOPT = $7003; + SO_CONNDATALEN = $7004; + SO_CONNOPTLEN = $7005; + SO_DISCDATALEN = $7006; + SO_DISCOPTLEN = $7007; + + { + Option for opening sockets for synchronous access. + } + SO_OPENTYPE = $7008; + SO_SYNCHRONOUS_ALERT = $10; + SO_SYNCHRONOUS_NONALERT = $20; + + { + Other NT-specific options. + } + SO_MAXDG = $7009; + SO_MAXPATHDG = $700A; + SO_UPDATE_ACCEPT_CONTEXT = $700B; + SO_CONNECT_TIME = $700C; + + { + TCP options. + } + TCP_NODELAY = $0001; + TCP_BSDURGENT = $7000; + + { Address families. } + { unspecified } + AF_UNSPEC = 0; + { + * Although AF_UNSPEC is defined for backwards compatibility, using + * AF_UNSPEC for the "af" parameter when creating a socket is STRONGLY + * DISCOURAGED. The interpretation of the "protocol" parameter + * depends on the actual address family chosen. As environments grow + * to include more and more address families that use overlapping + * protocol values there is more and more chance of choosing an + * undesired address family when AF_UNSPEC is used. } + + { local to host (pipes, portals) } + AF_UNIX = 1; + { internetwork: UDP, TCP, etc. } + AF_INET = 2; + { arpanet imp addresses } + AF_IMPLINK = 3; + { pup protocols: e.g. BSP } + AF_PUP = 4; + { mit CHAOS protocols } + AF_CHAOS = 5; + { IPX and SPX } + AF_IPX = 6; + { XEROX NS protocols } + AF_NS = 6; + { ISO protocols } + AF_ISO = 7; + { OSI is ISO } + AF_OSI = AF_ISO; + { european computer manufacturers } + AF_ECMA = 8; + { datakit protocols } + AF_DATAKIT = 9; + { CCITT protocols, X.25 etc } + AF_CCITT = 10; + { IBM SNA } + AF_SNA = 11; + { DECnet } + AF_DECnet = 12; + { Direct data link interface } + AF_DLI = 13; + { LAT } + AF_LAT = 14; + { NSC Hyperchannel } + AF_HYLINK = 15; + { AppleTalk } + AF_APPLETALK = 16; + { NetBios-style addresses } + AF_NETBIOS = 17; + { VoiceView } + AF_VOICEVIEW = 18; + { FireFox } + AF_FIREFOX = 19; + { Somebody is using this! } + AF_UNKNOWN1 = 20; + { Banyan } + AF_BAN = 21; + + AF_ATM = 22; + AF_INET6 = 23; + AF_CLUSTER = 24; + AF_12844 = 25; + AF_IRDA = 26; + + AF_MAX = 27; + + type + { + Structure used by kernel to pass protocol + information in raw sockets. + } + sockproto = record + sp_family : u_short; + sp_protocol : u_short; + end; + TSockProto = sockproto; + PSockProto = ^TSockProto; + + const + { + Protocol families, same as address families for now. + } + PF_UNSPEC = AF_UNSPEC; + PF_UNIX = AF_UNIX; + PF_INET = AF_INET; + PF_IMPLINK = AF_IMPLINK; + PF_PUP = AF_PUP; + PF_CHAOS = AF_CHAOS; + PF_NS = AF_NS; + PF_IPX = AF_IPX; + PF_ISO = AF_ISO; + PF_OSI = AF_OSI; + PF_ECMA = AF_ECMA; + PF_DATAKIT = AF_DATAKIT; + PF_CCITT = AF_CCITT; + PF_SNA = AF_SNA; + PF_DECnet = AF_DECnet; + PF_DLI = AF_DLI; + PF_LAT = AF_LAT; + PF_HYLINK = AF_HYLINK; + PF_APPLETALK = AF_APPLETALK; + PF_VOICEVIEW = AF_VOICEVIEW; + PF_FIREFOX = AF_FIREFOX; + PF_UNKNOWN1 = AF_UNKNOWN1; + PF_BAN = AF_BAN; + PF_ATM = AF_ATM; + PF_INET6 = AF_INET6; + PF_MAX = AF_MAX; + + type + { + Structure used for manipulating linger option. + } + linger = record + l_onoff : u_short; + l_linger : u_short; + end; + TLinger = linger; + PLinger = ^TLinger; + + const + { + Level number for (get/set)sockopt() to apply to socket itself. + } + { options for socket level } + SOL_SOCKET = $ffff; + { + Maximum queue length specifiable by listen. + } + SOMAXCONN = $7fffffff; + { process out-of-band data } + MSG_OOB = $1; + { peek at incoming message } + MSG_PEEK = $2; + { send without using routing tables } + MSG_DONTROUTE = $4; + MSG_MAXIOVLEN = 16; + { partial send or recv for message xport } + MSG_PARTIAL = $8000; + + { + Define constant based on rfc883, used by gethostbyxxxx() calls. + } + MAXGETHOSTSTRUCT = 1024; + MAXHOSTNAMELEN = MAXGETHOSTSTRUCT; + + { Winsock2 extension -- new flags for WSASend, WSASendTo, WSARecv + and WSARecvFrom } + MSG_INTERRUPT = $10; { send/recv in the interrupt context } + + { Define flags to be used with the WSAAsyncSelect() call. } + FD_READ = $01; + FD_WRITE = $02; + FD_OOB = $04; + FD_ACCEPT = $08; + FD_CONNECT = $10; + FD_CLOSE = $20; + FD_QOS = $40; + FD_GROUP_QOS = $80; + FD_ROUTING_INTERFACE_CHANGE = $100; + FD_ADDRESS_LIST_CHANGE = $200; + FD_MAX_EVENTS = 10; + FD_ALL_EVENTS = $4ff; + + { All Windows Sockets error constants are biased by WSABASEERR from + the "normal" } + WSABASEERR = 10000; + + { Windows Sockets definitions of regular Microsoft C error constants } + WSAEINTR = WSABASEERR + 4; + WSAEBADF = WSABASEERR + 9; + WSAEACCES = WSABASEERR + 13; + WSAEFAULT = WSABASEERR + 14; + WSAEINVAL = WSABASEERR + 22; + WSAEMFILE = WSABASEERR + 24; + + { Windows Sockets definitions of regular Berkeley error constants } + WSAEWOULDBLOCK = WSABASEERR + 35; + WSAEINPROGRESS = WSABASEERR + 36; + WSAEALREADY = WSABASEERR + 37; + WSAENOTSOCK = WSABASEERR + 38; + WSAEDESTADDRREQ = WSABASEERR + 39; + WSAEMSGSIZE = WSABASEERR + 40; + WSAEPROTOTYPE = WSABASEERR + 41; + WSAENOPROTOOPT = WSABASEERR + 42; + WSAEPROTONOSUPPORT = WSABASEERR + 43; + WSAESOCKTNOSUPPORT = WSABASEERR + 44; + WSAEOPNOTSUPP = WSABASEERR + 45; + WSAEPFNOSUPPORT = WSABASEERR + 46; + WSAEAFNOSUPPORT = WSABASEERR + 47; + WSAEADDRINUSE = WSABASEERR + 48; + WSAEADDRNOTAVAIL = WSABASEERR + 49; + WSAENETDOWN = WSABASEERR + 50; + WSAENETUNREACH = WSABASEERR + 51; + WSAENETRESET = WSABASEERR + 52; + WSAECONNABORTED = WSABASEERR + 53; + WSAECONNRESET = WSABASEERR + 54; + WSAENOBUFS = WSABASEERR + 55; + WSAEISCONN = WSABASEERR + 56; + WSAENOTCONN = WSABASEERR + 57; + WSAESHUTDOWN = WSABASEERR + 58; + WSAETOOMANYREFS = WSABASEERR + 59; + WSAETIMEDOUT = WSABASEERR + 60; + WSAECONNREFUSED = WSABASEERR + 61; + WSAELOOP = WSABASEERR + 62; + WSAENAMETOOLONG = WSABASEERR + 63; + WSAEHOSTDOWN = WSABASEERR + 64; + WSAEHOSTUNREACH = WSABASEERR + 65; + WSAENOTEMPTY = WSABASEERR + 66; + WSAEPROCLIM = WSABASEERR + 67; + WSAEUSERS = WSABASEERR + 68; + WSAEDQUOT = WSABASEERR + 69; + WSAESTALE = WSABASEERR + 70; + WSAEREMOTE = WSABASEERR + 71; + + { Extended Windows Sockets error constant definitions } + WSASYSNOTREADY = WSABASEERR + 91; + WSAVERNOTSUPPORTED = WSABASEERR + 92; + WSANOTINITIALISED = WSABASEERR + 93; + WSAEDISCON = WSABASEERR + 101; + WSAENOMORE = WSABASEERR+102; + WSAECANCELLED = WSABASEERR+103; + WSAEINVALIDPROCTABLE = WSABASEERR+104; + WSAEINVALIDPROVIDER = WSABASEERR+105; + WSAEPROVIDERFAILEDINIT = WSABASEERR+106; + WSASYSCALLFAILURE = WSABASEERR+107; + WSASERVICE_NOT_FOUND = WSABASEERR+108; + WSATYPE_NOT_FOUND = WSABASEERR+109; + WSA_E_NO_MORE = WSABASEERR+110; + WSA_E_CANCELLED = WSABASEERR+111; + WSAEREFUSED = WSABASEERR+112; + + { + 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. + } + WSAHOST_NOT_FOUND = WSABASEERR + 1001; + HOST_NOT_FOUND = WSAHOST_NOT_FOUND; + { Non-Authoritative: Host not found, or SERVERFAIL } + WSATRY_AGAIN = WSABASEERR + 1002; + TRY_AGAIN = WSATRY_AGAIN; + + { Non recoverable errors, FORMERR, REFUSED, NOTIMP } + WSANO_RECOVERY = WSABASEERR + 1003; + NO_RECOVERY = WSANO_RECOVERY; + + { Valid name, no data record of requested type } + WSANO_DATA = WSABASEERR + 1004; + NO_DATA = WSANO_DATA; + + { no address, look for MX record } + WSANO_ADDRESS = WSANO_DATA; + NO_ADDRESS = WSANO_ADDRESS; + + { Define QOS related error return codes } + WSA_QOS_RECEIVERS = WSABASEERR + 1005; + { at least one Reserve has arrived } + WSA_QOS_SENDERS = WSABASEERR + 1006; + { at least one Path has arrived } + WSA_QOS_NO_SENDERS = WSABASEERR + 1007; + { there are no senders } + WSA_QOS_NO_RECEIVERS = WSABASEERR + 1008; + { there are no receivers } + WSA_QOS_REQUEST_CONFIRMED = WSABASEERR + 1009; + { Reserve has been confirmed } + WSA_QOS_ADMISSION_FAILURE = WSABASEERR + 1010; + + WSA_QOS_POLICY_FAILURE = WSABASEERR + 1011; + { rejected for administrative reasons - bad credentials } + WSA_QOS_BAD_STYLE = WSABASEERR + 1012; + { unknown or conflicting style } + WSA_QOS_BAD_OBJECT = WSABASEERR + 1013; + {* problem with some part of the filterspec or providerspecific + * buffer in general } + WSA_QOS_TRAFFIC_CTRL_ERROR = WSABASEERR + 1014; + { problem with some part of the flowspec } + WSA_QOS_GENERIC_ERROR = WSABASEERR + 1015; + { general error } + + const + { + Windows Sockets errors redefined as regular Berkeley error constants. + } + EWOULDBLOCK = WSAEWOULDBLOCK; + EINPROGRESS = WSAEINPROGRESS; + EALREADY = WSAEALREADY; + ENOTSOCK = WSAENOTSOCK; + EDESTADDRREQ = WSAEDESTADDRREQ; + EMSGSIZE = WSAEMSGSIZE; + EPROTOTYPE = WSAEPROTOTYPE; + ENOPROTOOPT = WSAENOPROTOOPT; + EPROTONOSUPPORT = WSAEPROTONOSUPPORT; + ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT; + EOPNOTSUPP = WSAEOPNOTSUPP; + EPFNOSUPPORT = WSAEPFNOSUPPORT; + EAFNOSUPPORT = WSAEAFNOSUPPORT; + EADDRINUSE = WSAEADDRINUSE; + EADDRNOTAVAIL = WSAEADDRNOTAVAIL; + ENETDOWN = WSAENETDOWN; + ENETUNREACH = WSAENETUNREACH; + ENETRESET = WSAENETRESET; + ECONNABORTED = WSAECONNABORTED; + ECONNRESET = WSAECONNRESET; + ENOBUFS = WSAENOBUFS; + EISCONN = WSAEISCONN; + ENOTCONN = WSAENOTCONN; + ESHUTDOWN = WSAESHUTDOWN; + ETOOMANYREFS = WSAETOOMANYREFS; + ETIMEDOUT = WSAETIMEDOUT; + ECONNREFUSED = WSAECONNREFUSED; + ELOOP = WSAELOOP; + ENAMETOOLONG = WSAENAMETOOLONG; + EHOSTDOWN = WSAEHOSTDOWN; + EHOSTUNREACH = WSAEHOSTUNREACH; + ENOTEMPTY = WSAENOTEMPTY; + EPROCLIM = WSAEPROCLIM; + EUSERS = WSAEUSERS; + EDQUOT = WSAEDQUOT; + ESTALE = WSAESTALE; + EREMOTE = WSAEREMOTE; + + TF_DISCONNECT = $01; + TF_REUSE_SOCKET = $02; + TF_WRITE_BEHIND = $04; + + { + Options for use with [gs]etsockopt at the IP level. + } + IP_TTL = 7; + IP_TOS = 8; + IP_DONTFRAGMENT = 9; + + type + _TRANSMIT_FILE_BUFFERS = record + Head : Pointer; + HeadLength : dword; + Tail : Pointer; + TailLength : dword; + end; + TRANSMIT_FILE_BUFFERS = _TRANSMIT_FILE_BUFFERS; + TTransmitFileBuffers = _TRANSMIT_FILE_BUFFERS; + PTransmitFileBuffers = ^TTransmitFileBuffers; + + { WinSock 2 extension -- WSABUF and QOS struct, include qos.h + to pull in FLOWSPEC and related definitions } + { the length of the buffer } + (* far ignored *) + { the pointer to the buffer } + (* far ignored *) + + TWSABUF = record + len : u_long; + buf : ^char; + end; + _WSABUF = TWSABUF; + LPWSABUF = ^TWSABUF; + PWSABUF = ^TWSABUF; + + {$i qos.inc } + + { the flow spec for data sending } + { the flow spec for data receiving } + { additional provider specific stuff } + + type + + TQualityOfService = record + SendingFlowspec : TFLOWSPEC; + ReceivingFlowspec : TFLOWSPEC; + ProviderSpecific : TWSABUF; + end; + TQOS = TQualityOfService; + PQOS = ^TQOS; + + { WinSock 2 extension -- manifest constants for return values of the condition function } + + const + CF_ACCEPT = $0000; + CF_REJECT = $0001; + CF_DEFER = $0002; + + { WinSock 2 extension -- manifest constants for shutdown() } + SD_RECEIVE = $00; + SD_SEND = $01; + SD_BOTH = $02; + + { WinSock 2 extension -- data type and manifest constants for socket groups } + + type + TGROUP = dword; + PGROUP = ^TGROUP; + + const + SG_UNCONSTRAINED_GROUP = $01; + SG_CONSTRAINED_GROUP = $02; + + { WinSock 2 extension -- data type for WSAEnumNetworkEvents() } + + type + + TWSANETWORKEVENTS = record + lNetworkEvents : longint; + iErrorCode : array[0..(FD_MAX_EVENTS)-1] of longint; + end; + LPWSANETWORKEVENTS = ^TWSANETWORKEVENTS; + PWSANETWORKEVENTS = ^TWSANETWORKEVENTS; + + { WinSock 2 extension -- WSAPROTOCOL_INFO structure and associated + manifest constants } + + type + + TGUID = record + Data1 : dword; + Data2 : word; + Data3 : word; + Data4 : array[0..7] of byte; + end; + PGUID = ^TGUID; + LPGUID = PGUID; + + const + MAX_PROTOCOL_CHAIN = 7; + BASE_PROTOCOL = 1; + LAYERED_PROTOCOL = 0; + { the length of the chain, } + { length = 0 means layered protocol, } + { length = 1 means base protocol, } + { length > 1 means protocol chain } + { a list of dwCatalogEntryIds } + + type + + TWSAPROTOCOLCHAIN = record + ChainLen : longint; + ChainEntries : array[0..(MAX_PROTOCOL_CHAIN)-1] of DWORD; + end; + LPWSAPROTOCOLCHAIN = ^TWSAPROTOCOLCHAIN; + PWSAPROTOCOLCHAIN = ^TWSAPROTOCOLCHAIN; + + const + WSAPROTOCOL_LEN = 255; + (* far ignored *) + + type + + TWSAPROTOCOL_INFOA = record + dwServiceFlags1 : DWORD; + dwServiceFlags2 : DWORD; + dwServiceFlags3 : DWORD; + dwServiceFlags4 : DWORD; + dwProviderFlags : DWORD; + ProviderId : TGUID; + dwCatalogEntryId: DWORD; + ProtocolChain : TWSAPROTOCOLCHAIN; + iVersion : longint; + iAddressFamily : longint; + iMaxSockAddr : longint; + iMinSockAddr : longint; + iSocketType : longint; + iProtocol : longint; + iProtocolMaxOffset : longint; + iNetworkByteOrder : longint; + iSecurityScheme : longint; + dwMessageSize : DWORD; + dwProviderReserved : DWORD; + szProtocol : array[0..(WSAPROTOCOL_LEN + 1)-1] of CHAR; + end; + LPWSAPROTOCOL_INFOA = ^TWSAPROTOCOL_INFOA; + PWSAPROTOCOL_INFOA = ^TWSAPROTOCOL_INFOA; + + + TWSAPROTOCOL_INFOW = record + dwServiceFlags1 : DWORD; + dwServiceFlags2 : DWORD; + dwServiceFlags3 : DWORD; + dwServiceFlags4 : DWORD; + dwProviderFlags : DWORD; + ProviderId : TGUID; + dwCatalogEntryId: DWORD; + ProtocolChain : TWSAPROTOCOLCHAIN; + iVersion : longint; + iAddressFamily : longint; + iMaxSockAddr : longint; + iMinSockAddr : longint; + iSocketType : longint; + iProtocol : longint; + iProtocolMaxOffset : longint; + iNetworkByteOrder : longint; + iSecurityScheme : longint; + dwMessageSize : DWORD; + dwProviderReserved : DWORD; + szProtocol : array[0..(WSAPROTOCOL_LEN + 1)-1] of WCHAR; + end; + LPWSAPROTOCOL_INFOW = ^TWSAPROTOCOL_INFOW; + PWSAPROTOCOL_INFOW = ^TWSAPROTOCOL_INFOW; + +{$ifdef UNICODE} + type + TWSAPROTOCOL_INFO = TWSAPROTOCOL_INFOW; + LPWSAPROTOCOL_INFO = LPWSAPROTOCOL_INFOW; + PWSAPROTOCOL_INFO = PWSAPROTOCOL_INFOW; +{$else} + type + TWSAPROTOCOL_INFO = TWSAPROTOCOL_INFOA; + LPWSAPROTOCOL_INFO = LPWSAPROTOCOL_INFOA; + PWSAPROTOCOL_INFO = PWSAPROTOCOL_INFOA; +{$endif} + + { Flag bit definitions for dwProviderFlags } + + const + PFL_MULTIPLE_PROTO_ENTRIES = $00000001; + PFL_RECOMMENDED_PROTO_ENTRY = $00000002; + PFL_HIDDEN = $00000004; + PFL_MATCHES_PROTOCOL_ZERO = $00000008; + { Flag bit definitions for dwServiceFlags1 } + XP1_CONNECTIONLESS = $00000001; + XP1_GUARANTEED_DELIVERY = $00000002; + XP1_GUARANTEED_ORDER = $00000004; + XP1_MESSAGE_ORIENTED = $00000008; + XP1_PSEUDO_STREAM = $00000010; + XP1_GRACEFUL_CLOSE = $00000020; + XP1_EXPEDITED_DATA = $00000040; + XP1_CONNECT_DATA = $00000080; + XP1_DISCONNECT_DATA = $00000100; + XP1_SUPPORT_BROADCAST = $00000200; + XP1_SUPPORT_MULTIPOINT = $00000400; + XP1_MULTIPOINT_CONTROL_PLANE = $00000800; + XP1_MULTIPOINT_DATA_PLANE = $00001000; + XP1_QOS_SUPPORTED = $00002000; + XP1_INTERRUPT = $00004000; + XP1_UNI_SEND = $00008000; + XP1_UNI_RECV = $00010000; + XP1_IFS_HANDLES = $00020000; + XP1_PARTIAL_MESSAGE = $00040000; + BIGENDIAN = $0000; + LITTLEENDIAN = $0001; + SECURITY_PROTOCOL_NONE = $0000; + + { WinSock 2 extension -- manifest constants for WSAJoinLeaf() } + JL_SENDER_ONLY = $01; + JL_RECEIVER_ONLY = $02; + JL_BOTH = $04; + + { WinSock 2 extension -- manifest constants for WSASocket() } + WSA_FLAG_OVERLAPPED = $01; + WSA_FLAG_MULTIPOINT_C_ROOT = $02; + WSA_FLAG_MULTIPOINT_C_LEAF = $04; + WSA_FLAG_MULTIPOINT_D_ROOT = $08; + WSA_FLAG_MULTIPOINT_D_LEAF = $10; + + + { WinSock 2 extension -- manifest constants for WSAIoctl() } + IOC_UNIX = $00000000; + IOC_WS2 = $08000000; + IOC_PROTOCOL = $10000000; + IOC_VENDOR = $18000000; + + { WinSock 2 extension -- manifest constants for SIO_TRANSLATE_HANDLE ioctl } + + const + TH_NETDEV = $00000001; + TH_TAPI = $00000002; + + { Microsoft Windows Extended data types required for the functions to + convert back and forth between binary and string forms of + addresses. } + + type + //PSOCKADDR = sockaddr; + LPSOCKADDR = PSockAddr; + + { Manifest constants and type definitions related to name resolution and + registration (RNR) API } + type + TBLOB = record + cbSize : u_long; + pBlobData:ARRAY[0..0] OF POINTER; {???} + end; + PBLOB = ^TBLOB; + + { Service Install Flags } + + const + SERVICE_MULTIPLE = $00000001; + + { & Name Spaces } + NS_ALL = 0; + NS_SAP = 1; + NS_NDS = 2; + NS_PEER_BROWSE = 3; + NS_TCPIP_LOCAL = 10; + NS_TCPIP_HOSTS = 11; + NS_DNS = 12; + NS_NETBT = 13; + NS_WINS = 14; + NS_NBP = 20; + NS_MS = 30; + NS_STDA = 31; + NS_NTDS = 32; + NS_X500 = 40; + NS_NIS = 41; + NS_NISPLUS = 42; + NS_WRQ = 50; + + { Resolution flags for WSAGetAddressByName(). + Note these are also used by the 1.1 API GetAddressByName, so + leave them around. } + + RES_UNUSED_1 = $00000001; + RES_FLUSH_CACHE = $00000002; + + RES_SERVICE = $00000004; + + { RES_SERVICE } + { Well known value names for Service Types } + + const + SERVICE_TYPE_VALUE_IPXPORTA = 'IpxSocket'; +(* error #define SERVICE_TYPE_VALUE_IPXPORTW L"IpxSocket" *) + SERVICE_TYPE_VALUE_SAPIDA = 'SapId'; +(* error #define SERVICE_TYPE_VALUE_SAPIDW L"SapId" *) + SERVICE_TYPE_VALUE_TCPPORTA = 'TcpPort'; +(* error #define SERVICE_TYPE_VALUE_TCPPORTW L"TcpPort" *) + SERVICE_TYPE_VALUE_UDPPORTA = 'UdpPort'; +(* error #define SERVICE_TYPE_VALUE_UDPPORTW L"UdpPort" *) + SERVICE_TYPE_VALUE_OBJECTIDA = 'ObjectId'; +(* error #define SERVICE_TYPE_VALUE_OBJECTIDW L"ObjectId" *) + +{$ifdef UNICODE} + const + SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDW; + SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTW; + SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTW; + SERVICE_TYPE_VALUE_OBJECTID = SERVICE_TYPE_VALUE_OBJECTIDW; +{$else} + { not UNICODE } + const + SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDA; + SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTA; + SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTA; + SERVICE_TYPE_VALUE_OBJECTID = SERVICE_TYPE_VALUE_OBJECTIDA; +{$endif} + + { SockAddr Information } + type + + TSOCKET_ADDRESS = record + lpSockaddr : PSockAddr; + iSockaddrLength : tOS_INT; + end; + PSOCKET_ADDRESS = ^TSOCKET_ADDRESS; + LPSOCKET_ADDRESS = ^TSOCKET_ADDRESS; + + { CSAddr Information } + + TCSADDR_INFO = record + LocalAddr : TSOCKET_ADDRESS; + RemoteAddr : TSOCKET_ADDRESS; + iSocketType : tOS_INT; + iProtocol : tOS_INT; + end; + PCSADDR_INFO = ^TCSADDR_INFO; + LPCSADDR_INFO = ^TCSADDR_INFO; + + { Address list returned via SIO_ADDRESS_LIST_QUERY } + + type + + TSOCKET_ADDRESS_LIST = record + iAddressCount : tOS_INT; + Address : array[0..0] of TSOCKET_ADDRESS; + end; + LPSOCKET_ADDRESS_LIST = ^TSOCKET_ADDRESS_LIST; + PSOCKET_ADDRESS_LIST = ^TSOCKET_ADDRESS_LIST; + + { Address Family/Protocol Tuples } + + TAFPROTOCOLS = record + iAddressFamily : tOS_INT; + iProtocol : tOS_INT; + end; + PAFPROTOCOLS = ^TAFPROTOCOLS; + LPAFPROTOCOLS = ^TAFPROTOCOLS; + + { Client Query API Typedefs } + { The comparators } + + TWSAEcomparator = (COMP_EQUAL := 0,COMP_NOTLESS); + PWSAECOMPARATOR = ^TWSAEcomparator; + LPWSAECOMPARATOR = ^TWSAEcomparator; + + TWSAVersion = record + dwVersion : DWORD; + ecHow : TWSAECOMPARATOR; + end; + PWSAVERSION = ^TWSAVersion; + LPWSAVERSION = ^TWSAVersion; + + TWSAQuerySetA = record + dwSize : DWORD; + lpszServiceInstanceName : PChar; + lpServiceClassId : LPGUID; + lpVersion : LPWSAVERSION; + lpszComment : PChar; + dwNameSpace : DWORD; + lpNSProviderId : LPGUID; + lpszContext : PChar; + dwNumberOfProtocols : DWORD; + lpafpProtocols : LPAFPROTOCOLS; + lpszQueryString : PChar; + dwNumberOfCsAddrs : DWORD; + lpcsaBuffer : LPCSADDR_INFO; + dwOutputFlags : DWORD; + lpBlob : PBLOB; + end; + PWSAQUERYSETA = ^TWSAQuerySetA; + LPWSAQUERYSETA = ^TWSAQuerySetA; + + TWSAQuerySetW = record + dwSize : DWORD; + lpszServiceInstanceName : PWideChar; + lpServiceClassId : LPGUID; + lpVersion : LPWSAVERSION; + lpszComment : PWideChar; + dwNameSpace : DWORD; + lpNSProviderId : LPGUID; + lpszContext : PWideChar; + dwNumberOfProtocols : DWORD; + lpafpProtocols : LPAFPROTOCOLS; + lpszQueryString : PWideChar; + dwNumberOfCsAddrs : DWORD; + lpcsaBuffer : LPCSADDR_INFO; + dwOutputFlags : DWORD; + lpBlob : PBLOB; + end; + PWSAQUERYSETW = ^TWSAQuerySetW; + LPWSAQUERYSETW = ^TWSAQuerySetW; +{$ifdef UNICODE} + + type + TWSAQUERYSET = TWSAQUERYSETW; + PWSAQUERYSET = PWSAQUERYSETW; + LPWSAQUERYSET = LPWSAQUERYSETW; +{$else} + type + TWSAQUERYSET = TWSAQUERYSETA; + PWSAQUERYSET = PWSAQUERYSETA; + LPWSAQUERYSET = LPWSAQUERYSETA; +{$endif} + + const + LUP_DEEP = $0001; + LUP_CONTAINERS = $0002; + LUP_NOCONTAINERS = $0004; + LUP_NEAREST = $0008; + LUP_RETURN_NAME = $0010; + LUP_RETURN_TYPE = $0020; + LUP_RETURN_VERSION = $0040; + LUP_RETURN_COMMENT = $0080; + LUP_RETURN_ADDR = $0100; + LUP_RETURN_BLOB = $0200; + LUP_RETURN_ALIASES = $0400; + LUP_RETURN_QUERY_STRING = $0800; + LUP_RETURN_ALL = $0FF0; + LUP_RES_SERVICE = $8000; + LUP_FLUSHCACHE = $1000; + LUP_FLUSHPREVIOUS = $2000; + + { Return flags } + + RESULT_IS_ALIAS = $0001; + + { Service Address Registration and Deregistration Data Types. } + + type + + TWSAESETSERVICEOP = + (RNRSERVICE_REGISTER := 0,RNRSERVICE_DEREGISTER, RNRSERVICE_DELETE); + PWSAESETSERVICEOP = ^TWSAESETSERVICEOP; + LPWSAESETSERVICEOP = ^TWSAESETSERVICEOP; + + { Service Installation/Removal Data Types. } + + TWSANSClassInfoA = record + lpszName : PChar; + dwNameSpace : DWORD; + dwValueType : DWORD; + dwValueSize : DWORD; + lpValue : Pointer; + end; + PWSANSCLASSINFOA = ^TWSANSClassInfoA; + LPWSANSCLASSINFOA = ^TWSANSClassInfoA; + + TWSANSClassInfoW = record + lpszName : PWideChar; + dwNameSpace : DWORD; + dwValueType : DWORD; + dwValueSize : DWORD; + lpValue : Pointer; + end; + PWSANSCLASSINFOW = ^TWSANSClassInfoW; + LPWSANSCLASSINFOW = ^TWSANSClassInfoW; +{$ifdef UNICODE} + type + TWSANSCLASSINFO = TWSANSCLASSINFOW; + PWSANSCLASSINFO = PWSANSCLASSINFOW; + LPWSANSCLASSINFO = LPWSANSCLASSINFOW; +{$else} + type + TWSANSCLASSINFO = TWSANSCLASSINFOA; + PWSANSCLASSINFO = PWSANSCLASSINFOA; + LPWSANSCLASSINFO = LPWSANSCLASSINFOA; +{$endif} + + type + TWSAServiceClassInfoA = record + lpServiceClassId : LPGUID; + lpszServiceClassName : PChar; + dwCount : DWORD; + lpClassInfos : LPWSANSCLASSINFOA; + end; + PWSASERVICECLASSINFOA = ^TWSAServiceClassInfoA; + LPWSASERVICECLASSINFOA = ^TWSAServiceClassInfoA; + + TWSAServiceClassInfoW = record + lpServiceClassId : LPGUID; + lpszServiceClassName : PWideChar; + dwCount : DWORD; + lpClassInfos : LPWSANSCLASSINFOW; + end; + PWSASERVICECLASSINFOW = ^TWSAServiceClassInfoW; + LPWSASERVICECLASSINFOW = ^TWSAServiceClassInfoW; + +{$ifdef UNICODE} + type + TWSASERVICECLASSINFO = TWSASERVICECLASSINFOW; + PWSASERVICECLASSINFO = PWSASERVICECLASSINFOW; + LPWSASERVICECLASSINFO = LPWSASERVICECLASSINFOW; +{$else} + type + TWSASERVICECLASSINFO = TWSASERVICECLASSINFOA; + PWSASERVICECLASSINFO = PWSASERVICECLASSINFOA; + LPWSASERVICECLASSINFO = LPWSASERVICECLASSINFOA; +{$endif} + + type + TWSANAMESPACE_INFOA = record + NSProviderId : TGUID; + dwNameSpace : DWORD; + fActive : BOOL; + dwVersion : DWORD; + lpszIdentifier: PChar; + end; + PWSANAMESPACE_INFOA = ^TWSANAMESPACE_INFOA; + LPWSANAMESPACE_INFOA = ^TWSANAMESPACE_INFOA; + + TWSANAMESPACE_INFOW = record + NSProviderId : TGUID; + dwNameSpace : DWORD; + fActive : BOOL; + dwVersion : DWORD; + lpszIdentifier: PWideChar; + end; + PWSANAMESPACE_INFOW = ^TWSANAMESPACE_INFOW; + LPWSANAMESPACE_INFOW = ^TWSANAMESPACE_INFOW; +{$ifdef UNICODE} + type + TWSANAMESPACE_INFO = TWSANAMESPACE_INFOW; + PWSANAMESPACE_INFO = PWSANAMESPACE_INFOW; + LPWSANAMESPACE_INFO = LPWSANAMESPACE_INFOW; +{$else} + type + TWSANAMESPACE_INFO = TWSANAMESPACE_INFOA; + PWSANAMESPACE_INFO = PWSANAMESPACE_INFOA; + LPWSANAMESPACE_INFO = LPWSANAMESPACE_INFOA; +{$endif} + + { WinSock 2 extensions -- data types for the condition function in + WSAAccept() and overlapped I/O completion routine. } + + type + TWSAOVERLAPPED_COMPLETION_ROUTINE = + function (dwError,cbTransferred : longint; + lpOverlapped : PWSAOVERLAPPED; + dwFlags : longint) : longint; + {$ifdef netware} cdecl; {$else} stdcall; {$endif} + + TCONDITIONPROC = + function (lpCallerId, lpCallerData : PWSABUF; + lpSQOS, lpGQOS : PQOS; + lpCalleeId, lpCalleeData : PWSABUF; + g : PGROUP; + dwCallbackData : dword) : longint; + {$ifdef netware} cdecl; {$else} stdcall; {$endif} + +{--------------------------------------------------------------------} +{netware extensions from ws2nlm.h} +{$ifdef netware} + { New Address Types } + + const + AF_INET_ACP = 25; + AF_IPX_ACP = 26; + AF_ACP = 27; + + { NetWare SSL Ioctls } + + const + SECURITY_PROTOCOL_SSL = 1; + SECURITY_PROTOCOL_TLS = 2; + + { There are three interesting authentication types } + { CLIENT - Client initiates a SSL connection. } + { SERVER - Listener set up to listen for incoming SSL conns, (Server sends it's cert during auth) } + { MUTUAL is SSL Server requesting client authentication, (Server asks for client cert inaddition to sending it's cert) } + { optval is a DWORD defined as } + + const + MUTUAL = $00000002; + + { System flags not defined in NetWare } + + const + INFINITE = $FFFFFFFF; + WAIT_OBJECT_0 = 0; + + {Various Types that may not be defined } + { } + { } + { Predefined Value Types. } + { } + { No value type } + + const + REG_NONE = 0; + REG_SZ = 1; + REG_EXPAND_SZ = 2; + REG_BINARY = 3; + REG_DWORD = 4; + REG_DWORD_LITTLE_ENDIAN = 4; + REG_DWORD_BIG_ENDIAN = 5; + REG_LINK = 6; + REG_MULTI_SZ = 7; + REG_RESOURCE_LIST = 8; + REG_FULL_RESOURCE_DESCRIPTOR = 9; + REG_RESOURCE_REQUIREMENTS_LIST = 10; + + ERROR_INVALID_HANDLE = 6; + ERROR_NOT_ENOUGH_MEMORY = 8; + ERROR_INVALID_PARAMETER = 87; + ERROR_IO_PENDING = 997; + ERROR_OPERATION_ABORTED = 995; + ERROR_IO_INCOMPLETE = 996; + + { connect timeout } + + const + SO_CONNTIMEO = $1009; + { NetWare Fast Accept and Recv option structures } + { Fast Recv also has a cleanup routine returned. } + + type + + LPFASTACCEPT_COMPLETION_ROUTINE = longint; + LPFASTRECV_COMPLETION_ROUTINE = longint; + + TFASTACCEPT_OP = record + acceptHandler : LPFASTACCEPT_COMPLETION_ROUTINE; + arg : pointer; + end; + LPFAST_ACCEPT_OPT = ^TFASTACCEPT_OP; + PFAST_ACCEPT_OPT = ^TFASTACCEPT_OP; + + TFASTRECV_OP = record + recvHandler : LPFASTRECV_COMPLETION_ROUTINE; + Arg : pointer; + end; + LPFAST_RECV_OPT = ^TFASTRECV_OP; + PFAST_RECV_OPT = ^TFASTRECV_OP; + + { Winsock 2 applications that want to use SSL need to define WS_SSL } + type + time_t = dword; + + { Secure Sockets Layer - needed until Winsock SDK supplies ssl header file. } + { Taken from Winsock 2 protocol Annex for SSL Security Protocol. Unsupported } + { options are labeled "not supported". } + { This value is the SSL protocol tag and WSAIoctl dwIoControlCode + "T" value. } + + const + _SO_SSL = (2 shl 27) or ($73 shl 16); + { + These values are used to form the WSAIoctl dwIoControlCode + "Code" value. + } + _SO_SSL_FLAGS = $01; + _SO_SSL_CIPHERS = $02; + _SO_SSL_SERVER = $04; + { not supported } + _SO_SSL_AUTH_CERT_HOOK = $08; + { not supported } + _SO_SSL_RSA_ENCRYPT_HOOK = $10; + { not supported } + _SO_SSL_RSA_DECRYPT_HOOK = $20; + { _SO_SSL_CLIENT has been changed from 0x03 to 0x80 to avoid bitwise } + { conflicts with _SO_SSL_CIPHERS _SO_SSL_FLAGS. } + _SO_SSL_CLIENT = $80; + { Actual SSL Ioctl commands } + SO_SSL_GET_FLAGS = (IOC_IN or _SO_SSL) or _SO_SSL_FLAGS; + SO_SSL_SET_FLAGS = (IOC_OUT or _SO_SSL) or _SO_SSL_FLAGS; + SO_SSL_GET_CIPHERS = (IOC_IN or _SO_SSL) or _SO_SSL_CIPHERS; + {not supported } + SO_SSL_SET_CIPHERS = (IOC_OUT or _SO_SSL) or _SO_SSL_CIPHERS; + SO_SSL_GET_CLIENT = (IOC_IN or _SO_SSL) or _SO_SSL_CLIENT; + SO_SSL_SET_CLIENT = (IOC_OUT or _SO_SSL) or _SO_SSL_CLIENT; + SO_SSL_GET_SERVER = (IOC_IN or _SO_SSL) or _SO_SSL_SERVER; + SO_SSL_SET_SERVER = (IOC_OUT or _SO_SSL) or _SO_SSL_SERVER; + {not supported } + SO_SSL_GET_AUTH_CERT_HOOK = (IOC_IN or _SO_SSL) or _SO_SSL_AUTH_CERT_HOOK; + {not supported } + SO_SSL_SET_AUTH_CERT_HOOK = (IOC_OUT or _SO_SSL) or _SO_SSL_AUTH_CERT_HOOK; + {not supported } + SO_SSL_GET_RSA_ENCRYPT_HOOK = (IOC_IN or _SO_SSL) or _SO_SSL_RSA_ENCRYPT_HOOK; + {not supported } + SO_SSL_SET_RSA_ENCRYPT_HOOK = (IOC_OUT or _SO_SSL) or _SO_SSL_RSA_ENCRYPT_HOOK; + {not supported } + SO_SSL_GET_RSA_DECRYPT_HOOK = (IOC_IN or _SO_SSL) or _SO_SSL_RSA_DECRYPT_HOOK; + {not supported } + SO_SSL_SET_RSA_DECRYPT_HOOK = (IOC_OUT or _SO_SSL) or _SO_SSL_RSA_DECRYPT_HOOK; + SO_SSL_ENABLE = $001; + SO_SSL_SERVER = $002; + SO_SSL_AUTH_CLIENT = $004; + {not supported } + SO_SSL_ACCEPT_WEAK = $008; + + type + + Tsslcipheropts = record + n : longint; + specs : array[0..2] of char; + end; + + Tsslclientopts = record + cert : PChar; + certlen : longint; + sidtimeout : time_t; + sidentries : longint; + siddir : PChar; + end; + + Tsslserveropts = record + cert : PChar; + certlen : longint; + sidtimeout : time_t; + sidentries : longint; + siddir : PChar; + end; + + {not suppported } + {Tsslauthcertopts = record + _type : longint; + func : function (arg:pointer; cert:Pchar; len:longint):longint;cdecl; + arg : pointer; + end;} + + {not supported } + + const + SSL_ACK_OK = 1; + {not supported } + SSL_ACH_WEAK_OK = 2; + {not supported } + SSL_ACH_LONG_DATA = 3; + {not supported } + SSL_ACH_BAD_DATA = 4; + {not supported } + SSL_ACH_BAD_SIG = 5; + {not supported } + SSL_ACH_CERT_EXPIRED = 6; + {not suppported } + + type + sslrsaencrypthook = record + func : function (arg:pointer; blockType:longint; dest:Pchar; destlen:Plongint; src:Pchar; + srclen:longint):longint; cdecl; + arg : pointer; + end; + + {not supported } + + const + SSL_REH_OK = 0; + {not supported } + SSL_REH_BAD_TYPE = 1; + {not supported } + SSL_REH_BAD_LEN = 2; + {not suppported } + + type + Tsslrsadecrypthook = record + func : function (arg:pointer; blockType:longint; dest:Pchar; destlen:Plongint; src:Pchar; + srclen:longint):longint; cdecl; + arg : pointer; + end; + Psslrsadecrypthook = ^Tsslrsadecrypthook; + + {not supported } + + const + SSL_RDH_OK = 0; + {not supported } + SSL_RDH_BAD_TYPE = 1; + {not supported } + SSL_RDH_BAD_LEN = 2; + { TLS options } + { Secure Sockets Layer - needed until Winsock SDK supplies ssl header file. } + { Taken from Winsock 2 protocol Annex for SSL Security Protocol. Unsupported } + { options are labeled "not supported". } + { + This value is the SSL protocol tag and WSAIoctl dwIoControlCode + "T" value. This value is unique to distinguish a TLS Ioctl from an SSL + Ioctl due to different structure definitions. + } + _SO_TLS = (2 shl 27) or ($74 shl 16); + { + These values are used to form the WSAIoctl dwIoControlCode + "Code" value. + } + _SO_TLS_FLAGS = $01; + _SO_TLS_CIPHERS = $02; + _SO_TLS_SERVER = $04; + { not supported } + _SO_TLS_AUTH_CERT_HOOK = $08; + { not supported } + _SO_TLS_RSA_ENCRYPT_HOOK = $10; + { not supported } + _SO_TLS_RSA_DECRYPT_HOOK = $20; + _SO_TLS_CERT = $40; + { _SO_TLS_CLIENT has been changed from 0x03 to 0x80 to avoid bitwise } + { conflicts with _SO_TLS_CIPHERS _SO_TLS_FLAGS. } + _SO_TLS_CLIENT = $80; + { + Actual TLS Ioctl commands + } + SO_TLS_GET_FLAGS = (IOC_IN or _SO_TLS) or _SO_TLS_FLAGS; + SO_TLS_SET_FLAGS = (IOC_OUT or _SO_TLS) or _SO_TLS_FLAGS; + SO_TLS_GET_CIPHERS = (IOC_IN or _SO_TLS) or _SO_TLS_CIPHERS; + {not supported } + SO_TLS_SET_CIPHERS = (IOC_OUT or _SO_TLS) or _SO_TLS_CIPHERS; + SO_TLS_GET_CLIENT = (IOC_IN or _SO_TLS) or _SO_TLS_CLIENT; + SO_TLS_SET_CLIENT = (IOC_OUT or _SO_TLS) or _SO_TLS_CLIENT; + SO_TLS_GET_SERVER = (IOC_IN or _SO_TLS) or _SO_TLS_SERVER; + SO_TLS_SET_SERVER = (IOC_OUT or _SO_TLS) or _SO_TLS_SERVER; + SO_TLS_GET_CERT = (IOC_IN or _SO_TLS) or _SO_TLS_CERT; + {not supported } + SO_TLS_GET_AUTH_CERT_HOOK = (IOC_IN or _SO_TLS) or _SO_TLS_AUTH_CERT_HOOK; + {not supported } + SO_TLS_SET_AUTH_CERT_HOOK = (IOC_OUT or _SO_TLS) or _SO_TLS_AUTH_CERT_HOOK; + {not supported } + SO_TLS_GET_RSA_ENCRYPT_HOOK = (IOC_IN or _SO_TLS) or _SO_TLS_RSA_ENCRYPT_HOOK; + {not supported } + SO_TLS_SET_RSA_ENCRYPT_HOOK = (IOC_OUT or _SO_TLS) or _SO_TLS_RSA_ENCRYPT_HOOK; + {not supported } + SO_TLS_GET_RSA_DECRYPT_HOOK = (IOC_IN or _SO_TLS) or _SO_TLS_RSA_DECRYPT_HOOK; + {not supported } + SO_TLS_SET_RSA_DECRYPT_HOOK = (IOC_OUT or _SO_TLS) or _SO_TLS_RSA_DECRYPT_HOOK; + SO_TLS_ENABLE = $0001; + SO_TLS_SERVER = $0002; + SO_TLS_AUTH_CLIENT = $0004; + {not supported } + SO_TLS_ACCEPT_WEAK = $0008; + SO_TLS_MAP_DISABLE = $0010; + SO_TLS_MAP_IDENTITY = $0020; + SO_TLS_BLIND_ACCEPT = $0040; + SO_TLS_INTERACTIVE_ACCEPT = $0080; + + type + Ttlscipheropts = record + n : longint; + specs : array[0..2] of char; + end; + Ptlscipheropts = ^Ttlscipheropts; + + Ttlsclientopts = record + wallet : PWideChar; // ^unicode; + walletlen : longint; + sidtimeout : time_t; + sidentries : longint; + siddir : PChar; // ^char; + options : pointer; + end; + Ptlsclientopts = ^Ttlsclientopts; + + Ttlsserveropts = record + wallet : PWideChar; // ^unicode; + walletlen : longint; + sidtimeout : time_t; + sidentries : longint; + siddir : PChar; // ^char; + options : pointer; + end; + Ptlsserveropts = ^Ttlsserveropts; + + {wallet content provider e.g. PFX, KMO, DER. } + {alias for private key in wallet to be used } + { not used for anything but pfx wallet provider } + {number of elements in the array } + {array of trusted root names } + {number of elements in the array } + {reserved to set ciphers } + {reserved for CRL } + {reserved for CRL len. } + Tnwtlsopts = record + walletProvider : PWideChar; //^unicode; + keysList : PPWideChar; // ^^unicode; + numElementsInKeyList : longint; + TrustedRootList : PPWideChar; // ^^unicode; + numElementsInTRList : longint; + reservedforfutureuse : pointer; + reservedforfutureCRL : pointer; + reservedforfutureCRLLen : longint; + reserved1 : pointer; + reserved2 : pointer; + reserved3 : pointer; + end; + Pnwtlsopts=^Tnwtlsopts; + + {not suppported } + {tlsauthcertopts = record + _type : longint; + func : function (arg:pointer; cert:Pchar; len:longint):longint; cdecl; + arg : pointer; + end;} + + {not supported } + + const + TLS_ACK_OK = 1; + {not supported } + TLS_ACH_WEAK_OK = 2; + {not supported } + TLS_ACH_LONG_DATA = 3; + {not supported } + TLS_ACH_BAD_DATA = 4; + {not supported } + TLS_ACH_BAD_SIG = 5; + {not supported } + TLS_ACH_CERT_EXPIRED = 6; + {not suppported } + + type + Ttlsrsaencrypthook = record + func : function (arg:pointer; blockType:longint; dest:Pchar; destlen:Plongint; src:Pchar; + srclen:longint):longint; cdecl; + arg : pointer; + end; + Ptlsrsaencrypthook=^Ttlsrsaencrypthook; + + {not supported } + + const + TLS_REH_OK = 0; + {not supported } + TLS_REH_BAD_TYPE = 1; + {not supported } + TLS_REH_BAD_LEN = 2; + {not suppported } + + type + Ttlsrsadecrypthook = record + func : function (arg:pointer; blockType:longint; dest:Pchar; destlen:Plongint; src:Pchar; + srclen:longint):longint; cdecl; + arg : pointer; + end; + Ptlsrsadecrypthook=^Ttlsrsadecrypthook; + {not supported } + + const + TLS_RDH_OK = 0; + {not supported } + TLS_RDH_BAD_TYPE = 1; + {not supported } + TLS_RDH_BAD_LEN = 2; + + type + Ttlscert = record + cert : PChar; + certlen : longint; + end; + Ptlscert = ^Ttlscert; + + const SIO_RAWCALLBACKS = $1ADD0002; + SIO_WORKTODOCALLBACKS = $1ADD0004; + SIO_FASTACCEPTCALLBACK = $1ADD0008; + SIO_FASTRECVCALLBACK = $1ADD000C; + SIO_RCVFULLMSG = $1ADD0010; + SIO_SSL_CRYPTFILE = $1ADD0010; + SIO_SSL_AUTHTYPE = $1ADD0020; + SIO_SSL_CONVERT = $1ADD0040; + SKTS_RAWCALLBACKS = $40000000; + SKTS_WORKTODOCALLBACKS = $20000000; + WAIT_ABANDONED = $00000080; + WAIT_TIMEOUT = $00000102; + WAIT_FAILED = $FFFFFFFF; + MAXIMUM_WAIT_OBJECTS = 64; + WAIT_IO_COMPLETION = $000000C0; + + { This file contains proposed extensions to the Winsock 2 specification to } + { support Novell's implementation of namespace providers. } + + {___[ Manifest constants ]________________________________________________________________________ } + { Proposed output flag for deregistered services } + const + RESULT_IS_DEREGISTERED = $0002; + { Proposed output flag for containers } + RESULT_IS_CONTAINER = $0004; + + { Values used to indicate an attribute list in the blob } + { blob contains ASCII strings } + + WS_ATTRLIST_ASCII = $b10bea1a; + { blob contains UNICODE strings } + WS_ATTRLIST_UNICODE = $b10bea10; + { Name Spaces } + { Extends definitions in WINSOCK2.H } + NS_BINDERY = 4; + NS_SLP = 5; + { Predefined BLOB Value Types } + { Extends Predefined Value Types in winnt.h } + + REG_BOOL = 11; // Boolean value; TRUE or FALSE } + REG_KEYWORD = 12; // Keyword with no value + + {___[ Type definitions ]__________________________________________________________________________ } + + type + + TWSAATTRINFO = TWSANSCLASSINFO; + LPWSAATTRINFO = ^TWSAATTRINFO; + PWSAATTRINFO = ^TWSAATTRINFO; + { Structure of a blob containing an attribute list } + { Identifies the blob as an attribute list } + { Number of attributes present } + { Pointer to attribute array } + + TWSABlobAttrList = record + dwSignature : DWORD; + dwAttrCount : DWORD; + lpAttributes : PWSAATTRINFO; + end; + LPWSABLOBATTRLIST = ^TWSABlobAttrList; + PWSABLOBATTRLIST = ^TWSABlobAttrList; +{$endif netware} + +{--------------------------------------------------------------------} + + { Socket function prototypes } + const + {$ifndef netware} + winsockdll = 'ws2_32.dll'; + _fn_bind = 'bind'; + _fn_closesocket = 'closesocket'; + _fn_ioctlsocket = 'ioctlsocket'; + _fn_getpeername = 'getpeername'; + _fn_getsockopt = 'getsockopt'; + _fn_htonl = 'htonl'; + _fn_htons = 'htons'; + _fn_inet_addr = 'inet_addr'; + _fn_inet_ntoa = 'inet_ntoa'; + _fn_listen = 'listen'; + _fn_recv = 'recv'; + _fn_recvfrom = 'recvfrom'; + _fn_select = 'select'; + _fn_send = 'send'; + _fn_sendto = 'sendto'; + _fn_setsockopt = 'setsockopt'; + _fn_shutdown = 'shutdown'; + _fn_socket = 'socket'; + _fn_gethostbyaddr = 'gethostbyaddr'; + _fn_gethostbyname = 'gethostbyname'; + _fn_gethostname = 'gethostname'; + _fn_getservbyport = 'getservbyport'; + _fn_getservbyname = 'getservbyname'; + _fn_getprotobynumber = 'getprotobynumber'; + _fn_getprotobyname = 'getprotobyname'; + {$else} + winsockdll = 'ws2_32.nlm'; + {for netware the function names for the non WSA-functions are + different because the names are already present from bsd-sockets} + _fn_bind = 'WS2_32_bind'; + _fn_closesocket = 'WS2_32_closesocket'; + _fn_ioctlsocket = 'WS2_32_ioctlsocket'; + _fn_getpeername = 'WS2_32_getpeername'; + _fn_getsockopt = 'WS2_32_getsockopt'; + _fn_htonl = 'WS2_32_htonl'; + _fn_htons = 'WS2_32_htons'; + _fn_inet_addr = 'WS2_32_inet_addr'; + _fn_inet_ntoa = 'WS2_32_inet_ntoa'; + _fn_listen = 'WS2_32_listen'; + _fn_recv = 'WS2_32_recv'; + _fn_recvfrom = 'WS2_32_recvfrom'; + _fn_select = 'WS2_32_select'; + _fn_send = 'WS2_32_send'; + _fn_sendto = 'WS2_32_sendto'; + _fn_setsockopt = 'WS2_32_setsockopt'; + _fn_shutdown = 'WS2_32_shutdown'; + _fn_socket = 'WS2_32_socket'; + _fn_gethostbyaddr = 'WS2_32_gethostbyaddr'; + _fn_gethostbyname = 'WS2_32_gethostbyname'; + _fn_gethostname = 'WS2_32_gethostname'; + _fn_getservbyport = 'WS2_32_getservbyport'; + _fn_getservbyname = 'WS2_32_getservbyname'; + _fn_getprotobynumber = 'WS2_32_getprotobynumber'; + _fn_getprotobyname = 'WS2_32_getprotobyname'; + {$endif} + +{ +Winsock types all buffers as pchar (char *), modern POSIX does it the ANSI +C way with pointer (void *). If the pointer overloaded version doesn't exist, +a "pointer" will be passed to the "var" version. (bug 3142). +So if there are var/const versions: +- To keep ported unix code working, there must be "pointer" variants (ANSI) +- To keep Delphi/ported C Winsock code working there must be pchar variants + (K&R) +IOW, there _must_ be 3 versions then: var/const, pchar and pointer} + + {$ifdef netware} + function accept(s:TSocket; addr: PSockAddr; addrlen : ptOS_INT) : TSocket; + function accept(s:TSocket; addr: PSockAddr; var addrlen : tOS_INT) : TSocket; + {$else} + function accept(s:TSocket; addr: PSockAddr; addrlen : ptOS_INT) : TSocket;stdcall;external winsockdll name 'accept'; + function accept(s:TSocket; addr: PSockAddr; var addrlen : tOS_INT) : TSocket;stdcall;external winsockdll name 'accept'; + {$endif} + function bind(s:TSocket; addr: PSockaddr;namelen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_Bind; + function bind(s:TSocket; const addr: TSockaddr;namelen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_Bind; + function closesocket(s:TSocket):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_closesocket; + {$ifdef netware} + function connect(s:TSocket; addr:PSockAddr; namelen:tOS_INT):tOS_INT; + function connect(s:TSocket; Const name:TSockAddr; namelen:tOS_INT):tOS_INT; + {$else} + function connect(s:TSocket; addr:PSockAddr; namelen:tOS_INT):tOS_INT; stdcall;external winsockdll name 'connect'; + function connect(s:TSocket; Const name:TSockAddr; namelen:tOS_INT):tOS_INT; stdcall;external winsockdll name 'connect'; + {$endif} + + function ioctlsocket(s:TSocket; cmd:longint; var arg:u_long):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_ioctlsocket; + function ioctlsocket(s:TSocket; cmd:longint; var arg:longint):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_ioctlsocket; + function ioctlsocket(s:TSocket; cmd:longint; argp:pu_long):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_ioctlsocket; + function getpeername(s:TSocket; var name:TSockAddr;var namelen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_getpeername; + function getsockname(s:TSocket; var name:TSockAddr;var namelen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_getpeername; + function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; optval:pchar;var optlen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_getsockopt; + function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; optval:pointer;var optlen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_getsockopt; + function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;var optval;var optlen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_getsockopt; + function htonl(hostlong:u_long):u_long;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_htonl; + function htons(hostshort:u_short):u_short;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_htons; + function inet_addr(cp:pchar):cardinal;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_inet_addr; + function inet_ntoa(i : TInAddr):pchar;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_inet_ntoa; + function listen(s:TSocket; backlog:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_listen; + { are ntohl and ntohs macros or bsd-functions (for netware) ?? } + {$ifndef netware} + function ntohl(netlong:u_long):u_long;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'ntohl'; + function ntohs(netshort:u_short):u_short;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'ntohs'; + {$endif} + + function recv(s:TSocket;buf:pchar; len:tOS_INT; flags:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_recv; + function recv(s:TSocket;buf:pointer; len:tOS_INT; flags:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_recv; + function recv(s:TSocket;var buf; len:tOS_INT; flags:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_recv; + function recvfrom(s:TSocket;buf:pchar; len:tOS_INT; flags:tOS_INT;from:PSockAddr; fromlen:ptOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_recvfrom; + function recvfrom(s:TSocket;buf:pointer; len:tOS_INT; flags:tOS_INT;from:PSockAddr; fromlen:ptOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_recvfrom; + function recvfrom(s:TSocket;var buf; len:tOS_INT; flags:tOS_INT;Const from:TSockAddr; var fromlen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_recvfrom; + function select(nfds:tOS_INT; readfds,writefds,exceptfds : PFDSet;timeout: PTimeVal):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_select; + function send(s:TSocket;const buf; len:tOS_INT; flags:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_send; + function send(s:TSocket;buf : pchar; len:tOS_INT; flags:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_send; + function send(s:TSocket;buf : pointer; len:tOS_INT; flags:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_send; + function sendto(s:TSocket; buf:pchar; len:tOS_INT; flags:tOS_INT;toaddr:PSockAddr; tolen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_sendto; + function sendto(s:TSocket; buf:pointer; len:tOS_INT; flags:tOS_INT;toaddr:PSockAddr; tolen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_sendto; + function sendto(s:TSocket; const buf; len:tOS_INT; flags:tOS_INT;Const toaddr:TSockAddr; tolen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} + external winsockdll name _fn_sendto; + + function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; optval:pchar; optlen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_setsockopt; + function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; Const optval; optlen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_setsockopt; + function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; optval:pointer; optlen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_setsockopt; + function shutdown(s:TSocket; how:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_shutdown; + function socket(af:tOS_INT; t:tOS_INT; protocol:tOS_INT):TSocket;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name _fn_socket; + + { Database function prototypes } + function gethostbyaddr(addr:pchar; len:tOS_INT; t:tOS_INT): PHostEnt;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_gethostbyaddr; + function gethostbyname(name:pchar):PHostEnt;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_gethostbyname; + function gethostname(name:pchar; namelen:tOS_INT):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_gethostname; + function getservbyport(port:tOS_INT; proto:pchar):PServEnt;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_getservbyport; + function getservbyname(name:pchar; proto:pchar):PServEnt;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_getservbyname; + function getprotobynumber(proto:tOS_INT):PProtoEnt;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_getprotobynumber; + function getprotobyname(name:pchar):PProtoEnt;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name _fn_getprotobyname; + + { Microsoft Windows Extension function prototypes } + function WSAStartup(wVersionRequired:word;var WSAData:TWSADATA):tOS_INT; + function WSACleanup:tOS_INT; + procedure WSASetLastError(iError:tOS_INT);{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSASetLastError'; + function WSAGetLastError:tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAGetLastError'; + {$ifndef netware} + //function WSAIsBlocking:BOOL;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAIsBlocking'; + // function WSAUnhookBlockingHook:tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAUnhookBlockingHook'; + // function WSASetBlockingHook(lpBlockFunc:TFarProc):TFarProc;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSASetBlockingHook'; + {$endif} + function WSACancelBlockingCall:tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSACancelBlockingCall'; + {$ifndef netware} + function WSAAsyncGetServByName(hWnd:HWND; wMsg:u_int; name:pchar; proto:pchar; buf:pchar; + buflen:tOS_INT):THandle;stdcall;external winsockdll name 'WSAAsyncGetServByName'; + function WSAAsyncGetServByPort(hWnd:HWND; wMsg:u_int; port:tOS_INT; proto:pchar; buf:pchar; + buflen:tOS_INT):THandle;stdcall;external winsockdll name 'WSAAsyncGetServByPort'; + function WSAAsyncGetProtoByName(hWnd:HWND; wMsg:u_int; name:pchar; buf:pchar; buflen:tOS_INT):THandle;stdcall; + external winsockdll name 'WSAAsyncGetProtoByName'; + function WSAAsyncGetProtoByNumber(hWnd:HWND; wMsg:u_int; number:tOS_INT; buf:pchar; buflen:tOS_INT):THandle;stdcall; + external winsockdll name 'WSAAsyncGetProtoByNumber'; + function WSAAsyncGetHostByName(hWnd:HWND; wMsg:u_int; name:pchar; buf:pchar; buflen:tOS_INT):THandle;stdcall; + external winsockdll name 'WSAAsyncGetHostByName'; + function WSAAsyncGetHostByAddr(hWnd:HWND; wMsg:u_int; addr:pchar; len:tOS_INT; t:tOS_INT; + buf:pchar; buflen:tOS_INT):THandle;stdcall; + external winsockdll name 'WSAAsyncGetHostByAddr'; + function WSACancelAsyncRequest(hAsyncTaskHandle:THandle):tOS_INT;stdcall; + external winsockdll name 'WSACancelAsyncRequest'; + function WSAAsyncSelect(s:TSocket; hWnd:HWND; wMsg:u_int; lEvent:longint):tOS_INT; stdcall; + external winsockdll name 'WSAAsyncSelect'; + function WSARecvEx(s:TSocket;var buf; len:tOS_INT; flags:ptOS_INT):tOS_INT;stdcall; + external winsockdll name 'WSARecvEx'; + {$endif} + function __WSAFDIsSet(s:TSocket; var FDSet:TFDSet):Bool;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name '__WSAFDIsSet'; + function __WSAFDIsSet_(s:TSocket; var FDSet:TFDSet):tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name '__WSAFDIsSet'; + + {$ifndef netware} + function TransmitFile(hSocket:TSocket; hFile:THandle; nNumberOfBytesToWrite:dword; + nNumberOfBytesPerSend:DWORD; lpOverlapped:POverlapped; + lpTransmitBuffers:PTransmitFileBuffers; dwReserved:dword):Bool;stdcall; + external winsockdll name 'TransmitFile'; + + function AcceptEx(sListenSocket,sAcceptSocket:TSocket; + lpOutputBuffer:Pointer; dwReceiveDataLength,dwLocalAddressLength, + dwRemoteAddressLength:dword; var lpdwBytesReceived:dword; + lpOverlapped:POverlapped):Bool;stdcall; + external winsockdll name 'AcceptEx'; + + procedure GetAcceptExSockaddrs(lpOutputBuffer:Pointer; + dwReceiveDataLength,dwLocalAddressLength,dwRemoteAddressLength:dword; + var LocalSockaddr:TSockAddr; var LocalSockaddrLength:tOS_INT; + var RemoteSockaddr:TSockAddr; var RemoteSockaddrLength:tOS_INT);stdcall; + external winsockdll name 'GetAcceptExSockaddrs'; + {$endif} + + function WSAMakeSyncReply(Buflen,Error:Word):dword; + function WSAMakeSelectReply(Event,Error:Word):dword; + function WSAGetAsyncBuflen(Param:dword):Word; + function WSAGetAsyncError(Param:dword):Word; + function WSAGetSelectEvent(Param:dword):Word; + function WSAGetSelectError(Param:dword):Word; + procedure FD_CLR(Socket:TSocket; var FDSet:TFDSet); + function FD_ISSET(Socket:TSocket; var FDSet:TFDSet):Boolean; + procedure FD_SET(Socket:TSocket; var FDSet:TFDSet); + procedure FD_ZERO(var FDSet:TFDSet); + + function MAKELONG(a,b : longint) : LONGINT; + function MAKEWORD(a,b : longint) : WORD; + + { WinSock 2 API new function prototypes } + + function WSAAccept(s: TSocket; addr:PSockAddr; addrlen : ptOS_INT; + lpfnCondition : TCONDITIONPROC; + dwCallbackData: dword) : longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAAccept'; + + function WSAAccept(s: TSocket; addr:PSockAddr; var addrlen:longint; + lpfnCondition : TCONDITIONPROC; + dwCallbackData: dword) : longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAAccept'; + + function WSACloseEvent (hEvent : TWSAEVENT) : longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSACloseEvent'; + + function WSAconnect (s:TSocket; Const name:TSockAddr; + namelen: tOS_INT; + lpCallerData, lpCaleeData : PWSABUF; + lpSQOS, lpGQOS : PQOS) : tOS_INT; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAConnect'; + + function WSAconnect (s:TSocket; name:PSockAddr; + namelen: tOS_INT; + lpCallerData, lpCaleeData : PWSABUF; + lpSQOS, lpGQOS : PQOS) : tOS_INT; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAConnect'; + + {$ifndef netware} + function WSADuplicateSocket (s:TSocket; dwProcessId:dword; lpProtoInfo: PWSAPROTOCOL_INFOA) : longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSADuplicateSocketA'; + {$endif} + + function WSAEnumNetworkEvents(s:TSocket;hEventObject:TWSAEVENT;lpNetworkEvents:PWSANETWORKEVENTS): longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAEnumNetworkEvents'; + + function WSAEnumProtocols (lpiProtocols:LPINT; + lpProtocolBuffer:PWSAPROTOCOL_INFOA; + var lpdwBufferLength : dword) : longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAEnumProtocolsA'; + + function WSAEventSelect(s:TSocket; hEventObject: TWSAEvent;lNetworkEvents:longint):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAEventSelect'; + + function WSAGetOverlappedResult (s:TSocket; + lpOverlapped:PWSAOVERLAPPED; + lpcbTransfer : LPDWORD; + fWait : BOOL; + lpdwFlags : LPDWORD) : longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAGetOverlappedResult'; + + function WSAGetQOSByName(s:TSocket; lpQOSName: LPWSABUF; lpQOS:PQOS) : longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAGetQOSByName'; + + function WSAHtonl(s:TSocket; hostlong:u_long;lpnetlong:pu_long):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAHtonl'; + + function WSAHtonl(s:TSocket; hostlong:u_long;var lpnetlong:u_long):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAHtonl'; + + function WSAHtons(s:TSocket; hostshort:u_short;lpnetshort:pu_short):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAHtons'; + + function WSAHtons(s:TSocket; hostshort:u_short;var lpnetshort:u_short):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAHtons'; + + function WSAIoctl(s:TSocket;dwIoControlCode:dword; + lpvInBuffer:pointer; cbInBuffer:dword; + lpvOutBuffer:pointer; cbOutBuffer:dword; + lpcbBytesReturned:LPDWORD; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAIoctl'; + + function WSAIoctl(s:TSocket;dwIoControlCode:dword; + var lpvInBuffer; cbInBuffer:dword; + var lpvOutBuffer; cbOutBuffer:dword; + var lpcbBytesReturned:DWORD; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAIoctl'; + + function WSAJoinLeaf(s:TSocket; name: PSockAddr; namelen:longint; + lpCallerData,lpCalleeData:PWSABUF; + lpSQOS, lpGQOS : PQOS; dwFlags:dword):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAJoinLeaf'; + + function WSANtohl(s:TSocket;netlong:u_long;lphostlong:pu_long):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSANtohl'; + + function WSANtohl(s:TSocket;netlong:u_long;var hostlong:u_long):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSANtohl'; + + function WSANtohs(s:TSocket;netshort:u_short;lphostshort:pu_short):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSANtohs'; + + function WSANtohs(s:TSocket;netshort:u_short;var hostshort:u_short):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSANtohs'; + + function WSARecv(s:TSocket;buf:pchar; dwBufferCount:dword; + lpNumberOfBytesRecvd,lpFlags : LPDWORD; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSARecv'; + + function WSARecv(s:TSocket;buf:pointer; dwBufferCount:dword; + lpNumberOfBytesRecvd,lpFlags : LPDWORD; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSARecv'; + + function WSARecv(s:TSocket;var buf; dwBufferCount:dword; + var lpNumberOfBytesRecvd,lpFlags : DWORD; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSARecv'; + + function WSARecvDisconnect(s:TSocket;lpInboundDisconnectData:PWSABUF):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSARecvDisconnect'; + + function WSARecvDisconnect(s:TSocket;var InboundDisconnectData:TWSABUF):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSARecvDisconnect'; + + function WSARecvFrom(s:TSocket;buf:pchar; dwBufferCount:dword; + lpNumberOfBytesRecvd,lpFlags : LPDWORD; + lpFrom: PSockaddr; + lpFromlen: PDWORD; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSARecvFrom'; + + function WSARecvFrom(s:TSocket;buf:pointer; dwBufferCount:dword; + lpNumberOfBytesRecvd,lpFlags : LPDWORD; + lpFrom: PSockaddr; + lpFromlen: PDWORD; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSARecvFrom'; + + function WSARecvFrom(s:TSocket;var buf; dwBufferCount:dword; + var lpNumberOfBytesRecvd,lpFlags : DWORD; + var lpFrom: TSockaddr; + var lpFromlen: DWORD; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSARecvFrom'; + + function WSAResetEvent(hEvent:TWSAEVENT):BOOL; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAResetEvent'; + + function WSASend(s:TSocket;buf:pchar;len:dword; + NumberOfBytesSent:PDWORD; Flags:dword; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSASend'; + + function WSASend(s:TSocket;buf:pointer;len:dword; + NumberOfBytesSent:PDWORD; Flags:dword; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSASend'; + + function WSASend(s:TSocket;var buf;len:dword; + var NumberOfBytesSent: DWORD; Flags:dword; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSASend'; + + function WSASendDisconnect(s:TSocket;lpOutboundDisconnectData:PWSABUF):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSASendDisconnect'; + + function WSASendTo(s:TSocket;buf:pchar;len:dword; + NumberOfBytesSent:LPDWORD; + Flags:dword; + lpTo: PSockaddr; + iToLen:dword; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSASendTo'; + + function WSASendTo(s:TSocket;buf:pointer;len:dword; + NumberOfBytesSent:LPDWORD; + Flags:dword; + lpTo: PSockaddr; + iToLen:dword; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSASendTo'; + + function WSASendTo(s:TSocket;var buf;len:dword; + var NumberOfBytesSent:DWORD; + Flags:dword; + var lpTo: TSockaddr; + iToLen:dword; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSASendTo'; + + function WSASetEvent(hEvent:TWSAEVENT):BOOL; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSASetEvent'; + + function WSASocket(af,typ,proto:tOS_INT; + lpProtocolInfo:PWSAPROTOCOL_INFO; + g : TGROUP; Flags:dword):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSASocketA'; + + function WSAWaitForMultipleEvents(cEvents:dword; + lphEvents:pointer; {IN const WSAEVENT FAR * lphEvents,} + fWaitAll:BOOL; dwTimeout:dword; fAlertable:BOOL):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAWaitForMultipleEvents'; + + function WSAAddressToString(addr:PSockAddr; len:dword; + ProtocolInfo:PWSAPROTOCOL_INFO; + lpszAddressString:pchar; + lpdwAddressStringLength:lpdword):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAAddressToStringA'; + + function WSAAddressToString(var addr:TSockAddr; len:dword; + ProtocolInfo:PWSAPROTOCOL_INFO; + lpszAddressString:pchar; + var lpdwAddressStringLength:dword):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAAddressToStringA'; + + function WSAStringToAddress (AddressString : pchar; + AddressFamily : longint; + lpProtocolInfo : PWSAPROTOCOL_INFOA; + VAR lpAddress : TSOCKADDR; + VAR lpAddressLength: LONGINT) : longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} external winsockdll name 'WSAStringToAddressA'; + + function WSAStringToAddress (AddressString : pchar; + AddressFamily : longint; + lpProtocolInfo : PWSAPROTOCOL_INFOA; + lpAddress : PSOCKADDR; + VAR lpAddressLength: LONGINT) : longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAStringToAddressA'; + + function WSALookupServiceBegin(lpqsRestrictions:PWSAQUERYSET; + ControlFlags:dword;lphLookup:PHandle):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSALookupServiceBeginA'; + + function WSALookupServiceBegin(var Restrictions:TWSAQUERYSET; + ControlFlags:dword;var hLookup:THandle):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSALookupServiceBeginA'; + + function WSALookupServiceNext(hLookup:THandle;ControlFlags:dword; + lpdwBufferLength:LPDWORD; + lpqsResults:PWSAQUERYSET):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSALookupServiceNextA'; + + function WSAInstallServiceClass(lpServiceClassInfo:PWSASERVICECLASSINFO):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAInstallServiceClassA'; + + function WSARemoveServiceClass(lpServiceClassId:PGUID):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSARemoveServiceClass'; + + function WSAGetServiceClassInfo(lpProviderId,lpServiceClassId:PGUID; + lpdwBufSize:LPDWORD; + lpServiceClassInfo:PWSASERVICECLASSINFO):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAGetServiceClassInfoA'; + + function WSAGetServiceClassInfo(var ProviderId,ServiceClassId:TGUID; + var BufSize:DWORD; + var ServiceClassInfo:TWSASERVICECLASSINFO):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAGetServiceClassInfoA'; + + function WSAEnumNameSpaceProviders(lpdwBufferLength:LPDWORD;lpnspBuffer:PWSANAMESPACE_INFO):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAEnumNameSpaceProvidersA'; + + function WSAEnumNameSpaceProviders(var BufferLength:DWORD;var Buffer:TWSANAMESPACE_INFO):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAEnumNameSpaceProvidersA'; + + function WSAGetServiceClassNameByClassId(lpServiceClassId:PGUID;lpszServiceClassName:pchar;buflen:PDWORD):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAGetServiceClassNameByClassIdA'; + + function WSAGetServiceClassNameByClassId(var lpServiceClassId:TGUID;lpszServiceClassName:pchar;var buflen:DWORD):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAGetServiceClassNameByClassIdA'; + + function WSASetService(lpqsRegInfo:PWSAQUERYSET;essoperation:TWSAESETSERVICEOP;flags:dword):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSASetServiceA'; + + {$ifndef Netware} + function WSAProviderConfigChange(lpNotificationHandle:LPHANDLE; + lpOverlapped:PWSAOVERLAPPED; + lpCompletionRoutine:TWSAOVERLAPPED_COMPLETION_ROUTINE):longint; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSAProviderConfigChange'; + {$endif} + + + + implementation + + { was #define dname(params) def_expr } + { argument types are unknown } + function MAKELONG(a,b : longint) : LONGINT; + begin + MAKELONG:=LONGINT((WORD(a)) or ((DWORD(WORD(b))) shl 16)); + end; + + function MAKEWORD(a,b : longint) : WORD; + begin + MAKEWORD:=WORD((BYTE(a)) or ((WORD(BYTE(b))) shl 8)); + end; + + { + Implementation of the helper routines + } + function WSAMakeSyncReply(Buflen,Error:Word):dword; + + begin + WSAMakeSyncReply:=MakeLong(Buflen, Error); + end; + + function WSAMakeSelectReply(Event,Error:Word):dword; + + begin + WSAMakeSelectReply:=MakeLong(Event,Error); + end; + + function WSAGetAsyncBuflen(Param:dword):Word; + + begin + WSAGetAsyncBuflen:=lo(Param); + end; + + function WSAGetAsyncError(Param:dword):Word; + + begin + WSAGetAsyncError:=hi(Param); + end; + + function WSAGetSelectEvent(Param:dword):Word; + + begin + WSAGetSelectEvent:=lo(Param); + end; + + function WSAGetSelectError(Param:dword):Word; + + begin + WSAGetSelectError:=hi(Param); + end; + + procedure FD_CLR(Socket:TSocket; var FDSet:TFDSet); + + var + i : u_int; + + begin + i:=0; + while i<FDSet.fd_count do + begin + if FDSet.fd_array[i]=Socket then + begin + while i<FDSet.fd_count-1 do + begin + FDSet.fd_array[i]:=FDSet.fd_array[i+1]; + inc(i); + end; + dec(FDSet.fd_count); + break; + end; + inc(i); + end; + end; + + function FD_ISSET(Socket:TSocket; var FDSet:TFDSet):Boolean; + begin + FD_ISSET:=__WSAFDIsSet(Socket,FDSet); + end; + + procedure FD_SET(Socket:TSocket; var FDSet:TFDSet); + var i : integer; + begin + if FDSet.fd_count > FD_SETSIZE then + FDSet.fd_count := FD_SETSIZE; + for i := 1 to FDSet.fd_count do + if FDSet.fd_array[i-1] = Socket then exit; {this is what the c macro FD_SET does} + if FDSet.fd_count<FD_SETSIZE then + begin + FDSet.fd_array[FDSet.fd_count]:=Socket; + Inc(FDSet.fd_count); + end; + end; + + procedure FD_ZERO(var FDSet:TFDSet); + begin + fillchar(FDSet,sizeof(FDSet),0); + {FDSet.fd_count:=0;} + end; + + {$ifdef netware} + {windows has connect and accept in ws2_32.dll, netware has not, they + are defined as macros in ws2nlm.h } + + function connect(s:TSocket; addr:PSockAddr; namelen:tOS_INT):tOS_INT; + begin + connect := WSAConnect (s,addr,namelen,nil,nil,nil,nil); + end; + + function connect(s:TSocket; Const name:TSockAddr; namelen:tOS_INT):tOS_INT; //cdecl;external winsockdll name 'WSAConnect'; + begin + connect := WSAConnect (s,@name,namelen,nil,nil,nil,nil); + end; + + function accept(s:TSocket; addr: PSockAddr; addrlen : ptOS_INT) : TSocket; + begin + accept := WSAAccept (s,addr,addrlen,nil,0); + end; + + function accept(s:TSocket; addr: PSockAddr; var addrlen : tOS_INT) : TSocket; + begin + accept := WSAAccept (s,addr,@addrlen,nil,0); + end; + + + {$endif} + + {AD 2003/03/25: Special for netware + if WSAStartup is called more than once, bad thinks will happen + on netware. This is not a problem under windows. + This happens with fcl because the unit initialization of SSockets and + resolve both calls WSAStartup, for the second startup we simply + return success without calling the WS2_32 WSAStartup } + + function __WSAStartup(wVersionRequired:word;var WSAData:TWSADATA):tOS_INT; + {$ifdef Netware}cdecl;{$else}stdcall;{$endif} + external winsockdll name 'WSAStartup'; + + function __WSACleanup:tOS_INT;{$ifdef Netware}cdecl;{$else}stdcall;{$endif}external winsockdll name 'WSACleanup'; + + var WSAstartupData : TWSADATA; + + function WSACleanup:tOS_INT; + begin + if WSAstartupData.wVersion <> $ffff then + begin + Result := __WSACleanup; + if Result = 0 then WSAstartupData.wVersion := $ffff; + end else Result := WSANOTINITIALISED; + end; + + function WSAStartup(wVersionRequired:word;var WSAData:TWSADATA):tOS_INT; + begin + if WSAstartupData.wVersion = $ffff then + begin + Result := __WSAStartup(wVersionRequired,WSAData); + if Result = 0 then WSAstartupData := WSAData; + {Writeln (stderr,'WSAStartup called');} + end else + begin + result := 0; + {Writeln (stderr,'WSAStartup should be called only once !');} + end; + end; + +var + oldUnloadProc : pointer; + + procedure exitProc; + begin + {$ifdef DEBUG_MT} + ConsolePrintf (#13'winsock.exitProc called'#13#10); + {$endif} + NetwareUnloadProc := oldUnloadProc; + WSACleanup; + end; + + + +initialization + WSAstartupData.wVersion := $ffff; + oldUnloadProc := NetwareUnloadProc; + NetwareUnloadProc := @exitProc; +finalization + WSACleanUp; +end. diff --git a/packages/rtl-extra/src/netwlibc/netwsockh.inc b/packages/rtl-extra/src/netwlibc/netwsockh.inc new file mode 100644 index 0000000000..f8cdae57cc --- /dev/null +++ b/packages/rtl-extra/src/netwlibc/netwsockh.inc @@ -0,0 +1,57 @@ +const + AF_UNSPEC = winsock.AF_UNSPEC; + AF_UNIX = winsock.AF_UNIX; + AF_INET = winsock.AF_INET; + AF_IMPLINK = winsock.AF_IMPLINK; + AF_PUP = winsock.AF_PUP; + AF_CHAOS = winsock.AF_CHAOS; + AF_NS = winsock.AF_NS; + AF_IPX = winsock.AF_IPX; + AF_ISO = winsock.AF_ISO; + AF_OSI = winsock.AF_OSI; + AF_ECMA = winsock.AF_ECMA; + AF_DATAKIT = winsock.AF_DATAKIT; + AF_CCITT = winsock.AF_CCITT; + AF_SNA = winsock.AF_SNA; + AF_DECnet = winsock.AF_DECnet; + AF_DLI = winsock.AF_DLI; + AF_LAT = winsock.AF_LAT; + AF_HYLINK = winsock.AF_HYLINK; + AF_APPLETALK = winsock.AF_APPLETALK; + AF_VOICEVIEW = winsock.AF_VOICEVIEW; + AF_FIREFOX = winsock.AF_FIREFOX; + AF_UNKNOWN1 = winsock.AF_UNKNOWN1; + AF_BAN = winsock.AF_BAN; + AF_ATM = winsock.AF_ATM; + AF_INET6 = winsock.AF_INET6; + AF_MAX = winsock.AF_MAX; + + PF_UNSPEC = AF_UNSPEC; + PF_UNIX = AF_UNIX; + PF_INET = AF_INET; + PF_IMPLINK = AF_IMPLINK; + PF_PUP = AF_PUP; + PF_CHAOS = AF_CHAOS; + PF_NS = AF_NS; + PF_IPX = AF_IPX; + PF_ISO = AF_ISO; + PF_OSI = AF_OSI; + PF_ECMA = AF_ECMA; + PF_DATAKIT = AF_DATAKIT; + PF_CCITT = AF_CCITT; + PF_SNA = AF_SNA; + PF_DECnet = AF_DECnet; + PF_DLI = AF_DLI; + PF_LAT = AF_LAT; + PF_HYLINK = AF_HYLINK; + PF_APPLETALK = AF_APPLETALK; + PF_VOICEVIEW = AF_VOICEVIEW; + PF_FIREFOX = AF_FIREFOX; + PF_UNKNOWN1 = AF_UNKNOWN1; + PF_BAN = AF_BAN; + PF_ATM = AF_ATM; + PF_INET6 = AF_INET6; + PF_MAX = AF_MAX; + + INVALID_SOCKET = -1; + SOCKET_ERROR = -1; diff --git a/packages/rtl-extra/src/netwlibc/sockets.pp b/packages/rtl-extra/src/netwlibc/sockets.pp new file mode 100644 index 0000000000..ab8bb76a53 --- /dev/null +++ b/packages/rtl-extra/src/netwlibc/sockets.pp @@ -0,0 +1,299 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2004 by the Free Pascal development team + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +{$mode objfpc} +unit Sockets; + +Interface + +{$macro on} +{$define maybelibc:=} + +{$R-} + +Uses + winsock; + +Type + cushort=word; + cuint8 =byte; + cuint16=word; + cuint32=cardinal; + size_t =cuint32; + ssize_t=cuint16; + cint =longint; + pcint =^cint; + tsocklen=cint; + psocklen=^tsocklen; + +const + EsockEINTR = WSAEINTR; + EsockEBADF = WSAEBADF; + EsockEFAULT = WSAEFAULT; + EsockEINVAL = WSAEINVAL; + EsockEACCESS = WSAEACCES; + EsockEMFILE = WSAEMFILE; + EsockEMSGSIZE = WSAEMSGSIZE; + EsockENOBUFS = WSAENOBUFS; + EsockENOTCONN = WSAENOTCONN; + EsockENOTSOCK = WSAENOTSOCK; + EsockEPROTONOSUPPORT = WSAEPROTONOSUPPORT; + EsockEWOULDBLOCK = WSAEWOULDBLOCK; + +{$i netwsockh.inc} +{$i socketsh.inc} + +Implementation + +{****************************************************************************** + Basic Socket Functions +******************************************************************************} + + + +//function fprecvmsg (s:cint; msg: pmsghdr; flags:cint):ssize_t; +//function fpsendmsg (s:cint; hdr: pmsghdr; flags:cint):ssize; + +//function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; + + +function SocketError: cint; +begin + SocketError := WSAGetLastError; +end; + +function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; +begin + fpSocket:=WinSock.Socket(Domain,xtype,ProtoCol); +end; + +function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t; +begin + fpSend:=WinSock.Send(S,msg,len,flags); +end; + +function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t; +begin + // Dubious construct, this should be checked. (IPV6 fails ?) + fpSendTo:=WinSock.SendTo(S,msg,Len,Flags,Winsock.TSockAddr(tox^),toLen); +end; + +function fprecv (s:cint; buf: pointer; len: size_t; flags: cint):ssize_t; +begin + fpRecv:=WinSock.Recv(S,Buf,Len,Flags); +end; + +function fprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t; +begin +fpRecvFrom:=WinSock.RecvFrom(S,Buf,Len,Flags,Winsock.TSockAddr(from^),FromLen^); +end; + +function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; +begin + fpConnect:=WinSock.Connect(S,WinSock.TSockAddr(name^),nameLen); +end; + +function fpshutdown (s:cint; how:cint):cint; +begin + fpShutDown:=WinSock.ShutDown(S,How); +end; + +Function socket(Domain,SocketType,Protocol:Longint):Longint; +begin + socket:=fpsocket(Domain,sockettype,protocol); +end; + +Function Send(Sock:Longint;Const Buf;BufLen,Flags:Longint):Longint; +begin + send:=fpsend(sock,@buf,buflen,flags); +end; + +Function SendTo(Sock:Longint;Const Buf;BufLen,Flags:Longint;Var Addr; AddrLen : Longint):Longint; +begin + sendto:=fpsendto(sock,@buf,buflen,flags,@addr,addrlen); +end; + +Function Recv(Sock:Longint;Var Buf;BufLen,Flags:Longint):Longint; +begin + Recv:=fpRecv(Sock,@Buf,BufLen,Flags); +end; + +Function RecvFrom(Sock : Longint; Var Buf; Buflen,Flags : Longint; Var Addr; var AddrLen : longint) : longint; +begin + RecvFrom:=fpRecvFrom(Sock,@Buf,BufLen,Flags,@Addr,@AddrLen); +end; + +function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; +begin + fpbind:=WinSock.Bind(S,WinSock.PSockAddr(Addrx),AddrLen); +end; + +function fplisten (s:cint; backlog : cint):cint; +begin + fplisten:=WinSock.Listen(S,backlog); +end; + +function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; +begin + fpAccept:=WinSock.Accept(S,WinSock.PSockAddr(Addrx),plongint(AddrLen)); +end; + +function fpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpGetSockName:=WinSock.GetSockName(S,WinSock.TSockAddr(name^),nameLen^); +end; + +function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpGetPeerName:=WinSock.GetPeerName(S,WinSock.TSockAddr(name^),NameLen^); +end; + +function fpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint; +begin + fpGetSockOpt:=WinSock.GetSockOpt(S,Level,OptName,OptVal,OptLen^); +end; + +function fpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen :tsocklen):cint; +begin + fpSetSockOpt:=WinSock.SetSockOpt(S,Level,OptName,OptVal,OptLen); +end; + +function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; +begin + fpSocketPair := -1; +end; + +Function CloseSocket(Sock:Longint):Longint; +begin + CloseSocket := Winsock.CloseSocket (Sock); +end; + +Function Bind(Sock:Longint;Const Addr;AddrLen:Longint):Boolean; +begin + bind:=fpBind(Sock,@Addr,AddrLen)=0; +end; + +Function Listen(Sock,MaxConnect:Longint):Boolean; +begin + Listen:=fplisten(Sock,MaxConnect)=0; +end; + +Function Accept(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + Accept:=FPAccept(sock,@addr,@addrlen); +end; + +Function Shutdown(Sock:Longint;How:Longint):Longint; +begin + shutdown:=fpshutdown(sock,how); +end; + +Function Connect(Sock:Longint;Const Addr;Addrlen:Longint):Boolean; +begin + connect:=fpconnect(sock,@addr,addrlen)=0; +end; + +Function GetSocketName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + GetSocketName:=fpGetSockName(sock,@addr,@addrlen); +end; + +Function GetPeerName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + GetPeerName:=fpGetPeerName(Sock,@addr,@addrlen); +end; + +Function GetSocketOptions(Sock,Level,OptName:Longint;Var OptVal;Var optlen:longint):Longint; +begin + GetSocketOptions:=fpGetSockOpt(sock,level,optname,@optval,@optlen); +end; + +Function SetSocketOptions(Sock,Level,OptName:Longint;Const OptVal;optlen:longint):Longint; +begin + SetSocketOptions:=fpsetsockopt(sock,level,optname,@optval,optlen); +end; + +Function SocketPair(Domain,SocketType,Protocol:Longint;var Pair:TSockArray):Longint; +begin + // SocketPair:=SocketCall(Socket_Sys_SocketPair,Domain,SocketType,Protocol,longint(@Pair),0,0); + SocketPair := -1; +end; + + +{$ifdef unix} +{ mimic the linux fpWrite/fpRead calls for the file/text socket wrapper } +function fpWrite(handle : longint;Const bufptr;size : dword) : dword; +begin + fpWrite := dword(WinSock.send(handle, bufptr, size, 0)); + if fpWrite = dword(SOCKET_ERROR) then + fpWrite := 0; +end; + +function fpRead(handle : longint;var bufptr;size : dword) : dword; +var + d : dword; +begin + if ioctlsocket(handle,FIONREAD,@d) = SOCKET_ERROR then + begin + fpRead:=0; + exit; + end; + if d>0 then + begin + if size>d then + size:=d; + fpRead := dword(WinSock.recv(handle, bufptr, size, 0)); + if fpRead = dword(SOCKET_ERROR) then + fpRead := 0; + end; + end; +{$else} +{ mimic the linux fpWrite/fpRead calls for the file/text socket wrapper } +function fpWrite(handle : longint;Const bufptr;size : dword) : dword; +begin + fpWrite := dword(WinSock.send(handle, bufptr, size, 0)); + if fpWrite = dword(SOCKET_ERROR) then + fpWrite := 0; +end; + +function fpRead(handle : longint;var bufptr;size : dword) : dword; +var + d : dword; +begin + if ioctlsocket(handle,FIONREAD,@d) = SOCKET_ERROR then + begin + fpRead:=0; + exit; + end; + if d>0 then + begin + if size>d then + size:=d; + fpRead := dword(WinSock.recv(handle, bufptr, size, 0)); + if fpRead = dword(SOCKET_ERROR) then + fpRead := 0; + end; + end; +{$endif} + +{$i sockets.inc} + +{ winsocket stack needs an init. and cleanup code } +var + wsadata : twsadata; + +initialization + WSAStartUp($2,wsadata); +finalization + WSACleanUp; +end. diff --git a/packages/rtl-extra/src/openbsd/osdefs.inc b/packages/rtl-extra/src/openbsd/osdefs.inc new file mode 100644 index 0000000000..27bcdfb374 --- /dev/null +++ b/packages/rtl-extra/src/openbsd/osdefs.inc @@ -0,0 +1,30 @@ +{ + Copyright (c) 2000-2002 by Marco van de Voort + + Target dependent defines used when compiling the baseunix unit + Copied over to opensd directory because of + missing SigTimedWait syscall + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + ****************************************************************************} + +{$define usedomain} // Allow uname with "domain" entry. + // (which is a GNU extension) +{$define hassysctl} // Use sysctl unit + +{ SigTimedWait syscal does not seem to exist for OpenBSD OS } +{$define FPC_SYS_SIGTIMEDWAIT_UNAVAILABLE} diff --git a/packages/rtl-extra/src/os2commn/sockets.pp b/packages/rtl-extra/src/os2commn/sockets.pp new file mode 100644 index 0000000000..99bf16c378 --- /dev/null +++ b/packages/rtl-extra/src/os2commn/sockets.pp @@ -0,0 +1,866 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 2002 Yuri Prokushev + Copyright (c) 2005 Soren Ager + + Sockets implementation for OS/2 + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +{$MODE ObjFPC} +{ $DEFINE notUnix} // To make ssockets.pp compile +unit Sockets; + +interface + +uses + so32dll, ctypes; + +const + AF_UNSPEC = so32dll.AF_UNSPEC; // unspecified + AF_LOCAL = so32dll.AF_LOCAL; // local to host (pipes, portals) + AF_UNIX = so32dll.AF_UNIX; + AF_OS2 = so32dll.AF_OS2; + AF_INET = so32dll.AF_INET; // internetwork: UDP, TCP, etc. + AF_IMPLINK = so32dll.AF_IMPLINK; // arpanet imp addresses + AF_PUP = so32dll.AF_PUP; // pup protocols: e.g. BSP + AF_CHAOS = so32dll.AF_CHAOS; // mit CHAOS protocols + AF_NS = so32dll.AF_NS; // XEROX NS protocols + AF_ISO = so32dll.AF_ISO; // ISO protocols + AF_OSI = so32dll.AF_OSI; + AF_ECMA = so32dll.AF_ECMA; // european computer manufacturers + AF_DATAKIT = so32dll.AF_DATAKIT; // datakit protocols + AF_CCITT = so32dll.AF_CCITT; // CCITT protocols, X.25 etc + AF_SNA = so32dll.AF_SNA; // IBM SNA + AF_DECnet = so32dll.AF_DECnet; // DECnet + AF_DLI = so32dll.AF_DLI; // DEC Direct data link interface + AF_LAT = so32dll.AF_LAT; // LAT + AF_HYLINK = so32dll.AF_HYLINK; // NSC Hyperchannel + AF_APPLETALK = so32dll.AF_APPLETALK; // Apple Talk + AF_NB = so32dll.AF_NB; // Netbios + AF_NETBIOS = so32dll.AF_NETBIOS; // Netbios + AF_LINK = so32dll.AF_LINK; // Link layer interface + pseudo_AF_XTP = so32dll.pseudo_AF_XTP; // eXpress Transfer Protocol (no AF) + AF_COIP = so32dll.AF_COIP; // connection-oriented IP, aka ST II + AF_CNT = so32dll.AF_CNT; // Computer Network Technology + pseudo_AF_RTIP = so32dll.pseudo_AF_RTIP; // Help Identify RTIP packets + AF_IPX = so32dll.AF_IPX; // Novell Internet Protocol + AF_SIP = so32dll.AF_SIP; // Simple Internet Protocol + AF_INET6 = so32dll.AF_INET6; + pseudo_AF_PIP = so32dll.pseudo_AF_PIP; // Help Identify PIP packets + AF_ROUTE = so32dll.AF_ROUTE; // Internal Routing Protocol + AF_FWIP = so32dll.AF_FWIP; // firewall support + AF_IPSEC = so32dll.AF_IPSEC; // IPSEC and encryption techniques + AF_DES = so32dll.AF_DES; // DES + AF_MD5 = so32dll.AF_MD5; + AF_CDMF = so32dll.AF_CDMF; + + AF_MAX = so32dll.AF_MAX; + +// PF_LOCAL = so32dll.PF_LOCAL; + PF_OS2 = so32dll.PF_OS2; + PF_IMPLINK = so32dll.PF_IMPLINK; + PF_PUP = so32dll.PF_PUP; + PF_CHAOS = so32dll.PF_CHAOS; + PF_NS = so32dll.PF_NS; + PF_ISO = so32dll.PF_ISO; + PF_OSI = so32dll.PF_OSI; + PF_ECMA = so32dll.PF_ECMA; + PF_DATAKIT = so32dll.PF_DATAKIT; + PF_CCITT = so32dll.PF_CCITT; + PF_SNA = so32dll.PF_SNA; + PF_DECnet = so32dll.PF_DECnet; + PF_DLI = so32dll.PF_DLI; + PF_LAT = so32dll.PF_LAT; + PF_HYLINK = so32dll.PF_HYLINK; + PF_APPLETALK = so32dll.PF_APPLETALK; + PF_NETBIOS = so32dll.PF_NB; + PF_NB = so32dll.PF_NB; + PF_ROUTE = so32dll.PF_ROUTE; + PF_LINK = so32dll.PF_LINK; + PF_XTP = so32dll.PF_XTP; // really just proto family, no AF + PF_COIP = so32dll.PF_COIP; + PF_CNT = so32dll.PF_CNT; + PF_SIP = so32dll.PF_SIP; + PF_INET6 = so32dll.PF_INET6; + PF_IPX = so32dll.PF_IPX; // same format as AF_NS + PF_RTIP = so32dll.PF_RTIP; // same format as AF_INET + PF_PIP = so32dll.PF_PIP; + + PF_MAX = so32dll.PF_MAX; + + EsockEINTR = SOCEINTR; + EsockEBADF = SOCEBADF; + EsockEFAULT = SOCEFAULT; + EsockEINVAL = SOCEINVAL; + EsockEACCESS = SOCEACCES; + EsockEMFILE = SOCEMFILE; + EsockEMSGSIZE = SOCEMSGSIZE; + EsockENOBUFS = SOCENOBUFS; + EsockENOTCONN = SOCENOTCONN; + EsockENOTSOCK = SOCENOTSOCK; + EsockEPROTONOSUPPORT = SOCEPROTONOSUPPORT; + EsockEWOULDBLOCK = SOCEWOULDBLOCK; + + +(***************************************************************************) +(* *) +(* Option flags per-socket *) +(* *) +(***************************************************************************) +const + // turn on debugging info recording + SO_DEBUG = $0001; + // socket has had listen() + SO_ACCEPTCONN = $0002; + // allow local address reuse + SO_REUSEADDR = $0004; + // keep connections alive + SO_KEEPALIVE = $0008; + // just use interface addresses + SO_DONTROUTE = $0010; + // permit sending of broadcast msgs + SO_BROADCAST = $0020; + // bypass hardware when possible + SO_USELOOPBACK = $0040; + // linger on close if data present + SO_LINGER = $0080; + // leave received OOB data in line + SO_OOBINLINE = $0100; + // limited broadcast sent on all IFs + SO_L_BROADCAST = $0200; + // set if shut down called for rcv + SO_RCV_SHUTDOWN = $0400; + // set if shutdown called for send + SO_SND_SHUTDOWN = $0800; + // allow local address & port reuse + SO_REUSEPORT = $1000; + // allow t/tcp on socket + SO_TTCP = $2000; + // aliases so we are cross-platform + SHUT_RD = SO_RCV_SHUTDOWN; + SHUT_WR = SO_SND_SHUTDOWN; + SHUT_RDWR = SO_RCV_SHUTDOWN or SO_SND_SHUTDOWN; + +(***************************************************************************) +(* *) +(* Additional options, not kept in so_options *) +(* *) +(***************************************************************************) + // send buffer size + SO_SNDBUF = $1001; + // receive buffer size + SO_RCVBUF = $1002; + // send low-water mark + SO_SNDLOWAT = $1003; + // receive low-water mark + SO_RCVLOWAT = $1004; + // send timeout + SO_SNDTIMEO = $1005; + // receive timeout + SO_RCVTIMEO = $1006; + // get error status and clear + SO_ERROR = $1007; + // get socket type + SO_TYPE = $1008; + // get socket options + SO_OPTIONS = $1010; + + +(***************************************************************************) +(* *) +(* Level number for (get/set)sockopt() to apply to socket itself *) +(* *) +(***************************************************************************) + // options for socket level + SOL_SOCKET = $ffff; + + +(***************************************************************************) +(* *) +(* Definitions for sysctl call. The sysctl call uses a hierarchical name *) +(* for objects that can be examined or modified. The name is expressed as *) +(* a sequence of integers. Like a file path name, the meaning of each *) +(* component depends on its place in the hierarchy. The top-level and kern *) +(* identifiers are defined here, and other identifiers are defined in the *) +(* respective subsystem header files. *) +(* *) +(***************************************************************************) + +// largest number of components supported + CTL_MAXNAME = 12; + + // name is a node + CTLTYPE_NODE =1; + // name describes an integer + CTLTYPE_INT =2; + // name describes a string + CTLTYPE_STRING =3; + // name describes a 64-bit number + CTLTYPE_QUAD =4; + // name describes a structure + CTLTYPE_STRUCT =5; + // inetcfg sysctl code + CTLTYPE_INETCFG =6; + // inetver sysctl code + CTLTYPE_INEVER =7; + +(* + * Top-level identifiers + *) + // "high kernel": proc, limits + CTL_KERN = 1; + // network, see socket.h + CTL_NET = 4; + // OS/2 specific codes + CTL_OS2 = 9; + + +{ +/* + * PF_ROUTE - Routing table + * + * Three additional levels are defined: + * Fourth: address family, 0 is wildcard + * Fifth: type of info, defined below + * Sixth: flag(s) to mask with for NET_RT_FLAGS + */ +} + // dump; may limit to a.f. + NET_RT_DUMP = 1; + // by flags, e.g. RESOLVING + NET_RT_FLAGS = 2; + // survey interface list + NET_RT_IFLIST = 3; + NET_RT_MAXID = 4; + + +(***************************************************************************) +(* *) +(* Maximum queue length specifiable by listen *) +(* *) +(***************************************************************************) + // Maximum queue length specifiable by listen + SOMAXCONN = 1024; + + + // process out-of-band data + MSG_OOB = $1; + // peek at incoming message + MSG_PEEK = $2; + // send without using routing tables + MSG_DONTROUTE = $4; + // send without using routing tables + MSG_FULLREAD = $8; + // data completes record + MSG_EOR = $10; + // data discarded before delivery + MSG_TRUNC = $20; + // control data lost before delivery + MSG_CTRUNC = $40; + // wait for full request or error + MSG_WAITALL = $80; + // this message should be nonblocking + MSG_DONTWAIT = $100; + MSG_EOF = $200; + // mem mapped io + MSG_MAPIO = $400; + + +(***************************************************************************) +(* *) +(* "Socket"-level control message types *) +(* *) +(***************************************************************************) + // access rights (array of int) + SCM_RIGHTS = $01; + + +// * bsd select definitions + +{ + * Select uses bit masks of file descriptors in longs. These macros + * manipulate such bit fields (the filesystem macros use chars). + * FD_SETSIZE may be defined by the user, but the default here should + * be enough for most uses. +} + FD_SETSIZE = 64; + +{ + * ioctl & ip trace support +} + FIONREAD = (Ord('f') SHL 8) OR 127; + FIONBIO = (Ord('f') SHL 8) OR 126; + + FIOASYNC = (Ord('f') SHL 8) OR 125; + FIOTCPCKSUM = (Ord('f') SHL 8) OR 128; + FIONSTATUS = (Ord('f') SHL 8) OR 120; + FIONURG = (Ord('f') SHL 8) OR 121; + + SIOCSHIWAT = (Ord('s') SHL 8) OR 0; + SIOCGHIWAT = (Ord('s') SHL 8) OR 1; + SIOCSLOWAT = (Ord('s') SHL 8) OR 2; + SIOCGLOWAT = (Ord('s') SHL 8) OR 3; + SIOCATMARK = (Ord('s') SHL 8) OR 7; + SIOCSPGRP = (Ord('s') SHL 8) OR 8; + SIOCGPGRP = (Ord('s') SHL 8) OR 9; + SIOCSHOSTID = (Ord('s') SHL 8) OR 10; + + SIOCADDRT = (Ord('r') SHL 8) OR 10; + SIOCDELRT = (Ord('r') SHL 8) OR 11; + SIOMETRIC1RT = (Ord('r') SHL 8) OR 12; + SIOMETRIC2RT = (Ord('r') SHL 8) OR 13; + SIOMETRIC3RT = (Ord('r') SHL 8) OR 14; + SIOMETRIC4RT = (Ord('r') SHL 8) OR 15; + + SIOCREGADDNET = (Ord('r') SHL 8) OR 12; + SIOCREGDELNET = (Ord('r') SHL 8) OR 13; + SIOCREGROUTES = (Ord('r') SHL 8) OR 14; + SIOCFLUSHROUTES=(Ord('r') SHL 8) OR 15; + + SIOCSIFADDR = (Ord('i') SHL 8) OR 12; + SIOCGIFADDR = (Ord('i') SHL 8) OR 13; + SIOCSIFDSTADDR= (Ord('i') SHL 8) OR 14; + SIOCGIFDSTADDR= (Ord('i') SHL 8) OR 15; + SIOCSIFFLAGS = (Ord('i') SHL 8) OR 16; + SIOCGIFFLAGS = (Ord('i') SHL 8) OR 17; + SIOCGIFBRDADDR= (Ord('i') SHL 8) OR 18; + SIOCSIFBRDADDR= (Ord('i') SHL 8) OR 19; + SIOCGIFCONF = (Ord('i') SHL 8) OR 20; + SIOCGIFNETMASK= (Ord('i') SHL 8) OR 21; + SIOCSIFNETMASK= (Ord('i') SHL 8) OR 22; + SIOCGIFMETRIC = (Ord('i') SHL 8) OR 23; + SIOCSIFMETRIC = (Ord('i') SHL 8) OR 24; + SIOCSIFSETSIG = (Ord('i') SHL 8) OR 25; + SIOCSIFCLRSIG = (Ord('i') SHL 8) OR 26; + SIOCSIFBRD = (Ord('i') SHL 8) OR 27; { SINGLE-rt bcst. using old # for bkw cmpt } + SIOCSIFALLRTB = (Ord('i') SHL 8) OR 63; { added to configure all-route broadcst } + + SIOCGIFLOAD =(Ord('i') SHL 8) OR 27; + SIOCSIFFILTERSRC=(Ord('i') SHL 8) OR 28; + SIOCGIFFILTERSRC=(Ord('i') SHL 8) OR 29; + + SIOCSARP = (Ord('i') SHL 8) OR 30; + SIOCGARP = (Ord('i') SHL 8) OR 31; + SIOCDARP = (Ord('i') SHL 8) OR 32; + SIOCSIFSNMPSIG= (Ord('i') SHL 8) OR 33; + SIOCSIFSNMPCLR= (Ord('i') SHL 8) OR 34; + SIOCSIFSNMPCRC= (Ord('i') SHL 8) OR 35; + SIOCSIFPRIORITY=(Ord('i') SHL 8) OR 36; + SIOCGIFPRIORITY=(Ord('i') SHL 8) OR 37; + SIOCSIFFILTERDST=(Ord('i') SHL 8) OR 38; + SIOCGIFFILTERDST=(Ord('i') SHL 8) OR 39; + SIOCSIF802_3 = (Ord('i') SHL 8) OR 40; + SIOCSIFNO802_3= (Ord('i') SHL 8) OR 41; + SIOCSIFNOREDIR= (Ord('i') SHL 8) OR 42; + SIOCSIFYESREDIR= (Ord('i') SHL 8) OR 43; + + SIOCSIFMTU = (Ord('i') SHL 8) OR 45; + SIOCSIFFDDI = (Ord('i') SHL 8) OR 46; + SIOCSIFNOFDDI = (Ord('i') SHL 8) OR 47; + SIOCSRDBRD = (Ord('i') SHL 8) OR 48; + SIOCSARP_TR = (Ord('i') SHL 8) OR 49; + SIOCGARP_TR = (Ord('i') SHL 8) OR 50; + +{ multicast ioctls } + SIOCADDMULTI = (Ord('i') SHL 8) OR 51; { add m'cast addr } + SIOCDELMULTI = (Ord('i') SHL 8) OR 52; { del m'cast addr } + SIOCMULTISBC = (Ord('i') SHL 8) OR 61; { use broadcast to send IP multicast } + SIOCMULTISFA = (Ord('i') SHL 8) OR 62; { use functional addr to send IP multicast } + + +{$IFDEF SLBOOTP} + SIOCGUNIT = (Ord('i') SHL 8) OR 70; { Used to retreive unit number on } + { serial interface } +{$ENDIF} + + SIOCSIFSPIPE = (Ord('i') SHL 8) OR 71; { used to set pipe size on interface } + { this is used as tcp send buffer size } + SIOCSIFRPIPE = (Ord('i') SHL 8) OR 72; { used to set pipe size on interface } + { this is used as tcp recv buffer size } + SIOCSIFTCPSEG = (Ord('i') SHL 8) OR 73; { set the TCP segment size on interface } + SIOCSIFUSE576 = (Ord('i') SHL 8) OR 74; { enable/disable the automatic change of mss to 576 } + { if going through a router } + SIOCGIFVALID = (Ord('i') SHL 8) OR 75; { to check if the interface is Valid or not } + { sk June 14 1995 } + SIOCGIFBOUND = (Ord('i') SHL 8) OR 76; { ioctl to return bound/shld bind ifs } +{ Interface Tracing Support } + SIOCGIFEFLAGS = (Ord('i') SHL 8) OR 150; + SIOCSIFEFLAGS = (Ord('i') SHL 8) OR 151; + SIOCGIFTRACE = (Ord('i') SHL 8) OR 152; + SIOCSIFTRACE = (Ord('i') SHL 8) OR 153; + +{$IFDEF SLSTATS} + SIOCSSTAT = (Ord('i') SHL 8) OR 154; + SIOCGSTAT = (Ord('i') SHL 8) OR 155; +{$ENDIF} + +{ NETSTAT stuff } + SIOSTATMBUF = (Ord('n') SHL 8) OR 40; + SIOSTATTCP = (Ord('n') SHL 8) OR 41; + SIOSTATUDP = (Ord('n') SHL 8) OR 42; + SIOSTATIP = (Ord('n') SHL 8) OR 43; + SIOSTATSO = (Ord('n') SHL 8) OR 44; + SIOSTATRT = (Ord('n') SHL 8) OR 45; + SIOFLUSHRT = (Ord('n') SHL 8) OR 46; + SIOSTATICMP = (Ord('n') SHL 8) OR 47; + SIOSTATIF = (Ord('n') SHL 8) OR 48; + SIOSTATAT = (Ord('n') SHL 8) OR 49; + SIOSTATARP = (Ord('n') SHL 8) OR 50; + SIOSTATIF42 = (Ord('n') SHL 8) OR 51; + + +{* + * User-settable options (used with setsockopt). + *} + TCP_NODELAY = $01; // don't delay send to coalesce packets + TCP_MAXSEG = $02; // set maximum segment size + TCP_MSL = $03; // MSL HACK + TCP_TIMESTMP = $04; // RFC 1323 (RTTM TimeStamp) + TCP_WINSCALE = $05; // RFC 1323 (Window Scale) + TCP_CC = $06; // RFC 1644 (Connection Count) + + + IFF_UP = $1; // interface is up + IFF_BROADCAST = $2; // broadcast address valid + IFF_DEBUG = $4; // turn on debugging + IFF_LOOPBACK = $8; // is a loopback net + IFF_POINTOPOINT = $10; // interface is point-to-point link + IFF_LINK2 = $20; // was trailers, not used + IFF_NOTRAILERS = IFF_LINK2; + IFF_RUNNING = $40; // resources allocated + IFF_NOARP = $80; // no address resolution protocol + IFF_PROMISC = $100; // receive all packets + IFF_ALLMULTI = $200; // receive all multicast packets + IFF_BRIDGE = $1000; // support token ring routine field + IFF_SNAP = $2000; // support extended SAP header + IFF_DEFMTU = $400; // default mtu of 1500 + IFF_RFC1469_BC = 1; // using broadcast + IFF_RFC1469_FA = 2; // using functional + IFF_RFC1469_MA = 3; // using multicast + IFF_ETHER = $4000; // Ethernet interface + IFF_LOOPBRD = $8000; // loop back broadcasts + IFF_MULTICAST = $800; // supports multicast + + IFF_SIMPLEX = $10000; // can't hear own transmissions + IFF_OACTIVE = $20000; // transmission in progress + IFF_802_3 = $40000; + IFF_CANONICAL = $80000; + IFF_RUNNINGBLK = $100000; // threads waited for intf running + + { Interface enhanced flags } + IFFE_PKTTRACE = $00000001; // trace datalink where possible + IFFE_IPTRACE = $00000002; // trace ONLY IP packets + + + { physical protocols IDs } + HT_IP = $01; // IP + HT_ETHER = $06; // Ethernet + HT_ISO88023 = $07; // CSMA CD + HT_ISO88025 = $09; // Token Ring + HT_SLIP = $1c; // Serial Line IP + HT_PPP = $18; // PPP IP + + + IFNAMSIZ = 16; // interface name length + +{ in.h / inet.h const & func } + +{ + * Protocols +} + IPPROTO_IP = 0; { dummy for IP } + IPPROTO_ICMP = 1; { control message protocol } + IPPROTO_GGP = 3; { gateway^2 (deprecated) } + IPPROTO_TCP = 6; { tcp } + IPPROTO_EGP = 8; { exterior gateway protocol } + IPPROTO_PUP = 12; { pup } + IPPROTO_UDP = 17; { user datagram protocol } + IPPROTO_IDP = 22; { xns idp } + + IPPROTO_RAW = 255; { raw IP packet } + IPPROTO_MAX = 256; + +{ + * Ports < IPPORT_RESERVED are reserved for + * privileged processes (e.g. root). + * Ports > IPPORT_USERRESERVED are reserved + * for servers, not necessarily privileged. +} + IPPORT_RESERVED = 1024; + IPPORT_USERRESERVED = 5000; + +{ + * Link numbers +} + IMPLINK_IP = 155; + IMPLINK_LOWEXPER = 156; + IMPLINK_HIGHEXPER = 158; + +{ + * 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. +} + IN_CLASSA_NET = $ff000000; + IN_CLASSA_NSHIFT = 24; + IN_CLASSA_HOST = $00ffffff; + IN_CLASSA_MAX = 128; + IN_CLASSB_NET = $ffff0000; + IN_CLASSB_NSHIFT = 16; + IN_CLASSB_HOST = $0000ffff; + IN_CLASSB_MAX = 65536; + + IN_CLASSC_NET = $ffffff00; + IN_CLASSC_NSHIFT = 8; + IN_CLASSC_HOST = $000000ff; + + INADDR_BROADCAST = $ffffffff; { must be masked } + + IN_LOOPBACKNET = 127; { official! } + +{* + * Options for use with [gs]etsockopt at the IP level. + * } + IP_OPTIONS = 1; // buf/ip_opts; set/get IP options + IP_MULTICAST_IF = 2; // u_char; set/get IP multicast i/f + IP_MULTICAST_TTL = 3; // u_char; set/get IP multicast ttl + IP_MULTICAST_LOOP = 4; // u_char; set/get IP multicast loopback + IP_ADD_MEMBERSHIP = 5; // ip_mreq; add an IP group membership + IP_DROP_MEMBERSHIP = 6; // ip_mreq; drop an IP group membership + IP_HDRINCL = 7; // int; header is included with data + IP_TOS = 8; // int; IP type of service and preced. + IP_TTL = 9; // int; IP time to live + IP_RECVOPTS = 10; // bool; receive all IP opts w/dgram + IP_RECVRETOPTS = 11; // bool; receive IP opts for response + IP_RECVDSTADDR = 12; // bool; receive IP dst addr w/dgram + IP_RETOPTS = 13; // ip_opts; set/get IP options + IP_RECVTRRI = 14; // bool; receive token ring routing inf + + IP_DEFAULT_MULTICAST_TTL = 1; // normally limit m'casts to 1 hop + IP_DEFAULT_MULTICAST_LOOP = 1; // normally hear sends if a member + IP_MAX_MEMBERSHIPS = 20; // per socket; must fit in one mbuf + MAX_IN_MULTI = 16*IP_MAX_MEMBERSHIPS; // 320 max per os2 + + +type + cushort=word; + cuint16=word; + cuint32=cardinal; + size_t =cuint32; + ssize_t=cuint16; + cint =longint; + pcint =^cint; + tsocklen=cint; + psocklen=^tsocklen; + +function InitEMXHandles: boolean; +(* This procedure shall be called before touching any socket. Once called, *) +(* it forces dynamic loading of emx.dll and all functions start with socket *) +(* handles compatible to EMX in order to allow interworking with external *) +(* libraries using EMX libc (e.g. OpenSSL compiled with EMX port of GCC). *) +(* It returns true in case of successful initialization, false otherwise. *) + +function CheckEMXHandles: boolean; +(* This function checks whether EMX compatible socket handles are used. *) + +function EMXSocket (ANativeSocket: cInt): cInt; + +function NativeSocket (AEMXSocket: cInt): cInt; + +// OS/2 stack based on BSD stack +{$DEFINE BSD} +{$I socketsh.inc} + INVALID_SOCKET = TSocket(not(0)); + SOCKET_ERROR = -1; + + +Implementation + +uses + DosCalls; + +{****************************************************************************** + Basic Socket Functions +******************************************************************************} + +const + EMXHandles: boolean = false; + EMXSysCall: pointer = nil; + EMXLibHandle: THandle = THandle (-1); + +function CheckEMXHandles: boolean; +begin + CheckEMXHandles := EMXHandles; +end; + +function InitEMXHandles: boolean; +const + EMXLib: string [8] = 'emx.dll'#0; + CBufLen = 260; +var + CBuf: array [1..CBufLen] of char; +begin + if not EMXHandles then + begin + if DosLoadModule (@CBuf [1], SizeOf (CBuf), @EMXLib [1], EMXLibHandle) = 0 + then + begin + if DosQueryProcAddr (EMXLibHandle, 2, nil, EMXSysCall) = 0 then + EMXHandles := true; + end; + InitEMXHandles := EMXHandles; + end; +end; + +{$ASMMODE INTEL} +function EMXSocket (ANativeSocket: cInt): cInt; assembler; +asm + or EMXHandles, 0 + jz @EMXSocketEnd + mov edx, eax + mov eax, 7F54h + mov ecx, 0 + call EMXSysCall +@EMXSocketEnd: +end; + +function NativeSocket (AEMXSocket: cInt): cInt; assembler; +asm + or EMXHandles, 0 + jz @NativeSocketEnd + push ebx + mov ebx, eax + mov eax, 7F3Bh + call EMXSysCall + pop ebx +@NativeSocketEnd: +end; + +function SocketError: cint; +begin + SocketError := so32dll.Sock_ErrNo; +end; + +Function Socket(Domain,SocketType,Protocol:Longint):Longint; +begin + Socket := fpSocket (Domain, SocketType, Protocol); +end; + +Function Send(Sock:Longint;Const Buf;BufLen,Flags:Longint):Longint; +begin + Send:=fpSend(Sock,@Buf,BufLen,Flags); +end; + +Function SendTo(Sock:Longint;Const Buf;BufLen,Flags:Longint;Var Addr; AddrLen : Longint):Longint; +begin + SendTo:=fpSendTo(Sock,@Buf,BufLen,Flags,@Addr,AddrLen); +end; + +Function Recv(Sock:Longint;Var Buf;BufLen,Flags:Longint):Longint; +begin + Sock := NativeSocket (Sock); + Recv:=so32dll.Recv(Sock,Buf,BufLen,Flags); +end; + +Function RecvFrom(Sock : Longint; Var Buf; Buflen,Flags : Longint; Var Addr; var AddrLen : longInt) : longint; +begin + Sock := NativeSocket (Sock); + RecvFrom:=so32dll.RecvFrom(Sock,Buf,BufLen,Flags,so32dll.SockAddr(Addr),AddrLen); +end; + +Function Bind(Sock:Longint;Const Addr;AddrLen:Longint):Boolean; +begin + Bind:=fpBind(Sock,@Addr,AddrLen)=0; +end; + +Function Listen(Sock,MaxConnect:Longint):Boolean; +begin + Sock := NativeSocket (Sock); + Listen := so32dll.Listen(Sock,MaxConnect) = 0; +end; + +Function Accept(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + Sock := NativeSocket (Sock); + Accept:=so32dll.Accept(Sock,so32dll.SockAddr(Addr), AddrLen); +end; + +Function Connect(Sock:Longint;const Addr; Addrlen:Longint):Boolean; +begin + Connect:=fpConnect(Sock,@Addr,AddrLen)=0; +end; + +Function Shutdown(Sock:Longint;How:Longint):Longint; +begin + ShutDown:=fpShutDown(Sock,How); +end; + +Function GetSocketName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + Sock := NativeSocket (Sock); + GetSocketName:=so32dll.GetSockName(Sock, so32dll.SockAddr(Addr),AddrLen); +end; + +Function GetPeerName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + Sock := NativeSocket (Sock); + GetPeerName:=so32dll.GetPeerName(Sock,so32dll.SockAddr(Addr),AddrLen); +end; + +Function SetSocketOptions(Sock,Level,OptName:Longint;Const OptVal;optlen:longint):Longint; +begin + SetSocketOptions:=fpSetSockOpt(Sock,Level,OptName,@OptVal,OptLen); +end; + +Function GetSocketOptions(Sock,Level,OptName:Longint;Var OptVal;Var optlen:longint):Longint; +begin + Sock := NativeSocket (Sock); + GetSocketOptions:=so32dll.GetSockOpt(Sock,Level,OptName,OptVal,OptLen); +end; + +Function SocketPair(Domain,SocketType,Protocol:Longint;var Pair:TSockArray):Longint; +begin +{!!TODO!! + SocketPair:=so32dll.socketpair(Domain,SocketType,Protocol,Pair);} + //SocketCall(Socket_Sys_SocketPair,Domain,SocketType,Protocol,longint(@Pair),0,0); + SocketPair:=-1; +end; + +{ mimic the linux fpWrite/fpRead calls for the file/text socket wrapper } +function fpWrite(handle : longint;Const bufptr;size : dword) : dword; +begin + fpWrite := dword(fpsend(handle, @bufptr, size, 0)); + if fpWrite = dword(-1) then + fpWrite := 0; +end; + +function fpRead(handle : longint;var bufptr;size : dword) : dword; +var + d : dword; +begin + Handle := NativeSocket (Handle); + d:=dword(so32dll.os2_ioctl(handle,FIONREAD,d,SizeOf(d))); + if d=dword(-1) then + fpRead:=0 + else + begin + if size>d then + size:=d; + fpRead := dword(so32dll.recv(handle, bufptr, size, 0)); + if fpRead = dword(-1) then + fpRead := 0 + end; +end; + +{$i sockets.inc} + +function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; +begin + if EMXHandles then + fpSocket := EMXSocket (so32dll.Socket (Domain, xtype, Protocol)) + else + fpSocket:=so32dll.Socket(Domain,xtype,Protocol); +end; + +function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t; +begin + S := NativeSocket (S); + fpSend:=so32dll.Send(S,msg^,len,flags); +end; + +function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t; +begin + S := NativeSocket (S); + // Dubious construct, this should be checked. (IPV6 fails ?) + fpSendTo:=so32dll.SendTo(S,msg^,Len,Flags,so32dll.SockAddr(tox^),toLen); +end; + +function fprecv (s:cint; buf: pointer; len: size_t; flags: cint):ssize_t; +begin + S := NativeSocket (S); + fpRecv:=so32dll.Recv(S,Buf,Len,Flags); +end; + +function fprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t; +begin + S := NativeSocket (S); + fpRecvFrom:=so32dll.RecvFrom(S,Buf,Len,Flags,so32dll.SockAddr(from^),FromLen^); +end; + +function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; +begin + S := NativeSocket (S); + fpConnect:=so32dll.Connect(S,so32dll.SockAddr(name^),nameLen); +end; + +function fpshutdown (s:cint; how:cint):cint; +begin + S := NativeSocket (S); + fpShutDown:=so32dll.ShutDown(S,How); +end; + +function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; +begin + S := NativeSocket (S); + fpbind:=so32dll.Bind(S,so32dll.SockAddr(Addrx^),AddrLen); +end; + +function fplisten (s:cint; backlog : cint):cint; +begin + S := NativeSocket (S); + fplisten:=so32dll.Listen(S,backlog); +end; + +function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; +begin + S := NativeSocket (S); + fpAccept:=so32dll.Accept(S,so32dll.SockAddr(Addrx^),longint(@AddrLen)); +end; + +function fpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + S := NativeSocket (S); + fpGetSockName:=so32dll.GetSockName(S,so32dll.SockAddr(name^),nameLen^); +end; + +function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + S := NativeSocket (S); + fpGetPeerName:=so32dll.GetPeerName(S,so32dll.SockAddr(name^),NameLen^); +end; + +function fpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint; +begin + S := NativeSocket (S); + fpGetSockOpt:=so32dll.GetSockOpt(S,Level,OptName,OptVal,OptLen^); +end; + +function fpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen :tsocklen):cint; +begin + S := NativeSocket (S); + fpSetSockOpt:=so32dll.SetSockOpt(S,Level,OptName,OptVal,OptLen); +end; + +function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; +begin + fpsocketpair:=-1; +end; + +Function CloseSocket(Sock:Longint):Longint; +begin + Sock := NativeSocket (Sock); + CloseSocket:=so32dll.soclose (Sock); +end; + + +Begin + so32dll.sock_init; +End. diff --git a/packages/rtl-extra/src/os2commn/winsock.pp b/packages/rtl-extra/src/os2commn/winsock.pp new file mode 100644 index 0000000000..e2e36369c6 --- /dev/null +++ b/packages/rtl-extra/src/os2commn/winsock.pp @@ -0,0 +1,21 @@ +{**************************************************************************** + + + This file is part of the Free Pascal run time library. + Copyrigth (c) 2003 by Yuri Prokushev (prokushev@freemail.ru) + + This file corresponds to version 1.1 of the Windows Sockets + specification. + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + ****************************************************************************} +unit winsock; +{$define winsock} +{$i pmwsock.pas} + diff --git a/packages/rtl-extra/src/solaris/osdefs.inc b/packages/rtl-extra/src/solaris/osdefs.inc new file mode 100644 index 0000000000..a411f44a96 --- /dev/null +++ b/packages/rtl-extra/src/solaris/osdefs.inc @@ -0,0 +1,25 @@ +{ + Copyright (c) 2000-2002 by Marco van de Voort + + Target dependent defines used when compileing the baseunix unit + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + ****************************************************************************} + +{$define usedomain} // Allow uname with "domain" entry. + // (which is a GNU extension) + diff --git a/packages/rtl-extra/src/unix/gpm.pp b/packages/rtl-extra/src/unix/gpm.pp new file mode 100644 index 0000000000..0de0063c1e --- /dev/null +++ b/packages/rtl-extra/src/unix/gpm.pp @@ -0,0 +1,984 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2000 by Peter Vreman + + GPM (>v1.17) mouse Interface for linux + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY;without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} +unit gpm; + +{Note: Libgpm is *the* interface for Linux text-mode programs. + Unfortunately it isn't suitable for anything else besides a blocky + cursor on a text mode interface. The GPM protocol suffers from serious + defficiencies and ideally, gpm is abolished as quickly as possible. + + With lack of a good alternative, GPM deserves good support. But + please keep this in mind while coding.} + +{*****************************************************************************} + interface +{*****************************************************************************} + +uses + baseUnix; + +{$ifdef use_external} +{$linklib gpm} +{$linklib c} +{$endif} + +{$inline on} +{$goto on} + +const + _PATH_VARRUN = '/var/run/'; + _PATH_DEV = '/dev/'; + GPM_NODE_DIR = _PATH_VARRUN; + GPM_NODE_DIR_MODE = 0775; + GPM_NODE_PID = '/var/run/gpm.pid'; + GPM_NODE_DEV = '/dev/gpmctl'; + GPM_NODE_CTL = GPM_NODE_DEV; + GPM_NODE_FIFO = '/dev/gpmdata'; + + GPM_B_LEFT = 4; + GPM_B_MIDDLE = 2; + GPM_B_RIGHT = 1; + +type + TGpmEtype = longint; + TGpmMargin = longint; + +const + GPM_MOVE = 1; + GPM_DRAG = 2; + GPM_DOWN = 4; + GPM_UP = 8; + GPM_SINGLE = 16; + GPM_DOUBLE = 32; + GPM_TRIPLE = 64; + GPM_MFLAG = 128; + GPM_HARD = 256; + GPM_ENTER = 512; + GPM_LEAVE = 1024; + + GPM_TOP = 1; + GPM_BOT = 2; + GPM_LFT = 4; + GPM_RGT = 8; + +type +{$PACKRECORDS c} + Pgpm_event=^Tgpm_event; + Tgpm_event=record + buttons : byte; + modifiers : byte; + vc : word; + dx : word; + dy : word; + x,y : word; + EventType : TGpmEType; + clicks : longint; + margin : TGpmMargin; + wdx,wdy : word; + end; + + Pgpmevent=Pgpm_event; + Tgpmevent=Tgpm_event; + + TGpmHandler=function(var event:TGpmEvent;clientdata:pointer):longint;cdecl; + + const + GPM_MAGIC = $47706D4C; + + type + Pgpm_connect = ^TGpm_connect; + Tgpm_connect = record + eventMask : word; + defaultMask : word; + minMod : word; + maxMod : word; + pid : longint; + vc : longint; +end; + + Pgpmconnect=Pgpm_connect; + Tgpmconnect=Tgpm_connect; + + Pgpm_roi=^Tgpm_roi; + Tgpm_roi= record + xmin,xmax:integer; + ymin,ymax:integer; + minmod,maxmod:word; + eventmask:word; + owned:word; + handler:Tgpmhandler; + clientdata:pointer; + prev,next:Pgpm_roi; + end; + + Pgpmroi=Pgpm_roi; + Tgpmroi=Tgpm_roi; + +{$ifdef external} +var + gpm_flag : longint;cvar;external; + gpm_fd : longint;cvar;external; + gpm_hflag : longint;cvar;external; + gpm_morekeys : Longbool;cvar;external; + gpm_zerobased : Longbool;cvar;external; + gpm_visiblepointer : Longbool;cvar;external; + gpm_mx : longint;cvar;external; + gpm_my : longint;cvar;external; + gpm_timeout : TTimeVal;cvar;external; + _gpm_buf : array[0..0] of char;cvar;external; + _gpm_arg : ^word;cvar;external; + gpm_handler : TGpmHandler;cvar;external; + gpm_data : pointer;cvar;external; + gpm_roi_handler : TGpmHandler;cvar;external; + gpm_roi_data : pointer;cvar;external; + gpm_roi : PGpmRoi;cvar;external; + gpm_current_roi : PGpmRoi;cvar;external; + gpm_consolefd : longint;cvar;external; + Gpm_HandleRoi : TGpmHandler;cvar;external; +{$else} +var gpm_roi:Pgpm_roi; + gpm_handler,gpm_roi_handler:Tgpmhandler; + gpm_current_roi:Pgpm_roi; + gpm_roi_data:pointer; +{$endif} + +function Gpm_StrictSingle(EventType : longint) : boolean; +function Gpm_AnySingle(EventType : longint) : boolean; +function Gpm_StrictDouble(EventType : longint) : boolean; +function Gpm_AnyDouble(EventType : longint) : boolean; +function Gpm_StrictTriple(EventType : longint) : boolean; +function Gpm_AnyTriple(EventType : longint) : boolean; + +{$ifdef use_external} +function Gpm_Open(var _para1:TGpmConnect; _para2:longint):longint;cdecl;external name 'Gpm_Open'; +function Gpm_Close:longint;cdecl;external name 'Gpm_Close'; +function Gpm_GetEvent(var _para1:TGpmEvent):longint;cdecl;external name 'Gpm_GetEvent'; +{function Gpm_Getc(_para1:pFILE):longint;cdecl;external; +function Gpm_Getchar : longint;} +function Gpm_Repeat(millisec:longint):longint;cdecl;external name 'Gpm_Repeat'; +function Gpm_FitValuesM(var x,y:longint; margin:longint):longint;cdecl;external name 'Gpm_FitValuesM'; +function Gpm_FitValues(var x,y:longint):longint;cdecl;external name 'Gpm_FitValues'; +{function GPM_DRAWPOINTER(ePtr : longint) : longint;} +function Gpm_PushRoi(x1:longint; y1:longint; X2:longint; Y2:longint; mask:longint; fun:TGpmHandler; xtradata:pointer):PGpmRoi;cdecl;external name 'Gpm_PushRoi'; +function Gpm_PopRoi(which:PGpmRoi):PGpmRoi;cdecl;external name 'Gpm_PopRoi'; +function Gpm_RaiseRoi(which:PGpmRoi; before:PGpmRoi):PGpmRoi;cdecl;external name 'Gpm_RaiseRoi'; +function Gpm_LowerRoi(which:PGpmRoi; after:PGpmRoi):PGpmRoi;cdecl;external name 'Gpm_LowerRoi'; +{function Gpm_Wgetch:longint;cdecl;external; +function Gpm_Getch:longint;} +function Gpm_GetLibVersion(var where:longint):pchar;cdecl;external name 'Gpm_GetLibVersion'; +function Gpm_GetServerVersion(var where:longint):pchar;cdecl;external name 'Gpm_GetServerVersion'; +function gpm_getsnapshot(eptr:Pgpmevent):longint;cdecl;external name 'Gpm_GetSnapshot'; +function Gpm_GetSnapshot(var ePtr:TGpmEvent):longint;cdecl;external name 'Gpm_GetSnapshot'; +{$else} +function gpm_open(var conn:Tgpm_connect;flag:longint):longint; +function gpm_close:longint; +function gpm_getevent(var event:Tgpm_event):longint; +{function Gpm_Getc(_para1:pFILE):longint;cdecl;external; +function Gpm_Getchar : longint;} +function gpm_repeat(millisec:longint):longint; +function gpm_fitvaluesM(var x,y:longint; margin:longint):longint; +function gpm_fitvalues(var x,y:longint):longint;inline; +function gpm_pushroi(x1:longint;y1:longint;x2:longint;y2:longint; + mask:longint;fun:Tgpmhandler;xtradata:pointer):Pgpm_roi; +function gpm_poproi(which:Pgpm_roi):Pgpm_roi; +function gpm_raiseroi(which:Pgpm_roi;before:Pgpm_roi):Pgpm_roi; +function gpm_lowerroi(which:Pgpm_roi;after:Pgpm_roi):Pgpm_roi; +{Should be pointer because proc accepts nil.} +function gpm_getsnapshot(eptr:Pgpmevent):longint; +{Overload for compatibility.} +function gpm_getsnapshot(var eptr:Tgpmevent):longint;inline; +{$endif} + + +{*****************************************************************************} + implementation +{*****************************************************************************} + +{$ifndef use_external} +uses termio,sockets,strings,unix; + +type Pgpm_stst=^Tgpm_stst; + Tgpm_stst=record + info:Tgpmconnect; + next:Pgpm_stst; + end; + + Pmicetab=^Tmicetab; + Tmicetab=record + next:Pmicetab; + device,protocol,options:Pchar; + end; + + string63=string[63]; + + Toptions=record + autodetect:longint; + mice_count:longint; + repeater:longint; + repeater_type:Pchar; + run_status:longint; + micelist:Pmicetab; + progname, + consolename:string63; + end; + +var options:Toptions; + gpm_stack:Pgpm_stst; + gpm_mx,gpm_my:longint; + gpm_saved_winch_hook,gpm_saved_suspend_hook:sigactionrec; + +const gpm_flag:boolean=false; {almost unuseful now -- where was it used for ? can + we remove it now ? FIXME} + gpm_tried:boolean=false; + gpm_hflag:boolean=false; + gpm_fd:longint=-1; + gpm_consolefd:longint=-1; + gpm_zerobased:longint=0; + +const GPM_DEVFS_CONSOLE='/dev/vc/0'; + GPM_OLD_CONSOLE='/dev/tty0'; + + GPM_REQ_SNAPSHOT=0; + GPM_REQ_BUTTONS=1; + GPM_REQ_CONFIG=2; + GPM_REQ_NOPASTE=3; +{$endif} + +function Gpm_StrictSingle(EventType : longint) : boolean; +begin + Gpm_StrictSingle:=(EventType and GPM_SINGLE<>0) and not(EventType and GPM_MFLAG<>0); +end; + +function Gpm_AnySingle(EventType : longint) : boolean; +begin + Gpm_AnySingle:=(EventType and GPM_SINGLE<>0); +end; + +function Gpm_StrictDouble(EventType : longint) : boolean; +begin + Gpm_StrictDouble:=(EventType and GPM_DOUBLE<>0) and not(EventType and GPM_MFLAG<>0); +end; + +function Gpm_AnyDouble(EventType : longint) : boolean; +begin + Gpm_AnyDouble:=(EventType and GPM_DOUBLE<>0); +end; + +function Gpm_StrictTriple(EventType : longint) : boolean; +begin + Gpm_StrictTriple:=(EventType and GPM_TRIPLE<>0) and not(EventType and GPM_MFLAG<>0); +end; + +function Gpm_AnyTriple(EventType : longint) : boolean; +begin + Gpm_AnyTriple:=(EventType and GPM_TRIPLE<>0); +end; + +{$ifdef use_external} +procedure Gpm_CheckVersion; +var + l : longint; +begin + Gpm_GetLibVersion(l); + if l<11700 then + begin + writeln('You need at least gpm 1.17'); + halt(1); + end; +end; + +{$else} + +const checked_con:boolean=false; + +function putdata(where:longint;const what:Tgpmconnect):boolean; +var + res: cint; +begin + putdata:=true; + repeat + res:=fpwrite(where,what,sizeof(Tgpmconnect)); + until (res<>-1) or (fpgeterrno<>ESysEINTR); + if res<>sizeof(Tgpmconnect) then + begin +{ gpm_report(GPM_PR_ERR,GPM_MESS_WRITE_ERR,strerror(errno));} + putdata:=false; + end; +end; + +function gpm_get_console:string63; + +var buf:stat; + +begin + {First try the devfs device, because in the next time this will be + the preferred one. If that fails, take the old console.} + + {Check for open new console.} + if fpstat(GPM_DEVFS_CONSOLE,buf)=0 then + gpm_get_console:=GPM_DEVFS_CONSOLE + {Failed, try OLD console.} + else if fpstat(GPM_OLD_CONSOLE,buf)=0 then + gpm_get_console:=GPM_OLD_CONSOLE + else + gpm_get_console:=''; +end; + +procedure gpm_winch_hook(signum:longint;SigInfo: PSigInfo; SigContext: PSigContext);cdecl; + +var win:winsize; + +begin + if (sigactionhandler(SIG_IGN)<>gpm_saved_winch_hook.sa_handler) and + (sigactionhandler(SIG_DFL)<>gpm_saved_winch_hook.sa_handler) then + gpm_saved_winch_hook.sa_handler(signum,nil,nil); + if fpioctl(gpm_consolefd,TIOCGWINSZ,@win)=-1 then + exit; + if (win.ws_col=0) or (win.ws_row=0) then + begin + win.ws_col:=80; + win.ws_row:=25; + end; + gpm_mx:=win.ws_col - gpm_zerobased; + gpm_my:=win.ws_row - gpm_zerobased; +end; + +procedure gpm_suspend_hook(signum:longint;SigInfo: PSigInfo; SigContext: PSigContext);cdecl; + +var conn:Tgpmconnect; + old_sigset,new_sigset:Tsigset; + sa:sigactionrec; + success:boolean; + +begin + fpsigemptyset(new_sigset); + fpsigaddset(new_sigset,SIGTSTP); + fpsigprocmask(SIG_BLOCK,new_sigset,old_sigset); + + {Open a completely transparent gpm connection.} + conn.eventmask:=0; + conn.defaultMask:=$ffff; + conn.minmod:=$ffff; + conn.maxmod:=0; + {cannot do this under xterm, tough} + success:=gpm_open(conn,0)>=0; + + {take the default action, whatever it is (probably a stop :)} + fpsigprocmask(SIG_SETMASK,@old_sigset,nil); + fpsigaction(SIGTSTP,@gpm_saved_suspend_hook,nil); + fpkill(fpgetpid,SIGTSTP); + + { in bardo here } + + { Reincarnation. Prepare for another death early. } + fpsigemptyset(sa.sa_mask); + sa.sa_handler:=@gpm_suspend_hook; + sa.sa_flags:=SA_NOMASK; + fpsigaction(SIGTSTP,@sa,nil); + + { Pop the gpm stack by closing the useless connection } + { but do it only when we know we opened one.. } + if success then + gpm_close; +end; + +function gpm_open(var conn:Tgpmconnect;flag:longint):longint; + +var tty:string; + flagstr:string[10]; + term:Pchar; + i:cardinal; + addr:Tunixsockaddr; + win:Twinsize; + n:Pgpm_stst; + l:byte; + p:byte; {there max 256 console ttys} + buf:stat; + sa:sigactionrec; + res: cint; + +label err; + +begin + tty:=''; + options.consolename:=''; + +{ gpm_report(GPM_PR_DEBUG,"VC: %d",flag);} + + {....................................... First of all, check xterm} + +(* + term:=fpgetenv('TERM'); + if (term<>nil) and (strcomp(term,'xterm')=0) then + begin + if gpm_tried then + begin + gpm_open:=gpm_fd; { no stack } + exit; + end; + gpm_fd:=-2; + {save old hilit tracking and enable mouse tracking} + write(#27'[?1001s'#27'[?1000h'); + flush(output); + + gpm_flag:=true; + gpm_open:=gpm_fd; + exit; + end; +*) + {....................................... No xterm, go on} + + { check whether we know what name the console is: what's with the lib??? } + if not checked_con then + begin + options.consolename:=gpm_get_console; + checked_con:=true; + end; + + { So I chose to use the current tty, instead of /dev/console, which + has permission problems. (I am fool, and my console is + readable/writeable by everybody. + + However, making this piece of code work has been a real hassle.} + + if not gpm_flag and gpm_tried then + begin + gpm_open:=-1; + exit; + end; + gpm_tried:=true; {do or die} + + new(n); + n^.next:=gpm_stack; + gpm_stack:=n; + + conn.pid:=fpgetpid; { fill obvious values } + if n^.next<>nil then + conn.vc:=n^.next^.info.vc {inherit} + else + begin + conn.vc:=0; { default handler } + if (flag>0) then + begin { forced vc number } + conn.vc:=flag; + str(flag,flagstr); + tty:=options.consolename+flagstr; + end + else + begin {use your current vc} + if isatty(0)<>0 then + tty:=ttyname(0); { stdin } + if (tty='') and (isatty(1)<>0) then + tty:=ttyname(1); { stdout } + if (tty='') and (isatty(2)<>0) then + tty:=ttyname(2); { stderr } + if (tty='') then + begin +{ gpm_report(GPM_PR_ERR,"checking tty name failed");} + goto err; + end; + conn.vc:=0; + l:=length(tty); + p:=1; + while tty[l] in ['0'..'9'] do + begin + inc(conn.vc,p*(byte(tty[l])-byte('0'))); + p:=p*10; + dec(l); + end; + end; + + if (gpm_consolefd=-1) then + begin + repeat + gpm_consolefd:=fpopen(tty,O_WRONLY); + until (gpm_consolefd<>-1) or (fpgeterrno<>ESysEINTR); + if gpm_consolefd<0 then + begin +{ gpm_report(GPM_PR_ERR,GPM_MESS_DOUBLE_S,tty,strerror(errno));} + goto err; + end; + end; + end; + n^.info:=conn; + + {....................................... Get screen dimensions } + + fpioctl(gpm_consolefd, TIOCGWINSZ, @win); + + if (win.ws_col or win.ws_row)=0 then + begin + {Hmmmm. The mad terminal didn't return it's size :/ } +{ fprintf(stderr, "libgpm: zero screen dimension, assuming 80x25.\n");} + win.ws_col:=80; + win.ws_row:=25; + end; + gpm_mx:=win.ws_col-gpm_zerobased; + gpm_my:=win.ws_row-gpm_zerobased; + + {....................................... Connect to the control socket} + if not gpm_flag then + begin + gpm_fd:=fpsocket(AF_UNIX,SOCK_STREAM,0); + if gpm_fd<0 then + begin +{ gpm_report(GPM_PR_ERR,GPM_MESS_SOCKET,strerror(errno));} + goto err; + end; + end; + + fillchar(addr,sizeof(addr),0); + addr.family:=PF_UNIX; + strcopy(addr.path, GPM_NODE_CTL); + i:=sizeof(addr.family)+length(GPM_NODE_CTL); + + repeat + res:=fpconnect(gpm_fd,psockaddr(@addr),i); + until (res<>-1) or (fpgeterrno<>ESysEINTR); + if res<0 then + begin +{ gpm_report(GPM_PR_INFO,GPM_MESS_DOUBLE_S,GPM_NODE_CTL,strerror(errno));} + {Well, try to open a chr device called /dev/gpmctl. This should + be forward-compatible with a kernel server.} + repeat + res:=fpclose(gpm_fd); {the socket} + until (res<>-1) or (fpgeterrno<>ESysEINTR); + repeat + gpm_fd:=fpopen(GPM_NODE_DEV,O_RDWR); + until (gpm_fd<>-1) or (fpgeterrno<>ESysEINTR); + if gpm_fd=-1 then + begin +{ gpm_report(GPM_PR_ERR,GPM_MESS_DOUBLE_S,GPM_NODE_DEV + ,strerror(errno));} + goto err; + end; + if (fpfstat(gpm_fd,buf)=-1) or (buf.st_mode and STAT_IFMT<>STAT_IFCHR) then + goto err; + end; + {....................................... Put your data} + if putdata(gpm_fd,conn) then + begin + { itz Wed Dec 16 23:22:16 PST 1998 use sigaction, the old + code caused a signal loop under XEmacs } + fpsigemptyset(sa.sa_mask); + + { And the winch (window-resize) hook .. } + sa.sa_handler:=@gpm_winch_hook; + sa.sa_flags:=0; + fpsigaction(SIGWINCH,@sa,@gpm_saved_winch_hook); + + if gpm_flag then + begin + { Install suspend hook } + sa.sa_handler:=sigactionhandler(SIG_IGN); + fpsigaction(SIGTSTP,@sa,@gpm_saved_suspend_hook); + + {if signal was originally ignored, job control is not supported} + if gpm_saved_suspend_hook.sa_handler<>sigactionhandler(SIG_IGN) then + begin + sa.sa_flags:=SA_NOMASK; + sa.sa_handler:=@gpm_suspend_hook; + fpsigaction(SIGTSTP,@sa,nil); + end; + end; + end; + gpm_open:=gpm_fd; + exit; + {....................................... Error: free all memory} +err: +{ gpm_report(GPM_PR_ERR,'Oh, oh, it''s an error! possibly I die! ');} + repeat + n:=gpm_stack^.next; + dispose(gpm_stack); + gpm_stack:=n; + until gpm_stack=nil; + if gpm_fd>=0 then + begin + repeat + res:=fpclose(gpm_fd); + until (res<>-1) or (fpgeterrno<>ESysEINTR); + end; + gpm_flag:=false; + gpm_open:=-1; +end; + +function gpm_close:longint; + +var + next:Pgpm_stst; + res: cint; + + +begin + gpm_tried:=false; { reset the error flag for next time } +(* + if gpm_fd=-2 then { xterm } + begin + write(#27'[?1000l'#27'[?1001r'); + flush(output); + end + else { linux } +*) + begin + if not gpm_flag then + gpm_close:=0 + else + begin + next:=gpm_stack^.next; + dispose(gpm_stack); + gpm_stack:=next; + if next<>nil then + putdata(gpm_fd,next^.info); + + gpm_flag:=false; + end; + end; + + if gpm_fd>=0 then + begin + repeat + res:=fpclose(gpm_fd); + until (res<>-1) or (fpgeterrno<>ESysEINTR); + end; + gpm_fd:=-1; + fpsigaction(SIGTSTP,@gpm_saved_suspend_hook,nil); + fpsigaction(SIGWINCH,@gpm_saved_winch_hook,nil); + fpclose(gpm_consolefd); + gpm_consolefd:=-1; + gpm_close:=0; +end; + +function gpm_getevent(var event:Tgpm_event):longint; + +var count:cint; + +begin + gpm_getevent:=0; + if gpm_fd=-1 then + exit; + + repeat + count:=fpread(gpm_fd,event,sizeof(Tgpm_event)); + until (count<>-1) or (fpgeterrno<>ESysEINTR); + if count<>sizeof(Tgpm_event) then + begin + {avoid to send the message if there is no data; sometimes it makes + sense to poll the mouse descriptor any now an then using a + non-blocking descriptor} +{ if (count<>-1) or (errno<>EAGAIN) + gpm_report(GPM_PR_INFO,"Read too few bytes (%i) at %s:%d", + count,__FILE__,__LINE__);} + gpm_getevent:=-1; + exit; + end; + + dec(event.x,gpm_zerobased); + dec(event.y,gpm_zerobased); + gpm_getevent:=1; +end; + +function gpm_repeat(millisec:longint):longint; + +var fd:longint; + selset:Tfdset; + +begin + fd:=0; {Default to stdin (xterm).} + if gpm_fd>=0 then + fd:=gpm_fd; + + fpFD_ZERO(selset); + fpFD_SET(fd,selset); + gpm_repeat:=fpselect(fd+1,@selset,nil,nil,millisec); +end; + +function gpm_fitvaluesM(var x,y:longint;margin:longint):longint; + +begin + gpm_fitvaluesM:=0; + if margin=-1 then + begin + if x<gpm_zerobased then + x:=gpm_zerobased + else if x>gpm_mx then + x:=gpm_mx; + if y<gpm_zerobased then + y:=gpm_zerobased + else if y>gpm_my then + y:=gpm_my; + end + else + case margin of + GPM_TOP: + inc(y); + GPM_BOT: + dec(y); + GPM_RGT: + dec(x); + GPM_LFT: + inc(x); + end; +end; + +function gpm_fitvalues(var x,y:longint):longint;inline; + +begin + gpm_fitvalues:=gpm_fitvaluesm(x,y,-1); +end; + +function gpm_handle_roi(var eptr:Tgpm_event;clientdata:pointer):longint;cdecl; + +var backevent:Tgpm_event; + roi:Pgpm_roi; + +begin + roi:=gpm_current_roi; + + {If motion or press, look for the interested roi. + Drag and release will be reported to the old roi.} + + if eptr.eventtype and (GPM_MOVE or GPM_DOWN)<>0 then + begin + roi:=gpm_roi; + while roi<>nil do + begin + if not ((roi^.xmin>eptr.x) or (roi^.xmax<eptr.x)) and + not ((roi^.ymin>eptr.y) or (roi^.ymax<eptr.y)) and + not ((roi^.minmod and eptr.modifiers)<roi^.minmod) and + not ((roi^.maxmod and eptr.modifiers)<eptr.modifiers) then + break; + roi:=roi^.next; + end; + end; + + {Now generate the leave/enter events} + + if roi<>gpm_current_roi then + begin + if (gpm_current_roi<>nil) and (gpm_current_roi^.eventmask and GPM_LEAVE<>0) then + begin + backevent.eventtype:=GPM_LEAVE; + gpm_current_roi^.handler(backevent,gpm_current_roi^.clientdata); + end; + if (roi<>nil) and (roi^.eventmask and GPM_ENTER<>0) then + begin + backevent.eventtype:=GPM_ENTER; + roi^.handler(backevent,roi^.clientdata); + end; + end; + gpm_current_roi:=roi; + + {events not requested are discarded} + if (roi<>nil) and (eptr.eventtype and ($0f or GPM_ENTER or GPM_LEAVE) and roi^.eventmask=0) then + gpm_handle_roi:=0 + else + begin + backevent:=eptr; {copy it, so the main one is unchanged} + if roi=nil then + if gpm_roi_handler<>nil then + gpm_handle_roi:=gpm_roi_handler(backevent,gpm_roi_data) + else + gpm_handle_roi:=0 + else + begin + {Ok, now report the event as it is, after modifying x and y} + dec(backevent.x,roi^.xmin); + dec(backevent.y,roi^.ymin); + roi^.handler(backevent,roi^.clientdata); + end; + end; +end; + +function gpm_pushroi(x1:longint;y1:longint;x2:longint;y2:longint; + mask:longint;fun:Tgpmhandler;xtradata:pointer):Pgpm_roi; + +var n:Pgpm_roi; + +begin + {create a roi and push it} + new(n); + {use the roi handler, if still null} + if (gpm_roi<>nil) and (gpm_handler<>nil) then + gpm_handler:=@gpm_handle_roi; + + n^.xmin:=x1; n^.xmax:=x2; + n^.ymin:=y1; n^.ymax:=y2; + n^.minmod:=0; n^.maxmod:=$ffff; + n^.prev:=nil; n^.next:=nil; + n^.eventmask:=mask; + n^.owned:=0; { use dispose } + n^.handler:=fun; + if xtradata=nil then + n^.clientdata:=n + else + n^.clientdata:=xtradata; + gpm_pushroi:=gpm_raiseroi(n,nil); +end; + +function gpm_useroi(n:Pgpm_roi):Pgpm_roi; + +begin + { use a Roi by pushing it } + n^.prev:=nil; + n^.next:=nil; + n^.owned:=1; + + { use the roi handler, if still nil } + if (gpm_roi=nil) and (gpm_handler=nil) then + gpm_handler:=@gpm_handle_roi; + + gpm_useroi:=gpm_raiseroi(n,nil); +end; + +function gpm_poproi(which:Pgpmroi):Pgpmroi; + +begin + {extract the Roi and remove it} + if which^.prev<>nil then + which^.prev^.next:=which^.next; + if which^.next<>nil then + which^.next^.prev:=which^.prev; + if gpm_roi=which then + gpm_roi:=which^.next; + + if which^.owned=0 then + dispose(which); + if gpm_current_roi=which then + gpm_current_roi:=nil; + + gpm_poproi:=gpm_roi; {return the new top-of-stack} +end; + + +function gpm_raiseroi(which:Pgpmroi;before:Pgpmroi):Pgpmroi; + +begin + {raise a Roi above another, or to top-of-stack} + if gpm_roi=nil then + begin + gpm_roi:=which; + gpm_raiseroi:=which; + exit; + end; + if before=nil then + before:=gpm_roi; + if before=which then + begin + gpm_raiseroi:=gpm_roi; + exit; + end; + + if which^.prev<>nil then + which^.prev^.next:=which^.next; + if which^.next<>nil then + which^.next^.prev:=which^.prev; + if gpm_roi=which then + gpm_roi:=which^.next; + + which^.prev:=before^.prev; + before^.prev:=which; + which^.next:=before; + + if which^.prev<>nil then + which^.prev^.next:=which + else + gpm_roi:=which; + + gpm_raiseroi:=gpm_roi; { return the new top-of-stack } +end; + +function gpm_lowerroi(which:Pgpmroi;after:Pgpmroi):Pgpmroi; + +begin + {lower a Roi below another, or to bottom-of-stack} + if after=nil then + begin + after:=gpm_roi; + while after^.next<>nil do + after:=after^.next; + end; + if after=which then + begin + gpm_lowerroi:=gpm_roi; + exit; + end; + if which^.prev<>nil then + which^.prev^.next:=which^.next; + if which^.next<>nil then + which^.next^.prev:=which^.prev; + if gpm_roi=which then + gpm_roi:=which^.next; + + which^.next:=after^.next; + after^.next:=which; + which^.prev:=after; + + if which^.next<>nil then + which^.next^.prev:=which; + + gpm_lowerroi:=gpm_roi; {return the new top-of-stack} +end; + +function gpm_getsnapshot(eptr:Pgpm_event):longint; + +var conn:Tgpm_connect; + event:Tgpm_event; + sillyset:Tfdset; + i:longint; + +begin + fillchar(conn,sizeof(conn),0); + if eptr<>nil then + conn.vc:=GPM_REQ_SNAPSHOT + else + begin + conn.vc:=GPM_REQ_BUTTONS; + eptr:=@event; + end; + if gpm_fd=-1 then + begin + gpm_getsnapshot:=-1; + exit; + end; + fpFD_ZERO(sillyset); + fpFD_SET(gpm_fd,sillyset); + if fpselect(gpm_fd+1,@sillyset,nil,nil,0)=1 then + gpm_getsnapshot:=0 + else + begin + fpwrite(gpm_fd,conn,sizeof(Tgpm_connect)); + + i:=gpm_getevent(eptr^); + if i<>1 then + gpm_getsnapshot:=-1 + else + begin + gpm_getsnapshot:=eptr^.eventtype; { number of buttons } + if eptr^.eventtype=0 then + gpm_getsnapshot:=15; + eptr^.eventtype:=0; + end; + end; +end; + +function gpm_getsnapshot(var eptr:Tgpmevent):longint;inline; + +begin + gpm_getsnapshot:=gpm_getsnapshot(@eptr); +end; + +{$endif} + +end. diff --git a/packages/rtl-extra/src/unix/sockets.pp b/packages/rtl-extra/src/unix/sockets.pp new file mode 100644 index 0000000000..2888aea723 --- /dev/null +++ b/packages/rtl-extra/src/unix/sockets.pp @@ -0,0 +1,99 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2000 by the Free Pascal development team + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} +unit Sockets; +Interface + +{$ifdef Unix} +Uses baseunix,UnixType; +{$endif} + +{$i osdefs.inc} { Compile time defines } + +{$if + defined(FreeBSD) or + defined(Darwin) or + defined(Haiku) +} +{$DEFINE SOCK_HAS_SINLEN} // BSD definition of socketaddr +{$endif} + +Type + TSockLen = BaseUnix.TSocklen; + +{$i unxsockh.inc} +{$i socketsh.inc} + +type + TUnixSockAddr = packed Record + {$ifdef SOCK_HAS_SINLEN} + sa_len : cuchar; + {$endif} + family : sa_family_t; + path:array[0..107] of char; //104 total for freebsd. + end; + +const + EsockEINTR = EsysEINTR; + EsockEBADF = EsysEBADF; + EsockEFAULT = EsysEFAULT; + EsockEINVAL = EsysEINVAL; + EsockEACCESS = ESysEAcces; + EsockEMFILE = ESysEmfile; +{$ifndef beos} + EsockEMSGSIZE = ESysEMsgSize; +{$endif beos} + EsockENOBUFS = ESysENoBufs; + EsockENOTCONN = ESysENotConn; +{$ifndef beos} + EsockENOTSOCK = ESysENotSock; +{$endif beos} + EsockEPROTONOSUPPORT = ESysEProtoNoSupport; + EsockEWOULDBLOCK = ESysEWouldBlock; + + +{ unix socket specific functions } +Procedure Str2UnixSockAddr(const addr:string;var t:TUnixSockAddr;var len:longint); deprecated; +Function Bind(Sock:longint;const addr:string):boolean; deprecated; +Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:text):Boolean; deprecated; +Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:file):Boolean; deprecated; +Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:text):Boolean; deprecated; +Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:File):Boolean; deprecated; + +//function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; maybelibc +//function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; maybelibc +//function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; maybelibc + +Implementation + +Uses {$ifndef FPC_USE_LIBC}SysCall{$else}initc{$endif}; + +threadvar internal_socketerror : cint; + +{****************************************************************************** + Kernel Socket Callings +******************************************************************************} + +function socketerror:cint; + +begin + socketerror:=internal_socketerror; +end; + +{$ifndef FPC_USE_LIBC} +{$i unixsock.inc} +{$else} +{$i stdsock.inc} +{$endif} +{$i sockovl.inc} +{$i sockets.inc} +end. diff --git a/packages/rtl-extra/src/unix/unixsockets.pp b/packages/rtl-extra/src/unix/unixsockets.pp new file mode 100644 index 0000000000..afd617ad70 --- /dev/null +++ b/packages/rtl-extra/src/unix/unixsockets.pp @@ -0,0 +1,19 @@ +unit unixsockets; + +{$mode objfpc}{$H+} + +{$packrecords C} + +interface + +uses + cTypes, BaseUnix; + +{$unixsocketsh.inc} + +implementation + +{$unixsockets.inc} + +end. + diff --git a/packages/rtl-extra/src/win/fpwinsockh.inc b/packages/rtl-extra/src/win/fpwinsockh.inc new file mode 100644 index 0000000000..c6b70a277f --- /dev/null +++ b/packages/rtl-extra/src/win/fpwinsockh.inc @@ -0,0 +1,207 @@ +{ + Should be aliases but I copy pasted them from winsock2 for now... +} + +const +{ Address families. } + AF_UNSPEC = winsock2.AF_UNSPEC; { unspecified } + AF_UNIX = winsock2.AF_UNIX; { local to host (pipes, portals) } + AF_INET = winsock2.AF_INET; { internetwork: UDP, TCP, etc. } + AF_IMPLINK = winsock2.AF_IMPLINK; { arpanet imp addresses } + AF_PUP = winsock2.AF_PUP; { pup protocols: e.g. BSP } + AF_CHAOS = winsock2.AF_CHAOS; { mit CHAOS protocols } + AF_IPX = winsock2.AF_IPX; { IPX and SPX } + AF_NS = winsock2.AF_NS; { XEROX NS protocols } + AF_ISO = winsock2.AF_ISO; { ISO protocols } + AF_OSI = winsock2.AF_OSI; { OSI is ISO } + AF_ECMA = winsock2.AF_ECMA; { european computer manufacturers } + AF_DATAKIT = winsock2.AF_DATAKIT; { datakit protocols } + AF_CCITT = winsock2.AF_CCITT; { CCITT protocols, X.25 etc } + AF_SNA = winsock2.AF_SNA; { IBM SNA } + AF_DECnet = winsock2.AF_DECnet; { DECnet } + AF_DLI = winsock2.AF_DLI; { Direct data link interface } + AF_LAT = winsock2.AF_LAT; { LAT } + AF_HYLINK = winsock2.AF_HYLINK; { NSC Hyperchannel } + AF_APPLETALK = winsock2.AF_APPLETALK; { AppleTalk } + AF_NETBIOS = winsock2.AF_NETBIOS; { NetBios-style addresses } + AF_VOICEVIEW = winsock2.AF_VOICEVIEW; { VoiceView } + AF_FIREFOX = winsock2.AF_FIREFOX; { FireFox } + AF_UNKNOWN1 = winsock2.AF_UNKNOWN1; { Somebody is using this! } + AF_BAN = winsock2.AF_BAN; { Banyan } + AF_ATM = winsock2.AF_ATM; // Native ATM Services + AF_INET6 = winsock2.AF_INET6; // Internetwork Version 6 + AF_MAX = winsock2.AF_MAX; + + PF_UNSPEC = AF_UNSPEC; + PF_UNIX = AF_UNIX; + PF_INET = AF_INET; + PF_IMPLINK = AF_IMPLINK; + PF_PUP = AF_PUP; + PF_CHAOS = AF_CHAOS; + PF_NS = AF_NS; + PF_IPX = AF_IPX; + PF_ISO = AF_ISO; + PF_OSI = AF_OSI; + PF_ECMA = AF_ECMA; + PF_DATAKIT = AF_DATAKIT; + PF_CCITT = AF_CCITT; + PF_SNA = AF_SNA; + PF_DECnet = AF_DECnet; + PF_DLI = AF_DLI; + PF_LAT = AF_LAT; + PF_HYLINK = AF_HYLINK; + PF_APPLETALK = AF_APPLETALK; + PF_VOICEVIEW = AF_VOICEVIEW; + PF_FIREFOX = AF_FIREFOX; + PF_UNKNOWN1 = AF_UNKNOWN1; + PF_BAN = AF_BAN; + PF_ATM = AF_ATM; + PF_INET6 = AF_INET6; + + PF_MAX = AF_MAX; + +{ Protocols } + IPPROTO_IP = winsock2.IPPROTO_IP; + IPPROTO_ICMP = winsock2.IPPROTO_ICMP; + IPPROTO_IGMP = winsock2.IPPROTO_IGMP; + IPPROTO_GGP = winsock2.IPPROTO_GGP; + IPPROTO_TCP = winsock2.IPPROTO_TCP; + IPPROTO_PUP = winsock2.IPPROTO_PUP; + IPPROTO_UDP = winsock2.IPPROTO_UDP; + IPPROTO_IDP = winsock2.IPPROTO_IDP; + IPPROTO_ND = winsock2.IPPROTO_ND; + + IPPROTO_RAW = winsock2.IPPROTO_RAW; + IPPROTO_MAX = winsock2.IPPROTO_MAX; + +{ Port/socket numbers: network standard functions} + + IPPORT_ECHO = winsock2.IPPORT_ECHO; + IPPORT_DISCARD = winsock2.IPPORT_DISCARD; + IPPORT_SYSTAT = winsock2.IPPORT_SYSTAT; + IPPORT_DAYTIME = winsock2.IPPORT_DAYTIME; + IPPORT_NETSTAT = winsock2.IPPORT_NETSTAT; + IPPORT_FTP = winsock2.IPPORT_FTP; + IPPORT_TELNET = winsock2.IPPORT_TELNET; + IPPORT_SMTP = winsock2.IPPORT_SMTP; + IPPORT_TIMESERVER = winsock2.IPPORT_TIMESERVER; + IPPORT_NAMESERVER = winsock2.IPPORT_NAMESERVER; + IPPORT_WHOIS = winsock2.IPPORT_WHOIS; + IPPORT_MTP = winsock2.IPPORT_MTP; + +{ Port/socket numbers: host specific functions } + + IPPORT_TFTP = winsock2.IPPORT_TFTP; + IPPORT_RJE = winsock2.IPPORT_RJE; + IPPORT_FINGER = winsock2.IPPORT_FINGER; + IPPORT_TTYLINK = winsock2.IPPORT_TTYLINK; + IPPORT_SUPDUP = winsock2.IPPORT_SUPDUP; + +{ UNIX TCP sockets } + + IPPORT_EXECSERVER = winsock2.IPPORT_EXECSERVER; + IPPORT_LOGINSERVER = winsock2.IPPORT_LOGINSERVER; + IPPORT_CMDSERVER = winsock2.IPPORT_CMDSERVER; + IPPORT_EFSSERVER = winsock2.IPPORT_EFSSERVER; + +{ UNIX UDP sockets } + + IPPORT_BIFFUDP = winsock2.IPPORT_BIFFUDP; + IPPORT_WHOSERVER = winsock2.IPPORT_WHOSERVER; + IPPORT_ROUTESERVER = winsock2.IPPORT_ROUTESERVER; + +{ Ports < IPPORT_RESERVED are reserved for + privileged processes (e.g. root). } + + IPPORT_RESERVED = winsock2.IPPORT_RESERVED; + +{ Options for use with [gs]etsockopt at the IP level. } + + IP_OPTIONS = winsock2.IP_OPTIONS; + IP_MULTICAST_IF = winsock2.IP_MULTICAST_IF; + IP_MULTICAST_TTL = winsock2.IP_MULTICAST_TTL; + IP_MULTICAST_LOOP = winsock2.IP_MULTICAST_LOOP; + IP_ADD_MEMBERSHIP = winsock2.IP_ADD_MEMBERSHIP; + IP_DROP_MEMBERSHIP = winsock2.IP_DROP_MEMBERSHIP; + IP_TTL = winsock2.IP_TTL; + IP_TOS = winsock2.IP_TOS; + IP_DONTFRAGMENT = winsock2.IP_DONTFRAGMENT; + +{ This is used instead of -1, since the + TSocket type is unsigned.} +{ + Tsocket might be unsigned, but the sockets unit uses + signed types. So, we cannot use these constants, signed + ones are defined in socketh.inc. + INVALID_SOCKET = winsock2.INVALID_SOCKET; + SOCKET_ERROR = winsock2.SOCKET_ERROR; +} + +{ Option flags per-socket. } + + SO_DEBUG = winsock2.SO_DEBUG; + SO_ACCEPTCONN = winsock2.SO_ACCEPTCONN; + SO_REUSEADDR = winsock2.SO_REUSEADDR; + SO_KEEPALIVE = winsock2.SO_KEEPALIVE; + SO_DONTROUTE = winsock2.SO_DONTROUTE; + SO_BROADCAST = winsock2.SO_BROADCAST; + SO_USELOOPBACK = winsock2.SO_USELOOPBACK; + SO_LINGER = winsock2.SO_LINGER; + SO_OOBINLINE = winsock2.SO_OOBINLINE; + + SO_DONTLINGER = winsock2.SO_DONTLINGER; + +{ Additional options. } + + SO_SNDBUF = winsock2.SO_SNDBUF; + SO_RCVBUF = winsock2.SO_RCVBUF; + SO_SNDLOWAT = winsock2.SO_SNDLOWAT; + SO_RCVLOWAT = winsock2.SO_RCVLOWAT; + SO_SNDTIMEO = winsock2.SO_SNDTIMEO; + SO_RCVTIMEO = winsock2.SO_RCVTIMEO; + SO_ERROR = winsock2.SO_ERROR; + SO_TYPE = winsock2.SO_TYPE; + +{ Options for connect and disconnect data and options. Used only by + non-TCP/IP transports such as DECNet, OSI TP4, etc. } + + SO_CONNDATA = winsock2.SO_CONNDATA; + SO_CONNOPT = winsock2.SO_CONNOPT; + SO_DISCDATA = winsock2.SO_DISCDATA; + SO_DISCOPT = winsock2.SO_DISCOPT; + SO_CONNDATALEN = winsock2.SO_CONNDATALEN; + SO_CONNOPTLEN = winsock2.SO_CONNOPTLEN; + SO_DISCDATALEN = winsock2.SO_DISCDATALEN; + SO_DISCOPTLEN = winsock2.SO_DISCOPTLEN; + +{ Option for opening sockets for synchronous access. } + SO_OPENTYPE = winsock2.SO_OPENTYPE; + SO_SYNCHRONOUS_ALERT = winsock2.SO_SYNCHRONOUS_ALERT; + SO_SYNCHRONOUS_NONALERT = winsock2.SO_SYNCHRONOUS_NONALERT; + +{ Other NT-specific options. } + SO_MAXDG = winsock2.SO_MAXDG; + SO_MAXPATHDG = winsock2.SO_MAXPATHDG; + SO_UPDATE_ACCEPT_CONTEXT = winsock2.SO_UPDATE_ACCEPT_CONTEXT; + SO_CONNECT_TIME = winsock2.SO_CONNECT_TIME; + +{ TCP options. } + TCP_NODELAY = winsock2.TCP_NODELAY; + TCP_BSDURGENT = winsock2.TCP_BSDURGENT; + + MSG_OOB = winsock2.MSG_OOB; + MSG_PEEK = winsock2.MSG_PEEK; + MSG_DONTROUTE = winsock2.MSG_DONTROUTE; + +{ WinSock 2 extension -- new flags for WSASend(), WSASendTo(), WSARecv() and WSARecvFrom() } + MSG_INTERRUPT = winsock2.MSG_INTERRUPT; + MSG_MAXIOVLEN = winsock2.MSG_MAXIOVLEN; + + MSG_PARTIAL = winsock2.MSG_PARTIAL; + + { options for socket level } + SOL_SOCKET = $ffff; + + INVALID_SOCKET = winsock2.INVALID_SOCKET; + SOCKET_ERROR = winsock2.SOCKET_ERROR; + diff --git a/packages/rtl-extra/src/win/sockets.pp b/packages/rtl-extra/src/win/sockets.pp new file mode 100644 index 0000000000..18e19a799d --- /dev/null +++ b/packages/rtl-extra/src/win/sockets.pp @@ -0,0 +1,281 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2000 by the Free Pascal development team + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} +{$mode objfpc} +unit Sockets; + +Interface + +{$macro on} +{$define maybelibc:=} + + Uses + winsock2,ctypes; + +Type + // the common socket functions are defined as size_t. + // without defining them for Windows this way, the + // sockets unit is not crossplatform. This is not a mistake + // wrt 64-bit, the types are "INT" in the headers. + // Mantis #22834 + size_t = cuint32; + ssize_t = cint32; + tsocklen= cint; + psocklen= ^tsocklen; + +const + EsockEINTR = WSAEINTR; + EsockEBADF = WSAEBADF; + EsockEFAULT = WSAEFAULT; + EsockEINVAL = WSAEINVAL; + EsockEACCESS = WSAEACCES; + EsockEMFILE = WSAEMFILE; + EsockEMSGSIZE = WSAEMSGSIZE; + EsockENOBUFS = WSAENOBUFS; + EsockENOTCONN = WSAENOTCONN; + EsockENOTSOCK = WSAENOTSOCK; + EsockEPROTONOSUPPORT = WSAEPROTONOSUPPORT; + EsockEWOULDBLOCK = WSAEWOULDBLOCK; + + SHUT_RD = SD_RECEIVE; // aliases so we are cross-platform + SHUT_WR = SD_SEND; + SHUT_RDWR = SD_BOTH; + +{$i socketsh.inc} +{$i fpwinsockh.inc} + +// finalizing Winsock2 stack might upset other DLLS. Mantis #22597 +var + NoWinsockCleanupCall : Boolean = false; + +Implementation + +{****************************************************************************** + Basic Socket Functions +******************************************************************************} + +//function fprecvmsg (s:cint; msg: pmsghdr; flags:cint):ssize_t; +//function fpsendmsg (s:cint; hdr: pmsghdr; flags:cint):ssize; + +//function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; + +function socketerror:cint; +begin + result:=wsagetlasterror; +end; + +function fpsocket (domain:cint; xtype:cint; protocol: cint):cint; +begin + fpSocket:=WinSock2.Socket(Domain,xtype,ProtoCol); +end; + +function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t; +begin + fpSend:=WinSock2.Send(S,msg,len,flags); +end; + +function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t; +begin + // Dubious construct, this should be checked. (IPV6 fails ?) + fpSendTo:=WinSock2.SendTo(S,msg,Len,Flags,Winsock2.PSockAddr(tox),toLen); +end; + +function fprecv (s:cint; buf: pointer; len: size_t; flags: cint):ssize_t; +begin + fpRecv:=WinSock2.Recv(S,Buf,Len,Flags); +end; + +function fprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t; + +begin + fpRecvFrom:=WinSock2.RecvFrom(S,Buf,Len,Flags,WinSock2.PSockAddr(From),FromLen); +end; + +function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; + +begin + fpConnect:=Winsock2.Connect(S,WinSock2.PSockAddr(name),nameLen); +end; + +function fpshutdown (s:cint; how:cint):cint; +begin + fpShutDown:=Winsock2.ShutDown(S,How); +end; + +Function socket(Domain,SocketType,Protocol:Longint):Longint; +begin + socket:=fpsocket(Domain,sockettype,protocol); +end; + +Function Send(Sock:Longint;Const Buf;BufLen,Flags:Longint):Longint; + +begin + send:=fpsend(sock,@buf,buflen,flags); +end; + +Function SendTo(Sock:Longint;Const Buf;BufLen,Flags:Longint;Var Addr; AddrLen : Longint):Longint; + +begin + sendto:=fpsendto(sock,@buf,buflen,flags,@addr,addrlen); +end; + +Function Recv(Sock:Longint;Var Buf;BufLen,Flags:Longint):Longint; +begin + Recv:=fpRecv(Sock,@Buf,BufLen,Flags); +end; + +Function RecvFrom(Sock : Longint; Var Buf; Buflen,Flags : Longint; Var Addr; var AddrLen : longint) : longint; +begin + RecvFrom:=fpRecvFrom(Sock,@Buf,BufLen,Flags,@Addr,@AddrLen); +end; + +function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; +begin + fpbind:=Winsock2.Bind(S,Winsock2.PSockAddr(Addrx),AddrLen); +end; + +function fplisten (s:cint; backlog : cint):cint; +begin + fplisten:=Winsock2.Listen(S,backlog); +end; + +function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; +begin + fpAccept:=Winsock2.Accept(S,Winsock2.PSockAddr(Addrx), AddrLen); +end; + +function fpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpGetSockName:=Winsock2.GetSockName(S,Winsock2.TSockAddr(name^),nameLen^); +end; + +function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint; +begin + fpGetPeerName:=Winsock2.GetPeerName(S,Winsock2.TSockAddr(name^),NameLen^); +end; + +function fpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint; +begin + fpGetSockOpt:=Winsock2.GetSockOpt(S,Level,OptName,OptVal,OptLen^); +end; + +function fpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen :tsocklen):cint; +begin + fpSetSockOpt:=Winsock2.SetSockOpt(S,Level,OptName,OptVal,OptLen); +end; + +function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint; +begin + fpsocketpair:=-1; + WSASetLastError(EOPNOTSUPP); // so that wsagetlasterror retrieves it +end; + +Function CloseSocket(Sock:Longint):Longint; +begin + result := Winsock2.CloseSocket (Sock); +end; + +Function Bind(Sock:Longint;Const Addr;AddrLen:Longint):Boolean; + +begin + bind:=fpBind(Sock,@Addr,AddrLen)=0; +end; + +Function Listen(Sock,MaxConnect:Longint):Boolean; + +begin + Listen:=fplisten(Sock,MaxConnect)=0; +end; + +Function Accept(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; + +begin + Accept:=FPAccept(sock,@addr,@addrlen); +end; + +Function Shutdown(Sock:Longint;How:Longint):Longint; + +begin + shutdown:=fpshutdown(sock,how); +end; + +Function Connect(Sock:Longint;Const Addr;Addrlen:Longint):Boolean; + +begin + connect:=fpconnect(sock,@addr,addrlen)=0; +end; + +Function GetSocketName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + GetSocketName:=fpGetSockName(sock,@addr,@addrlen); +end; + +Function GetPeerName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint; +begin + GetPeerName:=fpGetPeerName(Sock,@addr,@addrlen); +end; + +Function GetSocketOptions(Sock,Level,OptName:Longint;Var OptVal;Var optlen:longint):Longint; +begin + GetSocketOptions:=fpGetSockOpt(sock,level,optname,@optval,@optlen); +end; + +Function SetSocketOptions(Sock,Level,OptName:Longint;Const OptVal;optlen:longint):Longint; + +begin + SetSocketOptions:=fpsetsockopt(sock,level,optname,@optval,optlen); +end; + +Function SocketPair(Domain,SocketType,Protocol:Longint;var Pair:TSockArray):Longint; +begin + SocketPair:=fpsocketpair(domain,sockettype,protocol,@pair[1]); +end; + +function fpWrite(handle : longint;Const bufptr;size : dword) : dword; +begin + fpWrite := dword(Winsock2.send(handle, bufptr, size, 0)); + if fpWrite = dword(winsock2.SOCKET_ERROR) then + fpWrite := 0; +end; + +function fpRead(handle : longint;var bufptr;size : dword) : dword; + var + d : dword; + + begin + if ioctlsocket(handle,FIONREAD,@d) = winsock2.SOCKET_ERROR then + begin + fpRead:=0; + exit; + end; + if d>0 then + begin + if size>d then + size:=d; + fpRead := dword(Winsock2.recv(handle, bufptr, size, 0)); + if fpRead = dword(winsock2.SOCKET_ERROR) then + fpRead := 0; + end; + end; + +{$i sockets.inc} + +{ Winsocket stack needs an init. and cleanup code } +var + wsadata : twsadata; + +initialization + WSAStartUp(WINSOCK_VERSION,wsadata); +finalization + If Not NoWinsockCleanupCall Then + WSACleanUp; +end. diff --git a/packages/rtl-extra/src/win/winsock.pp b/packages/rtl-extra/src/win/winsock.pp new file mode 100644 index 0000000000..efa9e33663 --- /dev/null +++ b/packages/rtl-extra/src/win/winsock.pp @@ -0,0 +1,916 @@ +{ + This file is part of the Free Pascal run time library. + This unit contains the declarations for the Win32 Socket Library + + Copyright (c) 1999-2000 by Florian Klaempfl, + member of the Free Pascal development team. + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +{$ifndef NO_SMART_LINK} +{$smartlink on} +{$endif} +unit winsock; + + interface + + uses + windows; + + const + WINSOCK_VERSION = $0101; + { + Default maximium number of sockets. + this does not + mean that the underlying Windows Sockets implementation has to + support that many! + } + FD_SETSIZE = 64; + + type + tOS_INT = LongInt; + tOS_UINT = DWord; + ptOS_INT = ^tOS_INT; + ptOS_UINT = ^tOS_UINT; + u_char = char; + u_short = word; + u_int = tOS_UINT; + u_long = dword; + pu_long = ^u_long; + plongint = ^longint; + TSocket = UINT_PTR; + + { there is already a procedure called FD_SET, so this + record was renamed (FK) } + fdset = record + fd_count : u_int; + fd_array : array[0..(FD_SETSIZE)-1] of TSocket; + end; + + TFDSet = fdset; + PFDSet = ^fdset; + + timeval = record + tv_sec : longint; + tv_usec : longint; + end; + + TTimeVal = timeval; + PTimeVal = ^TTimeVal; + + { found no reference to this type in c header files and here. AlexS } + { minutes west of Greenwich } + { type of dst correction } + timezone = record + tz_minuteswest : longint; + tz_dsttime : longint; + end; + TTimeZone = timezone; + PTimeZone = ^TTimeZone; + + const + IOCPARM_MASK = $7f; + IOC_VOID = $20000000; + IOC_OUT = $40000000; + IOC_IN = $80000000; + IOC_INOUT = IOC_IN or IOC_OUT; + FIONREAD =cardinal( IOC_OUT or + ((4 and IOCPARM_MASK) shl 16) or + (102 shl 8) or 127); + FIONBIO = cardinal(IOC_IN or + ((4 and IOCPARM_MASK) shl 16) or + (102 shl 8) or 126); + FIOASYNC = cardinal(IOC_IN or + ((4 and IOCPARM_MASK) shl 16) or + (102 shl 8) or 125); + { + 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). + Slight modifications for differences between Linux and winsock.h + } + type + hostent = record + { official name of host } + h_name: pchar; + { alias list } + h_aliases: ^pchar; + { host address type } + h_addrtype: SmallInt; + { length of address } + h_length: SmallInt; + { list of addresses } + case byte of + 0: (h_addr_list: ^pchar); + 1: (h_addr: ^pchar) + end; + THostEnt = hostent; + PHostEnt = ^THostEnt; + + { + Assumption here is that a network number + fits in an unsigned long -- someday that won't be true! + } + netent = record + { official name of net } + n_name : ^char; + { alias list } + n_aliases : ^pchar; + { net address type } + n_addrtype : SmallInt; + n_pad1 : SmallInt; { ensure right packaging } + { network # } + n_net : u_long; + end; + TNetEnt = netent; + PNetEnt = ^TNetEnt; + + servent = record + { official service name } + s_name : ^char; + { alias list } + s_aliases : ^pchar; +{$ifdef WIN64} + { protocol to use } + s_proto : ^char; + { port # } + s_port : SmallInt; +{$else WIN64} + { port # } + s_port : SmallInt; + n_pad1 : SmallInt; { ensure right packaging } + { protocol to use } + s_proto : ^char; +{$endif WIN64} + end; + TServEnt = servent; + PServEnt = ^TServEnt; + + protoent = record + { official protocol name } + p_name : ^char; + { alias list } + p_aliases : ^pchar; + { protocol # } + p_proto : SmallInt; + p_pad1 : SmallInt; { ensure packaging } + end; + TProtoEnt = protoent; + PProtoEnt = ^TProtoEnt; + + const + { + Standard well-known IP protocols. + For some reason there are differences between Linx and winsock.h + } + IPPROTO_IP = 0; + IPPROTO_ICMP = 1; + IPPROTO_IGMP = 2; + IPPROTO_GGP = 3; + IPPROTO_TCP = 6; + IPPORT_ECHO = 7; + IPPORT_DISCARD = 9; + IPPORT_SYSTAT = 11; + IPPROTO_PUP = 12; + IPPORT_DAYTIME = 13; + IPPORT_NETSTAT = 15; + IPPROTO_UDP = 17; + IPPROTO_IDP = 22; + IPPROTO_ND = 77; + IPPROTO_RAW = 255; + IPPROTO_MAX = 256; + IPPORT_FTP = 21; + IPPORT_TELNET = 23; + IPPORT_SMTP = 25; + IPPORT_TIMESERVER = 37; + IPPORT_NAMESERVER = 42; + IPPORT_WHOIS = 43; + IPPORT_MTP = 57; + IPPORT_TFTP = 69; + IPPORT_RJE = 77; + IPPORT_FINGER = 79; + IPPORT_TTYLINK = 87; + IPPORT_SUPDUP = 95; + IPPORT_EXECSERVER = 512; + IPPORT_LOGINSERVER = 513; + IPPORT_CMDSERVER = 514; + IPPORT_EFSSERVER = 520; + IPPORT_BIFFUDP = 512; + IPPORT_WHOSERVER = 513; + IPPORT_ROUTESERVER = 520; + IPPORT_RESERVED = 1024; + + const + IMPLINK_IP = 155; + IMPLINK_LOWEXPER = 156; + IMPLINK_HIGHEXPER = 158; + + type + SunB = packed record + s_b1,s_b2,s_b3,s_b4 : u_char; + end; + + SunW = packed record + s_w1,s_w2 : u_short; + end; + + in_addr = record + case integer of + 0 : (S_un_b : SunB); + 1 : (S_un_w : SunW); + 2 : (S_addr : u_long); + end; + TInAddr = in_addr; + PInAddr = ^TInAddr; + + sockaddr_in = record + case integer of + 0 : ( (* equals to sockaddr_in, size is 16 byte *) + sin_family : SmallInt; (* 2 byte *) + sin_port : u_short; (* 2 byte *) + sin_addr : TInAddr; (* 4 byte *) + sin_zero : array[0..8-1] of char; (* 8 byte *) + ); + 1 : ((* equals to sockaddr, size is 16 byte *) + sa_family : Smallint; (* 2 byte *) + sa_data : array[0..14-1] of char; (* 14 byte *) + ); + end; + TSockAddrIn = sockaddr_in; + PSockAddrIn = ^TSockAddrIn; + TSockAddr = sockaddr_in; + PSockAddr = ^TSockAddr; + + const + INADDR_ANY = $00000000; + INADDR_LOOPBACK = $7F000001; + INADDR_BROADCAST = $FFFFFFFF; + + IN_CLASSA_NET = $ff000000; + IN_CLASSA_NSHIFT = 24; + IN_CLASSA_HOST = $00ffffff; + IN_CLASSA_MAX = 128; + IN_CLASSB_NET = $ffff0000; + IN_CLASSB_NSHIFT = 16; + IN_CLASSB_HOST = $0000ffff; + IN_CLASSB_MAX = 65536; + IN_CLASSC_NET = $ffffff00; + IN_CLASSC_NSHIFT = 8; + IN_CLASSC_HOST = $000000ff; + INADDR_NONE = $ffffffff; + + WSADESCRIPTION_LEN = 256; + WSASYS_STATUS_LEN = 128; + + type + WSADATA = record + wVersion : WORD; { 2 byte, ofs 0 } + wHighVersion : WORD; { 2 byte, ofs 2 } +{$ifdef win64} + iMaxSockets : word; { 2 byte, ofs 390 } + iMaxUdpDg : word; { 2 byte, ofs 392 } + lpVendorInfo : pchar; { 4 byte, ofs 396 } + szDescription : array[0..WSADESCRIPTION_LEN] of char; { 257 byte, ofs 4 } + szSystemStatus : array[0..WSASYS_STATUS_LEN] of char; { 129 byte, ofs 261 } +{$else win64} + szDescription : array[0..WSADESCRIPTION_LEN] of char; { 257 byte, ofs 4 } + szSystemStatus : array[0..WSASYS_STATUS_LEN] of char; { 129 byte, ofs 261 } + iMaxSockets : word; { 2 byte, ofs 390 } + iMaxUdpDg : word; { 2 byte, ofs 392 } + lpVendorInfo : pchar; { 4 byte, ofs 396 } +{$endif win64} + end; + TWSAData = WSADATA; + PWSAData = ^TWSAData; + + const + IP_OPTIONS = 1; + IP_MULTICAST_IF = 2; + IP_MULTICAST_TTL = 3; + IP_MULTICAST_LOOP = 4; + IP_ADD_MEMBERSHIP = 5; + IP_DROP_MEMBERSHIP = 6; + IP_DEFAULT_MULTICAST_TTL = 1; + IP_DEFAULT_MULTICAST_LOOP = 1; + IP_MAX_MEMBERSHIPS = 20; + + type + ip_mreq = record + imr_multiaddr : in_addr; + imr_interface : in_addr; + end; + + { + Definitions related to sockets: types, address families, options, + taken from the BSD file sys/socket.h. + } + const + INVALID_SOCKET = TSocket(not(0)); + SOCKET_ERROR = -1; + SOCK_STREAM = 1; + SOCK_DGRAM = 2; + SOCK_RAW = 3; + SOCK_RDM = 4; + SOCK_SEQPACKET = 5; + + { For setsockoptions(2) } + SO_DEBUG = $0001; + SO_ACCEPTCONN = $0002; + SO_REUSEADDR = $0004; + SO_KEEPALIVE = $0008; + SO_DONTROUTE = $0010; + SO_BROADCAST = $0020; + SO_USELOOPBACK = $0040; + SO_LINGER = $0080; + SO_OOBINLINE = $0100; + { + Additional options. + } + { send buffer size } + SO_SNDBUF = $1001; + { receive buffer size } + SO_RCVBUF = $1002; + { send low-water mark } + SO_SNDLOWAT = $1003; + { receive low-water mark } + SO_RCVLOWAT = $1004; + { send timeout } + SO_SNDTIMEO = $1005; + { receive timeout } + SO_RCVTIMEO = $1006; + { get error status and clear } + SO_ERROR = $1007; + { get socket type } + SO_TYPE = $1008; + + { + Options for connect and disconnect data and options. Used only by + non-TCP/IP transports such as DECNet, OSI TP4, etc. + } + SO_CONNDATA = $7000; + SO_CONNOPT = $7001; + SO_DISCDATA = $7002; + SO_DISCOPT = $7003; + SO_CONNDATALEN = $7004; + SO_CONNOPTLEN = $7005; + SO_DISCDATALEN = $7006; + SO_DISCOPTLEN = $7007; + + { + Option for opening sockets for synchronous access. + } + SO_OPENTYPE = $7008; + SO_SYNCHRONOUS_ALERT = $10; + SO_SYNCHRONOUS_NONALERT = $20; + + { + Other NT-specific options. + } + SO_MAXDG = $7009; + SO_MAXPATHDG = $700A; + SO_UPDATE_ACCEPT_CONTEXT = $700B; + SO_CONNECT_TIME = $700C; + + { + TCP options. + } + TCP_NODELAY = $0001; + TCP_BSDURGENT = $7000; + + { + Address families. + } + { unspecified } + AF_UNSPEC = 0; + { local to host (pipes, portals) } + AF_UNIX = 1; + { internetwork: UDP, TCP, etc. } + AF_INET = 2; + { arpanet imp addresses } + AF_IMPLINK = 3; + { pup protocols: e.g. BSP } + AF_PUP = 4; + { mit CHAOS protocols } + AF_CHAOS = 5; + { IPX and SPX } + AF_IPX = 6; + { XEROX NS protocols } + AF_NS = 6; + { ISO protocols } + AF_ISO = 7; + { OSI is ISO } + AF_OSI = AF_ISO; + { european computer manufacturers } + AF_ECMA = 8; + { datakit protocols } + AF_DATAKIT = 9; + { CCITT protocols, X.25 etc } + AF_CCITT = 10; + { IBM SNA } + AF_SNA = 11; + { DECnet } + AF_DECnet = 12; + { Direct data link interface } + AF_DLI = 13; + { LAT } + AF_LAT = 14; + { NSC Hyperchannel } + AF_HYLINK = 15; + { AppleTalk } + AF_APPLETALK = 16; + { NetBios-style addresses } + AF_NETBIOS = 17; + { VoiceView } + AF_VOICEVIEW = 18; + { FireFox } + AF_FIREFOX = 19; + { Somebody is using this! } + AF_UNKNOWN1 = 20; + { Banyan } + AF_BAN = 21; + + AF_MAX = 22; + + type + { + Structure used by kernel to pass protocol + information in raw sockets. + } + sockproto = record + sp_family : u_short; + sp_protocol : u_short; + end; + TSockProto = sockproto; + PSockProto = ^TSockProto; + + const + { + Protocol families, same as address families for now. + } + PF_UNSPEC = AF_UNSPEC; + PF_UNIX = AF_UNIX; + PF_INET = AF_INET; + PF_IMPLINK = AF_IMPLINK; + PF_PUP = AF_PUP; + PF_CHAOS = AF_CHAOS; + PF_NS = AF_NS; + PF_IPX = AF_IPX; + PF_ISO = AF_ISO; + PF_OSI = AF_OSI; + PF_ECMA = AF_ECMA; + PF_DATAKIT = AF_DATAKIT; + PF_CCITT = AF_CCITT; + PF_SNA = AF_SNA; + PF_DECnet = AF_DECnet; + PF_DLI = AF_DLI; + PF_LAT = AF_LAT; + PF_HYLINK = AF_HYLINK; + PF_APPLETALK = AF_APPLETALK; + PF_VOICEVIEW = AF_VOICEVIEW; + PF_FIREFOX = AF_FIREFOX; + PF_UNKNOWN1 = AF_UNKNOWN1; + PF_BAN = AF_BAN; + PF_MAX = AF_MAX; + + type + { + Structure used for manipulating linger option. + } + linger = record + l_onoff : u_short; + l_linger : u_short; + end; + TLinger = linger; + PLinger = ^TLinger; + + const + { + Level number for (get/set)sockopt() to apply to socket itself. + } + { options for socket level } + SOL_SOCKET = $ffff; + { + Maximum queue length specifiable by listen. + } + SOMAXCONN = 5; + { process out-of-band data } + MSG_OOB = $1; + { peek at incoming message } + MSG_PEEK = $2; + { send without using routing tables } + MSG_DONTROUTE = $4; + MSG_MAXIOVLEN = 16; + { partial send or recv for message xport } + MSG_PARTIAL = $8000; + + { + Define constant based on rfc883, used by gethostbyxxxx() calls. + } + MAXGETHOSTSTRUCT = 1024; + MAXHOSTNAMELEN = MAXGETHOSTSTRUCT; + + { + Define flags to be used with the WSAAsyncSelect() call. + } + FD_READ = $01; + FD_WRITE = $02; + FD_OOB = $04; + FD_ACCEPT = $08; + FD_CONNECT = $10; + FD_CLOSE = $20; + + { + All Windows Sockets error constants are biased by WSABASEERR from + the "normal" + } + WSABASEERR = 10000; + + { + Windows Sockets definitions of regular Microsoft C error constants + } + WSAEINTR = WSABASEERR + 4; + WSAEBADF = WSABASEERR + 9; + WSAEACCES = WSABASEERR + 13; + WSAEFAULT = WSABASEERR + 14; + WSAEINVAL = WSABASEERR + 22; + WSAEMFILE = WSABASEERR + 24; + + { + Windows Sockets definitions of regular Berkeley error constants + } + WSAEWOULDBLOCK = WSABASEERR + 35; + WSAEINPROGRESS = WSABASEERR + 36; + WSAEALREADY = WSABASEERR + 37; + WSAENOTSOCK = WSABASEERR + 38; + WSAEDESTADDRREQ = WSABASEERR + 39; + WSAEMSGSIZE = WSABASEERR + 40; + WSAEPROTOTYPE = WSABASEERR + 41; + WSAENOPROTOOPT = WSABASEERR + 42; + WSAEPROTONOSUPPORT = WSABASEERR + 43; + WSAESOCKTNOSUPPORT = WSABASEERR + 44; + WSAEOPNOTSUPP = WSABASEERR + 45; + WSAEPFNOSUPPORT = WSABASEERR + 46; + WSAEAFNOSUPPORT = WSABASEERR + 47; + WSAEADDRINUSE = WSABASEERR + 48; + WSAEADDRNOTAVAIL = WSABASEERR + 49; + WSAENETDOWN = WSABASEERR + 50; + WSAENETUNREACH = WSABASEERR + 51; + WSAENETRESET = WSABASEERR + 52; + WSAECONNABORTED = WSABASEERR + 53; + WSAECONNRESET = WSABASEERR + 54; + WSAENOBUFS = WSABASEERR + 55; + WSAEISCONN = WSABASEERR + 56; + WSAENOTCONN = WSABASEERR + 57; + WSAESHUTDOWN = WSABASEERR + 58; + WSAETOOMANYREFS = WSABASEERR + 59; + WSAETIMEDOUT = WSABASEERR + 60; + WSAECONNREFUSED = WSABASEERR + 61; + WSAELOOP = WSABASEERR + 62; + WSAENAMETOOLONG = WSABASEERR + 63; + WSAEHOSTDOWN = WSABASEERR + 64; + WSAEHOSTUNREACH = WSABASEERR + 65; + WSAENOTEMPTY = WSABASEERR + 66; + WSAEPROCLIM = WSABASEERR + 67; + WSAEUSERS = WSABASEERR + 68; + WSAEDQUOT = WSABASEERR + 69; + WSAESTALE = WSABASEERR + 70; + WSAEREMOTE = WSABASEERR + 71; + WSAEDISCON = WSABASEERR + 101; + + { + Extended Windows Sockets error constant definitions + } + WSASYSNOTREADY = WSABASEERR + 91; + WSAVERNOTSUPPORTED = WSABASEERR + 92; + 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. + } + WSAHOST_NOT_FOUND = WSABASEERR + 1001; + HOST_NOT_FOUND = WSAHOST_NOT_FOUND; + { Non-Authoritative: Host not found, or SERVERFAIL } + WSATRY_AGAIN = WSABASEERR + 1002; + TRY_AGAIN = WSATRY_AGAIN; + + { Non recoverable errors, FORMERR, REFUSED, NOTIMP } + WSANO_RECOVERY = WSABASEERR + 1003; + NO_RECOVERY = WSANO_RECOVERY; + + { Valid name, no data record of requested type } + WSANO_DATA = WSABASEERR + 1004; + NO_DATA = WSANO_DATA; + + { no address, look for MX record } + WSANO_ADDRESS = WSANO_DATA; + NO_ADDRESS = WSANO_ADDRESS; + + const + { + Windows Sockets errors redefined as regular Berkeley error constants. + } + EWOULDBLOCK = WSAEWOULDBLOCK; + EINPROGRESS = WSAEINPROGRESS; + EALREADY = WSAEALREADY; + ENOTSOCK = WSAENOTSOCK; + EDESTADDRREQ = WSAEDESTADDRREQ; + EMSGSIZE = WSAEMSGSIZE; + EPROTOTYPE = WSAEPROTOTYPE; + ENOPROTOOPT = WSAENOPROTOOPT; + EPROTONOSUPPORT = WSAEPROTONOSUPPORT; + ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT; + EOPNOTSUPP = WSAEOPNOTSUPP; + EPFNOSUPPORT = WSAEPFNOSUPPORT; + EAFNOSUPPORT = WSAEAFNOSUPPORT; + EADDRINUSE = WSAEADDRINUSE; + EADDRNOTAVAIL = WSAEADDRNOTAVAIL; + ENETDOWN = WSAENETDOWN; + ENETUNREACH = WSAENETUNREACH; + ENETRESET = WSAENETRESET; + ECONNABORTED = WSAECONNABORTED; + ECONNRESET = WSAECONNRESET; + ENOBUFS = WSAENOBUFS; + EISCONN = WSAEISCONN; + ENOTCONN = WSAENOTCONN; + ESHUTDOWN = WSAESHUTDOWN; + ETOOMANYREFS = WSAETOOMANYREFS; + ETIMEDOUT = WSAETIMEDOUT; + ECONNREFUSED = WSAECONNREFUSED; + ELOOP = WSAELOOP; + ENAMETOOLONG = WSAENAMETOOLONG; + EHOSTDOWN = WSAEHOSTDOWN; + EHOSTUNREACH = WSAEHOSTUNREACH; + ENOTEMPTY = WSAENOTEMPTY; + EPROCLIM = WSAEPROCLIM; + EUSERS = WSAEUSERS; + EDQUOT = WSAEDQUOT; + ESTALE = WSAESTALE; + EREMOTE = WSAEREMOTE; + + TF_DISCONNECT = $01; + TF_REUSE_SOCKET = $02; + TF_WRITE_BEHIND = $04; + + { + Options for use with [gs]etsockopt at the IP level. + } + IP_TTL = 7; + IP_TOS = 8; + IP_DONTFRAGMENT = 9; + + type + _TRANSMIT_FILE_BUFFERS = record + Head : Pointer; + HeadLength : dword; + Tail : Pointer; + TailLength : dword; + end; + TRANSMIT_FILE_BUFFERS = _TRANSMIT_FILE_BUFFERS; + TTransmitFileBuffers = _TRANSMIT_FILE_BUFFERS; + PTransmitFileBuffers = ^TTransmitFileBuffers; + + { Socket function prototypes } + const + winsockdll = 'wsock32.dll'; + +{ +Winsock types all buffers as pchar (char *), modern POSIX does it the ANSI +C way with pointer (void *). If the pointer overloaded version doesn't exist, +a "pointer" will be passed to the "var" version. (bug 3142). +So if there are var/const versions: +- To keep ported unix code working, there must be "pointer" variants (ANSI) +- To keep Delphi/ported C Winsock code working there must be pchar variants + (K&R) +IOW, there _must_ be 3 versions then: var/const, pchar and pointer} + + function accept(s:TSocket; addr: PSockAddr; addrlen : ptOS_INT) : TSocket;stdcall;external winsockdll name 'accept'; + function accept(s:TSocket; addr: PSockAddr; var addrlen : tOS_INT) : TSocket;stdcall;external winsockdll name 'accept'; + function bind(s:TSocket; addr: PSockaddr;namelen:tOS_INT):tOS_INT;stdcall;external winsockdll name 'bind'; + function bind(s:TSocket; const addr: TSockaddr;namelen:tOS_INT):tOS_INT;stdcall;external winsockdll name 'bind'; + function closesocket(s:TSocket):tOS_INT;stdcall;external winsockdll name 'closesocket'; + function connect(s:TSocket; addr:PSockAddr; namelen:tOS_INT):tOS_INT;stdcall;external winsockdll name 'connect'; + function connect(s:TSocket; Const name:TSockAddr; namelen:tOS_INT):tOS_INT;stdcall;external winsockdll name 'connect'; + function ioctlsocket(s:TSocket; cmd:longint; var arg:u_long):tOS_INT;stdcall;external winsockdll name 'ioctlsocket'; { really a c-long } + function ioctlsocket(s:TSocket; cmd:longint; var arg:longint):tOS_INT;stdcall;external winsockdll name 'ioctlsocket'; { really a c-long } + function ioctlsocket(s:TSocket; cmd:longint; argp:pu_long):tOS_INT;stdcall;external winsockdll name 'ioctlsocket'; { really a c-long } + function getpeername(s:TSocket; var name:TSockAddr;var namelen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'getpeername'; + function getsockname(s:TSocket; var name:TSockAddr;var namelen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'getsockname'; + function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;optval:pchar;var optlen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'getsockopt'; + function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;optval:pointer;var optlen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'getsockopt'; + function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;var optval;var optlen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'getsockopt'; + function htonl(hostlong:u_long):u_long;stdcall;external winsockdll name 'htonl'; + function htons(hostshort:u_short):u_short;stdcall;external winsockdll name 'htons'; + function inet_addr(cp:pchar):cardinal;stdcall;external winsockdll name 'inet_addr'; + function inet_ntoa(i : TInAddr):pchar;stdcall;external winsockdll name 'inet_ntoa'; + function listen(s:TSocket; backlog:tOS_INT):tOS_INT;stdcall;external winsockdll name 'listen'; + function ntohl(netlong:u_long):u_long;stdcall;external winsockdll name 'ntohl'; + function ntohs(netshort:u_short):u_short;stdcall;external winsockdll name 'ntohs'; + function recv(s:TSocket;buf:pchar; len:tOS_INT; flags:tOS_INT):tOS_INT;stdcall;external winsockdll name 'recv'; + function recv(s:TSocket;buf:pointer; len:tOS_INT; flags:tOS_INT):tOS_INT;stdcall;external winsockdll name 'recv'; + function recv(s:TSocket;var buf; len:tOS_INT; flags:tOS_INT):tOS_INT;stdcall;external winsockdll name 'recv'; + function recvfrom(s:TSocket;buf:pchar; len:tOS_INT; flags:tOS_INT;from:PSockAddr; fromlen:ptOS_INT):tOS_INT;stdcall; + external winsockdll name 'recvfrom'; + function recvfrom(s:TSocket;buf:pointer; len:tOS_INT; flags:tOS_INT;from:PSockAddr; fromlen:ptOS_INT):tOS_INT;stdcall; + external winsockdll name 'recvfrom'; + function recvfrom(s:TSocket;var buf; len:tOS_INT; flags:tOS_INT;Const from:TSockAddr; var fromlen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'recvfrom'; + function select(nfds:tOS_INT; readfds,writefds,exceptfds : PFDSet;timeout: PTimeVal):tOS_INT;stdcall; + external winsockdll name 'select'; + function send(s:TSocket;Const buf; len:tOS_INT; flags:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'send'; + function send(s:TSocket; buf:pchar; len:tOS_INT; flags:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'send'; + function send(s:TSocket;buf:pointer; len:tOS_INT; flags:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'send'; + function sendto(s:TSocket; buf:pchar; len:tOS_INT; flags:tOS_INT;toaddr:PSockAddr; tolen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'sendto'; + function sendto(s:TSocket; buf:pointer; len:tOS_INT; flags:tOS_INT;toaddr:PSockAddr; tolen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'sendto'; + function sendto(s:TSocket; Const buf; len:tOS_INT; flags:tOS_INT;Const toaddr:TSockAddr; tolen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'sendto'; + function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; optval:pchar; optlen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'setsockopt'; + function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;optval:pointer; optlen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'setsockopt'; + function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; Const optval; optlen:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'setsockopt'; + function shutdown(s:TSocket; how:tOS_INT):tOS_INT;stdcall; + external winsockdll name 'shutdown'; + function socket(af:tOS_INT; t:tOS_INT; protocol:tOS_INT):TSocket;stdcall; + external winsockdll name 'socket'; + + { Database function prototypes } + function gethostbyaddr(addr:pchar; len:tOS_INT; t:tOS_INT): PHostEnt;stdcall;external winsockdll name 'gethostbyaddr'; + function gethostbyname(name:pchar):PHostEnt;stdcall;external winsockdll name 'gethostbyname'; + function gethostname(name:pchar; namelen:tOS_INT):tOS_INT;stdcall;external winsockdll name 'gethostname'; + function getservbyport(port:tOS_INT; proto:pchar):PServEnt;stdcall;external winsockdll name 'getservbyport'; + function getservbyname(name:pchar; proto:pchar):PServEnt;stdcall;external winsockdll name 'getservbyname'; + function getprotobynumber(proto:tOS_INT):PProtoEnt;stdcall;external winsockdll name 'getprotobynumber'; + function getprotobyname(name:pchar):PProtoEnt;stdcall;external winsockdll name 'getprotobyname'; + + { Microsoft Windows Extension function prototypes } + function WSAStartup(wVersionRequired:word;var WSAData:TWSADATA):tOS_INT;stdcall; + external winsockdll name 'WSAStartup'; + function WSACleanup:tOS_INT;stdcall;external winsockdll name 'WSACleanup'; + procedure WSASetLastError(iError:tOS_INT);stdcall;external winsockdll name 'WSASetLastError'; + function WSAGetLastError:tOS_INT;stdcall;external winsockdll name 'WSAGetLastError'; + function WSAIsBlocking:BOOL;stdcall;external winsockdll name 'WSAIsBlocking'; + function WSAUnhookBlockingHook:tOS_INT;stdcall;external winsockdll name 'WSAUnhookBlockingHook'; + function WSASetBlockingHook(lpBlockFunc:TFarProc):TFarProc;stdcall;external winsockdll name 'WSASetBlockingHook'; + function WSACancelBlockingCall:tOS_INT;stdcall;external winsockdll name 'WSACancelBlockingCall'; + function WSAAsyncGetServByName(hWnd:HWND; wMsg:u_int; name:pchar; proto:pchar; buf:pchar; + buflen:tOS_INT):THandle;stdcall;external winsockdll name 'WSAAsyncGetServByName'; + function WSAAsyncGetServByPort(hWnd:HWND; wMsg:u_int; port:tOS_INT; proto:pchar; buf:pchar; + buflen:tOS_INT):THandle;stdcall;external winsockdll name 'WSAAsyncGetServByPort'; + function WSAAsyncGetProtoByName(hWnd:HWND; wMsg:u_int; name:pchar; buf:pchar; buflen:tOS_INT):THandle;stdcall; + external winsockdll name 'WSAAsyncGetProtoByName'; + function WSAAsyncGetProtoByNumber(hWnd:HWND; wMsg:u_int; number:tOS_INT; buf:pchar; buflen:tOS_INT):THandle;stdcall; + external winsockdll name 'WSAAsyncGetProtoByNumber'; + function WSAAsyncGetHostByName(hWnd:HWND; wMsg:u_int; name:pchar; buf:pchar; buflen:tOS_INT):THandle;stdcall; + external winsockdll name 'WSAAsyncGetHostByName'; + function WSAAsyncGetHostByAddr(hWnd:HWND; wMsg:u_int; addr:pchar; len:tOS_INT; t:tOS_INT; + buf:pchar; buflen:tOS_INT):THandle;stdcall; + external winsockdll name 'WSAAsyncGetHostByAddr'; + function WSACancelAsyncRequest(hAsyncTaskHandle:THandle):tOS_INT;stdcall; + external winsockdll name 'WSACancelAsyncRequest'; + function WSAAsyncSelect(s:TSocket; hWnd:HWND; wMsg:u_int; lEvent:longint):tOS_INT;stdcall; { really a c-long } + external winsockdll name 'WSAAsyncSelect'; + function WSARecvEx(s:TSocket;var buf; len:tOS_INT; flags:ptOS_INT):tOS_INT;stdcall; + external winsockdll name 'WSARecvEx'; + function __WSAFDIsSet(s:TSocket; var FDSet:TFDSet):Bool;stdcall; + external winsockdll name '__WSAFDIsSet'; + function __WSAFDIsSet_(s:TSocket; var FDSet:TFDSet):tOS_INT;stdcall; + external winsockdll name '__WSAFDIsSet'; + function TransmitFile(hSocket:TSocket; hFile:THandle; nNumberOfBytesToWrite:dword; + nNumberOfBytesPerSend:DWORD; lpOverlapped:POverlapped; + lpTransmitBuffers:PTransmitFileBuffers; dwReserved:dword):Bool;stdcall; + external winsockdll name 'TransmitFile'; + + function AcceptEx(sListenSocket,sAcceptSocket:TSocket; + lpOutputBuffer:Pointer; dwReceiveDataLength,dwLocalAddressLength, + dwRemoteAddressLength:dword; var lpdwBytesReceived:dword; + lpOverlapped:POverlapped):Bool;stdcall; + external winsockdll name 'AcceptEx'; + + procedure GetAcceptExSockaddrs(lpOutputBuffer:Pointer; + dwReceiveDataLength,dwLocalAddressLength,dwRemoteAddressLength:dword; + var LocalSockaddr:PSockAddr; var LocalSockaddrLength:tOS_INT; + var RemoteSockaddr:PSockAddr; var RemoteSockaddrLength:tOS_INT);stdcall; + external winsockdll name 'GetAcceptExSockaddrs'; + + function WSAMakeSyncReply(Buflen,Error:Word):dword; + function WSAMakeSelectReply(Event,Error:Word):dword; + function WSAGetAsyncBuflen(Param:dword):Word; + function WSAGetAsyncError(Param:dword):Word; + function WSAGetSelectEvent(Param:dword):Word; + function WSAGetSelectError(Param:dword):Word; + procedure FD_CLR(Socket:TSocket; var FDSet:TFDSet); + function FD_ISSET(Socket:TSocket; var FDSet:TFDSet):Boolean; + procedure FD_SET(Socket:TSocket; var FDSet:TFDSet); + procedure FD_ZERO(var FDSet:TFDSet); + + implementation + + { + Implementation of the helper routines + } + function WSAMakeSyncReply(Buflen,Error:Word):dword; + + begin + WSAMakeSyncReply:=MakeLong(Buflen, Error); + end; + + function WSAMakeSelectReply(Event,Error:Word):dword; + + begin + WSAMakeSelectReply:=MakeLong(Event,Error); + end; + + function WSAGetAsyncBuflen(Param:dword):Word; + + begin + WSAGetAsyncBuflen:=lo(Param); + end; + + function WSAGetAsyncError(Param:dword):Word; + + begin + WSAGetAsyncError:=hi(Param); + end; + + function WSAGetSelectEvent(Param:dword):Word; + + begin + WSAGetSelectEvent:=lo(Param); + end; + + function WSAGetSelectError(Param:dword):Word; + + begin + WSAGetSelectError:=hi(Param); + end; + + procedure FD_CLR(Socket:TSocket; var FDSet:TFDSet); + + var + i : u_int; + + begin + i:=0; + while i<FDSet.fd_count do + begin + if FDSet.fd_array[i]=Socket then + begin + while i<FDSet.fd_count-1 do + begin + FDSet.fd_array[i]:=FDSet.fd_array[i+1]; + inc(i); + end; + dec(FDSet.fd_count); + break; + end; + inc(i); + end; + end; + + function FD_ISSET(Socket:TSocket; var FDSet:TFDSet):Boolean; + + begin + FD_ISSET:=__WSAFDIsSet(Socket,FDSet); + end; + + procedure FD_SET(Socket:TSocket; var FDSet:TFDSet); + + begin + if FDSet.fd_count<FD_SETSIZE then + begin + FDSet.fd_array[FDSet.fd_count]:=Socket; + Inc(FDSet.fd_count); + end; + end; + + procedure FD_ZERO(var FDSet:TFDSet); + + begin + FDSet.fd_count:=0; + end; + +end. diff --git a/packages/rtl-extra/src/win/winsock2.pp b/packages/rtl-extra/src/win/winsock2.pp new file mode 100644 index 0000000000..48d3342ccf --- /dev/null +++ b/packages/rtl-extra/src/win/winsock2.pp @@ -0,0 +1,1486 @@ +{ Winsock2.h -- definitions to be used with the WinSock 2 DLL and WinSock 2 applications. + This header file corresponds to version 2.2.x of the WinSock API 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. } + +// converted by Alex Konshin, mailto:alexk@msmt.spb.su +// added FreePascal stuff: AlexS@freepage.de + +unit WinSock2; + +{$ifndef NO_SMART_LINK} +{$smartlink on} +{$endif} + +{$ifdef FPC_OS_UNICODE} + {$define UNICODE} +{$endif} + +interface + +Uses Windows; + +{ Define the current Winsock version. To build an earlier Winsock version + application redefine this value prior to including Winsock2.h. } +Const + WINSOCK_VERSION = $0202; + WINSOCK2_DLL = 'ws2_32.dll'; + +Type + u_char = Char; + u_short = Word; + u_int = DWord; + u_long = DWord; + pu_char = ^u_char; + pu_short = ^u_short; + pu_int = ^u_int; + pu_long = ^u_long; + + TSocket = UINT_PTR; { The new type to be used in all instances which refer to sockets. } + + WSAEVENT = THandle; + PWSAEVENT = ^WSAEVENT; + LPWSAEVENT = PWSAEVENT; +{$IFDEF UNICODE} + PMBChar = PWideChar; +{$ELSE} + PMBChar = PChar; +{$ENDIF} + +const + FD_SETSIZE = 64; + +type + PFDSet = ^TFDSet; + TFDSet = record + fd_count: u_int; + fd_array: array[0..FD_SETSIZE-1] of TSocket; + end; + fdset = TFDSet; + + PTimeVal = ^TTimeVal; + TTimeVal = record + tv_sec: Longint; + tv_usec: Longint; + end; + timeval = TTimeVal; + + timezone = record + tz_minuteswest : longint; + tz_dsttime : longint; + end; + TTimeZone = timezone; + PTimeZone = ^TTimeZone; + +const + IOCPARM_MASK = $7f; + IOC_VOID = $20000000; + IOC_OUT = $40000000; + IOC_IN = $80000000; + IOC_INOUT = (IOC_IN or IOC_OUT); + + FIONREAD = ULONG(IOC_OUT or { get # bytes to read } + ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or + (Longint(Byte('f')) shl 8) or 127); + FIONBIO = ULONG(IOC_IN or { set/clear non-blocking i/o } + ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or + (Longint(Byte('f')) shl 8) or 126); + FIOASYNC = ULONG(IOC_IN or { set/clear async i/o } + ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or + (Longint(Byte('f')) shl 8) or 125); + +type + PHostEnt = ^THostEnt; + THostEnt = record + h_name: PChar; + h_aliases: ^PChar; + h_addrtype: Smallint; + h_length: Smallint; + case Byte of + 0: (h_addr_list: ^PChar); + 1: (h_addr: ^PChar) + end; + hostent = THostEnt; + + PNetEnt = ^TNetEnt; + TNetEnt = record + n_name: PChar; + n_aliases: ^PChar; + n_addrtype: Smallint; + n_net: u_long; + end; + netent = TNetEnt; + + PServEnt = ^TServEnt; + TServEnt = record + s_name: PChar; + s_aliases: ^PChar; +{$ifdef WIN64} + s_proto: PChar; + s_port: Smallint; +{$else WIN64} + s_port: Smallint; + s_proto: PChar; +{$endif WIN64} + end; + servent = TServEnt; + + PProtoEnt = ^TProtoEnt; + TProtoEnt = record + p_name: PChar; + p_aliases: ^Pchar; + p_proto: Smallint; + end; + protoent = TProtoEnt; + +const + +{ Protocols } + IPPROTO_IP = 0; { dummy for IP } + IPPROTO_ICMP = 1; { control message protocol } + IPPROTO_IGMP = 2; { group management protocol } + IPPROTO_GGP = 3; { gateway^2 (deprecated) } + IPPROTO_TCP = 6; { tcp } + IPPROTO_PUP = 12; { pup } + IPPROTO_UDP = 17; { user datagram protocol } + IPPROTO_IDP = 22; { xns idp } + IPPROTO_ND = 77; { UNOFFICIAL net disk proto } + + IPPROTO_RAW = 255; { raw IP packet } + IPPROTO_MAX = 256; + +{ Port/socket numbers: network standard functions} + + IPPORT_ECHO = 7; + IPPORT_DISCARD = 9; + IPPORT_SYSTAT = 11; + IPPORT_DAYTIME = 13; + IPPORT_NETSTAT = 15; + IPPORT_FTP = 21; + IPPORT_TELNET = 23; + IPPORT_SMTP = 25; + IPPORT_TIMESERVER = 37; + IPPORT_NAMESERVER = 42; + IPPORT_WHOIS = 43; + IPPORT_MTP = 57; + +{ Port/socket numbers: host specific functions } + + IPPORT_TFTP = 69; + IPPORT_RJE = 77; + IPPORT_FINGER = 79; + IPPORT_TTYLINK = 87; + IPPORT_SUPDUP = 95; + +{ UNIX TCP sockets } + + IPPORT_EXECSERVER = 512; + IPPORT_LOGINSERVER = 513; + IPPORT_CMDSERVER = 514; + IPPORT_EFSSERVER = 520; + +{ UNIX UDP sockets } + + IPPORT_BIFFUDP = 512; + IPPORT_WHOSERVER = 513; + IPPORT_ROUTESERVER = 520; + +{ Ports < IPPORT_RESERVED are reserved for + privileged processes (e.g. root). } + + IPPORT_RESERVED = 1024; + +{ Link numbers } + + IMPLINK_IP = 155; + IMPLINK_LOWEXPER = 156; + IMPLINK_HIGHEXPER = 158; + + TF_DISCONNECT = $01; + TF_REUSE_SOCKET = $02; + TF_WRITE_BEHIND = $04; + +{ Options for use with [gs]etsockopt at the IP level. } + + IP_OPTIONS = 1; + IP_MULTICAST_IF = 2; { set/get IP multicast interface } + IP_MULTICAST_TTL = 3; { set/get IP multicast timetolive } + IP_MULTICAST_LOOP = 4; { set/get IP multicast loopback } + IP_ADD_MEMBERSHIP = 5; { add an IP group membership } + IP_DROP_MEMBERSHIP = 6; { drop an IP group membership } + IP_TTL = 7; { set/get IP Time To Live } + IP_TOS = 8; { set/get IP Type Of Service } + IP_DONTFRAGMENT = 9; { set/get IP Don't Fragment flag } + + + IP_DEFAULT_MULTICAST_TTL = 1; { normally limit m'casts to 1 hop } + IP_DEFAULT_MULTICAST_LOOP = 1; { normally hear sends if a member } + IP_MAX_MEMBERSHIPS = 20; { per socket; must fit in one mbuf } + +{ This is used instead of -1, since the + TSocket type is unsigned.} + + INVALID_SOCKET = TSocket(NOT(0)); + SOCKET_ERROR = -1; + +{ Types } + + SOCK_STREAM = 1; { stream socket } + SOCK_DGRAM = 2; { datagram socket } + SOCK_RAW = 3; { raw-protocol interface } + SOCK_RDM = 4; { reliably-delivered message } + SOCK_SEQPACKET = 5; { sequenced packet stream } + +{ Option flags per-socket. } + + SO_DEBUG = $0001; { turn on debugging info recording } + SO_ACCEPTCONN = $0002; { socket has had listen() } + SO_REUSEADDR = $0004; { allow local address reuse } + SO_KEEPALIVE = $0008; { keep connections alive } + SO_DONTROUTE = $0010; { just use interface addresses } + SO_BROADCAST = $0020; { permit sending of broadcast msgs } + SO_USELOOPBACK = $0040; { bypass hardware when possible } + SO_LINGER = $0080; { linger on close if data present } + SO_OOBINLINE = $0100; { leave received OOB data in line } + + SO_DONTLINGER = Integer(not SO_LINGER); + SO_EXCLUSIVEADDRUSE = Integer(not SO_REUSEADDR); { disallow local address reuse } + +{ Additional options. } + + SO_SNDBUF = $1001; { send buffer size } + SO_RCVBUF = $1002; { receive buffer size } + SO_SNDLOWAT = $1003; { send low-water mark } + SO_RCVLOWAT = $1004; { receive low-water mark } + SO_SNDTIMEO = $1005; { send timeout } + SO_RCVTIMEO = $1006; { receive timeout } + SO_ERROR = $1007; { get error status and clear } + SO_TYPE = $1008; { get socket type } + +{ Options for connect and disconnect data and options. Used only by + non-TCP/IP transports such as DECNet, OSI TP4, etc. } + + SO_CONNDATA = $7000; + SO_CONNOPT = $7001; + SO_DISCDATA = $7002; + SO_DISCOPT = $7003; + SO_CONNDATALEN = $7004; + SO_CONNOPTLEN = $7005; + SO_DISCDATALEN = $7006; + SO_DISCOPTLEN = $7007; + +{ Option for opening sockets for synchronous access. } + SO_OPENTYPE = $7008; + SO_SYNCHRONOUS_ALERT = $10; + SO_SYNCHRONOUS_NONALERT = $20; + +{ Other NT-specific options. } + SO_MAXDG = $7009; + SO_MAXPATHDG = $700A; + SO_UPDATE_ACCEPT_CONTEXT = $700B; + SO_CONNECT_TIME = $700C; + +{ TCP options. } + TCP_NODELAY = $0001; + TCP_BSDURGENT = $7000; + +{ WinSock 2 extension -- new options } + SO_GROUP_ID = $2001; // ID of a socket group + SO_GROUP_PRIORITY = $2002; // the relative priority within a group + SO_MAX_MSG_SIZE = $2003; // maximum message size + SO_PROTOCOL_INFOA = $2004; // WSAPROTOCOL_INFOA structure + SO_PROTOCOL_INFOW = $2005; // WSAPROTOCOL_INFOW structure +{$IFDEF UNICODE} + SO_PROTOCOL_INFO = SO_PROTOCOL_INFOW; +{$ELSE} + SO_PROTOCOL_INFO = SO_PROTOCOL_INFOA; +{$ENDIF} + PVD_CONFIG = $3001; // configuration info for service provider + SO_CONDITIONAL_ACCEPT = $3002; { enable true conditional accept: + connection is not ack-ed to the + other side until conditional + function returns CF_ACCEPT } + +{ Address families. } + AF_UNSPEC = 0; { unspecified } + AF_UNIX = 1; { local to host (pipes, portals) } + AF_INET = 2; { internetwork: UDP, TCP, etc. } + AF_IMPLINK = 3; { arpanet imp addresses } + AF_PUP = 4; { pup protocols: e.g. BSP } + AF_CHAOS = 5; { mit CHAOS protocols } + AF_IPX = 6; { IPX and SPX } + AF_NS = 6; { XEROX NS protocols } + AF_ISO = 7; { ISO protocols } + AF_OSI = AF_ISO; { OSI is ISO } + AF_ECMA = 8; { european computer manufacturers } + AF_DATAKIT = 9; { datakit protocols } + AF_CCITT = 10; { CCITT protocols, X.25 etc } + AF_SNA = 11; { IBM SNA } + AF_DECnet = 12; { DECnet } + AF_DLI = 13; { Direct data link interface } + AF_LAT = 14; { LAT } + AF_HYLINK = 15; { NSC Hyperchannel } + AF_APPLETALK = 16; { AppleTalk } + AF_NETBIOS = 17; { NetBios-style addresses } + AF_VOICEVIEW = 18; { VoiceView } + AF_FIREFOX = 19; { FireFox } + AF_UNKNOWN1 = 20; { Somebody is using this! } + AF_BAN = 21; { Banyan } + AF_ATM = 22; { Native ATM Services } + AF_INET6 = 23; { Internetwork Version 6 } + AF_CLUSTER = 24; { Microsoft Wolfpack } + AF_12844 = 25; { IEEE 1284.4 WG AF } + AF_IRDA = 26; { IrDA } + AF_NETDES = 28; { Network Designers OSI & gateway + enabled protocols } + AF_TCNPROCESS = 29; + AF_TCNMESSAGE = 30; + AF_ICLFXBM = 31; + + AF_MAX = 32; + +{ Socket I/O Controls } +{Const + SIOCSHIWAT = _IOW('s', 0, u_long); // set high watermark + SIOCGHIWAT = _IOR('s', 1, u_long); // get high watermark + SIOCSLOWAT = _IOW('s', 2, u_long); // set low watermark + SIOCGLOWAT = _IOR('s', 3, u_long); // get low watermark + SIOCATMARK = _IOR('s', 7, u_long); // at oob mark? } + +{ Protocol families, same as address families for now. } + + PF_UNSPEC = AF_UNSPEC; + PF_UNIX = AF_UNIX; + PF_INET = AF_INET; + PF_IMPLINK = AF_IMPLINK; + PF_PUP = AF_PUP; + PF_CHAOS = AF_CHAOS; + PF_NS = AF_NS; + PF_IPX = AF_IPX; + PF_ISO = AF_ISO; + PF_OSI = AF_OSI; + PF_ECMA = AF_ECMA; + PF_DATAKIT = AF_DATAKIT; + PF_CCITT = AF_CCITT; + PF_SNA = AF_SNA; + PF_DECnet = AF_DECnet; + PF_DLI = AF_DLI; + PF_LAT = AF_LAT; + PF_HYLINK = AF_HYLINK; + PF_APPLETALK = AF_APPLETALK; + PF_VOICEVIEW = AF_VOICEVIEW; + PF_FIREFOX = AF_FIREFOX; + PF_UNKNOWN1 = AF_UNKNOWN1; + PF_BAN = AF_BAN; + PF_ATM = AF_ATM; + PF_INET6 = AF_INET6; + PF_CLUSTER = AF_CLUSTER; + PF_12844 = AF_12844; + PF_IRDA = AF_IRDA; + PF_NETDES = AF_NETDES; + PF_TCNPROCESS = AF_TCNPROCESS; + PF_TCNMESSAGE = AF_TCNMESSAGE; + PF_ICLFXBM = AF_ICLFXBM; + + PF_MAX = AF_MAX; + +type + + SunB = record + s_b1, s_b2, s_b3, s_b4: u_char; + end; + + SunW = record + s_w1, s_w2: u_short; + end; + + PInAddr = ^TInAddr; + TInAddr = record + case integer of + 0: (S_un_b: SunB); + 1: (S_un_w: SunW); + 2: (S_addr: u_long); + end; + in_addr = TInAddr; + + PIn6Addr = ^TIn6Addr; + TIn6Addr = record + case byte of + 0: (u6_addr8 : array[0..15] of byte); + 1: (u6_addr16 : array[0..7] of Word); + 2: (u6_addr32 : array[0..3] of Cardinal); + 3: (s6_addr8 : array[0..15] of shortint); + 4: (s6_addr : array[0..15] of shortint); + 5: (s6_addr16 : array[0..7] of smallint); + 6: (s6_addr32 : array[0..3] of LongInt); + end; + + PSockAddrIn = ^TSockAddrIn; + TSockAddrIn = record + case Integer of + 0: (sin_family: u_short; + sin_port: u_short; + sin_addr: TInAddr; + sin_zero: array[0..7] of Char); + 1: (sa_family: u_short; + sa_data: array[0..13] of Char) + end; + sockaddr_in = TSockAddrIn; + + PSockAddrIn6 = ^TSockAddrIn6; + TSockAddrIn6 = record + sin6_family : u_short; + sin6_port : u_short; + sin6_flowinfo : u_long; + sin6_addr : TIn6Addr; + sin6_scope_id : u_long; + end; + sockaddr_in6 = TSockAddrIn6; + + { Structure used by kernel to store most addresses. } + + PSockAddr = ^TSockAddr; + TSockAddr = TSockAddrIn; + + { Structure used by kernel to pass protocol information in raw sockets. } + PSockProto = ^TSockProto; + TSockProto = record + sp_family: u_short; + sp_protocol: u_short; + end; + sockproto = TSockProto; + +{ Structure used for manipulating linger option. } + PLinger = ^TLinger; + TLinger = record + l_onoff: u_short; + l_linger: u_short; + end; + +const + INADDR_ANY = $00000000; + INADDR_LOOPBACK = $7F000001; + INADDR_BROADCAST = $FFFFFFFF; + INADDR_NONE = $FFFFFFFF; + + { options for socket level } + SOL_SOCKET = $ffff; + + MSG_OOB = $1; {process out-of-band data } + MSG_PEEK = $2; {peek at incoming message } + MSG_DONTROUTE = $4; {send without using routing tables } + +{ WinSock 2 extension -- new flags for WSASend(), WSASendTo(), WSARecv() and WSARecvFrom() } + MSG_INTERRUPT = $10; {/* send/recv in the interrupt context */} + MSG_MAXIOVLEN = 16; + + MSG_PARTIAL = $8000; {partial send or recv for message xport } + +{ Define constant based on rfc883, used by gethostbyxxxx() calls. } + + MAXGETHOSTSTRUCT = 1024; + +{ Maximum queue length specifiable by listen. } + SOMAXCONN = $7fffffff; + +{ WinSock 2 extension -- bit values and indices for FD_XXX network events } + FD_READ_BIT = 0; + FD_READ = (1 shl FD_READ_BIT); + FD_WRITE_BIT = 1; + FD_WRITE = (1 shl FD_WRITE_BIT); + FD_OOB_BIT = 2; + FD_OOB = (1 shl FD_OOB_BIT); + FD_ACCEPT_BIT = 3; + FD_ACCEPT = (1 shl FD_ACCEPT_BIT); + FD_CONNECT_BIT = 4; + FD_CONNECT = (1 shl FD_CONNECT_BIT); + FD_CLOSE_BIT = 5; + FD_CLOSE = (1 shl FD_CLOSE_BIT); + FD_QOS_BIT = 6; + FD_QOS = (1 shl FD_QOS_BIT); + FD_GROUP_QOS_BIT = 7; + FD_GROUP_QOS = (1 shl FD_GROUP_QOS_BIT); + FD_MAX_EVENTS = 8; + FD_ALL_EVENTS = ((1 shl FD_MAX_EVENTS) - 1); + +{ All Windows Sockets error constants are biased by WSABASEERR from the "normal" } + + WSABASEERR = 10000; + +{ Windows Sockets definitions of regular Microsoft C error constants } + + WSAEINTR = (WSABASEERR+4); + WSAEBADF = (WSABASEERR+9); + WSAEACCES = (WSABASEERR+13); + WSAEFAULT = (WSABASEERR+14); + WSAEINVAL = (WSABASEERR+22); + WSAEMFILE = (WSABASEERR+24); + +{ Windows Sockets definitions of regular Berkeley error constants } + + WSAEWOULDBLOCK = (WSABASEERR+35); + WSAEINPROGRESS = (WSABASEERR+36); + WSAEALREADY = (WSABASEERR+37); + WSAENOTSOCK = (WSABASEERR+38); + WSAEDESTADDRREQ = (WSABASEERR+39); + WSAEMSGSIZE = (WSABASEERR+40); + WSAEPROTOTYPE = (WSABASEERR+41); + WSAENOPROTOOPT = (WSABASEERR+42); + WSAEPROTONOSUPPORT = (WSABASEERR+43); + WSAESOCKTNOSUPPORT = (WSABASEERR+44); + WSAEOPNOTSUPP = (WSABASEERR+45); + WSAEPFNOSUPPORT = (WSABASEERR+46); + WSAEAFNOSUPPORT = (WSABASEERR+47); + WSAEADDRINUSE = (WSABASEERR+48); + WSAEADDRNOTAVAIL = (WSABASEERR+49); + WSAENETDOWN = (WSABASEERR+50); + WSAENETUNREACH = (WSABASEERR+51); + WSAENETRESET = (WSABASEERR+52); + WSAECONNABORTED = (WSABASEERR+53); + WSAECONNRESET = (WSABASEERR+54); + WSAENOBUFS = (WSABASEERR+55); + WSAEISCONN = (WSABASEERR+56); + WSAENOTCONN = (WSABASEERR+57); + WSAESHUTDOWN = (WSABASEERR+58); + WSAETOOMANYREFS = (WSABASEERR+59); + WSAETIMEDOUT = (WSABASEERR+60); + WSAECONNREFUSED = (WSABASEERR+61); + WSAELOOP = (WSABASEERR+62); + WSAENAMETOOLONG = (WSABASEERR+63); + WSAEHOSTDOWN = (WSABASEERR+64); + WSAEHOSTUNREACH = (WSABASEERR+65); + WSAENOTEMPTY = (WSABASEERR+66); + WSAEPROCLIM = (WSABASEERR+67); + WSAEUSERS = (WSABASEERR+68); + WSAEDQUOT = (WSABASEERR+69); + WSAESTALE = (WSABASEERR+70); + WSAEREMOTE = (WSABASEERR+71); + +{ Extended Windows Sockets error constant definitions } + + WSASYSNOTREADY = (WSABASEERR+91); + WSAVERNOTSUPPORTED = (WSABASEERR+92); + WSANOTINITIALISED = (WSABASEERR+93); + WSAEDISCON = (WSABASEERR+101); + WSAENOMORE = (WSABASEERR+102); + WSAECANCELLED = (WSABASEERR+103); + WSAEINVALIDPROCTABLE = (WSABASEERR+104); + WSAEINVALIDPROVIDER = (WSABASEERR+105); + WSAEPROVIDERFAILEDINIT = (WSABASEERR+106); + WSASYSCALLFAILURE = (WSABASEERR+107); + WSASERVICE_NOT_FOUND = (WSABASEERR+108); + WSATYPE_NOT_FOUND = (WSABASEERR+109); + WSA_E_NO_MORE = (WSABASEERR+110); + WSA_E_CANCELLED = (WSABASEERR+111); + WSAEREFUSED = (WSABASEERR+112); + + +{ 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 } + WSAHOST_NOT_FOUND = (WSABASEERR+1001); + HOST_NOT_FOUND = WSAHOST_NOT_FOUND; + +{ Non-Authoritative: Host not found, or SERVERFAIL } + WSATRY_AGAIN = (WSABASEERR+1002); + TRY_AGAIN = WSATRY_AGAIN; + +{ Non recoverable errors, FORMERR, REFUSED, NOTIMP } + WSANO_RECOVERY = (WSABASEERR+1003); + NO_RECOVERY = WSANO_RECOVERY; + +{ Valid name, no data record of requested type } + WSANO_DATA = (WSABASEERR+1004); + NO_DATA = WSANO_DATA; + +{ no address, look for MX record } + WSANO_ADDRESS = WSANO_DATA; + NO_ADDRESS = WSANO_ADDRESS; + +{ WinSock 2 extension -- new error codes and type definition } + WSA_IO_PENDING = ERROR_IO_PENDING; + WSA_IO_INCOMPLETE = ERROR_IO_INCOMPLETE; + WSA_INVALID_HANDLE = ERROR_INVALID_HANDLE; + WSA_INVALID_PARAMETER = ERROR_INVALID_PARAMETER; + WSA_NOT_ENOUGH_MEMORY = ERROR_NOT_ENOUGH_MEMORY; + WSA_OPERATION_ABORTED = ERROR_OPERATION_ABORTED; +{$ifndef FPC}{TODO} + WSA_INVALID_EVENT = WSAEVENT(nil); +{$endif} + WSA_MAXIMUM_WAIT_EVENTS = MAXIMUM_WAIT_OBJECTS; + WSA_WAIT_FAILED = $ffffffff; + WSA_WAIT_EVENT_0 = WAIT_OBJECT_0; + WSA_WAIT_IO_COMPLETION = WAIT_IO_COMPLETION; + WSA_WAIT_TIMEOUT = WAIT_TIMEOUT; + WSA_INFINITE = INFINITE; + +{ 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. } + + EWOULDBLOCK = WSAEWOULDBLOCK; + EINPROGRESS = WSAEINPROGRESS; + EALREADY = WSAEALREADY; + ENOTSOCK = WSAENOTSOCK; + EDESTADDRREQ = WSAEDESTADDRREQ; + EMSGSIZE = WSAEMSGSIZE; + EPROTOTYPE = WSAEPROTOTYPE; + ENOPROTOOPT = WSAENOPROTOOPT; + EPROTONOSUPPORT = WSAEPROTONOSUPPORT; + ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT; + EOPNOTSUPP = WSAEOPNOTSUPP; + EPFNOSUPPORT = WSAEPFNOSUPPORT; + EAFNOSUPPORT = WSAEAFNOSUPPORT; + EADDRINUSE = WSAEADDRINUSE; + EADDRNOTAVAIL = WSAEADDRNOTAVAIL; + ENETDOWN = WSAENETDOWN; + ENETUNREACH = WSAENETUNREACH; + ENETRESET = WSAENETRESET; + ECONNABORTED = WSAECONNABORTED; + ECONNRESET = WSAECONNRESET; + ENOBUFS = WSAENOBUFS; + EISCONN = WSAEISCONN; + ENOTCONN = WSAENOTCONN; + ESHUTDOWN = WSAESHUTDOWN; + ETOOMANYREFS = WSAETOOMANYREFS; + ETIMEDOUT = WSAETIMEDOUT; + ECONNREFUSED = WSAECONNREFUSED; + ELOOP = WSAELOOP; + ENAMETOOLONG = WSAENAMETOOLONG; + EHOSTDOWN = WSAEHOSTDOWN; + EHOSTUNREACH = WSAEHOSTUNREACH; + ENOTEMPTY = WSAENOTEMPTY; + EPROCLIM = WSAEPROCLIM; + EUSERS = WSAEUSERS; + EDQUOT = WSAEDQUOT; + ESTALE = WSAESTALE; + EREMOTE = WSAEREMOTE; + + + WSADESCRIPTION_LEN = 256; + WSASYS_STATUS_LEN = 128; + MAX_PROTOCOL_CHAIN = 7; + BASE_PROTOCOL = 1; + LAYERED_PROTOCOL = 0; + WSAPROTOCOL_LEN = 255; + +type + PWSAData = ^TWSAData; + TWSAData = record + wVersion : WORD; { 2 byte, ofs 0 } + wHighVersion : WORD; { 2 byte, ofs 2 } +{$ifdef win64} + iMaxSockets : word; + iMaxUdpDg : word; + lpVendorInfo : pchar; + szDescription : array[0..WSADESCRIPTION_LEN] of char; + szSystemStatus : array[0..WSASYS_STATUS_LEN] of char; +{$else win64} + szDescription : array[0..WSADESCRIPTION_LEN] of char; { 257 byte, ofs 4 } + szSystemStatus : array[0..WSASYS_STATUS_LEN] of char; { 129 byte, ofs 261 } + iMaxSockets : word; { 2 byte, ofs 390 } + iMaxUdpDg : word; { 2 byte, ofs 392 } + lpVendorInfo : pchar; { 4 byte, ofs 396 } +{$endif win64} + end; + WSAData = TWSAData; + +{ WSAOVERLAPPED = Record + Internal: LongInt; + InternalHigh: LongInt; + Offset: LongInt; + OffsetHigh: LongInt; + hEvent: WSAEVENT; + end;} + WSAOVERLAPPED = TOverlapped; + TWSAOverlapped = WSAOverlapped; + PWSAOverlapped = ^WSAOverlapped; + LPWSAOVERLAPPED = PWSAOverlapped; + +{ WinSock 2 extension -- WSABUF and QOS struct, include qos.h } +{ to pull in FLOWSPEC and related definitions } + + + WSABUF = record + len: U_LONG; { the length of the buffer } + buf: PChar; { the pointer to the buffer } + end {WSABUF}; + PWSABUF = ^WSABUF; + LPWSABUF = PWSABUF; + + TServiceType = LongInt; + + TFlowSpec = Record + TokenRate, // In Bytes/sec + TokenBucketSize, // In Bytes + PeakBandwidth, // In Bytes/sec + Latency, // In microseconds + DelayVariation : LongInt;// In microseconds + ServiceType : TServiceType; + MaxSduSize, MinimumPolicedSize : LongInt;// In Bytes + end; + PFlowSpec = ^TFLOWSPEC; + flowspec = TFlowSpec; + + TQualityOfService = record + SendingFlowspec: TFlowSpec; { the flow spec for data sending } + ReceivingFlowspec: TFlowSpec; { the flow spec for data receiving } + ProviderSpecific: WSABUF; { additional provider specific stuff } + end {TQualityOfService}; + PQOS = ^TQualityOfService; + LPQOS = PQOS; + +Const + SERVICETYPE_NOTRAFFIC = $00000000; // No data in this direction + SERVICETYPE_BESTEFFORT = $00000001; // Best Effort + SERVICETYPE_CONTROLLEDLOAD = $00000002; // Controlled Load + SERVICETYPE_GUARANTEED = $00000003; // Guaranteed + SERVICETYPE_NETWORK_UNAVAILABLE = $00000004; // Used to notify change to user + SERVICETYPE_GENERAL_INFORMATION = $00000005; // corresponds to "General Parameters" defined by IntServ + SERVICETYPE_NOCHANGE = $00000006; // used to indicate that the flow spec contains no change from any previous one +// to turn on immediate traffic control, OR this flag with the ServiceType field in teh FLOWSPEC + SERVICE_IMMEDIATE_TRAFFIC_CONTROL = $80000000; + +{ WinSock 2 extension -- manifest constants for return values of the condition function } + CF_ACCEPT = $0000; + CF_REJECT = $0001; + CF_DEFER = $0002; + +{ WinSock 2 extension -- manifest constants for shutdown() } + SD_RECEIVE = $00; + SD_SEND = $01; + SD_BOTH = $02; + +{ WinSock 2 extension -- data type and manifest constants for socket groups } + SG_UNCONSTRAINED_GROUP = $01; + SG_CONSTRAINED_GROUP = $02; +Type + GROUP = u_long; + +{ WinSock 2 extension -- data type for WSAEnumNetworkEvents() } + TWSANetworkEvents = record + lNetworkEvents: LongInt; + iErrorCode: Array[0..FD_MAX_EVENTS-1] of Longint; + end {TWSANetworkEvents}; + PWSANetworkEvents = ^TWSANetworkEvents; + LPWSANetworkEvents = PWSANetworkEvents; + + TWSAProtocolChain = record + ChainLen: Longint; // the length of the chain, + // length = 0 means layered protocol, + // length = 1 means base protocol, + // length > 1 means protocol chain + ChainEntries: Array[0..MAX_PROTOCOL_CHAIN-1] of LongInt; { a list of dwCatalogEntryIds } + end {TWSAPROTOCOLCHAIN}; + +Type + TWSAProtocol_InfoA = record + dwServiceFlags1: LongInt; + dwServiceFlags2: LongInt; + dwServiceFlags3: LongInt; + dwServiceFlags4: LongInt; + dwProviderFlags: LongInt; + ProviderId: TGUID; + dwCatalogEntryId: LongInt; + ProtocolChain: TWSAProtocolChain; + iVersion: Longint; + iAddressFamily: Longint; + iMaxSockAddr: Longint; + iMinSockAddr: Longint; + iSocketType: Longint; + iProtocol: Longint; + iProtocolMaxOffset: Longint; + iNetworkByteOrder: Longint; + iSecurityScheme: Longint; + dwMessageSize: LongInt; + dwProviderReserved: LongInt; + szProtocol: Array[0..WSAPROTOCOL_LEN+1-1] of Char; + end {TWSAProtocol_InfoA}; + PWSAProtocol_InfoA = ^TWSAProtocol_InfoA; + LPWSAProtocol_InfoA = PWSAProtocol_InfoA; + + TWSAProtocol_InfoW = record + dwServiceFlags1: LongInt; + dwServiceFlags2: LongInt; + dwServiceFlags3: LongInt; + dwServiceFlags4: LongInt; + dwProviderFlags: LongInt; + ProviderId: TGUID; + dwCatalogEntryId: LongInt; + ProtocolChain: TWSAProtocolChain; + iVersion: Longint; + iAddressFamily: Longint; + iMaxSockAddr: Longint; + iMinSockAddr: Longint; + iSocketType: Longint; + iProtocol: Longint; + iProtocolMaxOffset: Longint; + iNetworkByteOrder: Longint; + iSecurityScheme: Longint; + dwMessageSize: LongInt; + dwProviderReserved: LongInt; + szProtocol: Array[0..(WSAPROTOCOL_LEN+1-1)] of WideChar; + end {TWSAProtocol_InfoW}; + PWSAProtocol_InfoW = ^TWSAProtocol_InfoW; + LPWSAProtocol_InfoW = PWSAProtocol_InfoW; + +{$IFDEF UNICODE} + TWSAProtocol_Info = TWSAProtocol_InfoW; + LPWSAProtocol_Info = PWSAProtocol_InfoW; +{$ELSE} + TWSAProtocol_Info = TWSAProtocol_InfoA; + LPWSAProtocol_Info = PWSAProtocol_InfoA; +{$ENDIF} + +{ Flag bit definitions for dwProviderFlags */ } +Const + PFL_MULTIPLE_PROTO_ENTRIES = $00000001; + PFL_RECOMMENDED_PROTO_ENTRY = $00000002; + PFL_HIDDEN = $00000004; + PFL_MATCHES_PROTOCOL_ZERO = $00000008; + +{ Flag bit definitions for dwServiceFlags1 */ } + XP1_CONNECTIONLESS = $00000001; + XP1_GUARANTEED_DELIVERY = $00000002; + XP1_GUARANTEED_ORDER = $00000004; + XP1_MESSAGE_ORIENTED = $00000008; + XP1_PSEUDO_STREAM = $00000010; + XP1_GRACEFUL_CLOSE = $00000020; + XP1_EXPEDITED_DATA = $00000040; + XP1_CONNECT_DATA = $00000080; + XP1_DISCONNECT_DATA = $00000100; + XP1_SUPPORT_BROADCAST = $00000200; + XP1_SUPPORT_MULTIPOINT = $00000400; + XP1_MULTIPOINT_CONTROL_PLANE = $00000800; + XP1_MULTIPOINT_DATA_PLANE = $00001000; + XP1_QOS_SUPPORTED = $00002000; + XP1_INTERRUPT = $00004000; + XP1_UNI_SEND = $00008000; + XP1_UNI_RECV = $00010000; + XP1_IFS_HANDLES = $00020000; + XP1_PARTIAL_MESSAGE = $00040000; + + BIGENDIAN = $0000; + LITTLEENDIAN = $0001; + + SECURITY_PROTOCOL_NONE = $0000; + +{ WinSock 2 extension -- manifest constants for WSAJoinLeaf() } + JL_SENDER_ONLY = $01; + JL_RECEIVER_ONLY = $02; + JL_BOTH = $04; + +{ WinSock 2 extension -- manifest constants for WSASocket() } + WSA_FLAG_OVERLAPPED = $01; + WSA_FLAG_MULTIPOINT_C_ROOT = $02; + WSA_FLAG_MULTIPOINT_C_LEAF = $04; + WSA_FLAG_MULTIPOINT_D_ROOT = $08; + WSA_FLAG_MULTIPOINT_D_LEAF = $10; + +{ WinSock 2 extension -- manifest constants for WSAIoctl() } + IOC_UNIX = $00000000; + IOC_WS2 = $08000000; + IOC_PROTOCOL = $10000000; + IOC_VENDOR = $18000000; + + SIO_ASSOCIATE_HANDLE = IOC_IN or IOC_WS2 or 1; + SIO_ENABLE_CIRCULAR_QUEUEING = IOC_WS2 or 2; + SIO_FIND_ROUTE = IOC_OUT or IOC_WS2 or 3; + SIO_FLUSH = IOC_WS2 or 4; + SIO_GET_BROADCAST_ADDRESS = IOC_OUT or IOC_WS2 or 5; + SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT or IOC_WS2 or 6; + SIO_GET_QOS = IOC_INOUT or IOC_WS2 or 7; + SIO_GET_GROUP_QOS = IOC_INOUT or IOC_WS2 or 8; + SIO_MULTIPOINT_LOOPBACK = IOC_IN or IOC_WS2 or 9; + SIO_MULTICAST_SCOPE = IOC_IN or IOC_WS2 or 10; + SIO_SET_QOS = IOC_IN or IOC_WS2 or 11; + SIO_SET_GROUP_QOS = IOC_IN or IOC_WS2 or 12; + SIO_TRANSLATE_HANDLE = IOC_INOUT or IOC_WS2 or 13; + +{WinSock 2 extension -- manifest constants for SIO_TRANSLATE_HANDLE ioctl } + TH_NETDEV = $00000001; + TH_TAPI = $00000002; + +Const + SERVICE_MULTIPLE = $00000001; + +{ & Name Spaces } + NS_ALL = (0); + + NS_SAP = (1); + NS_NDS = (2); + NS_PEER_BROWSE = (3); + + NS_TCPIP_LOCAL = (10); + NS_TCPIP_HOSTS = (11); + NS_DNS = (12); + NS_NETBT = (13); + NS_WINS = (14); + + NS_NBP = (20); + + NS_MS = (30); + NS_STDA = (31); + NS_NTDS = (32); + + NS_X500 = (40); + NS_NIS = (41); + NS_NISPLUS = (42); + + NS_WRQ = (50); + +{ Resolution flags for WSAGetAddressByName(). + Note these are also used by the 1.1 API GetAddressByName, so leave them around. } + RES_UNUSED_1 = $00000001; + RES_FLUSH_CACHE = $00000002; + RES_SERVICE = $00000004; + +{ Well known value names for Service Types } + SERVICE_TYPE_VALUE_IPXPORTA = 'IpxSocket'; +{$ifndef FPC}{TODO} + SERVICE_TYPE_VALUE_IPXPORTW : PWideChar = 'IpxSocket'; + SERVICE_TYPE_VALUE_SAPIDA = 'SapId'; + SERVICE_TYPE_VALUE_SAPIDW : PWideChar = 'SapId'; + + SERVICE_TYPE_VALUE_TCPPORTA = 'TcpPort'; + SERVICE_TYPE_VALUE_TCPPORTW : PWideChar = 'TcpPort'; + + SERVICE_TYPE_VALUE_UDPPORTA = 'UdpPort'; + SERVICE_TYPE_VALUE_UDPPORTW : PWideChar = 'UdpPort'; + + SERVICE_TYPE_VALUE_OBJECTIDA = 'ObjectId'; + SERVICE_TYPE_VALUE_OBJECTIDW : PWideChar = 'ObjectId'; + +{$IFDEF UNICODE} + SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDW; + SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTW; + SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTW; + SERVICE_TYPE_VALUE_OBJECTID = SERVICE_TYPE_VALUE_OBJECTIDW; +{$ELSE} + SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDA; + SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTA; + SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTA; + SERVICE_TYPE_VALUE_OBJECTID = SERVICE_TYPE_VALUE_OBJECTIDA; +{$ENDIF} + +{$endif}{FPC} + +{ SockAddr Information } + + +Type + SOCKET_ADDRESS = record + lpSockaddr : PSockAddr; + iSockaddrLength : Longint; + end {SOCKET_ADDRESS}; + PSOCKET_ADDRESS = ^SOCKET_ADDRESS; + +{ CSAddr Information } + CSADDR_INFO = record + LocalAddr, RemoteAddr: SOCKET_ADDRESS; + iSocketType, iProtocol : LongInt; + end {CSADDR_INFO}; + PCSADDR_INFO = ^CSADDR_INFO; + +{ Address Family/Protocol Tuples } + TAFProtocols = record + iAddressFamily: Longint; + iProtocol: Longint; + end {AFPROTOCOLS}; + PAFProtocols = ^TAFProtocols; + +{ Client Query API Typedefs } + +{ The comparators } + TWSAEComparator = (COMP_EQUAL {= 0}, COMP_NOTLESS ); + + TWSAVersion = record + dwVersion: LongInt; + ecHow: TWSAEComparator; + end {TWSAVersion}; + PWSAVersion = ^TWSAVersion; + + TWSAQuerySetA = record + dwSize: LongInt; + lpszServiceInstanceName: PChar; + lpServiceClassId: PGUID; + lpVersion: PWSAVERSION; + lpszComment: PChar; + dwNameSpace: LongInt; + lpNSProviderId: PGUID; + lpszContext: PChar; + dwNumberOfProtocols: LongInt; + lpafpProtocols: PAFProtocols; + lpszQueryString: PChar; + dwNumberOfCsAddrs: LongInt; + lpcsaBuffer: PCSADDR_INFO; + dwOutputFlags: LongInt; + lpBlob: PBLOB; + end {TWSAQuerySetA}; + PWSAQuerySetA = ^TWSAQuerySetA; + LPWSAQuerySetA = PWSAQuerySetA; + TWSAQuerySetW = record + dwSize: LongInt; + lpszServiceInstanceName: PWideChar; + lpServiceClassId: PGUID; + lpVersion: PWSAVERSION; + lpszComment: PWideChar; + dwNameSpace: LongInt; + lpNSProviderId: PGUID; + lpszContext: PWideChar; + dwNumberOfProtocols: LongInt; + lpafpProtocols: PAFProtocols; + lpszQueryString: PWideChar; + dwNumberOfCsAddrs: LongInt; + lpcsaBuffer: PCSADDR_INFO; + dwOutputFlags: LongInt; + lpBlob: PBLOB; + end {TWSAQuerySetW}; + PWSAQuerySetW = ^TWSAQuerySetW; + LPWSAQuerySetW = PWSAQuerySetW; +{$IFDEF UNICODE} + PWSAQuerySet = PWSAQuerySetW; + LPWSAQuerySet = PWSAQuerySetW; +{$ELSE} + PWSAQuerySet = PWSAQuerySetA; + LPWSAQuerySet = PWSAQuerySetA; +{$ENDIF} + + PWSAMSG = ^TWSAMSG; + TWSAMSG = record + name: PSOCKET_ADDRESS; + namelen: Longint; + lpBuffers: LPWSABUF; + dwBufferCount: DWORD; + Control: WSABUF; + dwFlags: DWORD; + end; + WSAMSG = TWSAMSG; + LPWSAMSG = PWSAMSG; + +Const + LUP_DEEP = $0001; + LUP_CONTAINERS = $0002; + LUP_NOCONTAINERS = $0004; + LUP_NEAREST = $0008; + LUP_RETURN_NAME = $0010; + LUP_RETURN_TYPE = $0020; + LUP_RETURN_VERSION = $0040; + LUP_RETURN_COMMENT = $0080; + LUP_RETURN_ADDR = $0100; + LUP_RETURN_BLOB = $0200; + LUP_RETURN_ALIASES = $0400; + LUP_RETURN_QUERY_STRING = $0800; + LUP_RETURN_ALL = $0FF0; + LUP_RES_SERVICE = $8000; + + LUP_FLUSHCACHE = $1000; + LUP_FLUSHPREVIOUS = $2000; + + +{ Return flags } + RESULT_IS_ALIAS = $0001; + +Type +{ Service Address Registration and Deregistration Data Types. } + TWSAeSetServiceOp = (RNRSERVICE_REGISTER{=0},RNRSERVICE_DEREGISTER,RNRSERVICE_DELETE); + +{ Service Installation/Removal Data Types. } + TWSANSClassInfoA = record + lpszName: PChar; + dwNameSpace: LongInt; + dwValueType: LongInt; + dwValueSize: LongInt; + lpValue: Pointer; + end {_WSANSClassInfoA}; + PWSANSClassInfoA = ^TWSANSClassInfoA; + TWSANSClassInfoW = record + lpszName: PWideChar; + dwNameSpace: LongInt; + dwValueType: LongInt; + dwValueSize: LongInt; + lpValue: Pointer; + end {TWSANSClassInfoW}; + PWSANSClassInfoW = ^TWSANSClassInfoW; +{$IFDEF UNICODE} + TWSANSClassInfo = TWSANSClassInfoW; + PWSANSClassInfo = PWSANSClassInfoW; + LPWSANSClassInfo = PWSANSClassInfoW; +{$ELSE} + TWSANSClassInfo = TWSANSClassInfoA; + PWSANSClassInfo = PWSANSClassInfoA; + LPWSANSClassInfo = PWSANSClassInfoA; +{$ENDIF // UNICODE} + + TWSAServiceClassInfoA = record + lpServiceClassId: PGUID; + lpszServiceClassName: PChar; + dwCount: LongInt; + lpClassInfos: PWSANSClassInfoA; + end {TWSAServiceClassInfoA}; + PWSAServiceClassInfoA = ^TWSAServiceClassInfoA; + LPWSAServiceClassInfoA = PWSAServiceClassInfoA; + TWSAServiceClassInfoW = record + lpServiceClassId: PGUID; + lpszServiceClassName: PWideChar; + dwCount: LongInt; + lpClassInfos: PWSANSClassInfoW; + end {TWSAServiceClassInfoW}; + PWSAServiceClassInfoW = ^TWSAServiceClassInfoW; + LPWSAServiceClassInfoW = PWSAServiceClassInfoW; +{$IFDEF UNICODE} + TWSAServiceClassInfo = TWSAServiceClassInfoW; + PWSAServiceClassInfo = PWSAServiceClassInfoW; + LPWSAServiceClassInfo = PWSAServiceClassInfoW; +{$ELSE} + TWSAServiceClassInfo = TWSAServiceClassInfoA; + PWSAServiceClassInfo = PWSAServiceClassInfoA; + LPWSAServiceClassInfo = PWSAServiceClassInfoA; +{$ENDIF} + + TWSANameSpace_InfoA = record + NSProviderId: TGUID; + dwNameSpace: LongInt; + fActive: LongInt{Bool}; + dwVersion: LongInt; + lpszIdentifier: PChar; + end {TWSANameSpace_InfoA}; + PWSANameSpace_InfoA = ^TWSANameSpace_InfoA; + LPWSANameSpace_InfoA = PWSANameSpace_InfoA; + TWSANameSpace_InfoW = record + NSProviderId: TGUID; + dwNameSpace: LongInt; + fActive: LongInt{Bool}; + dwVersion: LongInt; + lpszIdentifier: PWideChar; + end {TWSANameSpace_InfoW}; + PWSANameSpace_InfoW = ^TWSANameSpace_InfoW; + LPWSANameSpace_InfoW = PWSANameSpace_InfoW; +{$IFDEF UNICODE} + TWSANameSpace_Info = TWSANameSpace_InfoW; + PWSANameSpace_Info = PWSANameSpace_InfoW; + LPWSANameSpace_Info = PWSANameSpace_InfoW; +{$ELSE} + TWSANameSpace_Info = TWSANameSpace_InfoA; + PWSANameSpace_Info = PWSANameSpace_InfoA; + LPWSANameSpace_Info = PWSANameSpace_InfoA; +{$ENDIF} + +{ WinSock 2 extensions -- data types for the condition function in } +{ WSAAccept() and overlapped I/O completion routine. } +Type + LPCONDITIONPROC = function (lpCallerId: LPWSABUF; lpCallerData : LPWSABUF; lpSQOS,lpGQOS : LPQOS; lpCalleeId,lpCalleeData : LPWSABUF; + g : GROUP; dwCallbackData : DWORD ) : Longint; stdcall; + LPWSAOVERLAPPED_COMPLETION_ROUTINE = procedure ( const dwError, cbTransferred : DWORD; const lpOverlapped : LPWSAOVERLAPPED; const dwFlags : DWORD ); stdcall; + +function accept( const s: TSocket; addr: PSockAddr; addrlen: PLongint ): TSocket; stdcall;external WINSOCK2_DLL name 'accept'; +function accept( const s: TSocket; addr: PSockAddr; var addrlen: Longint ): TSocket; stdcall;external WINSOCK2_DLL name 'accept'; +function bind( const s: TSocket; addr: PSockAddr; const namelen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'bind'; +function bind( const s: TSocket; const addr: TSockAddr; namelen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'bind'; +function closesocket( const s: TSocket ): Longint; stdcall;external WINSOCK2_DLL name 'closesocket'; +function connect( const s: TSocket; name: PSockAddr; namelen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'connect'; +function connect( const s: TSocket; const name: TSockAddr; namelen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'connect'; +function ioctlsocket( const s: TSocket; cmd: Longint; var arg: u_long ): Longint; stdcall;external WINSOCK2_DLL name 'ioctlsocket'; +function ioctlsocket( const s: TSocket; cmd: Longint; argp: pu_long ): Longint; stdcall;external WINSOCK2_DLL name 'ioctlsocket'; +function getpeername( const s: TSocket; var name: TSockAddr; var namelen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'getpeername'; +function getsockname( const s: TSocket; var name: TSockAddr; var namelen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'getsockname'; +function getsockopt( const s: TSocket; const level, optname: Longint; optval: PChar; var optlen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'getsockopt'; +function getsockopt( const s: TSocket; const level, optname: Longint; optval: Pointer; var optlen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'getsockopt'; +function getsockopt( const s: TSocket; const level, optname: Longint; var optval; var optlen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'getsockopt'; +function htonl(hostlong: u_long): u_long; stdcall;external WINSOCK2_DLL name 'htonl'; +function htons(hostshort: u_short): u_short; stdcall;external WINSOCK2_DLL name 'htons'; +function inet_addr(cp: PChar): u_long; stdcall;external WINSOCK2_DLL name 'inet_addr'; +function inet_ntoa(inaddr: TInAddr): PChar; stdcall;external WINSOCK2_DLL name 'inet_ntoa'; +function listen(s: TSocket; backlog: Longint): Longint; stdcall;external WINSOCK2_DLL name 'listen'; +function ntohl(netlong: u_long): u_long; stdcall;external WINSOCK2_DLL name 'ntohl'; +function ntohs(netshort: u_short): u_short; stdcall;external WINSOCK2_DLL name 'ntohs'; +function recv(s: TSocket; var Buf; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'recv'; +function recv(s: TSocket; Buf: PChar; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'recv'; +function recv(s: TSocket; Buf: Pointer; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'recv'; +function recvfrom(s: TSocket; Buf: PChar; len, flags: Longint; from: PSockAddr; fromlen: PLongint): Longint; stdcall;external WINSOCK2_DLL name 'recvfrom'; +function recvfrom(s: TSocket; Buf: Pointer; len, flags: Longint; from: PSockAddr; fromlen: PLongint): Longint; stdcall;external WINSOCK2_DLL name 'recvfrom'; +function recvfrom(s: TSocket; var Buf; len, flags: Longint; const from: TSockAddr; var fromlen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'recvfrom'; +function select(nfds: Longint; readfds, writefds, exceptfds: PFDSet; timeout: PTimeVal): Longint; stdcall;external WINSOCK2_DLL name 'select'; +function send(s: TSocket; const Buf; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'send'; +function send(s: TSocket; Buf: PChar; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'send'; +function send(s: TSocket; Buf: Pointer; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'send'; +function sendto(s: TSocket; const Buf; len, flags: Longint; const addrto: TSockAddr; tolen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'sendto'; +function sendto(s: TSocket; Buf: PChar; len, flags: Longint; addrto: PSockAddr; tolen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'sendto'; +function sendto(s: TSocket; Buf: Pointer; len, flags: Longint; addrto: PSockAddr; tolen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'sendto'; +function setsockopt(s: TSocket; level, optname: Longint; const optval; optlen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'setsockopt'; +function setsockopt(s: TSocket; level, optname: Longint; optval: PChar; optlen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'setsockopt'; +function setsockopt(s: TSocket; level, optname: Longint; optval: Pointer; optlen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'setsockopt'; +function shutdown(s: TSocket; how: Longint): Longint; stdcall;external WINSOCK2_DLL name 'shutdown'; +function socket(af, struct, protocol: Longint): TSocket; stdcall;external WINSOCK2_DLL name 'socket'; + +function gethostbyaddr(addr: Pointer; len, struct: Longint): PHostEnt; stdcall;external WINSOCK2_DLL name 'gethostbyaddr'; +function gethostbyname(name: PChar): PHostEnt; stdcall;external WINSOCK2_DLL name 'gethostbyname'; +function gethostname(name: PChar; len: Longint): Longint; stdcall;external WINSOCK2_DLL name 'gethostname'; +function getservbyport(port: Longint; proto: PChar): PServEnt; stdcall;external WINSOCK2_DLL name 'getservbyport'; +function getservbyname(name, proto: PChar): PServEnt; stdcall;external WINSOCK2_DLL name 'getservbyname'; +function getprotobynumber(proto: Longint): PProtoEnt; stdcall;external WINSOCK2_DLL name 'getprotobynumber'; +function getprotobyname(name: PChar): PProtoEnt; stdcall;external WINSOCK2_DLL name 'getprotobyname'; + +function WSAStartup(wVersionRequired: word; var WSData: TWSAData): Longint; stdcall; external WINSOCK2_DLL name 'WSAStartup'; +function WSACleanup: Longint; stdcall; external WINSOCK2_DLL name 'WSACleanup'; +procedure WSASetLastError(iError: Longint); stdcall; external WINSOCK2_DLL name 'WSASetLastError'; +function WSAGetLastError: Longint; stdcall; external WINSOCK2_DLL name 'WSAGetLastError'; +function WSAIsBlocking: BOOL; stdcall; external WINSOCK2_DLL name 'WSAIsBlocking'; +function WSAUnhookBlockingHook: Longint; stdcall; external WINSOCK2_DLL name 'WSAUnhookBlockingHook'; +function WSASetBlockingHook(lpBlockFunc: TFarProc): TFarProc; stdcall; external WINSOCK2_DLL name 'WSASetBlockingHook'; +function WSACancelBlockingCall: Longint; stdcall; external WINSOCK2_DLL name 'WSACancelBlockingCall'; +function WSAAsyncGetServByName(HWindow: HWND; wMsg: u_int; name, proto, buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetServByName'; +function WSAAsyncGetServByPort( HWindow: HWND; wMsg, port: u_int; proto, buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetServByPort'; +function WSAAsyncGetProtoByName(HWindow: HWND; wMsg: u_int; name, buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetProtoByName'; +function WSAAsyncGetProtoByNumber(HWindow: HWND; wMsg: u_int; number: Longint; buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetProtoByNumber'; +function WSAAsyncGetHostByName(HWindow: HWND; wMsg: u_int; name, buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetHostByName'; +function WSAAsyncGetHostByAddr(HWindow: HWND; wMsg: u_int; addr: PChar; len, struct: Longint; buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetHostByAddr'; +function WSACancelAsyncRequest(hAsyncTaskHandle: THandle): Longint; stdcall; external WINSOCK2_DLL name 'WSACancelAsyncRequest'; +function WSAAsyncSelect(s: TSocket; HWindow: HWND; wMsg: u_int; lEvent: Longint): Longint; stdcall; external WINSOCK2_DLL name 'WSAAsyncSelect'; +function __WSAFDIsSet(s: TSOcket; var FDSet: TFDSet): Bool; stdcall; external WINSOCK2_DLL name '__WSAFDIsSet'; + +{ WinSock 2 API new function prototypes } +function WSAAccept( s : TSocket; addr : TSockAddr; addrlen : PLongint; lpfnCondition : LPCONDITIONPROC; dwCallbackData : DWORD ): TSocket; stdcall; external WINSOCK2_DLL name 'WSAAccept'; +function WSACloseEvent( hEvent : WSAEVENT) : WordBool; stdcall; external WINSOCK2_DLL name 'WSACloseEvent'; +function WSAConnect( s : TSocket; const name : PSockAddr; namelen : Longint; lpCallerData,lpCalleeData : LPWSABUF; lpSQOS,lpGQOS : LPQOS ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAConnect'; +function WSACreateEvent : WSAEVENT; stdcall; external WINSOCK2_DLL name 'WSACreateEvent'; +function WSADuplicateSocketA( s : TSocket; dwProcessId : DWORD; lpProtocolInfo : LPWSAProtocol_InfoA ) : Longint; stdcall; external WINSOCK2_DLL name 'WSADuplicateSocketA'; +function WSADuplicateSocketW( s : TSocket; dwProcessId : DWORD; lpProtocolInfo : LPWSAProtocol_InfoW ) : Longint; stdcall; external WINSOCK2_DLL name 'WSADuplicateSocketW'; +{$ifndef Unicode} +function WSADuplicateSocket( s : TSocket; dwProcessId : DWORD; lpProtocolInfo : LPWSAProtocol_InfoA ) : Longint; stdcall; external WINSOCK2_DLL name 'WSADuplicateSocketA'; +{$else} +function WSADuplicateSocket( s : TSocket; dwProcessId : DWORD; lpProtocolInfo : LPWSAProtocol_InfoW ) : Longint; stdcall; external WINSOCK2_DLL name 'WSADuplicateSocketW'; +{$endif} +function WSAEnumNetworkEvents( const s : TSocket; const hEventObject : WSAEVENT; lpNetworkEvents : LPWSANETWORKEVENTS ) :Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumNetworkEvents'; +function WSAEnumProtocolsA( lpiProtocols : PLongint; lpProtocolBuffer : LPWSAProtocol_InfoA; var lpdwBufferLength : DWORD ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumProtocolsA'; +function WSAEnumProtocolsW( lpiProtocols : PLongint; lpProtocolBuffer : LPWSAProtocol_InfoW; var lpdwBufferLength : DWORD ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumProtocolsW'; +{$ifndef Unicode} +function WSAEnumProtocols( lpiProtocols : PLongint; lpProtocolBuffer : LPWSAProtocol_InfoA; var lpdwBufferLength : DWORD ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumProtocolsA'; +{$else} +function WSAEnumProtocols( lpiProtocols : PLongint; lpProtocolBuffer : LPWSAProtocol_InfoW; var lpdwBufferLength : DWORD ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumProtocolsW'; +{$endif} +function WSAEventSelect( s : TSocket; hEventObject : WSAEVENT; lNetworkEvents : LongInt ): Longint; stdcall; external WINSOCK2_DLL name 'WSAEventSelect'; +function WSAGetOverlappedResult( s : TSocket; lpOverlapped : LPWSAOVERLAPPED; lpcbTransfer : LPDWORD; fWait : BOOL; var lpdwFlags : DWORD ) : WordBool; stdcall; external WINSOCK2_DLL name 'WSAGetOverlappedResult'; +function WSAGetQosByName( s : TSocket; lpQOSName : LPWSABUF; lpQOS : LPQOS ): WordBool; stdcall; external WINSOCK2_DLL name 'WSAGetQosByName'; +function WSAhtonl( s : TSocket; hostlong : u_long; var lpnetlong : DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAhtonl'; +function WSAhtons( s : TSocket; hostshort : u_short; var lpnetshort : WORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAhtons'; +function WSAIoctl( s : TSocket; dwIoControlCode : DWORD; lpvInBuffer : Pointer; cbInBuffer : DWORD; lpvOutBuffer : Pointer; cbOutBuffer : DWORD; + lpcbBytesReturned : LPDWORD; lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAIoctl'; +function WSAJoinLeaf( s : TSocket; name : PSockAddr; namelen : Longint; lpCallerData,lpCalleeData : LPWSABUF; + lpSQOS,lpGQOS : LPQOS; dwFlags : DWORD ) : TSocket; stdcall; external WINSOCK2_DLL name 'WSAJoinLeaf'; +function WSANtohl( s : TSocket; netlong : u_long; var lphostlong : DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSANtohl'; +function WSANtohs( s : TSocket; netshort : u_short; var lphostshort : WORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSANtohs'; +function WSARecv( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesRecvd : DWORD; var lpFlags : DWORD; + lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; stdcall; external WINSOCK2_DLL name 'WSARecv'; +function WSARecvDisconnect( s : TSocket; lpInboundDisconnectData : LPWSABUF ): Longint; stdcall; external WINSOCK2_DLL name 'WSARecvDisconnect'; +function WSARecvFrom( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesRecvd : DWORD; var lpFlags : DWORD; + lpFrom : PSockAddr; lpFromlen : PLongint; lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; stdcall; external WINSOCK2_DLL name 'WSARecvFrom'; +function WSARecvMsg( s : TSocket; lpMsg : LPWSAMSG; lpdwNumberOfBytesRecvd : DWORD; lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE) : Longint; stdcall; external WINSOCK2_DLL name 'WSARecvMsg'; +function WSAResetEvent( hEvent : WSAEVENT ): WordBool; stdcall; external WINSOCK2_DLL name 'WSAResetEvent'; +function WSASend( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesSent : DWORD; dwFlags : DWORD; + lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; stdcall; external WINSOCK2_DLL name 'WSASend'; +function WSASendDisconnect( s : TSocket; lpOutboundDisconnectData : LPWSABUF ): Longint; stdcall; external WINSOCK2_DLL name 'WSASendDisconnect'; +function WSASendTo( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesSent : DWORD; dwFlags : DWORD; + lpTo : PSockAddr; iTolen : Longint; lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; stdcall; external WINSOCK2_DLL name 'WSASendTo'; +function WSASendMsg( s : TSocket; lpMsg : LPWSAMSG; dwFlags : DWORD; lpNumberOfBytesSent : DWORD; lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE) : Longint; stdcall; external WINSOCK2_DLL name 'WSASendMsg'; +function WSASetEvent( hEvent : WSAEVENT ): WordBool; stdcall; external WINSOCK2_DLL name 'WSASetEvent'; +function WSASocketA( af, iType, protocol : Longint; lpProtocolInfo : LPWSAProtocol_InfoA; g : GROUP; dwFlags : DWORD ): TSocket; stdcall; external WINSOCK2_DLL name 'WSASocketA'; +function WSASocketW( af, iType, protocol : Longint; lpProtocolInfo : LPWSAProtocol_InfoW; g : GROUP; dwFlags : DWORD ): TSocket; stdcall; external WINSOCK2_DLL name 'WSASocketW'; + +{$ifndef UNICODE} +function WSASocket ( af, iType, protocol : Longint; lpProtocolInfo : LPWSAProtocol_InfoA; g : GROUP; dwFlags : DWORD ): TSocket; stdcall; external WINSOCK2_DLL name 'WSASocketA'; +{$else} +function WSASocket ( af, iType, protocol : Longint; lpProtocolInfo : LPWSAProtocol_InfoW; g : GROUP; dwFlags : DWORD ): TSocket; stdcall; external WINSOCK2_DLL name 'WSASocketW'; +{$endif} + +function WSAWaitForMultipleEvents( cEvents : DWORD; lphEvents : PWSAEVENT; fWaitAll : LongBool; + dwTimeout : DWORD; fAlertable : LongBool ): DWORD; stdcall; external WINSOCK2_DLL name 'WSAWaitForMultipleEvents'; +function WSAAddressToStringA( var lpsaAddress : TSockAddr; const dwAddressLength : DWORD; const lpProtocolInfo : LPWSAProtocol_InfoA; + const lpszAddressString : PChar; var lpdwAddressStringLength : DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAAddressToStringA'; +function WSAAddressToStringW( var lpsaAddress : TSockAddr; const dwAddressLength : DWORD; const lpProtocolInfo : LPWSAProtocol_InfoW; + const lpszAddressString : PWideChar; var lpdwAddressStringLength : DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAAddressToStringW'; +{$ifndef Unicode} +function WSAAddressToString( var lpsaAddress : TSockAddr; const dwAddressLength : DWORD; const lpProtocolInfo : LPWSAProtocol_InfoA; + const lpszAddressString : PChar; var lpdwAddressStringLength : DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAAddressToStringA'; +{$else} +function WSAAddressToString( var lpsaAddress : TSockAddr; const dwAddressLength : DWORD; const lpProtocolInfo : LPWSAProtocol_InfoW; + const lpszAddressString : PWideChar; var lpdwAddressStringLength : DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAAddressToStringW'; +{$endif} + +function WSAStringToAddressA( const AddressString : PChar; const AddressFamily: Longint; const lpProtocolInfo : LPWSAProtocol_InfoA; + var lpAddress : TSockAddr; var lpAddressLength : Longint ): Longint; stdcall; external WINSOCK2_DLL name 'WSAStringToAddressA'; +function WSAStringToAddressW( const AddressString : PWideChar; const AddressFamily: Longint; const lpProtocolInfo : LPWSAProtocol_InfoA; + var lpAddress : TSockAddr; var lpAddressLength : Longint ): Longint; stdcall; external WINSOCK2_DLL name 'WSAStringToAddressW'; +{$ifndef Unicode} +function WSAStringToAddress( const AddressString : PChar; const AddressFamily: Longint; const lpProtocolInfo : LPWSAProtocol_InfoA; + var lpAddress : TSockAddr; var lpAddressLength : Longint ): Longint; stdcall; external WINSOCK2_DLL name 'WSAStringToAddressA'; +{$else} +function WSAStringToAddress( const AddressString : PWideChar; const AddressFamily: Longint; const lpProtocolInfo : LPWSAProtocol_InfoA; + var lpAddress : TSockAddr; var lpAddressLength : Longint ): Longint; stdcall; external WINSOCK2_DLL name 'WSAStringToAddressW'; +{$endif} + +{ Registration and Name Resolution API functions } +function WSALookupServiceBeginA( const lpqsRestrictions : LPWSAQuerySetA; const dwControlFlags : DWORD; lphLookup : PHANDLE ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceBeginA'; +function WSALookupServiceBeginW( const lpqsRestrictions : LPWSAQuerySetW; const dwControlFlags : DWORD; lphLookup : PHANDLE ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceBeginW'; +{$ifndef Unicode} +function WSALookupServiceBegin( const lpqsRestrictions : LPWSAQuerySetA; const dwControlFlags : DWORD; lphLookup : PHANDLE ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceBeginA'; +{$else} +function WSALookupServiceBegin( const lpqsRestrictions : LPWSAQuerySetW; const dwControlFlags : DWORD; lphLookup : PHANDLE ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceBeginW'; +{$endif} + +function WSALookupServiceNextA( const hLookup : THandle; const dwControlFlags : DWORD; var lpdwBufferLength : DWORD; lpqsResults : LPWSAQuerySetA ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceNextA'; +function WSALookupServiceNextW( const hLookup : THandle; const dwControlFlags : DWORD; var lpdwBufferLength : DWORD; lpqsResults : LPWSAQuerySetW ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceNextW'; +{$ifndef unicode} +function WSALookupServiceNext( const hLookup : THandle; const dwControlFlags : DWORD; var lpdwBufferLength : DWORD; lpqsResults : LPWSAQuerySetA ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceNextA'; +{$else} +function WSALookupServiceNext( const hLookup : THandle; const dwControlFlags : DWORD; var lpdwBufferLength : DWORD; lpqsResults : LPWSAQuerySetW ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceNextW'; +{$endif} +function WSALookupServiceEnd( const hLookup : THandle ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceEnd'; +function WSAInstallServiceClassA( const lpServiceClassInfo : LPWSAServiceClassInfoA ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAInstallServiceClassA'; +function WSAInstallServiceClassW( const lpServiceClassInfo : LPWSAServiceClassInfoW ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAInstallServiceClassW'; +{$ifndef unicode} +function WSAInstallServiceClass( const lpServiceClassInfo : LPWSAServiceClassInfoA ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAInstallServiceClassA'; +{$else} +function WSAInstallServiceClass( const lpServiceClassInfo : LPWSAServiceClassInfoW ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAInstallServiceClassW'; +{$endif} +function WSARemoveServiceClass( const lpServiceClassId : PGUID ) : Longint; stdcall; external WINSOCK2_DLL name 'WSARemoveServiceClass'; +function WSAGetServiceClassInfoA( const lpProviderId : PGUID; const lpServiceClassId : PGUID; var lpdwBufSize : DWORD; + lpServiceClassInfo : LPWSAServiceClassInfoA ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassInfoA'; +function WSAGetServiceClassInfoW( const lpProviderId : PGUID; const lpServiceClassId : PGUID; var lpdwBufSize : DWORD; + lpServiceClassInfo : LPWSAServiceClassInfoW ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassInfoW'; +{$ifndef Unicode} +function WSAGetServiceClassInfo( const lpProviderId : PGUID; const lpServiceClassId : PGUID; var lpdwBufSize : DWORD; + lpServiceClassInfo : LPWSAServiceClassInfoA ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassInfoA'; +{$else} +function WSAGetServiceClassInfo( const lpProviderId : PGUID; const lpServiceClassId : PGUID; var lpdwBufSize : DWORD; + lpServiceClassInfo : LPWSAServiceClassInfoW ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassInfoW'; +{$endif} + +function WSAEnumNameSpaceProvidersA( var lpdwBufferLength: DWORD; const lpnspBuffer: LPWSANameSpace_InfoA ): Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumNameSpaceProvidersA'; +function WSAEnumNameSpaceProvidersW( var lpdwBufferLength: DWORD; const lpnspBuffer: LPWSANameSpace_InfoW ): Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumNameSpaceProvidersW'; +{$ifndef Unicode} +function WSAEnumNameSpaceProviders( var lpdwBufferLength: DWORD; const lpnspBuffer: LPWSANameSpace_InfoA ): Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumNameSpaceProvidersA'; +{$else} +function WSAEnumNameSpaceProviders( var lpdwBufferLength: DWORD; const lpnspBuffer: LPWSANameSpace_InfoW ): Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumNameSpaceProvidersW'; +{$endif} + +function WSAGetServiceClassNameByClassIdA( const lpServiceClassId: PGUID; lpszServiceClassName: PChar; + var lpdwBufferLength: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassNameByClassIdA'; +function WSAGetServiceClassNameByClassIdW( const lpServiceClassId: PGUID; lpszServiceClassName: PWideChar; + var lpdwBufferLength: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassNameByClassIdW'; +{$ifndef Unicode} +function WSAGetServiceClassNameByClassId( const lpServiceClassId: PGUID; lpszServiceClassName: PChar; + var lpdwBufferLength: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassNameByClassIdA'; +{$else} +function WSAGetServiceClassNameByClassId( const lpServiceClassId: PGUID; lpszServiceClassName: PWideChar; + var lpdwBufferLength: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassNameByClassIdW'; +{$endif} +function WSASetServiceA( const lpqsRegInfo: LPWSAQuerySetA; const essoperation: TWSAeSetServiceOp; + const dwControlFlags: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSASetServiceA'; +function WSASetServiceW( const lpqsRegInfo: LPWSAQuerySetW; const essoperation: TWSAeSetServiceOp; + const dwControlFlags: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSASetServiceW'; +{$ifndef Unicode} +function WSASetService( const lpqsRegInfo: LPWSAQuerySetA; const essoperation: TWSAeSetServiceOp; + const dwControlFlags: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSASetServiceA'; +{$else} +function WSASetService( const lpqsRegInfo: LPWSAQuerySetW; const essoperation: TWSAeSetServiceOp; + const dwControlFlags: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSASetServiceW'; +{$endif} + +{ Macros } +function WSAMakeSyncReply(Buflen, Error: Word): Longint; +function WSAMakeSelectReply(Event, Error: Word): Longint; +function WSAGetAsyncBuflen(Param: Longint): Word; +function WSAGetAsyncError(Param: Longint): Word; +function WSAGetSelectEvent(Param: Longint): Word; +function WSAGetSelectError(Param: Longint): Word; + +procedure FD_CLR(Socket: TSocket; var FDSet: TFDSet); +function FD_ISSET(Socket: TSocket; var FDSet: TFDSet): Boolean; +procedure FD_SET(Socket: TSocket; var FDSet: TFDSet); +procedure FD_ZERO(var FDSet: TFDSet); + +//============================================================= +implementation +//============================================================= + +function WSAMakeSyncReply(Buflen, Error: Word): Longint; +begin + WSAMakeSyncReply:= MakeLong(Buflen, Error); +end; + +function WSAMakeSelectReply(Event, Error: Word): Longint; +begin + WSAMakeSelectReply:= MakeLong(Event, Error); +end; + +function WSAGetAsyncBuflen(Param: Longint): Word; +begin + WSAGetAsyncBuflen:= LOWORD(Param); +end; + +function WSAGetAsyncError(Param: Longint): Word; +begin + WSAGetAsyncError:= HIWORD(Param); +end; + +function WSAGetSelectEvent(Param: Longint): Word; +begin + WSAGetSelectEvent:= LOWORD(Param); +end; + +function WSAGetSelectError(Param: Longint): Word; +begin + WSAGetSelectError:= HIWORD(Param); +end; + +procedure FD_CLR(Socket: TSocket; var FDSet: TFDSet); +var + I: cardinal; +begin + I := 0; + while I < FDSet.fd_count do + begin + if FDSet.fd_array[I] = Socket then + begin + while I < FDSet.fd_count - 1 do + begin + FDSet.fd_array[I] := FDSet.fd_array[I + 1]; + Inc(I); + end; + Dec(FDSet.fd_count); + Break; + end; + Inc(I); + end; +end; + +function FD_ISSET(Socket: TSocket; var FDSet: TFDSet): Boolean; +begin + FD_ISSET := __WSAFDIsSet(Socket, FDSet); +end; + +procedure FD_SET(Socket: TSocket; var FDSet: TFDSet); +begin + if FDSet.fd_count < FD_SETSIZE then + begin + FDSet.fd_array[FDSet.fd_count] := Socket; + Inc(FDSet.fd_count); + end; +end; + +procedure FD_ZERO(var FDSet: TFDSet); +begin + FDSet.fd_count := 0; +end; + +end. diff --git a/packages/rtl-extra/src/wince/winsock.pp b/packages/rtl-extra/src/wince/winsock.pp new file mode 100644 index 0000000000..2516a3f807 --- /dev/null +++ b/packages/rtl-extra/src/wince/winsock.pp @@ -0,0 +1,1132 @@ +{ + This file is part of the Free Pascal run time library. + This unit contains the declarations for the Wince Socket Library + + Copyright (c) 1999-2000 by Florian Klaempfl + member of the Free Pascal development team. + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +unit winsock; + +{ convention is cdecl for WinCE API} +{$calling cdecl} + +{$ifdef FPC_OS_UNICODE} + {$define UNICODE} +{$endif} + +{remaining functions exported from ws2.dll and not used yet = to do, + + * please remove functions done * + + WSAAccept + WSAAddressToStringW + WSAAsyncGetAddrInfo + WSACloseEvent + WSAConnect + WSACreateEvent + WSAEnumNameSpaceProvidersW + WSAEnumNetworkEvents + WSAEnumProtocolsW + WSAEventSelect + WSAGetOverlappedResult + WSAHtonl + WSAHtons + WSAIoctl + WSAJoinLeaf + WSALookupServiceBeginW + WSALookupServiceEnd + WSALookupServiceNextW + WSANtohl + WSANtohs + WSARecv + WSARecvFrom + WSAResetEvent + WSASend + WSASendTo + WSASetEvent + WSASetServiceW + WSASocketW + WSAStringToAddressW + WSAWaitForMultipleEvents + WSCDeinstallProvider + WSCEnumProtocols + WSCInstallNameSpace + WSCInstallProvider + WSCUnInstallNameSpace + freeaddrinfo + getaddrinfo + getnameinfo + in6addr_any + in6addr_loopback + sethostname +} + + interface + + uses + windows; + +//begin common win32 & wince + + const + winsockdll = 'ws2.dll'; + WINSOCK_VERSION = $0101; // hopefully is right for winCE too + + { + Default maximium number of sockets. + this does not + mean that the underlying Windows Sockets implementation has to + support that many! + } + FD_SETSIZE = 64; + + type + tOS_INT = LongInt; + tOS_UINT = DWord; + ptOS_INT = ^tOS_INT; + ptOS_UINT = ^tOS_UINT; + u_char = char; + u_short = word; + u_int = tOS_UINT; + u_long = dword; + pu_long = ^u_long; + plongint = ^longint; + TSocket = u_long; + + { there is already a procedure called FD_SET, so this + record was renamed (FK) } + fdset = record + fd_count : u_int; + fd_array : array[0..(FD_SETSIZE)-1] of TSocket; + end; + + TFDSet = fdset; + PFDSet = ^fdset; + + timeval = record + tv_sec : longint; + tv_usec : longint; + end; + + TTimeVal = timeval; + PTimeVal = ^TTimeVal; + + { found no reference to this type in c header files and here. AlexS } + { minutes west of Greenwich } + { type of dst correction } + timezone = record + tz_minuteswest : longint; + tz_dsttime : longint; + end; + TTimeZone = timezone; + PTimeZone = ^TTimeZone; + + { 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 + restrict parameters to at most 128 bytes.} + + const + IOCPARM_MASK = $7f; {parameters must be < 128 bytes} + IOC_VOID = $20000000; {no parameters} + IOC_OUT = $40000000; {copy out parameters} + IOC_IN = $80000000; {copy in parameters} + IOC_INOUT = IOC_IN or IOC_OUT; + + FIONREAD =cardinal( IOC_OUT or { get # bytes to read } + ((4 and IOCPARM_MASK) shl 16) or + (102 shl 8) or 127); + FIONBIO = cardinal(IOC_IN or { set/clear non-blocking i/o } + ((4 and IOCPARM_MASK) shl 16) or + (102 shl 8) or 126); + FIOASYNC = cardinal(IOC_IN or { set/clear async i/o = } + ((4 and IOCPARM_MASK) shl 16) or + (102 shl 8) or 125); + + { Socket I/O Controls } + SIOCSHIWAT = cardinal(IOC_IN or { set high watermark } + ((4 and IOCPARM_MASK) shl 16) or + (115 shl 8)); + + SIOCGHIWAT = cardinal(IOC_OUT or { get high watermark } + ((4 and IOCPARM_MASK) shl 16) or + (115 shl 8) or 1); + + SIOCSLOWAT = cardinal(IOC_IN or { set low watermark } + ((4 and IOCPARM_MASK) shl 16) or + (115 shl 8) or 2); + SIOCGLOWAT = cardinal(IOC_OUT or { get low watermark } + ((4 and IOCPARM_MASK) shl 16) or + (115 shl 8) or 3); + + SIOCATMARK = cardinal(IOC_OUT or { at oob mark? } + ((4 and IOCPARM_MASK) shl 16) or + (115 shl 8) or 7); + + + { + 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). + Slight modifications for differences between Linux and winsock.h + } + type + hostent = record + { official name of host } + h_name: pchar; + { alias list } + h_aliases: ^pchar; + { host address type } + h_addrtype: SmallInt; + { length of address } + h_length: SmallInt; + { list of addresses } + case byte of + 0: (h_addr_list: ^pchar); + 1: (h_addr: ^pchar) + end; + THostEnt = hostent; + PHostEnt = ^THostEnt; + + { + Assumption here is that a network number + fits in an unsigned long -- someday that won't be true! + } + netent = record + { official name of net } + n_name : ^char; + { alias list } + n_aliases : ^pchar; + { net address type } + n_addrtype : SmallInt; + n_pad1 : SmallInt; { ensure right packaging } + { network # } + n_net : u_long; + end; + TNetEnt = netent; + PNetEnt = ^TNetEnt; + + servent = record + { official service name } + s_name : ^char; + { alias list } + s_aliases : ^pchar; + { port # } + s_port : SmallInt; + n_pad1 : SmallInt; { ensure right packaging } + { protocol to use } + s_proto : ^char; + end; + TServEnt = servent; + PServEnt = ^TServEnt; + + protoent = record + { official protocol name } + p_name : ^char; + { alias list } + p_aliases : ^pchar; + { protocol # } + p_proto : SmallInt; + p_pad1 : SmallInt; { ensure packaging } + end; + TProtoEnt = protoent; + PProtoEnt = ^TProtoEnt; + + const + { + Standard well-known IP protocols. + For some reason there are differences between Linx and winsock.h + } + IPPROTO_IP = 0; + IPPROTO_ICMP = 1; + IPPROTO_IGMP = 2; + IPPROTO_GGP = 3; + IPPROTO_TCP = 6; + IPPROTO_PUP = 12; + IPPROTO_UDP = 17; + IPPROTO_IDP = 22; + IPPROTO_IPV6 = 41; { IPv6 } + IPPROTO_ND = 77; + IPPROTO_ICLFXBM = 78; + IPPROTO_RAW = 255; + IPPROTO_MAX = 256; + + IPPORT_ECHO = 7; + IPPORT_DISCARD = 9; + IPPORT_SYSTAT = 11; + IPPORT_DAYTIME = 13; + IPPORT_NETSTAT = 15; + IPPORT_FTP = 21; + IPPORT_TELNET = 23; + IPPORT_SMTP = 25; + IPPORT_TIMESERVER = 37; + IPPORT_NAMESERVER = 42; + IPPORT_WHOIS = 43; + IPPORT_MTP = 57; + IPPORT_TFTP = 69; + IPPORT_RJE = 77; + IPPORT_FINGER = 79; + IPPORT_TTYLINK = 87; + IPPORT_SUPDUP = 95; + IPPORT_EXECSERVER = 512; + IPPORT_LOGINSERVER = 513; + IPPORT_CMDSERVER = 514; + IPPORT_EFSSERVER = 520; + IPPORT_BIFFUDP = 512; + IPPORT_WHOSERVER = 513; + IPPORT_ROUTESERVER = 520; + IPPORT_RESERVED = 1024; + + const + IMPLINK_IP = 155; + IMPLINK_LOWEXPER = 156; + IMPLINK_HIGHEXPER = 158; + + type + SunB = record + s_b1,s_b2,s_b3,s_b4 : u_char; + end; + + SunW = record + s_w1,s_w2 : u_short; + end; + + in_addr = record + case integer of + 0 : (S_un_b : SunB); + 1 : (S_un_w : SunW); + 2 : (S_addr : u_long); + end; + TInAddr = in_addr; + PInAddr = ^TInAddr; + + sockaddr_in = record + case integer of + 0 : ( (* equals to sockaddr_in, size is 16 byte *) + sin_family : SmallInt; (* 2 byte *) + sin_port : u_short; (* 2 byte *) + sin_addr : TInAddr; (* 4 byte *) + sin_zero : array[0..8-1] of char; (* 8 byte *) + ); + 1 : ((* equals to sockaddr, size is 16 byte *) + sa_family : Smallint; (* 2 byte *) + sa_data : array[0..14-1] of char; (* 14 byte *) + ); + end; + TSockAddrIn = sockaddr_in; + PSockAddrIn = ^TSockAddrIn; + TSockAddr = sockaddr_in; + PSockAddr = ^TSockAddr; + + const + INADDR_ANY = $00000000; + INADDR_LOOPBACK = $7F000001; + INADDR_BROADCAST = $FFFFFFFF; + + IN_CLASSA_NET = $ff000000; + IN_CLASSA_NSHIFT = 24; + IN_CLASSA_HOST = $00ffffff; + IN_CLASSA_MAX = 128; + IN_CLASSB_NET = $ffff0000; + IN_CLASSB_NSHIFT = 16; + IN_CLASSB_HOST = $0000ffff; + IN_CLASSB_MAX = 65536; + IN_CLASSC_NET = $ffffff00; + IN_CLASSC_NSHIFT = 8; + IN_CLASSC_HOST = $000000ff; + + WSADESCRIPTION_LEN = 256; + WSASYS_STATUS_LEN = 128; + + type + WSADATA = record + wVersion : WORD; { 2 byte, ofs 0 } + wHighVersion : WORD; { 2 byte, ofs 2 } + szDescription : array[0..(WSADESCRIPTION_LEN+1)-1] of char; { 257 byte, ofs 4 } + szSystemStatus : array[0..(WSASYS_STATUS_LEN+1)-1] of char; { 129 byte, ofs 261 } + iMaxSockets : word; { 2 byte, ofs 390 } + iMaxUdpDg : word; { 2 byte, ofs 392 } + pad1 : SmallInt; { 2 byte, ofs 394 } { ensure right packaging } + lpVendorInfo : pchar; { 4 byte, ofs 396 } + end; { total size 400 } + TWSAData = WSADATA; + PWSAData = ^TWSAData; + + const + IP_OPTIONS = 1; + IP_MULTICAST_IF = 2; + IP_MULTICAST_TTL = 3; + IP_MULTICAST_LOOP = 4; + IP_ADD_MEMBERSHIP = 5; + IP_DROP_MEMBERSHIP = 6; + IP_DEFAULT_MULTICAST_TTL = 1; + IP_DEFAULT_MULTICAST_LOOP = 1; + IP_MAX_MEMBERSHIPS = 20; + + type + ip_mreq = record + imr_multiaddr : in_addr; + imr_interface : in_addr; + end; + + { + Definitions related to sockets: types, address families, options, + taken from the BSD file sys/socket.h. + } + const + INVALID_SOCKET = TSocket(not(0)); + SOCKET_ERROR = -1; + SOCK_STREAM = 1; + SOCK_DGRAM = 2; + SOCK_RAW = 3; + SOCK_RDM = 4; + SOCK_SEQPACKET = 5; + + { For setsockoptions(2) } + SO_DEBUG = $0001; + SO_ACCEPTCONN = $0002; + SO_REUSEADDR = $0004; + SO_KEEPALIVE = $0008; + SO_DONTROUTE = $0010; + SO_BROADCAST = $0020; + SO_USELOOPBACK = $0040; + SO_LINGER = $0080; + SO_OOBINLINE = $0100; + { + Additional options. + } + { send buffer size } + SO_SNDBUF = $1001; + { receive buffer size } + SO_RCVBUF = $1002; + { send low-water mark } + SO_SNDLOWAT = $1003; + { receive low-water mark } + SO_RCVLOWAT = $1004; + { send timeout } + SO_SNDTIMEO = $1005; + { receive timeout } + SO_RCVTIMEO = $1006; + { get error status and clear } + SO_ERROR = $1007; + { get socket type } + SO_TYPE = $1008; + + { WinSock 2 extension -- new options } + SO_GROUP_ID = $2001; { ID of a socket group } + SO_GROUP_PRIORITY = $2002; { the relative priority within a group} + SO_MAX_MSG_SIZE = $2003; { maximum message size } + SO_PROTOCOL_INFOA = $2004; { WSAPROTOCOL_INFOA structure } + SO_PROTOCOL_INFOW = $2005; { WSAPROTOCOL_INFOW structure } + {$ifdef UNICODE} + SO_PROTOCOL_INFO = SO_PROTOCOL_INFOW; + {$else} + SO_PROTOCOL_INFO = SO_PROTOCOL_INFOA; + {$endif UNICODE} + PVD_CONFIG = $3001; { configuration info for service provider } + SO_CONDITIONAL_ACCEPT = $3002; { enable true conditional accept: } + { connection is not ack-ed to the } + { other side until conditional } + { function returns CF_ACCEPT } + + { + Options for connect and disconnect data and options. Used only by + non-TCP/IP transports such as DECNet, OSI TP4, etc. + } + SO_CONNDATA = $7000; + SO_CONNOPT = $7001; + SO_DISCDATA = $7002; + SO_DISCOPT = $7003; + SO_CONNDATALEN = $7004; + SO_CONNOPTLEN = $7005; + SO_DISCDATALEN = $7006; + SO_DISCOPTLEN = $7007; + + { + Option for opening sockets for synchronous access. + } + SO_OPENTYPE = $7008; + SO_SYNCHRONOUS_ALERT = $10; + SO_SYNCHRONOUS_NONALERT = $20; + + { + Other NT-specific options. + } + SO_MAXDG = $7009; + SO_MAXPATHDG = $700A; + SO_UPDATE_ACCEPT_CONTEXT = $700B; + SO_CONNECT_TIME = $700C; + + { + TCP options. + } + TCP_NODELAY = $0001; + TCP_BSDURGENT = $7000; + + { + Address families. + } + { unspecified } + AF_UNSPEC = 0; + { local to host (pipes, portals) } + AF_UNIX = 1; + { internetwork: UDP, TCP, etc. } + AF_INET = 2; + { arpanet imp addresses } + AF_IMPLINK = 3; + { pup protocols: e.g. BSP } + AF_PUP = 4; + { mit CHAOS protocols } + AF_CHAOS = 5; + { IPX and SPX } + AF_IPX = 6; + { XEROX NS protocols } + AF_NS = 6; + { ISO protocols } + AF_ISO = 7; + { OSI is ISO } + AF_OSI = AF_ISO; + { european computer manufacturers } + AF_ECMA = 8; + { datakit protocols } + AF_DATAKIT = 9; + { CCITT protocols, X.25 etc } + AF_CCITT = 10; + { IBM SNA } + AF_SNA = 11; + { DECnet } + AF_DECnet = 12; + { Direct data link interface } + AF_DLI = 13; + { LAT } + AF_LAT = 14; + { NSC Hyperchannel } + AF_HYLINK = 15; + { AppleTalk } + AF_APPLETALK = 16; + { NetBios-style addresses } + AF_NETBIOS = 17; + { VoiceView } + AF_VOICEVIEW = 18; + { FireFox } + AF_FIREFOX = 19; + { Somebody is using this! } + AF_UNKNOWN1 = 20; + { Banyan } + AF_BAN = 21; + {$ifdef UNDER_CE} + {IrDA} + AF_IRDA = 22; + {$else UNDER_CE} + {Native ATM Services} + AF_ATM = 22; + {$endif UNDER_CE} + {Internetwork Version 6} + AF_INET6 = 23; + {Microsoft Wolfpack} + AF_CLUSTER = 24; + {IEEE 1284.4 WG AF} + AF_12844 = 25; + {$ifdef UNDER_CE} + {Native ATM Services} + AF_ATM = 26; + {$else UNDER_CE} + {IrDA} + AF_IRDA = 26; + {$endif UNDER_CE} + {Network Designers OSI & gateway enabled protocols.} + AF_NETDES = 28; + AF_TCNPROCESS = 29; + AF_TCNMESSAGE = 30; + AF_ICLFXBM = 31; + AF_MAX = 32; + + type + + + { Structure used by kernel to pass protocol information in raw sockets.} + sockproto = record + sp_family : u_short; + sp_protocol : u_short; + end; + TSockProto = sockproto; + PSockProto = ^TSockProto; + + const + {Protocol families, same as address families for now.} + PF_UNSPEC = AF_UNSPEC; + PF_UNIX = AF_UNIX; + PF_INET = AF_INET; + PF_IMPLINK = AF_IMPLINK; + PF_PUP = AF_PUP; + PF_CHAOS = AF_CHAOS; + PF_NS = AF_NS; + PF_IPX = AF_IPX; + PF_ISO = AF_ISO; + PF_OSI = AF_OSI; + PF_ECMA = AF_ECMA; + PF_DATAKIT = AF_DATAKIT; + PF_CCITT = AF_CCITT; + PF_SNA = AF_SNA; + PF_DECnet = AF_DECnet; + PF_DLI = AF_DLI; + PF_LAT = AF_LAT; + PF_HYLINK = AF_HYLINK; + PF_APPLETALK = AF_APPLETALK; + PF_VOICEVIEW = AF_VOICEVIEW; + PF_FIREFOX = AF_FIREFOX; + PF_UNKNOWN1 = AF_UNKNOWN1; + PF_BAN = AF_BAN; + PF_ATM = AF_ATM; + PF_INET6 = AF_INET6; + PF_MAX = AF_MAX; + + type + { + Structure used for manipulating linger option. + } + linger = record + l_onoff : u_short; + l_linger : u_short; + end; + TLinger = linger; + PLinger = ^TLinger; + + const + { + Level number for (get/set)sockopt() to apply to socket itself. + } + { options for socket level } + SOL_SOCKET = $ffff; + { + Maximum queue length specifiable by listen. + } + SOMAXCONN = $7fffffff; + { process out-of-band data } + MSG_OOB = $1; + { peek at incoming message } + MSG_PEEK = $2; + { send without using routing tables } + MSG_DONTROUTE = $4; + MSG_MAXIOVLEN = 16; + { partial send or recv for message xport } + MSG_PARTIAL = $8000; + {WinSock 2 extension -- new flags for WSASend(), WSASendTo(), WSARecv() + and WSARecvFrom()} + MSG_INTERRUPT = $10; { send/recv in the interrupt context } + + { + Define constant based on rfc883, used by gethostbyxxxx() calls. + } + MAXGETHOSTSTRUCT = 1024; + MAXHOSTNAMELEN = MAXGETHOSTSTRUCT; + + {Define flags to be used with the WSAAsyncSelect() call.} + FD_READ = $01; + FD_WRITE = $02; + FD_OOB = $04; + FD_ACCEPT = $08; + FD_CONNECT = $10; + FD_CLOSE = $20; + FD_QOS = $40; + FD_GROUP_QOS = $80; + FD_ROUTING_INTERFACE_CHANGE = $100; + FD_ADDRESS_LIST_CHANGE = $200; + FD_MAX_EVENTS = 10; + FD_ALL_EVENTS = $3FF; + + { + All Windows Sockets error constants are biased by WSABASEERR from + the "normal" + } + WSABASEERR = 10000; + + { + Windows Sockets definitions of regular Microsoft C error constants + } + WSAEINTR = WSABASEERR + 4; + WSAEBADF = WSABASEERR + 9; + WSAEACCES = WSABASEERR + 13; + WSAEFAULT = WSABASEERR + 14; + WSAEINVAL = WSABASEERR + 22; + WSAEMFILE = WSABASEERR + 24; + + { + Windows Sockets definitions of regular Berkeley error constants + } + WSAEWOULDBLOCK = WSABASEERR + 35; + WSAEINPROGRESS = WSABASEERR + 36; + WSAEALREADY = WSABASEERR + 37; + WSAENOTSOCK = WSABASEERR + 38; + WSAEDESTADDRREQ = WSABASEERR + 39; + WSAEMSGSIZE = WSABASEERR + 40; + WSAEPROTOTYPE = WSABASEERR + 41; + WSAENOPROTOOPT = WSABASEERR + 42; + WSAEPROTONOSUPPORT = WSABASEERR + 43; + WSAESOCKTNOSUPPORT = WSABASEERR + 44; + WSAEOPNOTSUPP = WSABASEERR + 45; + WSAEPFNOSUPPORT = WSABASEERR + 46; + WSAEAFNOSUPPORT = WSABASEERR + 47; + WSAEADDRINUSE = WSABASEERR + 48; + WSAEADDRNOTAVAIL = WSABASEERR + 49; + WSAENETDOWN = WSABASEERR + 50; + WSAENETUNREACH = WSABASEERR + 51; + WSAENETRESET = WSABASEERR + 52; + WSAECONNABORTED = WSABASEERR + 53; + WSAECONNRESET = WSABASEERR + 54; + WSAENOBUFS = WSABASEERR + 55; + WSAEISCONN = WSABASEERR + 56; + WSAENOTCONN = WSABASEERR + 57; + WSAESHUTDOWN = WSABASEERR + 58; + WSAETOOMANYREFS = WSABASEERR + 59; + WSAETIMEDOUT = WSABASEERR + 60; + WSAECONNREFUSED = WSABASEERR + 61; + WSAELOOP = WSABASEERR + 62; + WSAENAMETOOLONG = WSABASEERR + 63; + WSAEHOSTDOWN = WSABASEERR + 64; + WSAEHOSTUNREACH = WSABASEERR + 65; + WSAENOTEMPTY = WSABASEERR + 66; + WSAEPROCLIM = WSABASEERR + 67; + WSAEUSERS = WSABASEERR + 68; + WSAEDQUOT = WSABASEERR + 69; + WSAESTALE = WSABASEERR + 70; + WSAEREMOTE = WSABASEERR + 71; + + { + Extended Windows Sockets error constant definitions + } + WSASYSNOTREADY = WSABASEERR + 91; + WSAVERNOTSUPPORTED = WSABASEERR + 92; + WSANOTINITIALISED = WSABASEERR + 93; + WSAEDISCON = WSABASEERR + 101; + WSAENOMORE = WSABASEERR+102; + WSAECANCELLED = WSABASEERR+103; + WSAEINVALIDPROCTABLE = WSABASEERR+104; + WSAEINVALIDPROVIDER = WSABASEERR+105; + WSAEPROVIDERFAILEDINIT = WSABASEERR+106; + WSASYSCALLFAILURE = WSABASEERR+107; + WSASERVICE_NOT_FOUND = WSABASEERR+108; + WSATYPE_NOT_FOUND = WSABASEERR+109; + WSA_E_NO_MORE = WSABASEERR+110; + WSA_E_CANCELLED = WSABASEERR+111; + WSAEREFUSED = WSABASEERR+112; + {$ifdef UNDER_CE} + WSAEDUPLICATE_NAME = WSABASEERR+900; + {$endif UNDER_CE} + { + 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. + } + WSAHOST_NOT_FOUND = WSABASEERR + 1001; + HOST_NOT_FOUND = WSAHOST_NOT_FOUND; + { Non-Authoritative: Host not found, or SERVERFAIL } + WSATRY_AGAIN = WSABASEERR + 1002; + TRY_AGAIN = WSATRY_AGAIN; + + { Non recoverable errors, FORMERR, REFUSED, NOTIMP } + WSANO_RECOVERY = WSABASEERR + 1003; + NO_RECOVERY = WSANO_RECOVERY; + + { Valid name, no data record of requested type } + WSANO_DATA = WSABASEERR + 1004; + NO_DATA = WSANO_DATA; + { no address, look for MX record } + WSANO_ADDRESS = WSANO_DATA; + NO_ADDRESS = WSANO_ADDRESS; + + { Define QOS related error return codes } + WSA_QOS_RECEIVERS = WSABASEERR + 1005; + { at least one Reserve has arrived } + WSA_QOS_SENDERS = WSABASEERR + 1006; + { at least one Path has arrived } + WSA_QOS_NO_SENDERS = WSABASEERR + 1007; + { there are no senders } + WSA_QOS_NO_RECEIVERS = WSABASEERR + 1008; + { there are no receivers } + WSA_QOS_REQUEST_CONFIRMED = WSABASEERR + 1009; + { Reserve has been confirmed } + WSA_QOS_ADMISSION_FAILURE = WSABASEERR + 1010; + { error due to lack of resources } + WSA_QOS_POLICY_FAILURE = WSABASEERR + 1011; + { rejected for administrative reasons - bad credentials } + WSA_QOS_BAD_STYLE = WSABASEERR + 1012; + { unknown or conflicting style } + WSA_QOS_BAD_OBJECT = WSABASEERR + 1013; + { problem with some part of the filterspec or providerspecific buffer } + WSA_QOS_TRAFFIC_CTRL_ERROR = WSABASEERR + 1014; + { problem with some part of the flowspec } + WSA_QOS_GENERIC_ERROR = WSABASEERR + 1015; + { general error } + WSA_QOS_ESERVICETYPE = WSABASEERR + 1016; + { invalid service type in flowspec } + WSA_QOS_EFLOWSPEC = WSABASEERR + 1017; + { invalid flowspec } + WSA_QOS_EPROVSPECBUF = WSABASEERR + 1018; + { invalid provider specific buffer } + WSA_QOS_EFILTERSTYLE = WSABASEERR + 1019; + { invalid filter style } + WSA_QOS_EFILTERTYPE = WSABASEERR + 1020; + { invalid filter type } + WSA_QOS_EFILTERCOUNT = WSABASEERR + 1021; + { incorrect number of filters } + WSA_QOS_EOBJLENGTH = WSABASEERR + 1022; + { invalid object length } + WSA_QOS_EFLOWCOUNT = WSABASEERR + 1023; + { incorrect number of flows } + WSA_QOS_EUNKOWNPSOBJ = WSABASEERR + 1024; + { unknown object in provider specific buffer } + WSA_QOS_EPOLICYOBJ = WSABASEERR + 1025; + { invalid policy object in provider specific buffer } + WSA_QOS_EFLOWDESC = WSABASEERR + 1026; + { invalid flow descriptor in the list } + WSA_QOS_EPSFLOWSPEC = WSABASEERR + 1027; + { inconsistent flow spec in provider specific buffer } + WSA_QOS_EPSFILTERSPEC = WSABASEERR + 1028; + { invalid filter spec in provider specific buffer } + WSA_QOS_ESDMODEOBJ = WSABASEERR + 1029; + { invalid shape discard mode object in provider specific buffer } + WSA_QOS_ESHAPERATEOBJ = WSABASEERR + 1030; + { invalid shaping rate object in provider specific buffer } + WSA_QOS_RESERVED_PETYPE = WSABASEERR + 1031; + { reserved policy element in provider specific buffer } + + + const + { + Windows Sockets errors redefined as regular Berkeley error constants. + } + EWOULDBLOCK = WSAEWOULDBLOCK; + EINPROGRESS = WSAEINPROGRESS; + EALREADY = WSAEALREADY; + ENOTSOCK = WSAENOTSOCK; + EDESTADDRREQ = WSAEDESTADDRREQ; + EMSGSIZE = WSAEMSGSIZE; + EPROTOTYPE = WSAEPROTOTYPE; + ENOPROTOOPT = WSAENOPROTOOPT; + EPROTONOSUPPORT = WSAEPROTONOSUPPORT; + ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT; + EOPNOTSUPP = WSAEOPNOTSUPP; + EPFNOSUPPORT = WSAEPFNOSUPPORT; + EAFNOSUPPORT = WSAEAFNOSUPPORT; + EADDRINUSE = WSAEADDRINUSE; + EADDRNOTAVAIL = WSAEADDRNOTAVAIL; + ENETDOWN = WSAENETDOWN; + ENETUNREACH = WSAENETUNREACH; + ENETRESET = WSAENETRESET; + ECONNABORTED = WSAECONNABORTED; + ECONNRESET = WSAECONNRESET; + ENOBUFS = WSAENOBUFS; + EISCONN = WSAEISCONN; + ENOTCONN = WSAENOTCONN; + ESHUTDOWN = WSAESHUTDOWN; + ETOOMANYREFS = WSAETOOMANYREFS; + ETIMEDOUT = WSAETIMEDOUT; + ECONNREFUSED = WSAECONNREFUSED; + ELOOP = WSAELOOP; + ENAMETOOLONG = WSAENAMETOOLONG; + EHOSTDOWN = WSAEHOSTDOWN; + EHOSTUNREACH = WSAEHOSTUNREACH; + ENOTEMPTY = WSAENOTEMPTY; + EPROCLIM = WSAEPROCLIM; + EUSERS = WSAEUSERS; + EDQUOT = WSAEDQUOT; + ESTALE = WSAESTALE; + EREMOTE = WSAEREMOTE; + + TF_DISCONNECT = $01; + TF_REUSE_SOCKET = $02; + TF_WRITE_BEHIND = $04; + + { + Options for use with [gs]etsockopt at the IP level. + } + IP_TTL = 7; + IP_TOS = 8; + IP_DONTFRAGMENT = 9; + + type + _TRANSMIT_FILE_BUFFERS = record + Head : Pointer; + HeadLength : dword; + Tail : Pointer; + TailLength : dword; + end; + TRANSMIT_FILE_BUFFERS = _TRANSMIT_FILE_BUFFERS; + TTransmitFileBuffers = _TRANSMIT_FILE_BUFFERS; + PTransmitFileBuffers = ^TTransmitFileBuffers; + + +{ +Winsock types all buffers as pchar (char *), modern POSIX does it the ANSI +C way with pointer (void *). If the pointer overloaded version doesn't exist, +a "pointer" will be passed to the "var" version. (bug 3142). +So if there are var/const versions: +- To keep ported unix code working, there must be "pointer" variants (ANSI) +- To keep Delphi/ported C Winsock code working there must be pchar variants + (K&R) +IOW, there _must_ be 3 versions then: var/const, pchar and pointer} + + function accept(s:TSocket; addr: PSockAddr; addrlen : ptOS_INT) : TSocket;external winsockdll name 'accept'; + function accept(s:TSocket; addr: PSockAddr; var addrlen : tOS_INT) : TSocket;external winsockdll name 'accept'; + function bind(s:TSocket; addr: PSockaddr;namelen:tOS_INT):tOS_INT; external winsockdll name 'bind'; + function bind(s:TSocket; const addr: TSockaddr;namelen:tOS_INT):tOS_INT; external winsockdll name 'bind'; + function closesocket(s:TSocket):tOS_INT;external winsockdll name 'closesocket'; + function connect(s:TSocket; addr:PSockAddr; namelen:tOS_INT):tOS_INT;external winsockdll name 'connect'; + function connect(s:TSocket; Const name:TSockAddr; namelen:tOS_INT):tOS_INT;external winsockdll name 'connect'; + function ioctlsocket(s:TSocket; cmd:longint; var arg:u_long):tOS_INT;external winsockdll name 'ioctlsocket'; { really a c-long } + function ioctlsocket(s:TSocket; cmd:longint; var arg:longint):tOS_INT;external winsockdll name 'ioctlsocket'; { really a c-long } + function ioctlsocket(s:TSocket; cmd:longint; argp:pu_long):tOS_INT;external winsockdll name 'ioctlsocket'; { really a c-long } + function getpeername(s:TSocket; var name:TSockAddr;var namelen:tOS_INT):tOS_INT; + external winsockdll name 'getpeername'; + function getsockname(s:TSocket; var name:TSockAddr;var namelen:tOS_INT):tOS_INT; + external winsockdll name 'getsockname'; + function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;optval:pchar;var optlen:tOS_INT):tOS_INT; + external winsockdll name 'getsockopt'; + function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;optval:pointer;var optlen:tOS_INT):tOS_INT; + external winsockdll name 'getsockopt'; + function getsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;var optval;var optlen:tOS_INT):tOS_INT; + external winsockdll name 'getsockopt'; + function htonl(hostlong:u_long):u_long;external winsockdll name 'htonl'; + function htons(hostshort:u_short):u_short;external winsockdll name 'htons'; + function inet_addr(cp:pchar):cardinal;external winsockdll name 'inet_addr'; + function inet_ntoa(i : TInAddr):pchar;external winsockdll name 'inet_ntoa'; + function listen(s:TSocket; backlog:tOS_INT):tOS_INT;external winsockdll name 'listen'; + function ntohl(netlong:u_long):u_long;external winsockdll name 'ntohl'; + function ntohs(netshort:u_short):u_short;external winsockdll name 'ntohs'; + function recv(s:TSocket;buf:pchar; len:tOS_INT; flags:tOS_INT):tOS_INT;external winsockdll name 'recv'; + function recv(s:TSocket;buf:pointer; len:tOS_INT; flags:tOS_INT):tOS_INT;external winsockdll name 'recv'; + function recv(s:TSocket;var buf; len:tOS_INT; flags:tOS_INT):tOS_INT;external winsockdll name 'recv'; + function recvfrom(s:TSocket;buf:pchar; len:tOS_INT; flags:tOS_INT;from:PSockAddr; fromlen:ptOS_INT):tOS_INT; + external winsockdll name 'recvfrom'; + function recvfrom(s:TSocket;buf:pointer; len:tOS_INT; flags:tOS_INT;from:PSockAddr; fromlen:ptOS_INT):tOS_INT; + external winsockdll name 'recvfrom'; + function recvfrom(s:TSocket;var buf; len:tOS_INT; flags:tOS_INT;Const from:TSockAddr; var fromlen:tOS_INT):tOS_INT; + external winsockdll name 'recvfrom'; + function select(nfds:tOS_INT; readfds,writefds,exceptfds : PFDSet;timeout: PTimeVal):tOS_INT; + external winsockdll name 'select'; + function send(s:TSocket;Const buf; len:tOS_INT; flags:tOS_INT):tOS_INT; + external winsockdll name 'send'; + function send(s:TSocket; buf:pchar; len:tOS_INT; flags:tOS_INT):tOS_INT; + external winsockdll name 'send'; + function send(s:TSocket;buf:pointer; len:tOS_INT; flags:tOS_INT):tOS_INT; + external winsockdll name 'send'; + function sendto(s:TSocket; buf:pchar; len:tOS_INT; flags:tOS_INT;toaddr:PSockAddr; tolen:tOS_INT):tOS_INT; + external winsockdll name 'sendto'; + function sendto(s:TSocket; buf:pointer; len:tOS_INT; flags:tOS_INT;toaddr:PSockAddr; tolen:tOS_INT):tOS_INT; + external winsockdll name 'sendto'; + function sendto(s:TSocket; Const buf; len:tOS_INT; flags:tOS_INT;Const toaddr:TSockAddr; tolen:tOS_INT):tOS_INT; + external winsockdll name 'sendto'; + function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; optval:pchar; optlen:tOS_INT):tOS_INT; + external winsockdll name 'setsockopt'; + function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT;optval:pointer; optlen:tOS_INT):tOS_INT; + external winsockdll name 'setsockopt'; + function setsockopt(s:TSocket; level:tOS_INT; optname:tOS_INT; Const optval; optlen:tOS_INT):tOS_INT; + external winsockdll name 'setsockopt'; + function shutdown(s:TSocket; how:tOS_INT):tOS_INT; + external winsockdll name 'shutdown'; + function socket(af:tOS_INT; t:tOS_INT; protocol:tOS_INT):TSocket; + external winsockdll name 'socket'; + + { Database function prototypes } + function gethostbyaddr(addr:pchar; len:tOS_INT; t:tOS_INT): PHostEnt;external winsockdll name 'gethostbyaddr'; + function gethostbyname(name:pchar):PHostEnt;external winsockdll name 'gethostbyname'; + function gethostname(name:pchar; namelen:tOS_INT):tOS_INT;external winsockdll name 'gethostname'; + function getservbyport(port:tOS_INT; proto:pchar):PServEnt;external winsockdll name 'getservbyport'; + function getservbyname(name:pchar; proto:pchar):PServEnt;external winsockdll name 'getservbyname'; + function getprotobynumber(proto:tOS_INT):PProtoEnt;external winsockdll name 'getprotobynumber'; + function getprotobyname(name:pchar):PProtoEnt;external winsockdll name 'getprotobyname'; + + { Microsoft Windows Extension function prototypes } + function WSAStartup(wVersionRequired:word;var WSAData:TWSADATA):tOS_INT; + external winsockdll name 'WSAStartup'; + function WSACleanup:tOS_INT;external winsockdll name 'WSACleanup'; + procedure WSASetLastError(iError:tOS_INT);external winsockdll name 'WSASetLastError'; + function WSAGetLastError:tOS_INT;external winsockdll name 'WSAGetLastError'; + function WSAAsyncGetHostByName(hWnd:HWND; wMsg:u_int; name:pchar; buf:pchar; buflen:tOS_INT):THandle; + external winsockdll name 'WSAAsyncGetHostByName'; + function WSACancelAsyncRequest(hAsyncTaskHandle:THandle):tOS_INT; + external winsockdll name 'WSACancelAsyncRequest'; + function WSAAsyncSelect(s:TSocket; hWnd:HWND; wMsg:u_int; lEvent:longint):tOS_INT; { really a c-long } + external winsockdll name 'WSAAsyncSelect'; + function __WSAFDIsSet(s:TSocket; var FDSet:TFDSet):Bool; + external winsockdll name '__WSAFDIsSet'; + + function WSAMakeSyncReply(Buflen,Error:Word):dword; + function WSAMakeSelectReply(Event,Error:Word):dword; + function WSAGetAsyncBuflen(Param:dword):Word; + function WSAGetAsyncError(Param:dword):Word; + function WSAGetSelectEvent(Param:dword):Word; + function WSAGetSelectError(Param:dword):Word; + procedure FD_CLR(Socket:TSocket; var FDSet:TFDSet); + function FD_ISSET(Socket:TSocket; var FDSet:TFDSet):Boolean; + procedure FD_SET(Socket:TSocket; var FDSet:TFDSet); + procedure FD_ZERO(var FDSet:TFDSet); + +//end common win32 & wince + +{$ifdef WIN32} +//begin win32 only + function WSAIsBlocking:BOOL;external winsockdll name 'WSAIsBlocking'; + function WSAUnhookBlockingHook:tOS_INT;external winsockdll name 'WSAUnhookBlockingHook'; + function WSASetBlockingHook(lpBlockFunc:TFarProc):TFarProc;external winsockdll name 'WSASetBlockingHook'; + function WSACancelBlockingCall:tOS_INT;external winsockdll name 'WSACancelBlockingCall'; + function WSAAsyncGetServByName(hWnd:HWND; wMsg:u_int; name:pchar; proto:pchar; buf:pchar; + buflen:tOS_INT):THandle;external winsockdll name 'WSAAsyncGetServByName'; + function WSAAsyncGetServByPort(hWnd:HWND; wMsg:u_int; port:tOS_INT; proto:pchar; buf:pchar; + buflen:tOS_INT):THandle;external winsockdll name 'WSAAsyncGetServByPort'; + function WSAAsyncGetProtoByName(hWnd:HWND; wMsg:u_int; name:pchar; buf:pchar; buflen:tOS_INT):THandle; + external winsockdll name 'WSAAsyncGetProtoByName'; + function WSAAsyncGetProtoByNumber(hWnd:HWND; wMsg:u_int; number:tOS_INT; buf:pchar; buflen:tOS_INT):THandle; + external winsockdll name 'WSAAsyncGetProtoByNumber'; + function WSAAsyncGetHostByAddr(hWnd:HWND; wMsg:u_int; addr:pchar; len:tOS_INT; t:tOS_INT; + buf:pchar; buflen:tOS_INT):THandle; + external winsockdll name 'WSAAsyncGetHostByAddr'; + function WSARecvEx(s:TSocket;var buf; len:tOS_INT; flags:ptOS_INT):tOS_INT; + external winsockdll name 'WSARecvEx'; + function TransmitFile(hSocket:TSocket; hFile:THandle; nNumberOfBytesToWrite:dword; + nNumberOfBytesPerSend:DWORD; lpOverlapped:POverlapped; + lpTransmitBuffers:PTransmitFileBuffers; dwReserved:dword):Bool; + external winsockdll name 'TransmitFile'; + function AcceptEx(sListenSocket,sAcceptSocket:TSocket; + lpOutputBuffer:Pointer; dwReceiveDataLength,dwLocalAddressLength, + dwRemoteAddressLength:dword; var lpdwBytesReceived:dword; + lpOverlapped:POverlapped):Bool; + external winsockdll name 'AcceptEx'; + + procedure GetAcceptExSockaddrs(lpOutputBuffer:Pointer; + dwReceiveDataLength,dwLocalAddressLength,dwRemoteAddressLength:dword; + var LocalSockaddr:PSockAddr; var LocalSockaddrLength:tOS_INT; + var RemoteSockaddr:PSockAddr; var RemoteSockaddrLength:tOS_INT); + external winsockdll name 'GetAcceptExSockaddrs'; +//end win32 only +{$endif WIN32} + +{$ifdef WINCE} +//begin wince only + +//end wince only +{$endif WINCE} + + implementation + + +//begin common win32 & wince + + { + Implementation of the helper routines + } + function WSAMakeSyncReply(Buflen,Error:Word):dword; + + begin + WSAMakeSyncReply:=MakeLong(Buflen, Error); + end; + + function WSAMakeSelectReply(Event,Error:Word):dword; + + begin + WSAMakeSelectReply:=MakeLong(Event,Error); + end; + + function WSAGetAsyncBuflen(Param:dword):Word; + + begin + WSAGetAsyncBuflen:=lo(Param); + end; + + function WSAGetAsyncError(Param:dword):Word; + + begin + WSAGetAsyncError:=hi(Param); + end; + + function WSAGetSelectEvent(Param:dword):Word; + + begin + WSAGetSelectEvent:=lo(Param); + end; + + function WSAGetSelectError(Param:dword):Word; + + begin + WSAGetSelectError:=hi(Param); + end; + + procedure FD_CLR(Socket:TSocket; var FDSet:TFDSet); + + var + i : u_int; + + begin + i:=0; + while i<FDSet.fd_count do + begin + if FDSet.fd_array[i]=Socket then + begin + while i<FDSet.fd_count-1 do + begin + FDSet.fd_array[i]:=FDSet.fd_array[i+1]; + inc(i); + end; + dec(FDSet.fd_count); + break; + end; + inc(i); + end; + end; + + function FD_ISSET(Socket:TSocket; var FDSet:TFDSet):Boolean; + + begin + FD_ISSET:=__WSAFDIsSet(Socket,FDSet); + end; + + procedure FD_SET(Socket:TSocket; var FDSet:TFDSet); + + begin + if FDSet.fd_count<FD_SETSIZE then + begin + FDSet.fd_array[FDSet.fd_count]:=Socket; + Inc(FDSet.fd_count); + end; + end; + + procedure FD_ZERO(var FDSet:TFDSet); + + begin + FDSet.fd_count:=0; + end; + +//end common win32 & wince + +{$ifdef WIN32} +//begin win32 only + +//end win32 only +{$endif WIN32} + +{$ifdef WINCE} +//begin wince only + +//end wince only +{$endif WINCE} + + +end. diff --git a/packages/rtl-extra/src/wince/winsock2.pp b/packages/rtl-extra/src/wince/winsock2.pp new file mode 100644 index 0000000000..5a5e708bc1 --- /dev/null +++ b/packages/rtl-extra/src/wince/winsock2.pp @@ -0,0 +1,1411 @@ +{ Winsock2.h -- definitions to be used with the WinSock 2 DLL and WinSock 2 applications. + This header file corresponds to version 2.2.x of the WinSock API 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. } + +// converted by Alex Konshin, mailto:alexk@msmt.spb.su +// added FreePascal stuff: AlexS@freepage.de +// updated for wince : orinaudo@gmail.com +// based on svn3257 rtl/win/winsock2.pas + +unit WinSock2; + +{$ifndef NO_SMART_LINK} +{$smartlink on} +{$endif} +{ convention is cdecl for WinCE API} +{$calling cdecl} + +{$ifdef FPC_OS_UNICODE} + {$define UNICODE} +{$endif} + +interface + +Uses Windows; + +{ Define the current Winsock version. To build an earlier Winsock version + application redefine this value prior to including Winsock2.h. } +Const + WINSOCK_VERSION = $0202; +{$IFNDEF WINCE} + WINSOCK2_DLL = 'ws2_32.dll'; +{$ELSE WINCE} + WINSOCK2_DLL = 'ws2.dll'; +{$ENDIF WINCE} + +Type + u_char = Char; + u_short = Word; + u_int = DWord; + u_long = DWord; + pu_char = ^u_char; + pu_short = ^u_short; + pu_int = ^u_int; + pu_long = ^u_long; + + TSocket = u_int; { The new type to be used in all instances which refer to sockets. } + + WSAEVENT = THandle; + PWSAEVENT = ^WSAEVENT; + LPWSAEVENT = PWSAEVENT; +{$IFDEF UNICODE} + PMBChar = PWideChar; +{$ELSE} + PMBChar = PChar; +{$ENDIF} + +const + FD_SETSIZE = 64; + +type + PFDSet = ^TFDSet; + TFDSet = record + fd_count: u_int; + fd_array: array[0..FD_SETSIZE-1] of TSocket; + end; + + PTimeVal = ^TTimeVal; + TTimeVal = record + tv_sec: Longint; + tv_usec: Longint; + end; + +const + IOCPARM_MASK = $7f; + IOC_VOID = $20000000; + IOC_OUT = $40000000; + IOC_IN = $80000000; + IOC_INOUT = (IOC_IN or IOC_OUT); + + FIONREAD = IOC_OUT or { get # bytes to read } + ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or + (Longint(Byte('f')) shl 8) or 127; + FIONBIO = IOC_IN or { set/clear non-blocking i/o } + ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or + (Longint(Byte('f')) shl 8) or 126; + FIOASYNC = IOC_IN or { set/clear async i/o } + ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or + (Longint(Byte('f')) shl 8) or 125; + +type + PHostEnt = ^THostEnt; + THostEnt = record + h_name: PChar; + h_aliases: ^PChar; + h_addrtype: Smallint; + h_length: Smallint; + case Byte of + 0: (h_addr_list: ^PChar); + 1: (h_addr: ^PChar) + end; + + PNetEnt = ^TNetEnt; + TNetEnt = record + n_name: PChar; + n_aliases: ^PChar; + n_addrtype: Smallint; + n_net: u_long; + end; + + PServEnt = ^TServEnt; + TServEnt = record + s_name: PChar; + s_aliases: ^PChar; + s_port: Smallint; + s_proto: PChar; + end; + + PProtoEnt = ^TProtoEnt; + TProtoEnt = record + p_name: PChar; + p_aliases: ^Pchar; + p_proto: Smallint; + end; + +const + +{ Protocols } + IPPROTO_IP = 0; { dummy for IP } + IPPROTO_ICMP = 1; { control message protocol } + IPPROTO_IGMP = 2; { group management protocol } + IPPROTO_GGP = 3; { gateway^2 (deprecated) } + IPPROTO_TCP = 6; { tcp } + IPPROTO_PUP = 12; { pup } + IPPROTO_UDP = 17; { user datagram protocol } + IPPROTO_IDP = 22; { xns idp } + IPPROTO_ND = 77; { UNOFFICIAL net disk proto } + + IPPROTO_RAW = 255; { raw IP packet } + IPPROTO_MAX = 256; + +{ Port/socket numbers: network standard functions} + + IPPORT_ECHO = 7; + IPPORT_DISCARD = 9; + IPPORT_SYSTAT = 11; + IPPORT_DAYTIME = 13; + IPPORT_NETSTAT = 15; + IPPORT_FTP = 21; + IPPORT_TELNET = 23; + IPPORT_SMTP = 25; + IPPORT_TIMESERVER = 37; + IPPORT_NAMESERVER = 42; + IPPORT_WHOIS = 43; + IPPORT_MTP = 57; + +{ Port/socket numbers: host specific functions } + + IPPORT_TFTP = 69; + IPPORT_RJE = 77; + IPPORT_FINGER = 79; + IPPORT_TTYLINK = 87; + IPPORT_SUPDUP = 95; + +{ UNIX TCP sockets } + + IPPORT_EXECSERVER = 512; + IPPORT_LOGINSERVER = 513; + IPPORT_CMDSERVER = 514; + IPPORT_EFSSERVER = 520; + +{ UNIX UDP sockets } + + IPPORT_BIFFUDP = 512; + IPPORT_WHOSERVER = 513; + IPPORT_ROUTESERVER = 520; + +{ Ports < IPPORT_RESERVED are reserved for + privileged processes (e.g. root). } + + IPPORT_RESERVED = 1024; + +{ Link numbers } + + IMPLINK_IP = 155; + IMPLINK_LOWEXPER = 156; + IMPLINK_HIGHEXPER = 158; + + TF_DISCONNECT = $01; + TF_REUSE_SOCKET = $02; + TF_WRITE_BEHIND = $04; + +{ Options for use with [gs]etsockopt at the IP level. } + + IP_OPTIONS = 1; + IP_MULTICAST_IF = 2; { set/get IP multicast interface } + IP_MULTICAST_TTL = 3; { set/get IP multicast timetolive } + IP_MULTICAST_LOOP = 4; { set/get IP multicast loopback } + IP_ADD_MEMBERSHIP = 5; { add an IP group membership } + IP_DROP_MEMBERSHIP = 6; { drop an IP group membership } + IP_TTL = 7; { set/get IP Time To Live } + IP_TOS = 8; { set/get IP Type Of Service } + IP_DONTFRAGMENT = 9; { set/get IP Don't Fragment flag } + + + IP_DEFAULT_MULTICAST_TTL = 1; { normally limit m'casts to 1 hop } + IP_DEFAULT_MULTICAST_LOOP = 1; { normally hear sends if a member } + IP_MAX_MEMBERSHIPS = 20; { per socket; must fit in one mbuf } + +{ This is used instead of -1, since the + TSocket type is unsigned.} + + INVALID_SOCKET = TSocket(NOT(0)); + SOCKET_ERROR = -1; + +{ Types } + + SOCK_STREAM = 1; { stream socket } + SOCK_DGRAM = 2; { datagram socket } + SOCK_RAW = 3; { raw-protocol interface } + SOCK_RDM = 4; { reliably-delivered message } + SOCK_SEQPACKET = 5; { sequenced packet stream } + +{ Option flags per-socket. } + + SO_DEBUG = $0001; { turn on debugging info recording } + SO_ACCEPTCONN = $0002; { socket has had listen() } + SO_REUSEADDR = $0004; { allow local address reuse } + SO_KEEPALIVE = $0008; { keep connections alive } + SO_DONTROUTE = $0010; { just use interface addresses } + SO_BROADCAST = $0020; { permit sending of broadcast msgs } + SO_USELOOPBACK = $0040; { bypass hardware when possible } + SO_LINGER = $0080; { linger on close if data present } + SO_OOBINLINE = $0100; { leave received OOB data in line } + + SO_DONTLINGER = $ff7f; + +{ Additional options. } + + SO_SNDBUF = $1001; { send buffer size } + SO_RCVBUF = $1002; { receive buffer size } + SO_SNDLOWAT = $1003; { send low-water mark } + SO_RCVLOWAT = $1004; { receive low-water mark } + SO_SNDTIMEO = $1005; { send timeout } + SO_RCVTIMEO = $1006; { receive timeout } + SO_ERROR = $1007; { get error status and clear } + SO_TYPE = $1008; { get socket type } + +{ Options for connect and disconnect data and options. Used only by + non-TCP/IP transports such as DECNet, OSI TP4, etc. } + + SO_CONNDATA = $7000; + SO_CONNOPT = $7001; + SO_DISCDATA = $7002; + SO_DISCOPT = $7003; + SO_CONNDATALEN = $7004; + SO_CONNOPTLEN = $7005; + SO_DISCDATALEN = $7006; + SO_DISCOPTLEN = $7007; + +{ Option for opening sockets for synchronous access. } + SO_OPENTYPE = $7008; + SO_SYNCHRONOUS_ALERT = $10; + SO_SYNCHRONOUS_NONALERT = $20; + +{ Other NT-specific options. } + SO_MAXDG = $7009; + SO_MAXPATHDG = $700A; + SO_UPDATE_ACCEPT_CONTEXT = $700B; + SO_CONNECT_TIME = $700C; + +{ TCP options. } + TCP_NODELAY = $0001; + TCP_BSDURGENT = $7000; + +{ WinSock 2 extension -- new options } + SO_GROUP_ID = $2001; // ID of a socket group + SO_GROUP_PRIORITY = $2002; // the relative priority within a group + SO_MAX_MSG_SIZE = $2003; // maximum message size + SO_Protocol_InfoA = $2004; // WSAPROTOCOL_INFOA structure + SO_Protocol_InfoW = $2005; // WSAPROTOCOL_INFOW structure +{$IFDEF UNICODE} + SO_Protocol_Info = SO_Protocol_InfoW; +{$ELSE} + SO_Protocol_Info = SO_Protocol_InfoA; +{$ENDIF} + PVD_CONFIG = $3001; // configuration info for service provider + +{ Address families. } + AF_UNSPEC = 0; { unspecified } + AF_UNIX = 1; { local to host (pipes, portals) } + AF_INET = 2; { internetwork: UDP, TCP, etc. } + AF_IMPLINK = 3; { arpanet imp addresses } + AF_PUP = 4; { pup protocols: e.g. BSP } + AF_CHAOS = 5; { mit CHAOS protocols } + AF_IPX = 6; { IPX and SPX } + AF_NS = 6; { XEROX NS protocols } + AF_ISO = 7; { ISO protocols } + AF_OSI = AF_ISO; { OSI is ISO } + AF_ECMA = 8; { european computer manufacturers } + AF_DATAKIT = 9; { datakit protocols } + AF_CCITT = 10; { CCITT protocols, X.25 etc } + AF_SNA = 11; { IBM SNA } + AF_DECnet = 12; { DECnet } + AF_DLI = 13; { Direct data link interface } + AF_LAT = 14; { LAT } + AF_HYLINK = 15; { NSC Hyperchannel } + AF_APPLETALK = 16; { AppleTalk } + AF_NETBIOS = 17; { NetBios-style addresses } + AF_VOICEVIEW = 18; { VoiceView } + AF_FIREFOX = 19; { FireFox } + AF_UNKNOWN1 = 20; { Somebody is using this! } + AF_BAN = 21; { Banyan } + AF_ATM = 22; // Native ATM Services + AF_INET6 = 23; // Internetwork Version 6 + + AF_MAX = 24; + +{ Socket I/O Controls } +{Const + SIOCSHIWAT = _IOW('s', 0, u_long); // set high watermark + SIOCGHIWAT = _IOR('s', 1, u_long); // get high watermark + SIOCSLOWAT = _IOW('s', 2, u_long); // set low watermark + SIOCGLOWAT = _IOR('s', 3, u_long); // get low watermark + SIOCATMARK = _IOR('s', 7, u_long); // at oob mark? } + +{ Protocol families, same as address families for now. } + + PF_UNSPEC = AF_UNSPEC; + PF_UNIX = AF_UNIX; + PF_INET = AF_INET; + PF_IMPLINK = AF_IMPLINK; + PF_PUP = AF_PUP; + PF_CHAOS = AF_CHAOS; + PF_NS = AF_NS; + PF_IPX = AF_IPX; + PF_ISO = AF_ISO; + PF_OSI = AF_OSI; + PF_ECMA = AF_ECMA; + PF_DATAKIT = AF_DATAKIT; + PF_CCITT = AF_CCITT; + PF_SNA = AF_SNA; + PF_DECnet = AF_DECnet; + PF_DLI = AF_DLI; + PF_LAT = AF_LAT; + PF_HYLINK = AF_HYLINK; + PF_APPLETALK = AF_APPLETALK; + PF_VOICEVIEW = AF_VOICEVIEW; + PF_FIREFOX = AF_FIREFOX; + PF_UNKNOWN1 = AF_UNKNOWN1; + PF_BAN = AF_BAN; + PF_ATM = AF_ATM; + PF_INET6 = AF_INET6; + + PF_MAX = AF_MAX; + +type + + SunB = record + s_b1, s_b2, s_b3, s_b4: u_char; + end; + + SunW = record + s_w1, s_w2: u_short; + end; + + PInAddr = ^TInAddr; + TInAddr = record + case integer of + 0: (S_un_b: SunB); + 1: (S_un_w: SunW); + 2: (S_addr: u_long); + end; + + PSockAddrIn = ^TSockAddrIn; + TSockAddrIn = record + case Integer of + 0: (sin_family: u_short; + sin_port: u_short; + sin_addr: TInAddr; + sin_zero: array[0..7] of Char); + 1: (sa_family: u_short; + sa_data: array[0..13] of Char) + end; + + { Structure used by kernel to store most addresses. } + + PSockAddr = ^TSockAddr; + TSockAddr = TSockAddrIn; + +{* + * Portable socket structure (RFC 2553). + *} + +{* + * Desired design of maximum size and alignment. + * These are implementation specific. + *} +const + _SS_MAXSIZE = 128; // Maximum size. + _SS_ALIGNSIZE = SizeOf(Int64); // Desired alignment. + +{* + * Definitions used for sockaddr_storage structure paddings design. + *} +const + _SS_PAD1SIZE = _SS_ALIGNSIZE - SizeOf(SmallInt); + _SS_PAD2SIZE = _SS_MAXSIZE - (SizeOf(SmallInt) + _SS_PAD1SIZE + _SS_ALIGNSIZE); + +type + sockaddr_storage = record + ss_family:SmallInt; // Address family. + __ss_pad1:array[0.._SS_PAD1SIZE-1] of char; // 6 byte pad, this is to make + // implementation specific pad up to + // alignment field that follows explicit + // in the data structure. + __ss_align:Int64; // Field to force desired structure. + __ss_pad2:array[0.._SS_PAD2SIZE-1] of char; // 112 byte pad to achieve desired size; + // _SS_MAXSIZE value minus size of + // ss_family, __ss_pad1, and + // __ss_align fields is 112. + end; + + + { Structure used by kernel to pass protocol information in raw sockets. } + PSockProto = ^TSockProto; + TSockProto = record + sp_family: u_short; + sp_protocol: u_short; + end; + +{ Structure used for manipulating linger option. } + PLinger = ^TLinger; + TLinger = record + l_onoff: u_short; + l_linger: u_short; + end; + +const + INADDR_ANY = $00000000; + INADDR_LOOPBACK = $7F000001; + INADDR_BROADCAST = $FFFFFFFF; + INADDR_NONE = $FFFFFFFF; + + MSG_OOB = $1; {process out-of-band data } + MSG_PEEK = $2; {peek at incoming message } + MSG_DONTROUTE = $4; {send without using routing tables } + +{ WinSock 2 extension -- new flags for WSASend(), WSASendTo(), WSARecv() and WSARecvFrom() } + MSG_INTERRUPT = $10; {/* send/recv in the interrupt context */} + MSG_MAXIOVLEN = 16; + + MSG_PARTIAL = $8000; {partial send or recv for message xport } + +{ Define constant based on rfc883, used by gethostbyxxxx() calls. } + + MAXGETHOSTSTRUCT = 1024; + +{ Maximum queue length specifiable by listen. } + SOMAXCONN = $7fffffff; + +{ WinSock 2 extension -- bit values and indices for FD_XXX network events } + FD_READ_BIT = 0; + FD_READ = (1 shl FD_READ_BIT); + FD_WRITE_BIT = 1; + FD_WRITE = (1 shl FD_WRITE_BIT); + FD_OOB_BIT = 2; + FD_OOB = (1 shl FD_OOB_BIT); + FD_ACCEPT_BIT = 3; + FD_ACCEPT = (1 shl FD_ACCEPT_BIT); + FD_CONNECT_BIT = 4; + FD_CONNECT = (1 shl FD_CONNECT_BIT); + FD_CLOSE_BIT = 5; + FD_CLOSE = (1 shl FD_CLOSE_BIT); + FD_QOS_BIT = 6; + FD_QOS = (1 shl FD_QOS_BIT); + FD_GROUP_QOS_BIT = 7; + FD_GROUP_QOS = (1 shl FD_GROUP_QOS_BIT); + FD_MAX_EVENTS = 8; + FD_ALL_EVENTS = ((1 shl FD_MAX_EVENTS) - 1); + +{ All Windows Sockets error constants are biased by WSABASEERR from the "normal" } + + WSABASEERR = 10000; + +{ Windows Sockets definitions of regular Microsoft C error constants } + + WSAEINTR = (WSABASEERR+4); + WSAEBADF = (WSABASEERR+9); + WSAEACCES = (WSABASEERR+13); + WSAEFAULT = (WSABASEERR+14); + WSAEINVAL = (WSABASEERR+22); + WSAEMFILE = (WSABASEERR+24); + +{ Windows Sockets definitions of regular Berkeley error constants } + + WSAEWOULDBLOCK = (WSABASEERR+35); + WSAEINPROGRESS = (WSABASEERR+36); + WSAEALREADY = (WSABASEERR+37); + WSAENOTSOCK = (WSABASEERR+38); + WSAEDESTADDRREQ = (WSABASEERR+39); + WSAEMSGSIZE = (WSABASEERR+40); + WSAEPROTOTYPE = (WSABASEERR+41); + WSAENOPROTOOPT = (WSABASEERR+42); + WSAEPROTONOSUPPORT = (WSABASEERR+43); + WSAESOCKTNOSUPPORT = (WSABASEERR+44); + WSAEOPNOTSUPP = (WSABASEERR+45); + WSAEPFNOSUPPORT = (WSABASEERR+46); + WSAEAFNOSUPPORT = (WSABASEERR+47); + WSAEADDRINUSE = (WSABASEERR+48); + WSAEADDRNOTAVAIL = (WSABASEERR+49); + WSAENETDOWN = (WSABASEERR+50); + WSAENETUNREACH = (WSABASEERR+51); + WSAENETRESET = (WSABASEERR+52); + WSAECONNABORTED = (WSABASEERR+53); + WSAECONNRESET = (WSABASEERR+54); + WSAENOBUFS = (WSABASEERR+55); + WSAEISCONN = (WSABASEERR+56); + WSAENOTCONN = (WSABASEERR+57); + WSAESHUTDOWN = (WSABASEERR+58); + WSAETOOMANYREFS = (WSABASEERR+59); + WSAETIMEDOUT = (WSABASEERR+60); + WSAECONNREFUSED = (WSABASEERR+61); + WSAELOOP = (WSABASEERR+62); + WSAENAMETOOLONG = (WSABASEERR+63); + WSAEHOSTDOWN = (WSABASEERR+64); + WSAEHOSTUNREACH = (WSABASEERR+65); + WSAENOTEMPTY = (WSABASEERR+66); + WSAEPROCLIM = (WSABASEERR+67); + WSAEUSERS = (WSABASEERR+68); + WSAEDQUOT = (WSABASEERR+69); + WSAESTALE = (WSABASEERR+70); + WSAEREMOTE = (WSABASEERR+71); + +{ Extended Windows Sockets error constant definitions } + + WSASYSNOTREADY = (WSABASEERR+91); + WSAVERNOTSUPPORTED = (WSABASEERR+92); + WSANOTINITIALISED = (WSABASEERR+93); + WSAEDISCON = (WSABASEERR+101); + WSAENOMORE = (WSABASEERR+102); + WSAECANCELLED = (WSABASEERR+103); + WSAEINVALIDPROCTABLE = (WSABASEERR+104); + WSAEINVALIDPROVIDER = (WSABASEERR+105); + WSAEPROVIDERFAILEDINIT = (WSABASEERR+106); + WSASYSCALLFAILURE = (WSABASEERR+107); + WSASERVICE_NOT_FOUND = (WSABASEERR+108); + WSATYPE_NOT_FOUND = (WSABASEERR+109); + WSA_E_NO_MORE = (WSABASEERR+110); + WSA_E_CANCELLED = (WSABASEERR+111); + WSAEREFUSED = (WSABASEERR+112); + + +{ 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 } + WSAHOST_NOT_FOUND = (WSABASEERR+1001); + HOST_NOT_FOUND = WSAHOST_NOT_FOUND; + +{ Non-Authoritative: Host not found, or SERVERFAIL } + WSATRY_AGAIN = (WSABASEERR+1002); + TRY_AGAIN = WSATRY_AGAIN; + +{ Non recoverable errors, FORMERR, REFUSED, NOTIMP } + WSANO_RECOVERY = (WSABASEERR+1003); + NO_RECOVERY = WSANO_RECOVERY; + +{ Valid name, no data record of requested type } + WSANO_DATA = (WSABASEERR+1004); + NO_DATA = WSANO_DATA; + +{ no address, look for MX record } + WSANO_ADDRESS = WSANO_DATA; + NO_ADDRESS = WSANO_ADDRESS; + +{ WinSock 2 extension -- new error codes and type definition } + WSA_IO_PENDING = ERROR_IO_PENDING; + WSA_IO_INCOMPLETE = ERROR_IO_INCOMPLETE; + WSA_INVALID_HANDLE = ERROR_INVALID_HANDLE; + WSA_INVALID_PARAMETER = ERROR_INVALID_PARAMETER; + WSA_NOT_ENOUGH_MEMORY = ERROR_NOT_ENOUGH_MEMORY; + WSA_OPERATION_ABORTED = ERROR_OPERATION_ABORTED; +{$ifndef FPC}{TODO} + WSA_INVALID_EVENT = WSAEVENT(nil); +{$endif} + WSA_MAXIMUM_WAIT_EVENTS = MAXIMUM_WAIT_OBJECTS; + WSA_WAIT_FAILED = $ffffffff; + WSA_WAIT_EVENT_0 = WAIT_OBJECT_0; + WSA_WAIT_IO_COMPLETION = WAIT_IO_COMPLETION; + WSA_WAIT_TIMEOUT = WAIT_TIMEOUT; + WSA_INFINITE = INFINITE; + +{ 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. } + + EWOULDBLOCK = WSAEWOULDBLOCK; + EINPROGRESS = WSAEINPROGRESS; + EALREADY = WSAEALREADY; + ENOTSOCK = WSAENOTSOCK; + EDESTADDRREQ = WSAEDESTADDRREQ; + EMSGSIZE = WSAEMSGSIZE; + EPROTOTYPE = WSAEPROTOTYPE; + ENOPROTOOPT = WSAENOPROTOOPT; + EPROTONOSUPPORT = WSAEPROTONOSUPPORT; + ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT; + EOPNOTSUPP = WSAEOPNOTSUPP; + EPFNOSUPPORT = WSAEPFNOSUPPORT; + EAFNOSUPPORT = WSAEAFNOSUPPORT; + EADDRINUSE = WSAEADDRINUSE; + EADDRNOTAVAIL = WSAEADDRNOTAVAIL; + ENETDOWN = WSAENETDOWN; + ENETUNREACH = WSAENETUNREACH; + ENETRESET = WSAENETRESET; + ECONNABORTED = WSAECONNABORTED; + ECONNRESET = WSAECONNRESET; + ENOBUFS = WSAENOBUFS; + EISCONN = WSAEISCONN; + ENOTCONN = WSAENOTCONN; + ESHUTDOWN = WSAESHUTDOWN; + ETOOMANYREFS = WSAETOOMANYREFS; + ETIMEDOUT = WSAETIMEDOUT; + ECONNREFUSED = WSAECONNREFUSED; + ELOOP = WSAELOOP; + ENAMETOOLONG = WSAENAMETOOLONG; + EHOSTDOWN = WSAEHOSTDOWN; + EHOSTUNREACH = WSAEHOSTUNREACH; + ENOTEMPTY = WSAENOTEMPTY; + EPROCLIM = WSAEPROCLIM; + EUSERS = WSAEUSERS; + EDQUOT = WSAEDQUOT; + ESTALE = WSAESTALE; + EREMOTE = WSAEREMOTE; + + + WSADESCRIPTION_LEN = 256; + WSASYS_STATUS_LEN = 128; + MAX_PROTOCOL_CHAIN = 7; + BASE_PROTOCOL = 1; + LAYERED_PROTOCOL = 0; + WSAPROTOCOL_LEN = 255; + +type + PWSAData = ^TWSAData; + TWSAData = record + wVersion: Word; + wHighVersion: Word; + szDescription: array[0..WSADESCRIPTION_LEN] of Char; + szSystemStatus: array[0..WSASYS_STATUS_LEN] of Char; + iMaxSockets: Word; + iMaxUdpDg: Word; + lpVendorInfo: PChar; + end; + +{ WSAOVERLAPPED = Record + Internal: LongInt; + InternalHigh: LongInt; + Offset: LongInt; + OffsetHigh: LongInt; + hEvent: WSAEVENT; + end;} + WSAOVERLAPPED = TOverlapped; + TWSAOverlapped = WSAOverlapped; + PWSAOverlapped = ^WSAOverlapped; + LPWSAOVERLAPPED = PWSAOverlapped; + +{ WinSock 2 extension -- WSABUF and QOS struct, include qos.h } +{ to pull in FLOWSPEC and related definitions } + + + WSABUF = record + len: U_LONG; { the length of the buffer } + buf: PChar; { the pointer to the buffer } + end {WSABUF}; + PWSABUF = ^WSABUF; + LPWSABUF = PWSABUF; + + TServiceType = LongInt; + + TFlowSpec = Record + TokenRate, // In Bytes/sec + TokenBucketSize, // In Bytes + PeakBandwidth, // In Bytes/sec + Latency, // In microseconds + DelayVariation : LongInt;// In microseconds + ServiceType : TServiceType; + MaxSduSize, MinimumPolicedSize : LongInt;// In Bytes + end; + PFlowSpec = ^TFLOWSPEC; + + TQualityOfService = record + SendingFlowspec: TFlowSpec; { the flow spec for data sending } + ReceivingFlowspec: TFlowSpec; { the flow spec for data receiving } + ProviderSpecific: WSABUF; { additional provider specific stuff } + end {TQualityOfService}; + PQOS = ^TQualityOfService; + LPQOS = PQOS; + +Const + SERVICETYPE_NOTRAFFIC = $00000000; // No data in this direction + SERVICETYPE_BESTEFFORT = $00000001; // Best Effort + SERVICETYPE_CONTROLLEDLOAD = $00000002; // Controlled Load + SERVICETYPE_GUARANTEED = $00000003; // Guaranteed + SERVICETYPE_NETWORK_UNAVAILABLE = $00000004; // Used to notify change to user + SERVICETYPE_GENERAL_INFORMATION = $00000005; // corresponds to "General Parameters" defined by IntServ + SERVICETYPE_NOCHANGE = $00000006; // used to indicate that the flow spec contains no change from any previous one +// to turn on immediate traffic control, OR this flag with the ServiceType field in teh FLOWSPEC + SERVICE_IMMEDIATE_TRAFFIC_CONTROL = $80000000; + +{ WinSock 2 extension -- manifest constants for return values of the condition function } + CF_ACCEPT = $0000; + CF_REJECT = $0001; + CF_DEFER = $0002; + +{ WinSock 2 extension -- manifest constants for shutdown() } + SD_RECEIVE = $00; + SD_SEND = $01; + SD_BOTH = $02; + +{ WinSock 2 extension -- data type and manifest constants for socket groups } + SG_UNCONSTRAINED_GROUP = $01; + SG_CONSTRAINED_GROUP = $02; +Type + GROUP = u_int; + +{ WinSock 2 extension -- data type for WSAEnumNetworkEvents() } + TWSANetworkEvents = record + lNetworkEvents: LongInt; + iErrorCode: Array[0..FD_MAX_EVENTS-1] of Longint; + end {TWSANetworkEvents}; + PWSANetworkEvents = ^TWSANetworkEvents; + LPWSANetworkEvents = PWSANetworkEvents; + + TWSAProtocolChain = record + ChainLen: Longint; // the length of the chain, + // length = 0 means layered protocol, + // length = 1 means base protocol, + // length > 1 means protocol chain + ChainEntries: Array[0..MAX_PROTOCOL_CHAIN-1] of LongInt; { a list of dwCatalogEntryIds } + end {TWSAPROTOCOLCHAIN}; + +Type + TWSAProtocol_InfoA = record + dwServiceFlags1: LongInt; + dwServiceFlags2: LongInt; + dwServiceFlags3: LongInt; + dwServiceFlags4: LongInt; + dwProviderFlags: LongInt; + ProviderId: TGUID; + dwCatalogEntryId: LongInt; + ProtocolChain: TWSAProtocolChain; + iVersion: Longint; + iAddressFamily: Longint; + iMaxSockAddr: Longint; + iMinSockAddr: Longint; + iSocketType: Longint; + iProtocol: Longint; + iProtocolMaxOffset: Longint; + iNetworkByteOrder: Longint; + iSecurityScheme: Longint; + dwMessageSize: LongInt; + dwProviderReserved: LongInt; + szProtocol: Array[0..WSAPROTOCOL_LEN+1-1] of Char; + end {TWSAProtocol_InfoA}; + PWSAProtocol_InfoA = ^TWSAProtocol_InfoA; + LPWSAProtocol_InfoA = PWSAProtocol_InfoA; + + TWSAProtocol_InfoW = record + dwServiceFlags1: LongInt; + dwServiceFlags2: LongInt; + dwServiceFlags3: LongInt; + dwServiceFlags4: LongInt; + dwProviderFlags: LongInt; + ProviderId: TGUID; + dwCatalogEntryId: LongInt; + ProtocolChain: TWSAProtocolChain; + iVersion: Longint; + iAddressFamily: Longint; + iMaxSockAddr: Longint; + iMinSockAddr: Longint; + iSocketType: Longint; + iProtocol: Longint; + iProtocolMaxOffset: Longint; + iNetworkByteOrder: Longint; + iSecurityScheme: Longint; + dwMessageSize: LongInt; + dwProviderReserved: LongInt; + szProtocol: Array[0..(WSAPROTOCOL_LEN+1-1)] of WideChar; + end {TWSAProtocol_InfoW}; + PWSAProtocol_InfoW = ^TWSAProtocol_InfoW; + LPWSAProtocol_InfoW = PWSAProtocol_InfoW; + +{$IFDEF UNICODE} + TWSAProtocol_Info = TWSAProtocol_InfoW; + LPWSAProtocol_Info = PWSAProtocol_InfoW; +{$ELSE} + TWSAProtocol_Info = TWSAProtocol_InfoA; + LPWSAProtocol_Info = PWSAProtocol_InfoA; +{$ENDIF} + +{ Flag bit definitions for dwProviderFlags */ } +Const + PFL_MULTIPLE_PROTO_ENTRIES = $00000001; + PFL_RECOMMENDED_PROTO_ENTRY = $00000002; + PFL_HIDDEN = $00000004; + PFL_MATCHES_PROTOCOL_ZERO = $00000008; + +{ Flag bit definitions for dwServiceFlags1 */ } + XP1_CONNECTIONLESS = $00000001; + XP1_GUARANTEED_DELIVERY = $00000002; + XP1_GUARANTEED_ORDER = $00000004; + XP1_MESSAGE_ORIENTED = $00000008; + XP1_PSEUDO_STREAM = $00000010; + XP1_GRACEFUL_CLOSE = $00000020; + XP1_EXPEDITED_DATA = $00000040; + XP1_CONNECT_DATA = $00000080; + XP1_DISCONNECT_DATA = $00000100; + XP1_SUPPORT_BROADCAST = $00000200; + XP1_SUPPORT_MULTIPOINT = $00000400; + XP1_MULTIPOINT_CONTROL_PLANE = $00000800; + XP1_MULTIPOINT_DATA_PLANE = $00001000; + XP1_QOS_SUPPORTED = $00002000; + XP1_INTERRUPT = $00004000; + XP1_UNI_SEND = $00008000; + XP1_UNI_RECV = $00010000; + XP1_IFS_HANDLES = $00020000; + XP1_PARTIAL_MESSAGE = $00040000; + + BIGENDIAN = $0000; + LITTLEENDIAN = $0001; + + SECURITY_PROTOCOL_NONE = $0000; + +{ WinSock 2 extension -- manifest constants for WSAJoinLeaf() } + JL_SENDER_ONLY = $01; + JL_RECEIVER_ONLY = $02; + JL_BOTH = $04; + +{ WinSock 2 extension -- manifest constants for WSASocket() } + WSA_FLAG_OVERLAPPED = $01; + WSA_FLAG_MULTIPOINT_C_ROOT = $02; + WSA_FLAG_MULTIPOINT_C_LEAF = $04; + WSA_FLAG_MULTIPOINT_D_ROOT = $08; + WSA_FLAG_MULTIPOINT_D_LEAF = $10; + +{ WinSock 2 extension -- manifest constants for WSAIoctl() } + IOC_UNIX = $00000000; + IOC_WS2 = $08000000; + IOC_PROTOCOL = $10000000; + IOC_VENDOR = $18000000; + + SIO_ASSOCIATE_HANDLE = IOC_IN or IOC_WS2 or 1; + SIO_ENABLE_CIRCULAR_QUEUEING = IOC_WS2 or 2; + SIO_FIND_ROUTE = IOC_OUT or IOC_WS2 or 3; + SIO_FLUSH = IOC_WS2 or 4; + SIO_GET_BROADCAST_ADDRESS = IOC_OUT or IOC_WS2 or 5; + SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT or IOC_WS2 or 6; + SIO_GET_QOS = IOC_INOUT or IOC_WS2 or 7; + SIO_GET_GROUP_QOS = IOC_INOUT or IOC_WS2 or 8; + SIO_MULTIPOINT_LOOPBACK = IOC_IN or IOC_WS2 or 9; + SIO_MULTICAST_SCOPE = IOC_IN or IOC_WS2 or 10; + SIO_SET_QOS = IOC_IN or IOC_WS2 or 11; + SIO_SET_GROUP_QOS = IOC_IN or IOC_WS2 or 12; + SIO_TRANSLATE_HANDLE = IOC_INOUT or IOC_WS2 or 13; + +{WinSock 2 extension -- manifest constants for SIO_TRANSLATE_HANDLE ioctl } + TH_NETDEV = $00000001; + TH_TAPI = $00000002; + +Const + SERVICE_MULTIPLE = $00000001; + +{ & Name Spaces } + NS_ALL = (0); + + NS_SAP = (1); + NS_NDS = (2); + NS_PEER_BROWSE = (3); + + NS_TCPIP_LOCAL = (10); + NS_TCPIP_HOSTS = (11); + NS_DNS = (12); + NS_NETBT = (13); + NS_WINS = (14); + + NS_NBP = (20); + + NS_MS = (30); + NS_STDA = (31); + NS_NTDS = (32); + + NS_X500 = (40); + NS_NIS = (41); + NS_NISPLUS = (42); + + NS_WRQ = (50); + +{ Resolution flags for WSAGetAddressByName(). + Note these are also used by the 1.1 API GetAddressByName, so leave them around. } + RES_UNUSED_1 = $00000001; + RES_FLUSH_CACHE = $00000002; + RES_SERVICE = $00000004; + +{ Well known value names for Service Types } + SERVICE_TYPE_VALUE_IPXPORTA = 'IpxSocket'; +{$ifndef FPC}{TODO} + SERVICE_TYPE_VALUE_IPXPORTW : PWideChar = 'IpxSocket'; + SERVICE_TYPE_VALUE_SAPIDA = 'SapId'; + SERVICE_TYPE_VALUE_SAPIDW : PWideChar = 'SapId'; + + SERVICE_TYPE_VALUE_TCPPORTA = 'TcpPort'; + SERVICE_TYPE_VALUE_TCPPORTW : PWideChar = 'TcpPort'; + + SERVICE_TYPE_VALUE_UDPPORTA = 'UdpPort'; + SERVICE_TYPE_VALUE_UDPPORTW : PWideChar = 'UdpPort'; + + SERVICE_TYPE_VALUE_OBJECTIDA = 'ObjectId'; + SERVICE_TYPE_VALUE_OBJECTIDW : PWideChar = 'ObjectId'; + +{$IFDEF UNICODE} + SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDW; + SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTW; + SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTW; + SERVICE_TYPE_VALUE_OBJECTID = SERVICE_TYPE_VALUE_OBJECTIDW; +{$ELSE} + SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDA; + SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTA; + SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTA; + SERVICE_TYPE_VALUE_OBJECTID = SERVICE_TYPE_VALUE_OBJECTIDA; +{$ENDIF} + +{$endif}{FPC} + +{ SockAddr Information } + + +Type + SOCKET_ADDRESS = record + lpSockaddr : PSockAddr; + iSockaddrLength : Longint; + end {SOCKET_ADDRESS}; + PSOCKET_ADDRESS = ^SOCKET_ADDRESS; + +{ CSAddr Information } + CSADDR_INFO = record + LocalAddr, RemoteAddr: SOCKET_ADDRESS; + iSocketType, iProtocol : LongInt; + end {CSADDR_INFO}; + PCSADDR_INFO = ^CSADDR_INFO; + +{ Address Family/Protocol Tuples } + TAFProtocols = record + iAddressFamily: Longint; + iProtocol: Longint; + end {AFPROTOCOLS}; + PAFProtocols = ^TAFProtocols; + +{ Client Query API Typedefs } + +{ The comparators } + TWSAEComparator = (COMP_EQUAL {= 0}, COMP_NOTLESS ); + + TWSAVersion = record + dwVersion: LongInt; + ecHow: TWSAEComparator; + end {TWSAVersion}; + PWSAVersion = ^TWSAVersion; + + TWSAQuerySetA = record + dwSize: LongInt; + lpszServiceInstanceName: PChar; + lpServiceClassId: PGUID; + lpVersion: PWSAVERSION; + lpszComment: PChar; + dwNameSpace: LongInt; + lpNSProviderId: PGUID; + lpszContext: PChar; + dwNumberOfProtocols: LongInt; + lpafpProtocols: PAFProtocols; + lpszQueryString: PChar; + dwNumberOfCsAddrs: LongInt; + lpcsaBuffer: PCSADDR_INFO; + dwOutputFlags: LongInt; + lpBlob: PBLOB; + end {TWSAQuerySetA}; + PWSAQuerySetA = ^TWSAQuerySetA; + LPWSAQuerySetA = PWSAQuerySetA; + TWSAQuerySetW = record + dwSize: LongInt; + lpszServiceInstanceName: PWideChar; + lpServiceClassId: PGUID; + lpVersion: PWSAVERSION; + lpszComment: PWideChar; + dwNameSpace: LongInt; + lpNSProviderId: PGUID; + lpszContext: PWideChar; + dwNumberOfProtocols: LongInt; + lpafpProtocols: PAFProtocols; + lpszQueryString: PWideChar; + dwNumberOfCsAddrs: LongInt; + lpcsaBuffer: PCSADDR_INFO; + dwOutputFlags: LongInt; + lpBlob: PBLOB; + end {TWSAQuerySetW}; + PWSAQuerySetW = ^TWSAQuerySetW; + LPWSAQuerySetW = PWSAQuerySetW; +{$IFDEF UNICODE} + PWSAQuerySet = PWSAQuerySetW; + LPWSAQuerySet = PWSAQuerySetW; +{$ELSE} + PWSAQuerySet = PWSAQuerySetA; + LPWSAQuerySet = PWSAQuerySetA; +{$ENDIF} + +Const + LUP_DEEP = $0001; + LUP_CONTAINERS = $0002; + LUP_NOCONTAINERS = $0004; + LUP_NEAREST = $0008; + LUP_RETURN_NAME = $0010; + LUP_RETURN_TYPE = $0020; + LUP_RETURN_VERSION = $0040; + LUP_RETURN_COMMENT = $0080; + LUP_RETURN_ADDR = $0100; + LUP_RETURN_BLOB = $0200; + LUP_RETURN_ALIASES = $0400; + LUP_RETURN_QUERY_STRING = $0800; + LUP_RETURN_ALL = $0FF0; + LUP_RES_SERVICE = $8000; + + LUP_FLUSHCACHE = $1000; + LUP_FLUSHPREVIOUS = $2000; + + +{ Return flags } + RESULT_IS_ALIAS = $0001; + +Type +{ Service Address Registration and Deregistration Data Types. } + TWSAeSetServiceOp = (RNRSERVICE_REGISTER{=0},RNRSERVICE_DEREGISTER,RNRSERVICE_DELETE); + +{ Service Installation/Removal Data Types. } + TWSANSClassInfoA = record + lpszName: PChar; + dwNameSpace: LongInt; + dwValueType: LongInt; + dwValueSize: LongInt; + lpValue: Pointer; + end {_WSANSClassInfoA}; + PWSANSClassInfoA = ^TWSANSClassInfoA; + TWSANSClassInfoW = record + lpszName: PWideChar; + dwNameSpace: LongInt; + dwValueType: LongInt; + dwValueSize: LongInt; + lpValue: Pointer; + end {TWSANSClassInfoW}; + PWSANSClassInfoW = ^TWSANSClassInfoW; +{$IFDEF UNICODE} + TWSANSClassInfo = TWSANSClassInfoW; + PWSANSClassInfo = PWSANSClassInfoW; + LPWSANSClassInfo = PWSANSClassInfoW; +{$ELSE} + TWSANSClassInfo = TWSANSClassInfoA; + PWSANSClassInfo = PWSANSClassInfoA; + LPWSANSClassInfo = PWSANSClassInfoA; +{$ENDIF // UNICODE} + + TWSAServiceClassInfoA = record + lpServiceClassId: PGUID; + lpszServiceClassName: PChar; + dwCount: LongInt; + lpClassInfos: PWSANSClassInfoA; + end {TWSAServiceClassInfoA}; + PWSAServiceClassInfoA = ^TWSAServiceClassInfoA; + LPWSAServiceClassInfoA = PWSAServiceClassInfoA; + TWSAServiceClassInfoW = record + lpServiceClassId: PGUID; + lpszServiceClassName: PWideChar; + dwCount: LongInt; + lpClassInfos: PWSANSClassInfoW; + end {TWSAServiceClassInfoW}; + PWSAServiceClassInfoW = ^TWSAServiceClassInfoW; + LPWSAServiceClassInfoW = PWSAServiceClassInfoW; +{$IFDEF UNICODE} + TWSAServiceClassInfo = TWSAServiceClassInfoW; + PWSAServiceClassInfo = PWSAServiceClassInfoW; + LPWSAServiceClassInfo = PWSAServiceClassInfoW; +{$ELSE} + TWSAServiceClassInfo = TWSAServiceClassInfoA; + PWSAServiceClassInfo = PWSAServiceClassInfoA; + LPWSAServiceClassInfo = PWSAServiceClassInfoA; +{$ENDIF} + + TWSANameSpace_InfoA = record + NSProviderId: TGUID; + dwNameSpace: LongInt; + fActive: LongInt{Bool}; + dwVersion: LongInt; + lpszIdentifier: PChar; + end {TWSANameSpace_InfoA}; + PWSANameSpace_InfoA = ^TWSANameSpace_InfoA; + LPWSANameSpace_InfoA = PWSANameSpace_InfoA; + TWSANameSpace_InfoW = record + NSProviderId: TGUID; + dwNameSpace: LongInt; + fActive: LongInt{Bool}; + dwVersion: LongInt; + lpszIdentifier: PWideChar; + end {TWSANameSpace_InfoW}; + PWSANameSpace_InfoW = ^TWSANameSpace_InfoW; + LPWSANameSpace_InfoW = PWSANameSpace_InfoW; +{$IFDEF UNICODE} + TWSANameSpace_Info = TWSANameSpace_InfoW; + PWSANameSpace_Info = PWSANameSpace_InfoW; + LPWSANameSpace_Info = PWSANameSpace_InfoW; +{$ELSE} + TWSANameSpace_Info = TWSANameSpace_InfoA; + PWSANameSpace_Info = PWSANameSpace_InfoA; + LPWSANameSpace_Info = PWSANameSpace_InfoA; +{$ENDIF} + +{ WinSock 2 extensions -- data types for the condition function in } +{ WSAAccept() and overlapped I/O completion routine. } +Type + LPCONDITIONPROC = function (lpCallerId: LPWSABUF; lpCallerData : LPWSABUF; lpSQOS,lpGQOS : LPQOS; lpCalleeId,lpCalleeData : LPWSABUF; + g : GROUP; dwCallbackData : DWORD ) : Longint; + LPWSAOVERLAPPED_COMPLETION_ROUTINE = procedure ( const dwError, cbTransferred : DWORD; const lpOverlapped : LPWSAOVERLAPPED; const dwFlags : DWORD ); + + +//begin common win & wince +function accept( const s: TSocket; addr: PSockAddr; addrlen: PLongint ): TSocket; external WINSOCK2_DLL name 'accept'; +function accept( const s: TSocket; addr: PSockAddr; var addrlen: Longint ): TSocket; external WINSOCK2_DLL name 'accept'; +function bind( const s: TSocket; addr: PSockAddr; const namelen: Longint ): Longint; external WINSOCK2_DLL name 'bind'; +function bind( const s: TSocket; const addr: TSockAddr; namelen: Longint ): Longint; external WINSOCK2_DLL name 'bind'; +function closesocket( const s: TSocket ): Longint; external WINSOCK2_DLL name 'closesocket'; +function connect( const s: TSocket; name: PSockAddr; namelen: Longint): Longint; external WINSOCK2_DLL name 'connect'; +function connect( const s: TSocket; const name: TSockAddr; namelen: Longint): Longint; external WINSOCK2_DLL name 'connect'; + +function gethostbyaddr(addr: Pointer; len, struct: Longint): PHostEnt; external WINSOCK2_DLL name 'gethostbyaddr'; +function gethostbyname(name: PChar): PHostEnt; external WINSOCK2_DLL name 'gethostbyname'; +function gethostname(name: PChar; len: Longint): Longint; external WINSOCK2_DLL name 'gethostname'; +function getpeername( const s: TSocket; var name: TSockAddr; var namelen: Longint ): Longint; external WINSOCK2_DLL name 'getpeername'; +function getprotobyname(name: PChar): PProtoEnt; external WINSOCK2_DLL name 'getprotobyname'; +function getprotobynumber(proto: Longint): PProtoEnt; external WINSOCK2_DLL name 'getprotobynumber'; +function getservbyport(port: Longint; proto: PChar): PServEnt; external WINSOCK2_DLL name 'getservbyport'; +function getservbyname(name, proto: PChar): PServEnt; external WINSOCK2_DLL name 'getservbyname'; +function getsockname( const s: TSocket; var name: TSockAddr; var namelen: Longint ): Longint; external WINSOCK2_DLL name 'getsockname'; +function getsockopt( const s: TSocket; const level, optname: Longint; optval: PChar; var optlen: Longint ): Longint; external WINSOCK2_DLL name 'getsockopt'; +function getsockopt( const s: TSocket; const level, optname: Longint; optval: Pointer; var optlen: Longint ): Longint; external WINSOCK2_DLL name 'getsockopt'; +function getsockopt( const s: TSocket; const level, optname: Longint; var optval; var optlen: Longint ): Longint; external WINSOCK2_DLL name 'getsockopt'; +function htonl(hostlong: u_long): u_long; external WINSOCK2_DLL name 'htonl'; +function htons(hostshort: u_short): u_short; external WINSOCK2_DLL name 'htons'; +function inet_addr(cp: PChar): u_long; external WINSOCK2_DLL name 'inet_addr'; +function inet_ntoa(inaddr: TInAddr): PChar; external WINSOCK2_DLL name 'inet_ntoa'; +function ioctlsocket( const s: TSocket; cmd: Longint; var arg: u_long ): Longint; external WINSOCK2_DLL name 'ioctlsocket'; +function ioctlsocket( const s: TSocket; cmd: Longint; argp: pu_long ): Longint; external WINSOCK2_DLL name 'ioctlsocket'; +function listen(s: TSocket; backlog: Longint): Longint; external WINSOCK2_DLL name 'listen'; +function ntohl(netlong: u_long): u_long; external WINSOCK2_DLL name 'ntohl'; +function ntohs(netshort: u_short): u_short; external WINSOCK2_DLL name 'ntohs'; +function recv(s: TSocket; var Buf; len, flags: Longint): Longint; external WINSOCK2_DLL name 'recv'; +function recv(s: TSocket; Buf: PChar; len, flags: Longint): Longint; external WINSOCK2_DLL name 'recv'; +function recv(s: TSocket; Buf: Pointer; len, flags: Longint): Longint; external WINSOCK2_DLL name 'recv'; +function recvfrom(s: TSocket; Buf: PChar; len, flags: Longint; from: PSockAddr; fromlen: PLongint): Longint; external WINSOCK2_DLL name 'recvfrom'; +function recvfrom(s: TSocket; Buf: Pointer; len, flags: Longint; from: PSockAddr; fromlen: PLongint): Longint; external WINSOCK2_DLL name 'recvfrom'; +function recvfrom(s: TSocket; var Buf; len, flags: Longint; const from: TSockAddr; var fromlen: Longint): Longint; external WINSOCK2_DLL name 'recvfrom'; +function select(nfds: Longint; readfds, writefds, exceptfds: PFDSet; timeout: PTimeVal): Longint; external WINSOCK2_DLL name 'select'; +function send(s: TSocket; const Buf; len, flags: Longint): Longint; external WINSOCK2_DLL name 'send'; +function send(s: TSocket; Buf: PChar; len, flags: Longint): Longint; external WINSOCK2_DLL name 'send'; +function send(s: TSocket; Buf: Pointer; len, flags: Longint): Longint; external WINSOCK2_DLL name 'send'; +function sendto(s: TSocket; const Buf; len, flags: Longint; const addrto: TSockAddr; tolen: Longint): Longint; external WINSOCK2_DLL name 'sendto'; +function sendto(s: TSocket; Buf: PChar; len, flags: Longint; addrto: PSockAddr; tolen: Longint): Longint; external WINSOCK2_DLL name 'sendto'; +function sendto(s: TSocket; Buf: Pointer; len, flags: Longint; addrto: PSockAddr; tolen: Longint): Longint; external WINSOCK2_DLL name 'sendto'; +function setsockopt(s: TSocket; level, optname: Longint; const optval; optlen: Longint): Longint; external WINSOCK2_DLL name 'setsockopt'; +function setsockopt(s: TSocket; level, optname: Longint; optval: PChar; optlen: Longint): Longint; external WINSOCK2_DLL name 'setsockopt'; +function setsockopt(s: TSocket; level, optname: Longint; optval: Pointer; optlen: Longint): Longint; external WINSOCK2_DLL name 'setsockopt'; +function shutdown(s: TSocket; how: Longint): Longint; external WINSOCK2_DLL name 'shutdown'; +function socket(af, struct, protocol: Longint): TSocket; external WINSOCK2_DLL name 'socket'; + +{ WinSock 2 API new function prototypes } +function WSAAccept( s : TSocket; addr : TSockAddr; addrlen : PLongint; lpfnCondition : LPCONDITIONPROC; dwCallbackData : DWORD ): TSocket; external WINSOCK2_DLL name 'WSAAccept'; +function WSAAddressToStringW( var lpsaAddress : TSockAddr; const dwAddressLength : DWORD; const lpProtocolInfo : LPWSAProtocol_InfoW; + const lpszAddressString : PWideChar; var lpdwAddressStringLength : DWORD ): Longint; external WINSOCK2_DLL name 'WSAAddressToStringW'; +function WSAAsyncGetHostByName(HWindow: HWND; wMsg: u_int; name, buf: PChar; buflen: Longint): THandle; external WINSOCK2_DLL name 'WSAAsyncGetHostByName'; +function WSAAsyncSelect(s: TSocket; HWindow: HWND; wMsg: u_int; lEvent: Longint): Longint; external WINSOCK2_DLL name 'WSAAsyncSelect'; +function WSACancelAsyncRequest(hAsyncTaskHandle: THandle): Longint; external WINSOCK2_DLL name 'WSACancelAsyncRequest'; +function WSACleanup: Longint; external WINSOCK2_DLL name 'WSACleanup'; +function WSACloseEvent( hEvent : WSAEVENT) : WordBool; external WINSOCK2_DLL name 'WSACloseEvent'; +function WSAConnect( s : TSocket; const name : PSockAddr; namelen : Longint; lpCallerData,lpCalleeData : LPWSABUF; lpSQOS,lpGQOS : LPQOS ) : Longint; external WINSOCK2_DLL name 'WSAConnect'; +function WSACreateEvent : WSAEVENT; external WINSOCK2_DLL name 'WSACreateEvent'; +function WSAEnumNameSpaceProvidersW( var lpdwBufferLength: DWORD; const lpnspBuffer: LPWSANameSpace_InfoW ): Longint; external WINSOCK2_DLL name 'WSAEnumNameSpaceProvidersW'; +function WSAEnumNetworkEvents( const s : TSocket; const hEventObject : WSAEVENT; lpNetworkEvents : LPWSANETWORKEVENTS ) :Longint; external WINSOCK2_DLL name 'WSAEnumNetworkEvents'; +function WSAEnumProtocolsW( lpiProtocols : PLongint; lpProtocolBuffer : LPWSAProtocol_InfoW; var lpdwBufferLength : DWORD ) : Longint; external WINSOCK2_DLL name 'WSAEnumProtocolsW'; +function WSAEventSelect( s : TSocket; hEventObject : WSAEVENT; lNetworkEvents : LongInt ): Longint; external WINSOCK2_DLL name 'WSAEventSelect'; +function WSAGetLastError: Longint; external WINSOCK2_DLL name 'WSAGetLastError'; +function WSAGetOverlappedResult( s : TSocket; lpOverlapped : LPWSAOVERLAPPED; lpcbTransfer : LPDWORD; fWait : BOOL; var lpdwFlags : DWORD ) : WordBool; external WINSOCK2_DLL name 'WSAGetOverlappedResult'; +function WSAhtonl( s : TSocket; hostlong : u_long; var lpnetlong : DWORD ): Longint; external WINSOCK2_DLL name 'WSAhtonl'; +function WSAhtons( s : TSocket; hostshort : u_short; var lpnetshort : WORD ): Longint; external WINSOCK2_DLL name 'WSAhtons'; +function WSAIoctl( s : TSocket; dwIoControlCode : DWORD; lpvInBuffer : Pointer; cbInBuffer : DWORD; lpvOutBuffer : Pointer; cbOutBuffer : DWORD; + lpcbBytesReturned : LPDWORD; lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ) : Longint; external WINSOCK2_DLL name 'WSAIoctl'; +function WSAJoinLeaf( s : TSocket; name : PSockAddr; namelen : Longint; lpCallerData,lpCalleeData : LPWSABUF; + lpSQOS,lpGQOS : LPQOS; dwFlags : DWORD ) : TSocket; external WINSOCK2_DLL name 'WSAJoinLeaf'; +function WSALookupServiceBeginW( const lpqsRestrictions : LPWSAQuerySetW; const dwControlFlags : DWORD; lphLookup : PHANDLE ): Longint; external WINSOCK2_DLL name 'WSALookupServiceBeginW'; +function WSALookupServiceEnd( const hLookup : THandle ): Longint; external WINSOCK2_DLL name 'WSALookupServiceEnd'; +function WSALookupServiceNextW( const hLookup : THandle; const dwControlFlags : DWORD; var lpdwBufferLength : DWORD; lpqsResults : LPWSAQuerySetW ): Longint; external WINSOCK2_DLL name 'WSALookupServiceNextW'; +function WSANtohl( s : TSocket; netlong : u_long; var lphostlong : DWORD ): Longint; external WINSOCK2_DLL name 'WSANtohl'; +function WSANtohs( s : TSocket; netshort : u_short; var lphostshort : WORD ): Longint; external WINSOCK2_DLL name 'WSANtohs'; +function WSARecv( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesRecvd : DWORD; var lpFlags : DWORD; + lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; external WINSOCK2_DLL name 'WSARecv'; +function WSARecvFrom( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesRecvd : DWORD; var lpFlags : DWORD; + lpFrom : PSockAddr; lpFromlen : PLongint; lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; external WINSOCK2_DLL name 'WSARecvFrom'; +function WSAResetEvent( hEvent : WSAEVENT ): WordBool; external WINSOCK2_DLL name 'WSAResetEvent'; +function WSASend( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesSent : DWORD; dwFlags : DWORD; + lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; external WINSOCK2_DLL name 'WSASend'; +function WSASendTo( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesSent : DWORD; dwFlags : DWORD; + lpTo : PSockAddr; iTolen : Longint; lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; external WINSOCK2_DLL name 'WSASendTo'; +function WSASetEvent( hEvent : WSAEVENT ): WordBool; external WINSOCK2_DLL name 'WSASetEvent'; +procedure WSASetLastError(iError: Longint); external WINSOCK2_DLL name 'WSASetLastError'; +function WSASetServiceW( const lpqsRegInfo: LPWSAQuerySetW; const essoperation: TWSAeSetServiceOp; + const dwControlFlags: DWORD ): Longint; external WINSOCK2_DLL name 'WSASetServiceW'; +function WSASocketW( af, iType, protocol : Longint; lpProtocolInfo : LPWSAProtocol_InfoW; g : GROUP; dwFlags : DWORD ): TSocket; external WINSOCK2_DLL name 'WSASocketW'; +function WSAStartup(wVersionRequired: word; var WSData: TWSAData): Longint; external WINSOCK2_DLL name 'WSAStartup'; +function WSAStringToAddressW( const AddressString : PWideChar; const AddressFamily: Longint; const lpProtocolInfo : LPWSAProtocol_InfoA; + var lpAddress : TSockAddr; var lpAddressLength : Longint ): Longint; external WINSOCK2_DLL name 'WSAStringToAddressW'; +function WSAWaitForMultipleEvents( cEvents : DWORD; lphEvents : PWSAEVENT; fWaitAll : LongBool; + dwTimeout : DWORD; fAlertable : LongBool ): DWORD; external WINSOCK2_DLL name 'WSAWaitForMultipleEvents'; +function __WSAFDIsSet(s: TSOcket; var FDSet: TFDSet): Bool; external WINSOCK2_DLL name '__WSAFDIsSet'; + + +{ Macros } +function WSAMakeSyncReply(Buflen, Error: Word): Longint; +function WSAMakeSelectReply(Event, Error: Word): Longint; +function WSAGetAsyncBuflen(Param: Longint): Word; +function WSAGetAsyncError(Param: Longint): Word; +function WSAGetSelectEvent(Param: Longint): Word; +function WSAGetSelectError(Param: Longint): Word; + +procedure FD_CLR(Socket: TSocket; var FDSet: TFDSet); +function FD_ISSET(Socket: TSocket; var FDSet: TFDSet): Boolean; +procedure FD_SET(Socket: TSocket; var FDSet: TFDSet); +procedure FD_ZERO(var FDSet: TFDSet); +//end common win & wince + +{$IFNDEF WINCE} +//begin win only +function WSAIsBlocking: BOOL; external WINSOCK2_DLL name 'WSAIsBlocking'; +function WSAUnhookBlockingHook: Longint; external WINSOCK2_DLL name 'WSAUnhookBlockingHook'; +function WSASetBlockingHook(lpBlockFunc: TFarProc): TFarProc; external WINSOCK2_DLL name 'WSASetBlockingHook'; +function WSACancelBlockingCall: Longint; external WINSOCK2_DLL name 'WSACancelBlockingCall'; +function WSAAsyncGetServByName(HWindow: HWND; wMsg: u_int; name, proto, buf: PChar; buflen: Longint): THandle; external WINSOCK2_DLL name 'WSAAsyncGetServByName'; +function WSAAsyncGetServByPort( HWindow: HWND; wMsg, port: u_int; proto, buf: PChar; buflen: Longint): THandle; external WINSOCK2_DLL name 'WSAAsyncGetServByPort'; +function WSAAsyncGetProtoByName(HWindow: HWND; wMsg: u_int; name, buf: PChar; buflen: Longint): THandle; external WINSOCK2_DLL name 'WSAAsyncGetProtoByName'; +function WSAAsyncGetProtoByNumber(HWindow: HWND; wMsg: u_int; number: Longint; buf: PChar; buflen: Longint): THandle; external WINSOCK2_DLL name 'WSAAsyncGetProtoByNumber'; +function WSAAsyncGetHostByAddr(HWindow: HWND; wMsg: u_int; addr: PChar; len, struct: Longint; buf: PChar; buflen: Longint): THandle; external WINSOCK2_DLL name 'WSAAsyncGetHostByAddr'; + +function WSADuplicateSocketA( s : TSocket; dwProcessId : DWORD; lpProtocolInfo : LPWSAProtocol_InfoA ) : Longint; external WINSOCK2_DLL name 'WSADuplicateSocketA'; +function WSADuplicateSocketW( s : TSocket; dwProcessId : DWORD; lpProtocolInfo : LPWSAProtocol_InfoW ) : Longint; external WINSOCK2_DLL name 'WSADuplicateSocketW'; +function WSADuplicateSocket( s : TSocket; dwProcessId : DWORD; lpProtocolInfo : LPWSAProtocol_Info ) : Longint; external WINSOCK2_DLL name 'WSADuplicateSocket'; +function WSAEnumProtocolsA( lpiProtocols : PLongint; lpProtocolBuffer : LPWSAProtocol_InfoA; var lpdwBufferLength : DWORD ) : Longint; external WINSOCK2_DLL name 'WSAEnumProtocolsA'; +function WSAEnumProtocols( lpiProtocols : PLongint; lpProtocolBuffer : LPWSAProtocol_Info; var lpdwBufferLength : DWORD ) : Longint; external WINSOCK2_DLL name 'WSAEnumProtocols'; +function WSAGetQosByName( s : TSocket; lpQOSName : LPWSABUF; lpQOS : LPQOS ): WordBool; external WINSOCK2_DLL name 'WSAGetQosByName'; +function WSARecvDisconnect( s : TSocket; lpInboundDisconnectData : LPWSABUF ): Longint; external WINSOCK2_DLL name 'WSARecvDisconnect'; +function WSASendDisconnect( s : TSocket; lpOutboundDisconnectData : LPWSABUF ): Longint; external WINSOCK2_DLL name 'WSASendDisconnect'; +function WSASocketA( af, iType, protocol : Longint; lpProtocolInfo : LPWSAProtocol_InfoA; g : GROUP; dwFlags : DWORD ): TSocket; external WINSOCK2_DLL name 'WSASocketA'; +function WSASocket( af, iType, protocol : Longint; lpProtocolInfo : LPWSAProtocol_Info; g : GROUP; dwFlags : DWORD ): TSocket; external WINSOCK2_DLL name 'WSASocket'; +function WSAAddressToStringA( var lpsaAddress : TSockAddr; const dwAddressLength : DWORD; const lpProtocolInfo : LPWSAProtocol_InfoA; + const lpszAddressString : PChar; var lpdwAddressStringLength : DWORD ): Longint; external WINSOCK2_DLL name 'WSAAddressToStringA'; +function WSAAddressToString( var lpsaAddress : TSockAddr; const dwAddressLength : DWORD; const lpProtocolInfo : LPWSAProtocol_Info; + const lpszAddressString : PMBChar; var lpdwAddressStringLength : DWORD ): Longint; external WINSOCK2_DLL name 'WSAAddressToString'; +function WSAStringToAddressA( const AddressString : PChar; const AddressFamily: Longint; const lpProtocolInfo : LPWSAProtocol_InfoA; + var lpAddress : TSockAddr; var lpAddressLength : Longint ): Longint; external WINSOCK2_DLL name 'WSAStringToAddressA'; +function WSAStringToAddress( const AddressString : PMBChar; const AddressFamily: Longint; const lpProtocolInfo : LPWSAProtocol_Info; + var lpAddress : TSockAddr; var lpAddressLength : Longint ): Longint; external WINSOCK2_DLL name 'WSAStringToAddress'; + +{ Registration and Name Resolution API functions } +function WSALookupServiceBeginA( const lpqsRestrictions : LPWSAQuerySetA; const dwControlFlags : DWORD; lphLookup : PHANDLE ): Longint; external WINSOCK2_DLL name 'WSALookupServiceBeginA'; +function WSALookupServiceBegin( const lpqsRestrictions : LPWSAQuerySet; const dwControlFlags : DWORD; lphLookup : PHANDLE ): Longint; external WINSOCK2_DLL name 'WSALookupServiceBegin'; +function WSALookupServiceNextA( const hLookup : THandle; const dwControlFlags : DWORD; var lpdwBufferLength : DWORD; lpqsResults : LPWSAQuerySetA ): Longint; external WINSOCK2_DLL name 'WSALookupServiceNextA'; +function WSALookupServiceNext( const hLookup : THandle; const dwControlFlags : DWORD; var lpdwBufferLength : DWORD; lpqsResults : LPWSAQuerySet ): Longint; external WINSOCK2_DLL name 'WSALookupServiceNext'; +function WSAInstallServiceClassA( const lpServiceClassInfo : LPWSAServiceClassInfoA ) : Longint; external WINSOCK2_DLL name 'WSAInstallServiceClassA'; +function WSAInstallServiceClassW( const lpServiceClassInfo : LPWSAServiceClassInfoW ) : Longint; external WINSOCK2_DLL name 'WSAInstallServiceClassW'; +function WSAInstallServiceClass( const lpServiceClassInfo : LPWSAServiceClassInfo ) : Longint; external WINSOCK2_DLL name 'WSAInstallServiceClass'; +function WSARemoveServiceClass( const lpServiceClassId : PGUID ) : Longint; external WINSOCK2_DLL name 'WSARemoveServiceClass'; +function WSAGetServiceClassInfoA( const lpProviderId : PGUID; const lpServiceClassId : PGUID; var lpdwBufSize : DWORD; + lpServiceClassInfo : LPWSAServiceClassInfoA ): Longint; external WINSOCK2_DLL name 'WSAGetServiceClassInfoA'; +function WSAGetServiceClassInfoW( const lpProviderId : PGUID; const lpServiceClassId : PGUID; var lpdwBufSize : DWORD; + lpServiceClassInfo : LPWSAServiceClassInfoW ): Longint; external WINSOCK2_DLL name 'WSAGetServiceClassInfoW'; +function WSAGetServiceClassInfo( const lpProviderId : PGUID; const lpServiceClassId : PGUID; var lpdwBufSize : DWORD; + lpServiceClassInfo : LPWSAServiceClassInfo ): Longint; external WINSOCK2_DLL name 'WSAGetServiceClassInfo'; +function WSAEnumNameSpaceProvidersA( var lpdwBufferLength: DWORD; const lpnspBuffer: LPWSANameSpace_InfoA ): Longint; external WINSOCK2_DLL name 'WSAEnumNameSpaceProvidersA'; +function WSAEnumNameSpaceProviders( var lpdwBufferLength: DWORD; const lpnspBuffer: LPWSANameSpace_Info ): Longint; external WINSOCK2_DLL name 'WSAEnumNameSpaceProviders'; +function WSAGetServiceClassNameByClassIdA( const lpServiceClassId: PGUID; lpszServiceClassName: PChar; + var lpdwBufferLength: DWORD ): Longint; external WINSOCK2_DLL name 'WSAGetServiceClassNameByClassIdA'; +function WSAGetServiceClassNameByClassIdW( const lpServiceClassId: PGUID; lpszServiceClassName: PWideChar; + var lpdwBufferLength: DWORD ): Longint; external WINSOCK2_DLL name 'WSAGetServiceClassNameByClassIdW'; +function WSAGetServiceClassNameByClassId( const lpServiceClassId: PGUID; lpszServiceClassName: PMBChar; + var lpdwBufferLength: DWORD ): Longint; external WINSOCK2_DLL name 'WSAGetServiceClassNameByClassId'; +function WSASetServiceA( const lpqsRegInfo: LPWSAQuerySetA; const essoperation: TWSAeSetServiceOp; + const dwControlFlags: DWORD ): Longint; external WINSOCK2_DLL name 'WSASetServiceA'; +function WSASetService( const lpqsRegInfo: LPWSAQuerySet; const essoperation: TWSAeSetServiceOp; + const dwControlFlags: DWORD ): Longint; external WINSOCK2_DLL name 'WSASetService'; +//end win only +{$endif not WINCE} + +{$ifdef WINCE} +//begin wince only or not present in current winsock2 +{ + freeaddrinfo + getaddrinfo + getnameinfo + WSAAsyncGetAddrInfo + WSCDeinstallProvider + WSCEnumProtocols + WSCInstallNameSpace + WSCInstallProvider + WSCUnInstallNameSpace + in6addr_any + in6addr_loopback + sethostname + +} +//end wince only +{$endif WINCE} + +//============================================================= +implementation +//============================================================= + + +function WSAMakeSyncReply(Buflen, Error: Word): Longint; +begin + WSAMakeSyncReply:= MakeLong(Buflen, Error); +end; + +function WSAMakeSelectReply(Event, Error: Word): Longint; +begin + WSAMakeSelectReply:= MakeLong(Event, Error); +end; + +function WSAGetAsyncBuflen(Param: Longint): Word; +begin + WSAGetAsyncBuflen:= LOWORD(Param); +end; + +function WSAGetAsyncError(Param: Longint): Word; +begin + WSAGetAsyncError:= HIWORD(Param); +end; + +function WSAGetSelectEvent(Param: Longint): Word; +begin + WSAGetSelectEvent:= LOWORD(Param); +end; + +function WSAGetSelectError(Param: Longint): Word; +begin + WSAGetSelectError:= HIWORD(Param); +end; + +procedure FD_CLR(Socket: TSocket; var FDSet: TFDSet); +var + I: cardinal; +begin + I := 0; + while I < FDSet.fd_count do + begin + if FDSet.fd_array[I] = Socket then + begin + while I < FDSet.fd_count - 1 do + begin + FDSet.fd_array[I] := FDSet.fd_array[I + 1]; + Inc(I); + end; + Dec(FDSet.fd_count); + Break; + end; + Inc(I); + end; +end; + +function FD_ISSET(Socket: TSocket; var FDSet: TFDSet): Boolean; +begin + FD_ISSET := __WSAFDIsSet(Socket, FDSet); +end; + +procedure FD_SET(Socket: TSocket; var FDSet: TFDSet); +begin + if FDSet.fd_count < FD_SETSIZE then + begin + FDSet.fd_array[FDSet.fd_count] := Socket; + Inc(FDSet.fd_count); + end; +end; + +procedure FD_ZERO(var FDSet: TFDSet); +begin + FDSet.fd_count := 0; +end; + + + +end. |