📄 jwaws2tcpip.pas
字号:
{******************************************************************************}
{ }
{ Winsock2 TCP/IP Extensions API interface Unit for Object Pascal }
{ }
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
{ Corporation. All Rights Reserved. }
{ }
{ The original file is: ws2tcpip.h, released June 2000. The original Pascal }
{ code is: WS2tcpip.pas, released December 2000. The initial developer of the }
{ Pascal code is Marcel van Brakel (brakelm@chello.nl). }
{ }
{ Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
{ Marcel van Brakel. All Rights Reserved. }
{ }
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project JEDI home }
{ page, located at http://delphi-jedi.org or my personal homepage located at }
{ http://members.chello.nl/m.vanbrakel2 }
{ }
{ The contents of this file are used with permission, subject to the Mozilla }
{ Public License Version 1.1 (the "License"); you may not use this file except }
{ in compliance with the License. You may obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, }
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
{ the specific language governing rights and limitations under the License. }
{ }
{ Alternatively, the contents of this file may be used under the terms of the }
{ GNU Lesser General Public License (the "LGPL License"), in which case the }
{ provisions of the LGPL License are applicable instead of those above. }
{ If you wish to allow use of your version of this file only under the terms }
{ of the LGPL License and not to allow others to use your version of this file }
{ under the MPL, indicate your decision by deleting the provisions above and }
{ replace them with the notice and other provisions required by the LGPL }
{ License. If you do not delete the provisions above, a recipient may use }
{ your version of this file under either the MPL or the LGPL License. }
{ }
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
{ }
{******************************************************************************}
unit JwaWS2tcpip;
{$WEAKPACKAGEUNIT}
{$HPPEMIT ''}
{$HPPEMIT '#include "ws2tcpip.h"'}
{$HPPEMIT ''}
{$I WINDEFINES.INC}
interface
uses
JwaWinSock2, JwaWinType;
//
// WS2TCPIP.H - WinSock2 Extension for TCP/IP protocols
//
// This file contains TCP/IP specific information for use
// by WinSock2 compatible applications.
//
// Copyright (c) 1995-1999 Microsoft Corporation
//
// To provide the backward compatibility, all the TCP/IP
// specific definitions that were included in the WINSOCK.H
// file are now included in WINSOCK2.H file. WS2TCPIP.H
// file includes only the definitions introduced in the
// "WinSock 2 Protocol-Specific Annex" document.
//
// Rev 0.3 Nov 13, 1995
// Rev 0.4 Dec 15, 1996
//
// Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP
type
ip_mreq = record
imr_multiaddr: in_addr; // IP multicast address of group
imr_interface: in_addr; // local IP address of interface
end;
{$EXTERNALSYM ip_mreq}
TIPMReq = ip_mreq;
PIPMReq = ^ip_mreq;
// Argument structure for IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
// IP_BLOCK_SOURCE, and IP_UNBLOCK_SOURCE
//
ip_mreq_source = record
imr_multiaddr: in_addr; // IP multicast address of group
imr_sourceaddr: in_addr; // IP address of source
imr_interface: in_addr; // local IP address of interface
end;
{$EXTERNALSYM ip_mreq_source}
TIpMreqSource = ip_mreq_source;
PIpMreqSource = ^ip_mreq_source;
// Argument structure for SIO_{GET,SET}_MULTICAST_FILTER
ip_msfilter = record
imsf_multiaddr: in_addr; // IP multicast address of group
imsf_interface: in_addr; // local IP address of interface
imsf_fmode: u_long; // filter mode - INCLUDE or EXCLUDE
imsf_numsrc: u_long; // number of sources in src_list
imsf_slist: array [0..0] of in_addr;
end;
{$EXTERNALSYM ip_msfilter}
TIpMsFilter = ip_msfilter;
PIpMsFilter = ^ip_msfilter;
function IP_MSFILTER_SIZE(numsrc: Integer): Integer;
{$EXTERNALSYM IP_MSFILTER_SIZE(numsrc)}
const
MCAST_INCLUDE = 0;
{$EXTERNALSYM MCAST_INCLUDE}
MCAST_EXCLUDE = 1;
{$EXTERNALSYM MCAST_EXCLUDE}
// TCP/IP specific Ioctl codes
const
SIO_GET_INTERFACE_LIST = IOC_OUT or ((4 and IOCPARM_MASK) shl 16) or ((Ord('t')) shl 8) or (127);
{$EXTERNALSYM SIO_GET_INTERFACE_LIST}
// New IOCTL with address size independent address array
SIO_GET_INTERFACE_LIST_EX = IOC_OUT or ((4 and IOCPARM_MASK) shl 16) or ((Ord('t')) shl 8) or (126);
{$EXTERNALSYM SIO_GET_INTERFACE_LIST_EX}
SIO_SET_MULTICAST_FILTER = DWORD(IOC_IN or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('t') shl 8) or 125);
{$EXTERNALSYM SIO_SET_MULTICAST_FILTER}
SIO_GET_MULTICAST_FILTER = DWORD(IOC_IN or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('t') shl 8) or 124 or IOC_IN);
{$EXTERNALSYM SIO_GET_MULTICAST_FILTER}
// Option to use with [gs]etsockopt at the IPPROTO_IP level
const
IP_OPTIONS = 1; // set/get IP options
{$EXTERNALSYM IP_OPTIONS}
IP_HDRINCL = 2; // header is included with data
{$EXTERNALSYM IP_HDRINCL}
IP_TOS = 3; // IP type of service and preced
{$EXTERNALSYM IP_TOS}
IP_TTL = 4; // IP time to live
{$EXTERNALSYM IP_TTL}
IP_MULTICAST_IF = 9; // set/get IP multicast i/f
{$EXTERNALSYM IP_MULTICAST_IF}
IP_MULTICAST_TTL = 10; // set/get IP multicast ttl
{$EXTERNALSYM IP_MULTICAST_TTL}
IP_MULTICAST_LOOP = 11; // set/get IP multicast loopback
{$EXTERNALSYM IP_MULTICAST_LOOP}
IP_ADD_MEMBERSHIP = 12; // add an IP group membership
{$EXTERNALSYM IP_ADD_MEMBERSHIP}
IP_DROP_MEMBERSHIP = 13; // drop an IP group membership
{$EXTERNALSYM IP_DROP_MEMBERSHIP}
IP_DONTFRAGMENT = 14; // don't fragment IP datagrams
{$EXTERNALSYM IP_DONTFRAGMENT}
IP_ADD_SOURCE_MEMBERSHIP = 15; // join IP group/source
{$EXTERNALSYM IP_ADD_SOURCE_MEMBERSHIP}
IP_DROP_SOURCE_MEMBERSHIP = 16; // leave IP group/source
{$EXTERNALSYM IP_DROP_SOURCE_MEMBERSHIP}
IP_BLOCK_SOURCE = 17; // block IP group/source
{$EXTERNALSYM IP_BLOCK_SOURCE}
IP_UNBLOCK_SOURCE = 18; // unblock IP group/source
{$EXTERNALSYM IP_UNBLOCK_SOURCE}
IP_PKTINFO = 19; // receive packet information for ipv4
{$EXTERNALSYM IP_PKTINFO}
// Option to use with [gs]etsockopt at the IPPROTO_IPV6 level
IPV6_HDRINCL = 2; // Header is included with data
{$EXTERNALSYM IPV6_HDRINCL}
IPV6_UNICAST_HOPS = 4; // Set/get IP unicast hop limit
{$EXTERNALSYM IPV6_UNICAST_HOPS}
IPV6_MULTICAST_IF = 9; // Set/get IP multicast interface
{$EXTERNALSYM IPV6_MULTICAST_IF}
IPV6_MULTICAST_HOPS = 10; // Set/get IP multicast ttl
{$EXTERNALSYM IPV6_MULTICAST_HOPS}
IPV6_MULTICAST_LOOP = 11; // Set/get IP multicast loopback
{$EXTERNALSYM IPV6_MULTICAST_LOOP}
IPV6_ADD_MEMBERSHIP = 12; // Add an IP group membership
{$EXTERNALSYM IPV6_ADD_MEMBERSHIP}
IPV6_DROP_MEMBERSHIP = 13; // Drop an IP group membership
{$EXTERNALSYM IPV6_DROP_MEMBERSHIP}
IPV6_JOIN_GROUP = IPV6_ADD_MEMBERSHIP;
{$EXTERNALSYM IPV6_JOIN_GROUP}
IPV6_LEAVE_GROUP = IPV6_DROP_MEMBERSHIP;
{$EXTERNALSYM IPV6_LEAVE_GROUP}
IPV6_PKTINFO = 19; // Receive packet information for ipv6
{$EXTERNALSYM IPV6_PKTINFO}
// Option to use with [gs]etsockopt at the IPPROTO_UDP level
UDP_NOCHECKSUM = 1;
{$EXTERNALSYM UDP_NOCHECKSUM}
UDP_CHECKSUM_COVERAGE = 20; // Set/get UDP-Lite checksum coverage
{$EXTERNALSYM UDP_CHECKSUM_COVERAGE}
// Option to use with [gs]etsockopt at the IPPROTO_TCP level
TCP_EXPEDITED_1122 = $0002;
{$EXTERNALSYM TCP_EXPEDITED_1122}
// IPv6 definitions
type
in6_addr = record
case Integer of
0: (Byte: array [0..15] of u_char);
1: (Word: array[0..7] of u_short);
2: (s6_bytes: array [0..15] of u_char);
3: (s6_addr: array [0..15] of u_char);
4: (s6_words: array[0..7] of u_short);
end;
{$EXTERNALSYM in6_addr}
TIn6Addr = in6_addr;
PIn6Addr = ^in6_addr;
//
// Defines to match RFC 2553.
//
//#define _S6_un u
//#define _S6_u8 Byte
// Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP
type
ipv6_mreq = record
ipv6mr_multiaddr: in6_addr; // IPv6 multicast address
ipv6mr_interface: Cardinal; // Interface index
end;
{$EXTERNALSYM ipv6_mreq}
TIpV6MReq = ipv6_mreq;
PIpV6MReq = ^ipv6_mreq;
type
in_addr6 = record
s6_addr: array [0..15] of u_char; // IPv6 address
end;
{$EXTERNALSYM in_addr6}
TInAddr6 = in_addr6;
PInAddr6 = ^in_addr6;
// Old IPv6 socket address structure (retained for sockaddr_gen definition below)
type
sockaddr_in6_old = record
sin6_family: short; // AF_INET6
sin6_port: u_short; // Transport level port number
sin6_flowinfo: u_long; // IPv6 flow information
sin6_addr: in6_addr; // IPv6 address
end;
{$EXTERNALSYM sockaddr_in6_old}
TSockAddrIn6Old = sockaddr_in6_old;
PSockAddrIn6Old = ^sockaddr_in6_old;
// IPv6 socket address structure, RFC 2553
SOCKADDR_IN6 = record
sin6_family: short; // AF_INET6
sin6_port: u_short; // Transport level port number
sin6_flowinfo: u_long; // IPv6 flow information
sin6_addr: in6_addr; // IPv6 address
sin6_scope_id: u_long; // set of interfaces for a scope
end;
{$EXTERNALSYM SOCKADDR_IN6}
PSOCKADDR_IN6 = ^SOCKADDR_IN6;
{$EXTERNALSYM PSOCKADDR_IN6}
LPSOCKADDR_IN6 = ^SOCKADDR_IN6;
{$EXTERNALSYM LPSOCKADDR_IN6}
TSockAddrIn6 = SOCKADDR_IN6;
PSockAddrIn6 = LPSOCKADDR_IN6;
// Macro that works for both IPv4 and IPv6
function SS_PORT(ssp: Pointer): u_short;
{$EXTERNALSYM SS_PORT}
const
IN6ADDR_ANY_INIT: in6_addr = (Word: (0, 0, 0, 0, 0, 0, 0, 0));
{$EXTERNALSYM IN6ADDR_ANY_INIT}
IN6ADDR_LOOPBACK_INIT: in6_addr = (Byte: (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1));
{$EXTERNALSYM IN6ADDR_LOOPBACK_INIT}
in6addr_any: in6_addr = (Word: (0, 0, 0, 0, 0, 0, 0, 0));
{$EXTERNALSYM in6addr_any}
in6addr_loopback: in6_addr = (Byte: (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1));
{$EXTERNALSYM in6addr_loopback}
procedure IN6ADDR_SETANY(var x: TSockAddrIn6);
{$EXTERNALSYM IN6ADDR_SETANY}
procedure IN6ADDR_SETLOOPBACK(var x: TSockAddrIn6);
{$EXTERNALSYM IN6ADDR_SETLOOPBACK}
function IN6ADDR_ISANY(const x: TSockAddrIn6): Boolean;
{$EXTERNALSYM IN6ADDR_ISANY}
function IN6ADDR_ISLOOPBACK(const x: TSockAddrIn6): Boolean;
{$EXTERNALSYM IN6ADDR_ISLOOPBACK}
function IN6_ADDR_EQUAL(const a, b: in6_addr): Boolean;
{$EXTERNALSYM IN6_ADDR_EQUAL}
function IN6_IS_ADDR_UNSPECIFIED(const a: in6_addr): boolean;
{$EXTERNALSYM IN6_IS_ADDR_UNSPECIFIED}
function IN6_IS_ADDR_LOOPBACK(const a: in6_addr): Boolean;
{$EXTERNALSYM IN6_IS_ADDR_LOOPBACK}
function IN6_IS_ADDR_MULTICAST(const a: in6_addr): Boolean;
{$EXTERNALSYM IN6_IS_ADDR_MULTICAST}
function IN6_IS_ADDR_LINKLOCAL(const a: in6_addr): Boolean;
{$EXTERNALSYM IN6_IS_ADDR_LINKLOCAL}
function IN6_IS_ADDR_SITELOCAL(const a: in6_addr): Boolean;
{$EXTERNALSYM IN6_IS_ADDR_SITELOCAL}
function IN6_IS_ADDR_V4MAPPED(const a: in6_addr): Boolean;
{$EXTERNALSYM IN6_IS_ADDR_V4MAPPED}
function IN6_IS_ADDR_V4COMPAT(const a: in6_addr): Boolean;
{$EXTERNALSYM IN6_IS_ADDR_V4COMPAT}
function IN6_IS_ADDR_MC_NODELOCAL(const a: in6_addr): Boolean;
{$EXTERNALSYM IN6_IS_ADDR_MC_NODELOCAL}
function IN6_IS_ADDR_MC_LINKLOCAL(const a: in6_addr): Boolean;
{$EXTERNALSYM IN6_IS_ADDR_MC_LINKLOCAL}
function IN6_IS_ADDR_MC_SITELOCAL(const a: in6_addr): Boolean;
{$EXTERNALSYM IN6_IS_ADDR_MC_SITELOCAL}
function IN6_IS_ADDR_MC_ORGLOCAL(const a: in6_addr): Boolean;
{$EXTERNALSYM IN6_IS_ADDR_MC_ORGLOCAL}
function IN6_IS_ADDR_MC_GLOBAL(const a: in6_addr): Boolean;
{$EXTERNALSYM IN6_IS_ADDR_MC_GLOBAL}
type
sockaddr_gen = record
case Integer of
0: (Address: sockaddr);
1: (AddressIn: sockaddr_in);
2: (AddressIn6: sockaddr_in6_old);
end;
{$EXTERNALSYM sockaddr_gen}
TSockAddrGen = sockaddr_gen;
PSockAddrGen = ^sockaddr_gen;
// Structure to keep interface specific information
_INTERFACE_INFO = record
iiFlags: u_long; // Interface flags
iiAddress: sockaddr_gen; // Interface address
iiBroadcastAddress: sockaddr_gen; // Broadcast address
iiNetmask: sockaddr_gen; // Network mask
end;
{$EXTERNALSYM _INTERFACE_INFO}
INTERFACE_INFO = _INTERFACE_INFO;
{$EXTERNALSYM INTERFACE_INFO}
LPINTERFACE_INFO = ^INTERFACE_INFO;
{$EXTERNALSYM LPINTERFACE_INFO}
TInterfaceInfo = INTERFACE_INFO;
PInterfaceInfo = LPINTERFACE_INFO;
// New structure that does not have dependency on the address size
_INTERFACE_INFO_EX = record
iiFlags: u_long; // Interface flags
iiAddress: SOCKET_ADDRESS; // Interface address
iiBroadcastAddress: SOCKET_ADDRESS; // Broadcast address
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -