?? wsocket.pas
字號:
TGetProtoByName = function (name: PChar): PProtoEnt; stdcall;
TGetHostByName = function (name: PChar): PHostEnt; stdcall;
TGetHostByAddr = function (addr: Pointer; len, Struct: Integer): PHostEnt; stdcall;
TGetHostName = function (name: PChar; len: Integer): Integer; stdcall;
TOpenSocket = function (af, Struct, protocol: Integer): TSocket; stdcall;
TShutdown = function (s: TSocket; how: Integer): Integer; stdcall;
TSetSockOpt = function (s: TSocket; level, optname: Integer;
optval: PChar;
optlen: Integer): Integer; stdcall;
TGetSockOpt = function (s: TSocket; level, optname: Integer;
optval: PChar;
var optlen: Integer): Integer; stdcall;
TSendTo = function (s: TSocket; var Buf;
len, flags: Integer;
var addrto: TSockAddr;
tolen: Integer): Integer; stdcall;
TSend = function (s: TSocket; var Buf;
len, flags: Integer): Integer; stdcall;
TRecv = function (s: TSocket;
var Buf;
len, flags: Integer): Integer; stdcall;
TRecvFrom = function (s: TSocket;
var Buf; len, flags: Integer;
var from: TSockAddr;
var fromlen: Integer): Integer; stdcall;
Tntohs = function (netshort: u_short): u_short; stdcall;
Tntohl = function (netlong: u_long): u_long; stdcall;
TListen = function (s: TSocket;
backlog: Integer): Integer; stdcall;
TIoctlSocket = function (s: TSocket; cmd: DWORD;
var arg: u_long): Integer; stdcall;
TInet_ntoa = function (inaddr: TInAddr): PChar; stdcall;
TInet_addr = function (cp: PChar): u_long; stdcall;
Thtons = function (hostshort: u_short): u_short; stdcall;
Thtonl = function (hostlong: u_long): u_long; stdcall;
TGetSockName = function (s: TSocket; var name: TSockAddr;
var namelen: Integer): Integer; stdcall;
TGetPeerName = function (s: TSocket; var name: TSockAddr;
var namelen: Integer): Integer; stdcall;
TConnect = function (s: TSocket; var name: TSockAddr;
namelen: Integer): Integer; stdcall;
TCloseSocket = function (s: TSocket): Integer; stdcall;
TBind = function (s: TSocket; var addr: TSockAddr;
namelen: Integer): Integer; stdcall;
{$IFDEF VER90} { Delphi 2 has a special definition}
TAccept = function (s: TSocket; var addr: TSockAddr;
var addrlen: Integer): TSocket; stdcall;
{$ELSE}
TAccept = function (s: TSocket; addr: PSockAddr;
addrlen: PInteger): TSocket; stdcall;
{$ENDIF}
{$ENDIF}
var
FWSAStartup : TWSAStartup;
FWSACleanup : TWSACleanup;
FWSASetLastError : TWSASetLastError;
FWSAGetLastError : TWSAGetLastError;
FWSACancelAsyncRequest : TWSACancelAsyncRequest;
FWSAAsyncGetHostByName : TWSAAsyncGetHostByName;
FWSAAsyncGetHostByAddr : TWSAAsyncGetHostByAddr;
FWSAAsyncSelect : TWSAAsyncSelect;
FGetServByName : TGetServByName;
FGetProtoByName : TGetProtoByName;
FGetHostByName : TGetHostByName;
FGetHostByAddr : TGetHostByAddr;
FGetHostName : TGetHostName;
FOpenSocket : TOpenSocket;
FShutdown : TShutdown;
FSetSockOpt : TSetSockOpt;
FGetSockOpt : TGetSockOpt;
FSendTo : TSendTo;
FSend : TSend;
FRecv : TRecv;
FRecvFrom : TRecvFrom;
Fntohs : Tntohs;
Fntohl : Tntohl;
FListen : TListen;
FIoctlSocket : TIoctlSocket;
FInet_ntoa : TInet_ntoa;
FInet_addr : TInet_addr;
Fhtons : Thtons;
Fhtonl : Thtonl;
FGetSockName : TGetSockName;
FGetPeerName : TGetPeerName;
FConnect : TConnect;
FCloseSocket : TCloseSocket;
FBind : TBind;
FAccept : TAccept;
function WSocketGetProc(const ProcName : String) : Pointer;
function WSocket_WSAStartup(wVersionRequired: word;
var WSData: TWSAData): Integer;
function WSocket_WSACleanup : Integer;
procedure WSocket_WSASetLastError(iError: Integer);
function WSocket_WSAGetLastError: Integer;
function WSocket_WSACancelAsyncRequest(hAsyncTaskHandle: THandle): Integer;
function WSocket_WSAAsyncGetHostByName(HWindow: HWND; wMsg: u_int;
name, buf: PChar;
buflen: Integer): THandle;
function WSocket_WSAAsyncGetHostByAddr(HWindow: HWND;
wMsg: u_int; addr: PChar;
len, Struct: Integer;
buf: PChar;
buflen: Integer): THandle;
function WSocket_WSAAsyncSelect(s: TSocket; HWindow: HWND; wMsg: u_int; lEvent: Longint): Integer;
function WSocket_recv(s: TSocket;
var Buf; len, flags: Integer): Integer;
function WSocket_recvfrom(s: TSocket;
var Buf; len, flags: Integer;
var from: TSockAddr;
var fromlen: Integer): Integer;
function WSocket_getservbyname(name, proto: PChar): PServEnt;
function WSocket_getprotobyname(name: PChar): PProtoEnt;
function WSocket_gethostbyname(name: PChar): PHostEnt;
function WSocket_gethostbyaddr(addr: Pointer; len, Struct: Integer): PHostEnt;
function WSocket_gethostname(name: PChar; len: Integer): Integer;
function WSocket_socket(af, Struct, protocol: Integer): TSocket;
function WSocket_shutdown(s: TSocket; how: Integer): Integer;
function WSocket_setsockopt(s: TSocket; level, optname: Integer; optval: PChar;
optlen: Integer): Integer;
function WSocket_getsockopt(s: TSocket; level, optname: Integer; optval: PChar;
var optlen: Integer): Integer;
function WSocket_sendto(s: TSocket; var Buf; len, flags: Integer;
var addrto: TSockAddr;
tolen: Integer): Integer;
function WSocket_send(s: TSocket; var Buf; len, flags: Integer): Integer;
function WSocket_ntohs(netshort: u_short): u_short;
function WSocket_ntohl(netlong: u_long): u_long;
function WSocket_listen(s: TSocket; backlog: Integer): Integer;
function WSocket_ioctlsocket(s: TSocket; cmd: DWORD; var arg: u_long): Integer;
function WSocket_inet_ntoa(inaddr: TInAddr): PChar;
function WSocket_inet_addr(cp: PChar): u_long;
function WSocket_htons(hostshort: u_short): u_short;
function WSocket_htonl(hostlong: u_long): u_long;
function WSocket_getsockname(s: TSocket; var name: TSockAddr;
var namelen: Integer): Integer;
function WSocket_getpeername(s: TSocket; var name: TSockAddr;
var namelen: Integer): Integer;
function WSocket_connect(s: TSocket; var name: TSockAddr;
namelen: Integer): Integer;
function WSocket_closesocket(s: TSocket): Integer;
function WSocket_bind(s: TSocket; var addr: TSockAddr; namelen: Integer): Integer;
{$IFDEF VER80}
function WSocket_accept(s: TSocket; var addr: TSockAddr; var addrlen: Integer): TSocket;
{$ELSE}
{$IFDEF VER90}
function WSocket_accept(s: TSocket; var addr: TSockAddr; var addrlen: Integer): TSocket;
{$ELSE}
function WSocket_accept(s: TSocket; addr: PSockAddr; addrlen: PInteger): TSocket;
{$ENDIF}
{$ENDIF}
const
WSocketGCount : integer = 0;
WSocketGForced : boolean = FALSE;
implementation
const
{ WSocketGCount : integer = 0; }
{ DllStarted : Boolean = FALSE; 14/02/99}
FDllHandle : THandle = 0;
{ FDllName : String = winsocket; }
socksNoError = 20000;
socksProtocolError = 20001;
socksVersionError = 20002;
socksAuthMethodError = 20003;
socksGeneralFailure = 20004;
socksConnectionNotAllowed = 20005;
socksNetworkUnreachable = 20006;
socksHostUnreachable = 20007;
socksConnectionRefused = 20008;
socksTtlExpired = 20009;
socksUnknownCommand = 20010;
socksUnknownAddressType = 20011;
socksUnassignedError = 20012;
socksInternalError = 20013;
socksDataReceiveError = 20014;
socksAuthenticationFailed = 20015;
socksRejectedOrFailed = 20016;
socksHostResolutionFailed = 20017;
var
GInitData : TWSADATA;
IPList : TStrings;
procedure Register;
begin
RegisterComponents('FPiette', [TWSocket]);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{$IFDEF VER80}
procedure SetLength(var S: string; NewLength: Integer);
begin
S[0] := chr(NewLength);
end;
{$ENDIF}
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function atoi(value : string) : Integer;
var
i : Integer;
begin
Result := 0;
i := 1;
while (i <= Length(Value)) and (Value[i] = ' ') do
i := i + 1;
while (i <= Length(Value)) and (Value[i] >= '0') and (Value[i] <= '9')do begin
Result := Result * 10 + ord(Value[i]) - ord('0');
i := i + 1;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function IsDigit(Ch : Char) : Boolean;
begin
Result := (ch >= '0') and (ch <= '9');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ Check for a valid numeric dotted IP address such as 192.161.65.25 }
{ Accept leading and trailing spaces. }
function WSocketIsDottedIP(const S : String) : Boolean;
var
I : Integer;
DotCount : Integer;
NumVal : Integer;
begin
Result := FALSE;
DotCount := 0;
NumVal := 0;
I := 1;
{ Skip leading spaces }
while (S[I] = ' ') and (I <= Length(S)) do
Inc(I);
{ Can't begin with a dot }
if (I <= Length(S)) and (S[I] = '.') then
Exit;
{ Scan full string }
while I <= Length(S) do begin
if S[I] = '.'
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -