📄 idwinsock2.pas
字号:
{ $HDR$}
{**********************************************************************}
{ Unit archived using Team Coherence }
{ Team Coherence is Copyright 2002 by Quality Software Components }
{ }
{ For further information / comments, visit our WEB site at }
{ http://www.TeamCoherence.com }
{**********************************************************************}
{}
{ $Log: 10425: IdWinSock2.pas
{
{ Rev 1.2 4/20/03 1:54:08 PM RLebeau
{ Updated to better support C++Builder by adding $EXTERNSYM defines to most of
{ the interface declarations, so that they won't be included in the
{ auto-generated HPP file. The native winsock2.h header file is used instead.
{
{ Updated with more of the latest WinSock2 defines and declarations.
}
{
{ Rev 1.1 3/22/2003 09:55:58 PM JPMugaas
{ Commented out definition for TGUID. It is not needed because that is in D4,
{ D5, D6, and D7. It could cause conflicts with other code.
{ Fixed bug where a space would cause the WSACreateEvent not to load.
}
{
{ Rev 1.0 2002.11.12 11:00:26 PM czhower
}
//-------------------------------------------------------------
//
// Borland Delphi Runtime Library
// <API> interface unit
//
// Portions created by Microsoft are
// Copyright (C) 1995-1999 Microsoft Corporation.
// All Rights Reserved.
//
// The original file is: Winsock2.h from CBuilder5 distribution.
// The original Pascal code is: winsock2.pas, released 03 Mar 2001.
// The initial developer of the Pascal code is Alex Konshin
// (alexk@mtgroup.ru).
//-------------------------------------------------------------
{ 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. }
// Note that the original unit is copyrighted by the original author and I did obtain his
// permission to port and use this as part of Indy - J. Peter Mugaas
// 2002-01-28 - Hadi Hariri. Fixes for C++ Builder. Thanks to Chuck Smith.
// 2001 - Oct -25 J. Peter Mugaas
// Made adjustments for Indy usage by
// 1) including removing Trace logging
// 2) renaming and consolidating some .INC files as appropriate
// 3) modifying the unit to follow Indy conventions
// 4) Adding TransmitFile support for the HTTP Server
// 5) Removing all static loading code that was IFDEF'ed. {Do not Localize}
// 2001 - Mar - 1 Alex Konshin
// Revision 3
// converted by Alex Konshin, mailto:alexk@mtgroup.ru
// revision 3, March,1 2001
unit IdWinSock2;
interface
{$ALIGN OFF}
{$RANGECHECKS OFF}
{$WRITEABLECONST OFF}
uses SysUtils, Windows, IdException;
type
EIdWS2StubError = class(EIdException)
protected
FWin32Error : DWORD;
FWin32ErrorMessage : String;
FTitle : String;
public
constructor Build( const ATitle : String; AWin32Error : DWORD );
property Win32Error : DWORD read FWin32Error;
property Win32ErrorMessage : String read FWin32ErrorMessage;
property Title : String read FTitle;
end;
{$DEFINE WS2_DLL_FUNC_VARS}
{$DEFINE INCL_WINSOCK_API_PROTOTYPES}
{$DEFINE INCL_WINSOCK_API_TYPEDEFS}
// Define the current Winsock version. To build an earlier Winsock version
// application redefine this value prior to including Winsock2.h
const
{$EXTERNALSYM WINSOCK_VERSION}
WINSOCK_VERSION = $0202;
WINSOCK2_DLL = 'WS2_32.DLL'; {Do not Localize}
type
{$EXTERNALSYM u_char}
u_char = Byte;
{$EXTERNALSYM u_short}
u_short = Word;
{$EXTERNALSYM u_int}
//u_int = DWORD;
u_int = Integer;
{$EXTERNALSYM u_long}
u_long = DWORD;
// The new type to be used in all instances which refer to sockets.
{$EXTERNALSYM TSocket}
TSocket = u_int;
{$EXTERNALSYM WSAEVENT}
WSAEVENT = THandle;
PWSAEVENT = ^WSAEVENT;
{$EXTERNALSYM LPWSAEVENT}
LPWSAEVENT = PWSAEVENT;
{$IFDEF UNICODE}
PMBChar = PWideChar;
{$ELSE}
PMBChar = PChar;
{$ENDIF}
const
{$EXTERNALSYM FD_SETSIZE}
FD_SETSIZE = 64;
type
// the following emits are a workaround to the name conflicts
// with the winsock2 header files
(*$HPPEMIT '#include <winsock2.h>'*)
(*$HPPEMIT '#include <ws2tcpip.h>'*)
(*$HPPEMIT '#include <wsipx.h>'*)
(*$HPPEMIT '#include <wsnwlink.h>'*)
(*$HPPEMIT '#include <wsnetbs.h>'*)
(*$HPPEMIT '#include <ws2atm.h>'*)
(*$HPPEMIT ''*)
(*$HPPEMIT 'namespace Idwinsock2'*)
(*$HPPEMIT '{'*)
(*$HPPEMIT ' typedef fd_set *PFDSet;'*) // due to name conflict with procedure FD_SET
(*$HPPEMIT ' typedef fd_set TFDSet;'*) // due to name conflict with procedure FD_SET
(*$HPPEMIT '}'*)
(*$HPPEMIT ''*)
// the following emits are to ensure all supported versions
// of C++Builder know about the latest winsock2 structures
(*$HPPEMIT '// versions of Builder prior to 6.0 are missing some of the newer WinSock2 defines'*)
(*$HPPEMIT '#ifdef __BORLANDC__'*)
(*$HPPEMIT '#if (__BORLANDC__ < 0x560) // prior to BCB6'*)
(*$HPPEMIT 'typedef struct in_pktinfo {'*)
(*$HPPEMIT ' IN_ADDR ipi_addr; // destination IPv4 address'*)
(*$HPPEMIT ' UINT ipi_ifindex; // received interface index'*)
(*$HPPEMIT '} IN_PKTINFO;'*)
(*$HPPEMIT ''*)
(*$HPPEMIT 'typedef struct in6_pktinfo {'*)
(*$HPPEMIT ' IN6_ADDR ipi6_addr; // destination IPv6 address'*)
(*$HPPEMIT ' UINT ipi6_ifindex; // received interface index'*)
(*$HPPEMIT '} IN6_PKTINFO;'*)
(*$HPPEMIT ''*)
(*$HPPEMIT 'typedef struct addrinfo {'*)
(*$HPPEMIT ' int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */'*)
(*$HPPEMIT ' int ai_family; /* PF_xxx */'*)
(*$HPPEMIT ' int ai_socktype; /* SOCK_xxx */'*)
(*$HPPEMIT ' int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */'*)
(*$HPPEMIT ' size_t ai_addrlen; /* Length of ai_addr */'*)
(*$HPPEMIT ' char *ai_canonname; /* Canonical name for nodename */'*)
(*$HPPEMIT ' struct sockaddr *ai_addr; /* Binary address */'*)
(*$HPPEMIT ' struct addrinfo *ai_next; /* Next structure in linked list */'*)
(*$HPPEMIT '} ADDRINFO, FAR * LPADDRINFO;'*)
(*$HPPEMIT '#endif'*)
(*$HPPEMIT '#if (__BORLANDC__ < 0x550) // prior to BCB5'*)
(*$HPPEMIT 'typedef struct _INTERFACE_INFO_EX'*)
(*$HPPEMIT '{'*)
(*$HPPEMIT ' u_long iiFlags; /* Interface flags */'*)
(*$HPPEMIT ' SOCKET_ADDRESS iiAddress; /* Interface address */'*)
(*$HPPEMIT ' SOCKET_ADDRESS iiBroadcastAddress; /* Broadcast address */'*)
(*$HPPEMIT ' SOCKET_ADDRESS iiNetmask; /* Network mask */'*)
(*$HPPEMIT '} INTERFACE_INFO_EX, FAR * LPINTERFACE_INFO_EX;'*)
(*$HPPEMIT '#endif'*)
(*$HPPEMIT '#endif'*)
{$NODEFINE PFDSet}
PFDSet = ^TFDSet;
{$NODEFINE TFDSet}
TFDSet = packed record
fd_count: u_int;
fd_array: array[0..FD_SETSIZE-1] of TSocket;
end;
{$EXTERNALSYM timeval}
timeval = record
tv_sec: Longint;
tv_usec: Longint;
end;
TTimeVal = timeval;
PTimeVal = ^TTimeVal;
const
{$EXTERNALSYM IOCPARM_MASK}
IOCPARM_MASK = $7F;
{$EXTERNALSYM IOC_VOID}
IOC_VOID = $20000000;
{$EXTERNALSYM IOC_OUT}
IOC_OUT = $40000000;
{$EXTERNALSYM IOC_IN}
IOC_IN = $80000000;
{$EXTERNALSYM IOC_INOUT}
IOC_INOUT = (IOC_IN or IOC_OUT);
// get # bytes to read
{$EXTERNALSYM FIONREAD}
FIONREAD = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 127; {Do not Localize}
// set/clear non-blocking i/o
{$EXTERNALSYM FIONBIO}
FIONBIO = IOC_IN or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 126; {Do not Localize}
// set/clear async i/o
{$EXTERNALSYM FIOASYNC}
FIOASYNC = IOC_IN or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 125; {Do not Localize}
// Socket I/O Controls
// set high watermark
{$EXTERNALSYM SIOCSHIWAT}
SIOCSHIWAT = IOC_IN or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 0; {Do not Localize}
// get high watermark
{$EXTERNALSYM SIOCGHIWAT}
SIOCGHIWAT = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 1; {Do not Localize}
// set low watermark
{$EXTERNALSYM SIOCSLOWAT}
SIOCSLOWAT = IOC_IN or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 2; {Do not Localize}
// get low watermark
{$EXTERNALSYM SIOCGLOWAT}
SIOCGLOWAT = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 3; {Do not Localize}
// at oob mark?
{$EXTERNALSYM SIOCATMARK}
SIOCATMARK = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 7; {Do not Localize}
// 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).
type
{$EXTERNALSYM hostent}
hostent = packed record
h_name: PChar; // official name of host
h_aliases: ^PChar; // alias list
h_addrtype: Smallint; // host address type
h_length: Smallint; // length of address
case Byte of
0: (h_address_list: ^PChar);
1: (h_addr: PChar); // address, for backward compat
end;
THostEnt = hostent;
PHostEnt = ^THostEnt;
// It is assumed here that a network number
// fits in 32 bits.
{$EXTERNALSYM netent}
netent = packed record
n_name: PChar; // official name of net
n_aliases: ^PChar; // alias list
n_addrtype: Smallint; // net address type
n_net: u_long; // network #
end;
TNetEnt = netent;
PNetEnt = ^TNetEnt;
{$EXTERNALSYM servent}
servent = packed record
s_name: PChar; // official service name
s_aliases: ^PChar; // alias list
{$IFDEF _WIN64}
s_proto: PChar; // protocol to use
s_port: Smallint; // port #
{$ELSE}
s_port: Smallint; // port #
s_proto: PChar; // protocol to use
{$ENDIF}
end;
TServEnt = servent;
PServEnt = ^TServEnt;
{$EXTERNALSYM protoent}
protoent = packed record
p_name: PChar; // official protocol name
p_aliases: ^PChar; // alias list
p_proto: Smallint; // protocol #
end;
TProtoEnt = protoent;
PProtoEnt = ^TProtoEnt;
// Constants and structures defined by the internet system,
// Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
const
// Protocols
{$EXTERNALSYM IPPROTO_IP}
IPPROTO_IP = 0; // dummy for IP
{$EXTERNALSYM IPPROTO_ICMP}
IPPROTO_ICMP = 1; // control message protocol
{$EXTERNALSYM IPPROTO_IGMP}
IPPROTO_IGMP = 2; // group management protocol
{$EXTERNALSYM IPPROTO_GGP}
IPPROTO_GGP = 3; // gateway^2 (deprecated)
{$EXTERNALSYM IPPROTO_TCP}
IPPROTO_TCP = 6; // TCP
{$EXTERNALSYM IPPROTO_PUP}
IPPROTO_PUP = 12; // pup
{$EXTERNALSYM IPPROTO_UDP}
IPPROTO_UDP = 17; // UDP - user datagram protocol
{$EXTERNALSYM IPPROTO_IDP}
IPPROTO_IDP = 22; // xns idp
{$EXTERNALSYM IPPROTO_ND}
IPPROTO_ND = 77; // UNOFFICIAL net disk proto
{$EXTERNALSYM IPPROTO_IPV6}
IPPROTO_IPV6 = 41; // IPv6
{$EXTERNALSYM IPPROTO_ICLFXBM}
IPPROTO_ICLFXBM = 78;
{$EXTERNALSYM IPPROTO_RAW}
IPPROTO_RAW = 255; // raw IP packet
{$EXTERNALSYM IPPROTO_MAX}
IPPROTO_MAX = 256;
// Port/socket numbers: network standard functions
{$EXTERNALSYM IPPORT_ECHO}
IPPORT_ECHO = 7;
{$EXTERNALSYM IPPORT_DISCARD}
IPPORT_DISCARD = 9;
{$EXTERNALSYM IPPORT_SYSTAT}
IPPORT_SYSTAT = 11;
{$EXTERNALSYM IPPORT_DAYTIME}
IPPORT_DAYTIME = 13;
{$EXTERNALSYM IPPORT_NETSTAT}
IPPORT_NETSTAT = 15;
{$EXTERNALSYM IPPORT_FTP}
IPPORT_FTP = 21;
{$EXTERNALSYM IPPORT_TELNET}
IPPORT_TELNET = 23;
{$EXTERNALSYM IPPORT_SMTP}
IPPORT_SMTP = 25;
{$EXTERNALSYM IPPORT_TIMESERVER}
IPPORT_TIMESERVER = 37;
{$EXTERNALSYM IPPORT_NAMESERVER}
IPPORT_NAMESERVER = 42;
{$EXTERNALSYM IPPORT_WHOIS}
IPPORT_WHOIS = 43;
{$EXTERNALSYM IPPORT_MTP}
IPPORT_MTP = 57;
// Port/socket numbers: host specific functions
{$EXTERNALSYM IPPORT_TFTP}
IPPORT_TFTP = 69;
{$EXTERNALSYM IPPORT_RJE}
IPPORT_RJE = 77;
{$EXTERNALSYM IPPORT_FINGER}
IPPORT_FINGER = 79;
{$EXTERNALSYM ipport_ttylink}
IPPORT_TTYLINK = 87;
{$EXTERNALSYM IPPORT_SUPDUP}
IPPORT_SUPDUP = 95;
// UNIX TCP sockets
{$EXTERNALSYM IPPORT_EXECSERVER}
IPPORT_EXECSERVER = 512;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -