1
{******************************************************************************}
3
{ Winsock API interface Unit for Object Pascal }
5
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
6
{ Corporation. All Rights Reserved. }
8
{ The original file is: winsock.h, released June 2000. The original Pascal }
9
{ code is: WinSock.pas, released December 2000. The initial developer of the }
10
{ Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
12
{ Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
13
{ Marcel van Brakel. All Rights Reserved. }
15
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
17
{ You may retrieve the latest version of this file at the Project JEDI }
18
{ APILIB home page, located at http://jedi-apilib.sourceforge.net }
20
{ The contents of this file are used with permission, subject to the Mozilla }
21
{ Public License Version 1.1 (the "License"); you may not use this file except }
22
{ in compliance with the License. You may obtain a copy of the License at }
23
{ http://www.mozilla.org/MPL/MPL-1.1.html }
25
{ Software distributed under the License is distributed on an "AS IS" basis, }
26
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
27
{ the specific language governing rights and limitations under the License. }
29
{ Alternatively, the contents of this file may be used under the terms of the }
30
{ GNU Lesser General Public License (the "LGPL License"), in which case the }
31
{ provisions of the LGPL License are applicable instead of those above. }
32
{ If you wish to allow use of your version of this file only under the terms }
33
{ of the LGPL License and not to allow others to use your version of this file }
34
{ under the MPL, indicate your decision by deleting the provisions above and }
35
{ replace them with the notice and other provisions required by the LGPL }
36
{ License. If you do not delete the provisions above, a recipient may use }
37
{ your version of this file under either the MPL or the LGPL License. }
39
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
41
{******************************************************************************}
43
// $Id: jwawinsock.pas,v 1.1 2005/04/04 07:56:11 marco Exp $
50
{$HPPEMIT '#include "winsock.h"'}
58
JwaWinType, JwaWinBase;
61
* Basic system type definitions, taken from the BSD file sys/types.h.
68
{$EXTERNALSYM u_short}
75
* The new type to be used in all
76
* instances which refer to sockets.
83
* Select uses arrays of SOCKETs. These macros manipulate such
84
* arrays. FD_SETSIZE may be defined by the user before including
85
* this file, but the default here should be >= 64.
87
* CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
88
* INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
93
{$EXTERNALSYM FD_SETSIZE}
97
fd_count: u_int; // how many are SET?
98
fd_array: array [0..FD_SETSIZE - 1] of TSocket; // an array of SOCKETs
100
{$EXTERNALSYM fd_set}
104
function __WSAFDIsSet(s: TSocket; var FDSet: TFDSet): Integer; stdcall;
105
{$EXTERNALSYM __WSAFDIsSet}
107
procedure FD_CLR(fd: TSocket; var fdset: TFdSet);
108
{$EXTERNALSYM FD_CLR}
110
procedure _FD_SET(fd: TSocket; var fdset: TFDSet);
111
//{$EXTERNALSYM FD_SET}
113
procedure FD_ZERO(var fdset: TFdSet);
114
{$EXTERNALSYM FD_ZERO}
116
function FD_ISSET(fd: TSocket; var fdset: TFdSet): Boolean;
117
{$EXTERNALSYM FD_ISSET}
120
* Structure used in select() call, taken from the BSD file sys/time.h.
125
tv_sec: Longint; // seconds
126
tv_usec: Longint; // and microseconds
128
{$EXTERNALSYM timeval}
133
* Operations on timevals.
135
* NB: timercmp does not work for >= or <=.
138
function timerisset(const tvp: TTimeVal): Boolean;
139
{$EXTERNALSYM timerisset}
141
//function timercmp(const tvp, uvp: TTimeVal; cmp): Boolean;
142
//{$EXTERNALSYM timercmp}
144
procedure timerclear(var tvp: TTimeVal);
145
{$EXTERNALSYM timerclear}
148
* Commands for ioctlsocket(), taken from the BSD file fcntl.h.
151
* Ioctl's have the command encoded in the lower word,
152
* and the size of any in or out parameters in the upper
153
* word. The high 2 bits of the upper word are used
154
* to encode the in/out status of the parameter; for now
155
* we restrict parameters to at most 128 bytes.
159
IOCPARM_MASK = $7f; // parameters must be < 128 bytes
160
{$EXTERNALSYM IOCPARM_MASK}
161
IOC_VOID = $20000000; // no parameters
162
{$EXTERNALSYM IOC_VOID}
163
IOC_OUT = $40000000; // copy out parameters
164
{$EXTERNALSYM IOC_OUT}
165
IOC_IN = DWORD($80000000); // copy in parameters
166
{$EXTERNALSYM IOC_IN}
167
IOC_INOUT = DWORD(IOC_IN or IOC_OUT);
168
{$EXTERNALSYM IOC_INOUT}
170
// 0x20000000 distinguishes new & old ioctl's
172
function _IO(x, y: DWORD): DWORD;
175
function _IOR(x, y, t: DWORD): DWORD;
178
function _IOW(x, y, t: DWORD): DWORD;
182
FIONREAD = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 127; // get # bytes to read
183
{$EXTERNALSYM FIONREAD}
184
FIONBIO = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 126; // set/clear non-blocking i/o
185
{$EXTERNALSYM FIONBIO}
186
FIOASYNC = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 125; // set/clear async i/o
187
{$EXTERNALSYM FIOASYNC}
189
(* Socket I/O Controls *)
191
SIOCSHIWAT = DWORD(IOC_IN or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 0); // set high watermark
192
{$EXTERNALSYM SIOCSHIWAT}
193
SIOCGHIWAT = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 1; // get high watermark
194
{$EXTERNALSYM SIOCGHIWAT}
195
SIOCSLOWAT = DWORD(IOC_IN or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 2); // set low watermark
196
{$EXTERNALSYM SIOCSLOWAT}
197
SIOCGLOWAT = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 3; // get low watermark
198
{$EXTERNALSYM SIOCGLOWAT}
199
SIOCATMARK = IOC_OUT or ((SizeOf(u_long) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 7; // at oob mark?
200
{$EXTERNALSYM SIOCATMARK}
203
* Structures returned by network data base library, taken from the
204
* BSD file netdb.h. All addresses are supplied in host order, and
205
* returned in network order (suitable for use in system calls).
210
h_name: PChar; // official name of host
211
h_aliases: PPChar; // alias list
212
h_addrtype: Smallint; // host address type
213
h_length: Smallint; // length of address
215
0: (h_addr_list: PPChar); // list of addresses
216
1: (h_addr: PPChar); // address, for backward compat
218
{$EXTERNALSYM hostent}
223
* It is assumed here that a network number
229
n_name: PChar; // official name of net
230
n_aliases: PPChar; // alias list
231
n_addrtype: Smallint; // net address type
232
n_net: u_long; // network #
234
{$EXTERNALSYM netent}
239
s_name: PChar; // official service name
240
s_aliases: PPChar; // alias list
241
s_port: Smallint; // port #
242
s_proto: PChar; // protocol to use
244
{$EXTERNALSYM servent}
249
p_name: PChar; // official protocol name
250
p_aliases: PPChar; // alias list
251
p_proto: Smallint; // protocol #
253
{$EXTERNALSYM protoent}
254
TProtoEnt = protoent;
255
PProtoEnt = ^protoent;
258
* Constants and structures defined by the internet system,
259
* Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
267
IPPROTO_IP = 0; // dummy for IP
268
{$EXTERNALSYM IPPROTO_IP}
269
IPPROTO_ICMP = 1; // control message protocol
270
{$EXTERNALSYM IPPROTO_ICMP}
271
IPPROTO_IGMP = 2; // internet group management protocol
272
{$EXTERNALSYM IPPROTO_IGMP}
273
IPPROTO_GGP = 3; // gateway^2 (deprecated)
274
{$EXTERNALSYM IPPROTO_GGP}
275
IPPROTO_TCP = 6; // tcp
276
{$EXTERNALSYM IPPROTO_TCP}
277
IPPROTO_PUP = 12; // pup
278
{$EXTERNALSYM IPPROTO_PUP}
279
IPPROTO_UDP = 17; // user datagram protocol
280
{$EXTERNALSYM IPPROTO_UDP}
281
IPPROTO_IDP = 22; // xns idp
282
{$EXTERNALSYM IPPROTO_IDP}
283
IPPROTO_ND = 77; // UNOFFICIAL net disk proto
284
{$EXTERNALSYM IPPROTO_ND}
286
IPPROTO_RAW = 255; // raw IP packet
287
{$EXTERNALSYM IPPROTO_RAW}
289
{$EXTERNALSYM IPPROTO_MAX}
292
* Port/socket numbers: network standard functions
296
{$EXTERNALSYM IPPORT_ECHO}
298
{$EXTERNALSYM IPPORT_DISCARD}
300
{$EXTERNALSYM IPPORT_SYSTAT}
302
{$EXTERNALSYM IPPORT_DAYTIME}
304
{$EXTERNALSYM IPPORT_NETSTAT}
306
{$EXTERNALSYM IPPORT_FTP}
308
{$EXTERNALSYM IPPORT_TELNET}
310
{$EXTERNALSYM IPPORT_SMTP}
311
IPPORT_TIMESERVER = 37;
312
{$EXTERNALSYM IPPORT_TIMESERVER}
313
IPPORT_NAMESERVER = 42;
314
{$EXTERNALSYM IPPORT_NAMESERVER}
316
{$EXTERNALSYM IPPORT_WHOIS}
318
{$EXTERNALSYM IPPORT_MTP}
321
* Port/socket numbers: host specific functions
325
{$EXTERNALSYM IPPORT_TFTP}
327
{$EXTERNALSYM IPPORT_RJE}
329
{$EXTERNALSYM IPPORT_FINGER}
331
{$EXTERNALSYM IPPORT_TTYLINK}
333
{$EXTERNALSYM IPPORT_SUPDUP}
339
IPPORT_EXECSERVER = 512;
340
{$EXTERNALSYM IPPORT_EXECSERVER}
341
IPPORT_LOGINSERVER = 513;
342
{$EXTERNALSYM IPPORT_LOGINSERVER}
343
IPPORT_CMDSERVER = 514;
344
{$EXTERNALSYM IPPORT_CMDSERVER}
345
IPPORT_EFSSERVER = 520;
346
{$EXTERNALSYM IPPORT_EFSSERVER}
352
IPPORT_BIFFUDP = 512;
353
{$EXTERNALSYM IPPORT_BIFFUDP}
354
IPPORT_WHOSERVER = 513;
355
{$EXTERNALSYM IPPORT_WHOSERVER}
356
IPPORT_ROUTESERVER = 520;
357
{$EXTERNALSYM IPPORT_ROUTESERVER}
359
(* 520+1 also used *)
362
* Ports < IPPORT_RESERVED are reserved for
363
* privileged processes (e.g. root).
366
IPPORT_RESERVED = 1024;
367
{$EXTERNALSYM IPPORT_RESERVED}
374
{$EXTERNALSYM IMPLINK_IP}
375
IMPLINK_LOWEXPER = 156;
376
{$EXTERNALSYM IMPLINK_LOWEXPER}
377
IMPLINK_HIGHEXPER = 158;
378
{$EXTERNALSYM IMPLINK_HIGHEXPER}
381
* Internet address (old style... should be updated)
386
s_b1, s_b2, s_b3, s_b4: u_char;
400
// #define s_addr S_un.S_addr // can be used for most tcp & ip code
401
// #define s_host S_un.S_un_b.s_b2 // host on imp
402
// #define s_net S_un.S_un_b.s_b1 // netword
403
// #define s_imp S_un.S_un_w.s_w2 // imp
404
// #define s_impno S_un.S_un_b.s_b4 // imp #
405
// #define s_lh S_un.S_un_b.s_b3 // logical host
407
{$EXTERNALSYM in_addr}
412
* Definitions of bits in internet address integers.
413
* On subnets, the decomposition of addresses to host and net parts
414
* is done according to subnet mask, not the masks here.
417
function IN_CLASSA(i: DWORD): Boolean;
418
{$EXTERNALSYM IN_CLASSA}
421
IN_CLASSA_NET = DWORD($ff000000);
422
{$EXTERNALSYM IN_CLASSA_NET}
423
IN_CLASSA_NSHIFT = 24;
424
{$EXTERNALSYM IN_CLASSA_NSHIFT}
425
IN_CLASSA_HOST = $00ffffff;
426
{$EXTERNALSYM IN_CLASSA_HOST}
428
{$EXTERNALSYM IN_CLASSA_MAX}
430
function IN_CLASSB(i: DWORD): Boolean;
431
{$EXTERNALSYM IN_CLASSB}
434
IN_CLASSB_NET = DWORD($ffff0000);
435
{$EXTERNALSYM IN_CLASSB_NET}
436
IN_CLASSB_NSHIFT = 16;
437
{$EXTERNALSYM IN_CLASSB_NSHIFT}
438
IN_CLASSB_HOST = $0000ffff;
439
{$EXTERNALSYM IN_CLASSB_HOST}
440
IN_CLASSB_MAX = 65536;
441
{$EXTERNALSYM IN_CLASSB_MAX}
443
function IN_CLASSC(i: DWORD): Boolean;
444
{$EXTERNALSYM IN_CLASSC}
447
IN_CLASSC_NET = DWORD($ffffff00);
448
{$EXTERNALSYM IN_CLASSC_NET}
449
IN_CLASSC_NSHIFT = 8;
450
{$EXTERNALSYM IN_CLASSC_NSHIFT}
451
IN_CLASSC_HOST = $000000ff;
452
{$EXTERNALSYM IN_CLASSC_HOST}
455
INADDR_ANY = u_long($00000000);
456
{$EXTERNALSYM INADDR_ANY}
457
INADDR_LOOPBACK = $7f000001;
458
{$EXTERNALSYM INADDR_LOOPBACK}
459
INADDR_BROADCAST = u_long($ffffffff);
460
{$EXTERNALSYM INADDR_BROADCAST}
461
INADDR_NONE = DWORD($ffffffff);
462
{$EXTERNALSYM INADDR_NONE}
465
* Socket address, internet style.
470
sin_family: Smallint;
473
sin_zero: array [0..7] of Char;
475
{$EXTERNALSYM sockaddr_in}
476
TSockAddrIn = sockaddr_in;
477
PSockAddrIn = ^sockaddr_in;
480
WSADESCRIPTION_LEN = 256;
481
{$EXTERNALSYM WSADESCRIPTION_LEN}
482
WSASYS_STATUS_LEN = 128;
483
{$EXTERNALSYM WSASYS_STATUS_LEN}
489
szDescription: array [0..WSADESCRIPTION_LEN] of Char;
490
szSystemStatus: array [0..WSASYS_STATUS_LEN] of Char;
495
{$EXTERNALSYM WSAData}
496
LPWSADATA = ^WSAData;
497
{$EXTERNALSYM LPWSADATA}
499
PWsaData = LPWSADATA;
502
* Options for use with [gs]etsockopt at the IP level.
506
IP_OPTIONS = 1; (* set/get IP per-packet options *)
507
{$EXTERNALSYM IP_OPTIONS}
508
IP_MULTICAST_IF = 2; (* set/get IP multicast interface *)
509
{$EXTERNALSYM IP_MULTICAST_IF}
510
IP_MULTICAST_TTL = 3; (* set/get IP multicast timetolive *)
511
{$EXTERNALSYM IP_MULTICAST_TTL}
512
IP_MULTICAST_LOOP = 4; (* set/get IP multicast loopback *)
513
{$EXTERNALSYM IP_MULTICAST_LOOP}
514
IP_ADD_MEMBERSHIP = 5; (* add an IP group membership *)
515
{$EXTERNALSYM IP_ADD_MEMBERSHIP}
516
IP_DROP_MEMBERSHIP = 6; (* drop an IP group membership *)
517
{$EXTERNALSYM IP_DROP_MEMBERSHIP}
518
IP_TTL = 7; (* set/get IP Time To Live *)
519
{$EXTERNALSYM IP_TTL}
520
IP_TOS = 8; (* set/get IP Type Of Service *)
521
{$EXTERNALSYM IP_TOS}
522
IP_DONTFRAGMENT = 9; (* set/get IP Don't Fragment flag *)
523
{$EXTERNALSYM IP_DONTFRAGMENT}
525
IP_DEFAULT_MULTICAST_TTL = 1; (* normally limit m'casts to 1 hop *)
526
{$EXTERNALSYM IP_DEFAULT_MULTICAST_TTL}
527
IP_DEFAULT_MULTICAST_LOOP = 1; (* normally hear sends if a member *)
528
{$EXTERNALSYM IP_DEFAULT_MULTICAST_LOOP}
529
IP_MAX_MEMBERSHIPS = 20; (* per socket; must fit in one mbuf *)
530
{$EXTERNALSYM IP_MAX_MEMBERSHIPS}
533
* Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
538
imr_multiaddr: in_addr; (* IP multicast address of group *)
539
mr_interface: in_addr; (* local IP address of interface *)
541
{$EXTERNALSYM ip_mreq}
546
* Definitions related to sockets: types, address families, options,
547
* taken from the BSD file sys/socket.h.
551
* This is used instead of -1, since the
552
* SOCKET type is unsigned.
556
INVALID_SOCKET = TSocket(not 0);
557
{$EXTERNALSYM INVALID_SOCKET}
559
{$EXTERNALSYM SOCKET_ERROR}
565
SOCK_STREAM = 1; // stream socket
566
{$EXTERNALSYM SOCK_STREAM}
567
SOCK_DGRAM = 2; // datagram socket
568
{$EXTERNALSYM SOCK_DGRAM}
569
SOCK_RAW = 3; // raw-protocol interface
570
{$EXTERNALSYM SOCK_RAW}
571
SOCK_RDM = 4; // reliably-delivered message
572
{$EXTERNALSYM SOCK_RDM}
573
SOCK_SEQPACKET = 5; // sequenced packet stream
574
{$EXTERNALSYM SOCK_SEQPACKET}
577
* Option flags per-socket.
580
SO_DEBUG = $0001; // turn on debugging info recording
581
{$EXTERNALSYM SO_DEBUG}
582
SO_ACCEPTCONN = $0002; // socket has had listen()
583
{$EXTERNALSYM SO_ACCEPTCONN}
584
SO_REUSEADDR = $0004; // allow local address reuse
585
{$EXTERNALSYM SO_REUSEADDR}
586
SO_KEEPALIVE = $0008; // keep connections alive
587
{$EXTERNALSYM SO_KEEPALIVE}
588
SO_DONTROUTE = $0010; // just use interface addresses
589
{$EXTERNALSYM SO_DONTROUTE}
590
SO_BROADCAST = $0020; // permit sending of broadcast msgs
591
{$EXTERNALSYM SO_BROADCAST}
592
SO_USELOOPBACK = $0040; // bypass hardware when possible
593
{$EXTERNALSYM SO_USELOOPBACK}
594
SO_LINGER = $0080; // linger on close if data present
595
{$EXTERNALSYM SO_LINGER}
596
SO_OOBINLINE = $0100; // leave received OOB data in line
597
{$EXTERNALSYM SO_OOBINLINE}
599
SO_DONTLINGER = DWORD(not SO_LINGER);
600
{$EXTERNALSYM SO_DONTLINGER}
603
* Additional options.
606
SO_SNDBUF = $1001; // send buffer size
607
{$EXTERNALSYM SO_SNDBUF}
608
SO_RCVBUF = $1002; // receive buffer size
609
{$EXTERNALSYM SO_RCVBUF}
610
SO_SNDLOWAT = $1003; // send low-water mark
611
{$EXTERNALSYM SO_SNDLOWAT}
612
SO_RCVLOWAT = $1004; // receive low-water mark
613
{$EXTERNALSYM SO_RCVLOWAT}
614
SO_SNDTIMEO = $1005; // send timeout
615
{$EXTERNALSYM SO_SNDTIMEO}
616
SO_RCVTIMEO = $1006; // receive timeout
617
{$EXTERNALSYM SO_RCVTIMEO}
618
SO_ERROR = $1007; // get error status and clear
619
{$EXTERNALSYM SO_ERROR}
620
SO_TYPE = $1008; // get socket type
621
{$EXTERNALSYM SO_TYPE}
624
* Options for connect and disconnect data and options. Used only by
625
* non-TCP/IP transports such as DECNet, OSI TP4, etc.
629
{$EXTERNALSYM SO_CONNDATA}
631
{$EXTERNALSYM SO_CONNOPT}
633
{$EXTERNALSYM SO_DISCDATA}
635
{$EXTERNALSYM SO_DISCOPT}
636
SO_CONNDATALEN = $7004;
637
{$EXTERNALSYM SO_CONNDATALEN}
638
SO_CONNOPTLEN = $7005;
639
{$EXTERNALSYM SO_CONNOPTLEN}
640
SO_DISCDATALEN = $7006;
641
{$EXTERNALSYM SO_DISCDATALEN}
642
SO_DISCOPTLEN = $7007;
643
{$EXTERNALSYM SO_DISCOPTLEN}
646
* Option for opening sockets for synchronous access.
650
{$EXTERNALSYM SO_OPENTYPE}
652
SO_SYNCHRONOUS_ALERT = $10;
653
{$EXTERNALSYM SO_SYNCHRONOUS_ALERT}
654
SO_SYNCHRONOUS_NONALERT = $20;
655
{$EXTERNALSYM SO_SYNCHRONOUS_NONALERT}
658
* Other NT-specific options.
662
{$EXTERNALSYM SO_MAXDG}
663
SO_MAXPATHDG = $700A;
664
{$EXTERNALSYM SO_MAXPATHDG}
665
SO_UPDATE_ACCEPT_CONTEXT = $700B;
666
{$EXTERNALSYM SO_UPDATE_ACCEPT_CONTEXT}
667
SO_CONNECT_TIME = $700C;
668
{$EXTERNALSYM SO_CONNECT_TIME}
675
{$EXTERNALSYM TCP_NODELAY}
676
TCP_BSDURGENT = $7000;
677
{$EXTERNALSYM TCP_BSDURGENT}
683
AF_UNSPEC = 0; // unspecified
684
{$EXTERNALSYM AF_UNSPEC}
685
AF_UNIX = 1; // local to host (pipes, portals
686
{$EXTERNALSYM AF_UNIX}
687
AF_INET = 2; // internetwork: UDP, TCP, etc.
688
{$EXTERNALSYM AF_INET}
689
AF_IMPLINK = 3; // arpanet imp addresses
690
{$EXTERNALSYM AF_IMPLINK}
691
AF_PUP = 4; // pup protocols: e.g. BSP
692
{$EXTERNALSYM AF_PUP}
693
AF_CHAOS = 5; // mit CHAOS protocols
694
{$EXTERNALSYM AF_CHAOS}
695
AF_NS = 6; // XEROX NS protocols
697
AF_IPX = AF_NS; // IPX protocols: IPX, SPX, etc.
698
{$EXTERNALSYM AF_IPX}
699
AF_ISO = 7; // ISO protocols
700
{$EXTERNALSYM AF_ISO}
701
AF_OSI = AF_ISO; // OSI is ISO
702
{$EXTERNALSYM AF_OSI}
703
AF_ECMA = 8; // european computer manufacturers
704
{$EXTERNALSYM AF_ECMA}
705
AF_DATAKIT = 9; // datakit protocols
706
{$EXTERNALSYM AF_DATAKIT}
707
AF_CCITT = 10; // CCITT protocols, X.25 etc
708
{$EXTERNALSYM AF_CCITT}
709
AF_SNA = 11; // IBM SNA
710
{$EXTERNALSYM AF_SNA}
711
AF_DECnet = 12; // DECnet
712
{$EXTERNALSYM AF_DECnet}
713
AF_DLI = 13; // Direct data link interface
714
{$EXTERNALSYM AF_DLI}
716
{$EXTERNALSYM AF_LAT}
717
AF_HYLINK = 15; // NSC Hyperchannel
718
{$EXTERNALSYM AF_HYLINK}
719
AF_APPLETALK = 16; // AppleTalk
720
{$EXTERNALSYM AF_APPLETALK}
721
AF_NETBIOS = 17; // NetBios-style addresses
722
{$EXTERNALSYM AF_NETBIOS}
723
AF_VOICEVIEW = 18; // VoiceView
724
{$EXTERNALSYM AF_VOICEVIEW}
725
AF_FIREFOX = 19; // Protocols from Firefox
726
{$EXTERNALSYM AF_FIREFOX}
727
AF_UNKNOWN1 = 20; // Somebody is using this!
728
{$EXTERNALSYM AF_UNKNOWN1}
729
AF_BAN = 21; // Banyan
730
{$EXTERNALSYM AF_BAN}
733
{$EXTERNALSYM AF_MAX}
736
* Structure used by kernel to store most
742
sa_family: u_short; // address family
743
sa_data: array [0..13] of Char; // up to 14 bytes of direct address
745
{$EXTERNALSYM sockaddr}
746
TSockAddr = sockaddr;
747
PSockAddr = ^sockaddr;
750
* Structure used by kernel to pass protocol
751
* information in raw sockets.
755
sp_family: u_short; // address family
756
sp_protocol: u_short; // protocol
758
{$EXTERNALSYM sockproto}
759
TSockProto = sockproto;
760
PSockProto = ^sockproto;
763
* Protocol families, same as address families for now.
767
PF_UNSPEC = AF_UNSPEC;
768
{$EXTERNALSYM PF_UNSPEC}
770
{$EXTERNALSYM PF_UNIX}
772
{$EXTERNALSYM PF_INET}
773
PF_IMPLINK = AF_IMPLINK;
774
{$EXTERNALSYM PF_IMPLINK}
776
{$EXTERNALSYM PF_PUP}
778
{$EXTERNALSYM PF_CHAOS}
782
{$EXTERNALSYM PF_IPX}
784
{$EXTERNALSYM PF_ISO}
786
{$EXTERNALSYM PF_OSI}
788
{$EXTERNALSYM PF_ECMA}
789
PF_DATAKIT = AF_DATAKIT;
790
{$EXTERNALSYM PF_DATAKIT}
792
{$EXTERNALSYM PF_CCITT}
794
{$EXTERNALSYM PF_SNA}
795
PF_DECnet = AF_DECnet;
796
{$EXTERNALSYM PF_DECnet}
798
{$EXTERNALSYM PF_DLI}
800
{$EXTERNALSYM PF_LAT}
801
PF_HYLINK = AF_HYLINK;
802
{$EXTERNALSYM PF_HYLINK}
803
PF_APPLETALK = AF_APPLETALK;
804
{$EXTERNALSYM PF_APPLETALK}
805
PF_VOICEVIEW = AF_VOICEVIEW;
806
{$EXTERNALSYM PF_VOICEVIEW}
807
PF_FIREFOX = AF_FIREFOX;
808
{$EXTERNALSYM PF_FIREFOX}
809
PF_UNKNOWN1 = AF_UNKNOWN1;
810
{$EXTERNALSYM PF_UNKNOWN1}
812
{$EXTERNALSYM PF_BAN}
815
{$EXTERNALSYM PF_MAX}
818
* Structure used for manipulating linger option.
823
l_onoff: u_short; // option on/off
824
l_linger: u_short; // linger time
826
{$EXTERNALSYM linger}
831
* Level number for (get/set)sockopt() to apply to socket itself.
835
SOL_SOCKET = $ffff; // options for socket level
836
{$EXTERNALSYM SOL_SOCKET}
839
* Maximum queue length specifiable by listen.
842
SOMAXCONN = $7fffffff;
843
{$EXTERNALSYM SOMAXCONN}
845
MSG_OOB = $1; // process out-of-band data
846
{$EXTERNALSYM MSG_OOB}
847
MSG_PEEK = $2; // peek at incoming message
848
{$EXTERNALSYM MSG_PEEK}
849
MSG_DONTROUTE = $4; // send without using routing tables
850
{$EXTERNALSYM MSG_DONTROUTE}
853
{$EXTERNALSYM MSG_MAXIOVLEN}
855
MSG_PARTIAL = $8000; // partial send or recv for message xport
856
{$EXTERNALSYM MSG_PARTIAL}
859
* Define constant based on rfc883, used by gethostbyxxxx() calls.
862
MAXGETHOSTSTRUCT = 1024;
863
{$EXTERNALSYM MAXGETHOSTSTRUCT}
866
* Define flags to be used with the WSAAsyncSelect() call.
870
{$EXTERNALSYM FD_READ}
872
{$EXTERNALSYM FD_WRITE}
874
{$EXTERNALSYM FD_OOB}
876
{$EXTERNALSYM FD_ACCEPT}
878
{$EXTERNALSYM FD_CONNECT}
880
{$EXTERNALSYM FD_CLOSE}
883
* All Windows Sockets error constants are biased by WSABASEERR from
888
{$EXTERNALSYM WSABASEERR}
891
* Windows Sockets definitions of regular Microsoft C error constants
894
WSAEINTR = WSABASEERR + 4;
895
{$EXTERNALSYM WSAEINTR}
896
WSAEBADF = WSABASEERR + 9;
897
{$EXTERNALSYM WSAEBADF}
898
WSAEACCES = WSABASEERR + 13;
899
{$EXTERNALSYM WSAEACCES}
900
WSAEFAULT = WSABASEERR + 14;
901
{$EXTERNALSYM WSAEFAULT}
902
WSAEINVAL = WSABASEERR + 22;
903
{$EXTERNALSYM WSAEINVAL}
904
WSAEMFILE = WSABASEERR + 24;
905
{$EXTERNALSYM WSAEMFILE}
908
* Windows Sockets definitions of regular Berkeley error constants
911
WSAEWOULDBLOCK = WSABASEERR + 35;
912
{$EXTERNALSYM WSAEWOULDBLOCK}
913
WSAEINPROGRESS = WSABASEERR + 36;
914
{$EXTERNALSYM WSAEINPROGRESS}
915
WSAEALREADY = WSABASEERR + 37;
916
{$EXTERNALSYM WSAEALREADY}
917
WSAENOTSOCK = WSABASEERR + 38;
918
{$EXTERNALSYM WSAENOTSOCK}
919
WSAEDESTADDRREQ = WSABASEERR + 39;
920
{$EXTERNALSYM WSAEDESTADDRREQ}
921
WSAEMSGSIZE = WSABASEERR + 40;
922
{$EXTERNALSYM WSAEMSGSIZE}
923
WSAEPROTOTYPE = WSABASEERR + 41;
924
{$EXTERNALSYM WSAEPROTOTYPE}
925
WSAENOPROTOOPT = WSABASEERR + 42;
926
{$EXTERNALSYM WSAENOPROTOOPT}
927
WSAEPROTONOSUPPORT = WSABASEERR + 43;
928
{$EXTERNALSYM WSAEPROTONOSUPPORT}
929
WSAESOCKTNOSUPPORT = WSABASEERR + 44;
930
{$EXTERNALSYM WSAESOCKTNOSUPPORT}
931
WSAEOPNOTSUPP = WSABASEERR + 45;
932
{$EXTERNALSYM WSAEOPNOTSUPP}
933
WSAEPFNOSUPPORT = WSABASEERR + 46;
934
{$EXTERNALSYM WSAEPFNOSUPPORT}
935
WSAEAFNOSUPPORT = WSABASEERR + 47;
936
{$EXTERNALSYM WSAEAFNOSUPPORT}
937
WSAEADDRINUSE = WSABASEERR + 48;
938
{$EXTERNALSYM WSAEADDRINUSE}
939
WSAEADDRNOTAVAIL = WSABASEERR + 49;
940
{$EXTERNALSYM WSAEADDRNOTAVAIL}
941
WSAENETDOWN = WSABASEERR + 50;
942
{$EXTERNALSYM WSAENETDOWN}
943
WSAENETUNREACH = WSABASEERR + 51;
944
{$EXTERNALSYM WSAENETUNREACH}
945
WSAENETRESET = WSABASEERR + 52;
946
{$EXTERNALSYM WSAENETRESET}
947
WSAECONNABORTED = WSABASEERR + 53;
948
{$EXTERNALSYM WSAECONNABORTED}
949
WSAECONNRESET = WSABASEERR + 54;
950
{$EXTERNALSYM WSAECONNRESET}
951
WSAENOBUFS = WSABASEERR + 55;
952
{$EXTERNALSYM WSAENOBUFS}
953
WSAEISCONN = WSABASEERR + 56;
954
{$EXTERNALSYM WSAEISCONN}
955
WSAENOTCONN = WSABASEERR + 57;
956
{$EXTERNALSYM WSAENOTCONN}
957
WSAESHUTDOWN = WSABASEERR + 58;
958
{$EXTERNALSYM WSAESHUTDOWN}
959
WSAETOOMANYREFS = WSABASEERR + 59;
960
{$EXTERNALSYM WSAETOOMANYREFS}
961
WSAETIMEDOUT = WSABASEERR + 60;
962
{$EXTERNALSYM WSAETIMEDOUT}
963
WSAECONNREFUSED = WSABASEERR + 61;
964
{$EXTERNALSYM WSAECONNREFUSED}
965
WSAELOOP = WSABASEERR + 62;
966
{$EXTERNALSYM WSAELOOP}
967
WSAENAMETOOLONG = WSABASEERR + 63;
968
{$EXTERNALSYM WSAENAMETOOLONG}
969
WSAEHOSTDOWN = WSABASEERR + 64;
970
{$EXTERNALSYM WSAEHOSTDOWN}
971
WSAEHOSTUNREACH = WSABASEERR + 65;
972
{$EXTERNALSYM WSAEHOSTUNREACH}
973
WSAENOTEMPTY = WSABASEERR + 66;
974
{$EXTERNALSYM WSAENOTEMPTY}
975
WSAEPROCLIM = WSABASEERR + 67;
976
{$EXTERNALSYM WSAEPROCLIM}
977
WSAEUSERS = WSABASEERR + 68;
978
{$EXTERNALSYM WSAEUSERS}
979
WSAEDQUOT = WSABASEERR + 69;
980
{$EXTERNALSYM WSAEDQUOT}
981
WSAESTALE = WSABASEERR + 70;
982
{$EXTERNALSYM WSAESTALE}
983
WSAEREMOTE = WSABASEERR + 71;
984
{$EXTERNALSYM WSAEREMOTE}
986
WSAEDISCON = WSABASEERR + 101;
987
{$EXTERNALSYM WSAEDISCON}
990
* Extended Windows Sockets error constant definitions
993
WSASYSNOTREADY = WSABASEERR + 91;
994
{$EXTERNALSYM WSASYSNOTREADY}
995
WSAVERNOTSUPPORTED = WSABASEERR + 92;
996
{$EXTERNALSYM WSAVERNOTSUPPORTED}
997
WSANOTINITIALISED = WSABASEERR + 93;
998
{$EXTERNALSYM WSANOTINITIALISED}
1001
* Error return codes from gethostbyname() and gethostbyaddr()
1002
* (when using the resolver). Note that these errors are
1003
* retrieved via WSAGetLastError() and must therefore follow
1004
* the rules for avoiding clashes with error numbers from
1005
* specific implementations or language run-time systems.
1006
* For this reason the codes are based at WSABASEERR+1001.
1007
* Note also that [WSA]NO_ADDRESS is defined only for
1008
* compatibility purposes.
1011
// Authoritative Answer: Host not found
1013
WSAHOST_NOT_FOUND = WSABASEERR + 1001;
1014
{$EXTERNALSYM WSAHOST_NOT_FOUND}
1016
// Non-Authoritative: Host not found, or SERVERFAIL
1018
WSATRY_AGAIN = WSABASEERR + 1002;
1019
{$EXTERNALSYM WSATRY_AGAIN}
1021
// Non-recoverable errors, FORMERR, REFUSED, NOTIMP
1023
WSANO_RECOVERY = WSABASEERR + 1003;
1024
{$EXTERNALSYM WSANO_RECOVERY}
1026
// Valid name, no data record of requested type
1028
WSANO_DATA = WSABASEERR + 1004;
1029
{$EXTERNALSYM WSANO_DATA}
1032
* Compatibility macros.
1035
function h_errno: Integer;
1036
{$EXTERNALSYM h_errno}
1039
HOST_NOT_FOUND = WSAHOST_NOT_FOUND;
1040
{$EXTERNALSYM HOST_NOT_FOUND}
1041
TRY_AGAIN = WSATRY_AGAIN;
1042
{$EXTERNALSYM TRY_AGAIN}
1043
NO_RECOVERY = WSANO_RECOVERY;
1044
{$EXTERNALSYM NO_RECOVERY}
1045
NO_DATA = WSANO_DATA;
1046
{$EXTERNALSYM NO_DATA}
1048
// no address, look for MX record
1050
WSANO_ADDRESS = WSANO_DATA;
1051
{$EXTERNALSYM WSANO_ADDRESS}
1052
NO_ADDRESS = WSANO_ADDRESS;
1053
{$EXTERNALSYM NO_ADDRESS}
1056
* Windows Sockets errors redefined as regular Berkeley error constants.
1057
* These are commented out in Windows NT to avoid conflicts with errno.h.
1058
* Use the WSA constants instead.
1064
EWOULDBLOCK = WSAEWOULDBLOCK;
1065
{$EXTERNALSYM EWOULDBLOCK}
1066
EINPROGRESS = WSAEINPROGRESS;
1067
{$EXTERNALSYM EINPROGRESS}
1068
EALREADY = WSAEALREADY;
1069
{$EXTERNALSYM EALREADY}
1070
ENOTSOCK = WSAENOTSOCK;
1071
{$EXTERNALSYM ENOTSOCK}
1072
EDESTADDRREQ = WSAEDESTADDRREQ;
1073
{$EXTERNALSYM EDESTADDRREQ}
1074
EMSGSIZE = WSAEMSGSIZE;
1075
{$EXTERNALSYM EMSGSIZE}
1076
EPROTOTYPE = WSAEPROTOTYPE;
1077
{$EXTERNALSYM EPROTOTYPE}
1078
ENOPROTOOPT = WSAENOPROTOOPT;
1079
{$EXTERNALSYM ENOPROTOOPT}
1080
EPROTONOSUPPORT = WSAEPROTONOSUPPORT;
1081
{$EXTERNALSYM EPROTONOSUPPORT}
1082
ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT;
1083
{$EXTERNALSYM ESOCKTNOSUPPORT}
1084
EOPNOTSUPP = WSAEOPNOTSUPP;
1085
{$EXTERNALSYM EOPNOTSUPP}
1086
EPFNOSUPPORT = WSAEPFNOSUPPORT;
1087
{$EXTERNALSYM EPFNOSUPPORT}
1088
EAFNOSUPPORT = WSAEAFNOSUPPORT;
1089
{$EXTERNALSYM EAFNOSUPPORT}
1090
EADDRINUSE = WSAEADDRINUSE;
1091
{$EXTERNALSYM EADDRINUSE}
1092
EADDRNOTAVAIL = WSAEADDRNOTAVAIL;
1093
{$EXTERNALSYM EADDRNOTAVAIL}
1094
ENETDOWN = WSAENETDOWN;
1095
{$EXTERNALSYM ENETDOWN}
1096
ENETUNREACH = WSAENETUNREACH;
1097
{$EXTERNALSYM ENETUNREACH}
1098
ENETRESET = WSAENETRESET;
1099
{$EXTERNALSYM ENETRESET}
1100
ECONNABORTED = WSAECONNABORTED;
1101
{$EXTERNALSYM ECONNABORTED}
1102
ECONNRESET = WSAECONNRESET;
1103
{$EXTERNALSYM ECONNRESET}
1104
ENOBUFS = WSAENOBUFS;
1105
{$EXTERNALSYM ENOBUFS}
1106
EISCONN = WSAEISCONN;
1107
{$EXTERNALSYM EISCONN}
1108
ENOTCONN = WSAENOTCONN;
1109
{$EXTERNALSYM ENOTCONN}
1110
ESHUTDOWN = WSAESHUTDOWN;
1111
{$EXTERNALSYM ESHUTDOWN}
1112
ETOOMANYREFS = WSAETOOMANYREFS;
1113
{$EXTERNALSYM ETOOMANYREFS}
1114
ETIMEDOUT = WSAETIMEDOUT;
1115
{$EXTERNALSYM ETIMEDOUT}
1116
ECONNREFUSED = WSAECONNREFUSED;
1117
{$EXTERNALSYM ECONNREFUSED}
1119
{$EXTERNALSYM ELOOP}
1120
ENAMETOOLONG = WSAENAMETOOLONG;
1121
{$EXTERNALSYM ENAMETOOLONG}
1122
EHOSTDOWN = WSAEHOSTDOWN;
1123
{$EXTERNALSYM EHOSTDOWN}
1124
EHOSTUNREACH = WSAEHOSTUNREACH;
1125
{$EXTERNALSYM EHOSTUNREACH}
1126
ENOTEMPTY = WSAENOTEMPTY;
1127
{$EXTERNALSYM ENOTEMPTY}
1128
EPROCLIM = WSAEPROCLIM;
1129
{$EXTERNALSYM EPROCLIM}
1131
{$EXTERNALSYM EUSERS}
1133
{$EXTERNALSYM EDQUOT}
1135
{$EXTERNALSYM ESTALE}
1136
EREMOTE = WSAEREMOTE;
1137
{$EXTERNALSYM EREMOTE}
1141
(* Socket function prototypes *)
1143
function accept(s: TSocket; addr: PSockAddr; addrlen: PINT): TSocket; stdcall;
1144
{$EXTERNALSYM accept}
1145
function bind(s: TSocket; name: PSockAddr; namelen: Integer): Integer; stdcall;
1147
function closesocket(s: TSocket): Integer; stdcall;
1148
{$EXTERNALSYM closesocket}
1149
function connect(s: TSocket; name: PSockAddr; namelen: Integer): Integer; stdcall;
1150
{$EXTERNALSYM connect}
1151
function ioctlsocket(s: TSocket; cmd: Longint; var argp: u_long): Integer; stdcall;
1152
{$EXTERNALSYM ioctlsocket}
1153
function getpeername(s: TSocket; name: PSockAddr; var namelen: Integer): Integer; stdcall;
1154
{$EXTERNALSYM getpeername}
1155
function getsockname(s: TSocket; name: PSockAddr; var namelen: Integer): Integer; stdcall;
1156
{$EXTERNALSYM getsockname}
1157
function getsockopt(s: TSocket; level, optname: Integer; optval: PChar; var optlen: Integer): Integer; stdcall;
1158
{$EXTERNALSYM getsockopt}
1159
function htonl(hostlong: u_long): u_long; stdcall;
1160
{$EXTERNALSYM htonl}
1161
function htons(hostshort: u_short): u_short; stdcall;
1162
{$EXTERNALSYM htons}
1163
function inet_addr(cp: PChar): u_long; stdcall;
1164
{$EXTERNALSYM inet_addr}
1165
function inet_ntoa(inaddr: in_addr): PChar; stdcall;
1166
{$EXTERNALSYM inet_ntoa}
1167
function listen(s: TSocket; backlog: Integer): Integer; stdcall;
1168
{$EXTERNALSYM listen}
1169
function ntohl(netlong: u_long): u_long; stdcall;
1170
{$EXTERNALSYM ntohl}
1171
function ntohs(netshort: u_short): u_short; stdcall;
1172
{$EXTERNALSYM ntohs}
1173
function recv(s: TSocket; var buf; len, flags: Integer): Integer; stdcall;
1175
function recvfrom(s: TSocket; var buf; len, flags: Integer; from: PSockAddr; var fromlen: Integer): Integer; stdcall;
1176
{$EXTERNALSYM recvfrom}
1177
function select(nfds: Integer; readfds, writefds, exceptfds: PFdSet; timeout: PTimeVal): Integer; stdcall;
1178
{$EXTERNALSYM select}
1179
function send(s: TSocket; var buf; len, flags: Integer): Integer; stdcall;
1181
function sendto(s: TSocket; var buf; len, flags: Integer; toaddr: PSockAddr; tolen: Integer): Integer; stdcall;
1182
{$EXTERNALSYM sendto}
1183
function setsockopt(s: TSocket; level, optname: Integer; optval: PChar; optlen: Integer): Integer; stdcall;
1184
{$EXTERNALSYM setsockopt}
1185
function shutdown(s: TSocket; how: Integer): Integer; stdcall;
1186
{$EXTERNALSYM shutdown}
1187
function socket(af, type_, protocol: Integer): TSocket; stdcall;
1188
{$EXTERNALSYM socket}
1190
(* Database function prototypes *)
1192
function gethostbyaddr(addr: PChar; len, type_: Integer): PHostEnt; stdcall;
1193
{$EXTERNALSYM gethostbyaddr}
1194
function gethostbyname(name: PChar): PHostEnt; stdcall;
1195
{$EXTERNALSYM gethostbyname}
1196
function gethostname(name: PChar; namelen: Integer): Integer; stdcall;
1197
{$EXTERNALSYM gethostname}
1198
function getservbyport(port: Integer; proto: PChar): PServEnt; stdcall;
1199
{$EXTERNALSYM getservbyport}
1200
function getservbyname(name, proto: PChar): PServEnt; stdcall;
1201
{$EXTERNALSYM getservbyname}
1202
function getprotobynumber(number: Integer): PProtoEnt; stdcall;
1203
{$EXTERNALSYM getprotobynumber}
1204
function getprotobyname(name: PChar): PProtoEnt; stdcall;
1205
{$EXTERNALSYM getprotobyname}
1207
(* Microsoft Windows Extension function prototypes *)
1209
function WSAStartup(wVersionRequired: WORD; var lpWSAData: TWSAData): Integer; stdcall;
1210
{$EXTERNALSYM WSAStartup}
1211
function WSACleanup: Integer; stdcall;
1212
{$EXTERNALSYM WSACleanup}
1213
procedure WSASetLastError(iError: Integer); stdcall;
1214
{$EXTERNALSYM WSASetLastError}
1215
function WSAGetLastError: Integer; stdcall;
1216
{$EXTERNALSYM WSAGetLastError}
1217
function WSAIsBlocking: BOOL; stdcall;
1218
{$EXTERNALSYM WSAIsBlocking}
1219
function WSAUnhookBlockingHook: Integer; stdcall;
1220
{$EXTERNALSYM WSAUnhookBlockingHook}
1221
function WSASetBlockingHook(lpBlockFunc: FARPROC): FARPROC; stdcall;
1222
{$EXTERNALSYM WSASetBlockingHook}
1223
function WSACancelBlockingCall: Integer; stdcall;
1224
{$EXTERNALSYM WSACancelBlockingCall}
1225
function WSAAsyncGetServByName(hWnd: HWND; wMsg: u_int; name, proto, buf: PChar;
1226
buflen: Integer): HANDLE; stdcall;
1227
{$EXTERNALSYM WSAAsyncGetServByName}
1228
function WSAAsyncGetServByPort(hWnd: HWND; wMsg: u_int; port: Integer;
1229
proto, buf: PChar; buflen: Integer): HANDLE; stdcall;
1230
{$EXTERNALSYM WSAAsyncGetServByPort}
1231
function WSAAsyncGetProtoByName(hWnd: HWND; wMsg: u_int; name, buf: PChar;
1232
buflen: Integer): HANDLE; stdcall;
1233
{$EXTERNALSYM WSAAsyncGetProtoByName}
1234
function WSAAsyncGetProtoByNumber(hWnd: HWND; wMsg: u_int; number: Integer;
1235
buf: PChar; buflen: Integer): HANDLE; stdcall;
1236
{$EXTERNALSYM WSAAsyncGetProtoByNumber}
1237
function WSAAsyncGetHostByName(hWnd: HWND; wMsg: u_int; name, buf: PChar;
1238
buflen: Integer): HANDLE; stdcall;
1239
{$EXTERNALSYM WSAAsyncGetHostByName}
1240
function WSAAsyncGetHostByAddr(hWnd: HWND; wMsg: u_int; addr: PChar;
1241
len, type_: Integer; buf: PChar; buflen: Integer): HANDLE; stdcall;
1242
{$EXTERNALSYM WSAAsyncGetHostByAddr}
1243
function WSACancelAsyncRequest(hAsyncTaskHandle: HANDLE): Integer; stdcall;
1244
{$EXTERNALSYM WSACancelAsyncRequest}
1245
function WSAAsyncSelect(s: TSocket; hWnd: HWND; wMsg: u_int; lEvent: Longint): Integer; stdcall;
1246
{$EXTERNALSYM WSAAsyncSelect}
1248
function WSARecvEx(s: TSocket; var buf; len: Integer; var flags: Integer): Integer; stdcall;
1249
{$EXTERNALSYM WSARecvEx}
1252
_TRANSMIT_FILE_BUFFERS = record
1258
{$EXTERNALSYM _TRANSMIT_FILE_BUFFERS}
1259
TRANSMIT_FILE_BUFFERS = _TRANSMIT_FILE_BUFFERS;
1260
{$EXTERNALSYM TRANSMIT_FILE_BUFFERS}
1261
PTRANSMIT_FILE_BUFFERS = ^TRANSMIT_FILE_BUFFERS;
1262
{$EXTERNALSYM PTRANSMIT_FILE_BUFFERS}
1263
LPTRANSMIT_FILE_BUFFERS = ^TRANSMIT_FILE_BUFFERS;
1264
{$EXTERNALSYM LPTRANSMIT_FILE_BUFFERS}
1265
TTransmitFileBuffers = TRANSMIT_FILE_BUFFERS;
1266
PTransmitFileBuffers = LPTRANSMIT_FILE_BUFFERS;
1269
TF_DISCONNECT = $01;
1270
{$EXTERNALSYM TF_DISCONNECT}
1271
TF_REUSE_SOCKET = $02;
1272
{$EXTERNALSYM TF_REUSE_SOCKET}
1273
TF_WRITE_BEHIND = $04;
1274
{$EXTERNALSYM TF_WRITE_BEHIND}
1276
function TransmitFile(hSocket: TSocket; hFile: HANDLE; nNumberOfBytesToWrite: DWORD;
1277
nNumberOfBytesPerSend: DWORD; lpOverlapped: LPOVERLAPPED;
1278
lpTransmitBuffers: LPTRANSMIT_FILE_BUFFERS; dwReserved: DWORD): BOOL; stdcall;
1279
{$EXTERNALSYM TransmitFile}
1280
function AcceptEx(sListenSocket, sAcceptSocket: TSocket;
1281
lpOutputBuffer: LPVOID; dwReceiveDataLength, dwLocalAddressLength,
1282
dwRemoteAddressLength: DWORD; var lpdwBytesReceived: DWORD;
1283
lpOverlapped: LPOVERLAPPED): BOOL; stdcall;
1284
{$EXTERNALSYM AcceptEx}
1285
procedure GetAcceptExSockaddrs(lpOutputBuffer: Pointer;
1286
dwReceiveDataLength, dwLocalAddressLength, dwRemoteAddressLength: DWORD;
1287
out LocalSockaddr: PSockAddr; var LocalSockaddrLength: Integer;
1288
out RemoteSockaddr: PSockAddr; var RemoteSockaddrLength: Integer); stdcall;
1289
{$EXTERNALSYM GetAcceptExSockaddrs}
1291
(* Microsoft Windows Extended data types *)
1294
PSOCKADDR_IN = ^sockaddr_in;
1295
{$EXTERNALSYM PSOCKADDR_IN}
1296
LPSOCKADDR_IN = ^sockaddr_in;
1297
{$EXTERNALSYM LPSOCKADDR_IN}
1299
{$EXTERNALSYM LPLINGER}
1300
PIN_ADDR = ^in_addr;
1301
{$EXTERNALSYM PIN_ADDR}
1302
LPIN_ADDR = ^in_addr;
1303
{$EXTERNALSYM LPIN_ADDR}
1305
{$EXTERNALSYM PFD_SET}
1307
{$EXTERNALSYM LPFD_SET}
1308
LPHOSTENT = PHOSTENT;
1309
{$EXTERNALSYM LPHOSTENT}
1310
LPSERVENT = PSERVENT;
1311
{$EXTERNALSYM LPSERVENT}
1312
LPPROTOENT = PPROTOENT;
1313
{$EXTERNALSYM LPPROTOENT}
1314
LPTIMEVAL = PTIMEVAL;
1315
{$EXTERNALSYM LPTIMEVAL}
1318
* Windows message parameter composition and decomposition
1321
* WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
1322
* when constructing the response to a WSAAsyncGetXByY() routine.
1325
function WSAMAKEASYNCREPLY(buflen, error: WORD): DWORD;
1326
{$EXTERNALSYM WSAMAKEASYNCREPLY}
1329
* WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
1330
* when constructing the response to WSAAsyncSelect().
1333
function WSAMAKESELECTREPLY(event, error: WORD): DWORD;
1334
{$EXTERNALSYM WSAMAKESELECTREPLY}
1337
* WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
1338
* to extract the buffer length from the lParam in the response
1339
* to a WSAGetXByY().
1342
function WSAGETASYNCBUFLEN(lParam: DWORD): WORD;
1343
{$EXTERNALSYM WSAGETASYNCBUFLEN}
1346
* WSAGETASYNCERROR is intended for use by the Windows Sockets application
1347
* to extract the error code from the lParam in the response
1348
* to a WSAGetXByY().
1351
function WSAGETASYNCERROR(lParam: DWORD): WORD;
1352
{$EXTERNALSYM WSAGETASYNCERROR}
1355
* WSAGETSELECTEVENT is intended for use by the Windows Sockets application
1356
* to extract the event code from the lParam in the response
1357
* to a WSAAsyncSelect().
1360
function WSAGETSELECTEVENT(lParam: DWORD): WORD;
1361
{$EXTERNALSYM WSAGETSELECTEVENT}
1364
* WSAGETSELECTERROR is intended for use by the Windows Sockets application
1365
* to extract the error code from the lParam in the response
1366
* to a WSAAsyncSelect().
1369
function WSAGETSELECTERROR(lParam: DWORD): WORD;
1370
{$EXTERNALSYM WSAGETSELECTERROR}
1375
wsock32 = 'wsock32.dll';
1377
procedure FD_CLR(fd: TSocket; var fdset: TFdSet);
1382
while I < fdset.fd_count do
1384
if fdset.fd_array[I] = fd then
1386
while I < fdset.fd_count - 1 do
1388
fdset.fd_array[I] := fdset.fd_array[I + 1];
1391
fdset.fd_count := fdset.fd_count - 1;
1398
procedure _FD_SET(fd: TSocket; var fdset: TFDSet);
1403
while I < fdset.fd_count do
1405
if fdset.fd_array[I] = fd then
1409
if I = fdset.fd_count then
1411
if fdset.fd_count < FD_SETSIZE then
1413
fdset.fd_array[I] := fd;
1414
fdset.fd_count := fdset.fd_count + 1;
1419
procedure FD_ZERO(var fdset: TFdSet);
1421
fdset.fd_count := 0;
1424
function FD_ISSET(fd: TSocket; var fdset: TFdSet): Boolean;
1426
Result := __WSAFDIsSet(fd, fdset) <> 0;
1429
function timerisset(const tvp: TTimeVal): Boolean;
1431
Result := (tvp.tv_sec <> 0) or (tvp.tv_usec <> 0);
1434
procedure timerclear(var tvp: TTimeVal);
1440
function _IO(x, y: DWORD): DWORD;
1442
Result := IOC_VOID or (x shl 8) or y;
1445
function _IOR(x, y, t: DWORD): DWORD;
1447
Result := IOC_OUT or ((T and IOCPARM_MASK) shl 16) or (x shl 8) or y;
1450
function _IOW(x, y, t: DWORD): DWORD;
1452
Result := DWORD(IOC_IN or ((T and IOCPARM_MASK) shl 16) or (x shl 8) or y);
1455
function IN_CLASSA(i: DWORD): Boolean;
1457
Result := i and DWORD($80000000) = 0;
1460
function IN_CLASSB(i: DWORD): Boolean;
1462
Result := i and DWORD($C0000000) = DWORD($80000000);
1465
function IN_CLASSC(i: DWORD): Boolean;
1467
Result := (i and DWORD($e0000000)) = DWORD($C0000000);
1470
function h_errno: Integer;
1472
Result := WSAGetLastError;
1475
function WSAMAKEASYNCREPLY(buflen, error: WORD): DWORD;
1477
Result := MAKELONG(buflen, error);
1480
function WSAMAKESELECTREPLY(event, error: WORD): DWORD;
1482
Result := MAKELONG(event, error);
1485
function WSAGETASYNCBUFLEN(lParam: DWORD): WORD;
1487
Result := LOWORD(lParam);
1490
function WSAGETASYNCERROR(lParam: DWORD): WORD;
1492
Result := HIWORD(lParam);
1495
function WSAGETSELECTEVENT(lParam: DWORD): WORD;
1497
Result := LOWORD(lParam);
1500
function WSAGETSELECTERROR(lParam: DWORD): WORD;
1502
Result := HIWORD(lParam);
1505
{$IFDEF DYNAMIC_LINK}
1508
___WSAFDIsSet: Pointer;
1510
function __WSAFDIsSet;
1512
GetProcedureAddress(___WSAFDIsSet, wsock32, '__WSAFDIsSet');
1525
GetProcedureAddress(_accept, wsock32, 'accept');
1538
GetProcedureAddress(_bind, wsock32, 'bind');
1547
_closesocket: Pointer;
1549
function closesocket;
1551
GetProcedureAddress(_closesocket, wsock32, 'closesocket');
1564
GetProcedureAddress(_connect, wsock32, 'connect');
1573
_ioctlsocket: Pointer;
1575
function ioctlsocket;
1577
GetProcedureAddress(_ioctlsocket, wsock32, 'ioctlsocket');
1586
_getpeername: Pointer;
1588
function getpeername;
1590
GetProcedureAddress(_getpeername, wsock32, 'getpeername');
1599
_getsockname: Pointer;
1601
function getsockname;
1603
GetProcedureAddress(_getsockname, wsock32, 'getsockname');
1612
_getsockopt: Pointer;
1614
function getsockopt;
1616
GetProcedureAddress(_getsockopt, wsock32, 'getsockopt');
1629
GetProcedureAddress(_htonl, wsock32, 'htonl');
1642
GetProcedureAddress(_htons, wsock32, 'htons');
1651
_inet_addr: Pointer;
1655
GetProcedureAddress(_inet_addr, wsock32, 'inet_addr');
1664
_inet_ntoa: Pointer;
1668
GetProcedureAddress(_inet_ntoa, wsock32, 'inet_ntoa');
1681
GetProcedureAddress(_listen, wsock32, 'listen');
1694
GetProcedureAddress(_ntohl, wsock32, 'ntohl');
1707
GetProcedureAddress(_ntohs, wsock32, 'ntohs');
1720
GetProcedureAddress(_recv, wsock32, 'recv');
1733
GetProcedureAddress(_recvfrom, wsock32, 'recvfrom');
1746
GetProcedureAddress(_select, wsock32, 'select');
1759
GetProcedureAddress(_send, wsock32, 'send');
1772
GetProcedureAddress(_sendto, wsock32, 'sendto');
1781
_setsockopt: Pointer;
1783
function setsockopt;
1785
GetProcedureAddress(_setsockopt, wsock32, 'setsockopt');
1798
GetProcedureAddress(_shutdown, wsock32, 'shutdown');
1811
GetProcedureAddress(_socket, wsock32, 'socket');
1820
_gethostbyaddr: Pointer;
1822
function gethostbyaddr;
1824
GetProcedureAddress(_gethostbyaddr, wsock32, 'gethostbyaddr');
1828
JMP [_gethostbyaddr]
1833
_gethostbyname: Pointer;
1835
function gethostbyname;
1837
GetProcedureAddress(_gethostbyname, wsock32, 'gethostbyname');
1841
JMP [_gethostbyname]
1846
_gethostname: Pointer;
1848
function gethostname;
1850
GetProcedureAddress(_gethostname, wsock32, 'gethostname');
1859
_getservbyport: Pointer;
1861
function getservbyport;
1863
GetProcedureAddress(_getservbyport, wsock32, 'getservbyport');
1867
JMP [_getservbyport]
1872
_getservbyname: Pointer;
1874
function getservbyname;
1876
GetProcedureAddress(_getservbyname, wsock32, 'getservbyname');
1880
JMP [_getservbyname]
1885
_getprotobynumber: Pointer;
1887
function getprotobynumber;
1889
GetProcedureAddress(_getprotobynumber, wsock32, 'getprotobynumber');
1893
JMP [_getprotobynumber]
1898
_getprotobyname: Pointer;
1900
function getprotobyname;
1902
GetProcedureAddress(_getprotobyname, wsock32, 'getprotobyname');
1906
JMP [_getprotobyname]
1911
_WSAStartup: Pointer;
1913
function WSAStartup;
1915
GetProcedureAddress(_WSAStartup, wsock32, 'WSAStartup');
1924
_WSACleanup: Pointer;
1926
function WSACleanup;
1928
GetProcedureAddress(_WSACleanup, wsock32, 'WSACleanup');
1937
_WSASetLastError: Pointer;
1939
procedure WSASetLastError;
1941
GetProcedureAddress(_WSASetLastError, wsock32, 'WSASetLastError');
1945
JMP [_WSASetLastError]
1950
_WSAGetLastError: Pointer;
1952
function WSAGetLastError;
1954
GetProcedureAddress(_WSAGetLastError, wsock32, 'WSAGetLastError');
1958
JMP [_WSAGetLastError]
1963
_WSAIsBlocking: Pointer;
1965
function WSAIsBlocking;
1967
GetProcedureAddress(_WSAIsBlocking, wsock32, 'WSAIsBlocking');
1971
JMP [_WSAIsBlocking]
1976
_WSAUnhookBlockingHook: Pointer;
1978
function WSAUnhookBlockingHook;
1980
GetProcedureAddress(_WSAUnhookBlockingHook, wsock32, 'WSAUnhookBlockingHook');
1984
JMP [_WSAUnhookBlockingHook]
1989
_WSASetBlockingHook: Pointer;
1991
function WSASetBlockingHook;
1993
GetProcedureAddress(_WSASetBlockingHook, wsock32, 'WSASetBlockingHook');
1997
JMP [_WSASetBlockingHook]
2002
_WSACancelBlockingCall: Pointer;
2004
function WSACancelBlockingCall;
2006
GetProcedureAddress(_WSACancelBlockingCall, wsock32, 'WSACancelBlockingCall');
2010
JMP [_WSACancelBlockingCall]
2015
_WSAAsyncGetServByName: Pointer;
2017
function WSAAsyncGetServByName;
2019
GetProcedureAddress(_WSAAsyncGetServByName, wsock32, 'WSAAsyncGetServByName');
2023
JMP [_WSAAsyncGetServByName]
2028
_WSAAsyncGetServByPort: Pointer;
2030
function WSAAsyncGetServByPort;
2032
GetProcedureAddress(_WSAAsyncGetServByPort, wsock32, 'WSAAsyncGetServByPort');
2036
JMP [_WSAAsyncGetServByPort]
2041
_WSAAsyncGetProtoByName: Pointer;
2043
function WSAAsyncGetProtoByName;
2045
GetProcedureAddress(_WSAAsyncGetProtoByName, wsock32, 'WSAAsyncGetProtoByName');
2049
JMP [_WSAAsyncGetProtoByName]
2054
_WSAAsyncGetProtoByNumber: Pointer;
2056
function WSAAsyncGetProtoByNumber;
2058
GetProcedureAddress(_WSAAsyncGetProtoByNumber, wsock32, 'WSAAsyncGetProtoByNumber');
2062
JMP [_WSAAsyncGetProtoByNumber]
2067
_WSAAsyncGetHostByName: Pointer;
2069
function WSAAsyncGetHostByName;
2071
GetProcedureAddress(_WSAAsyncGetHostByName, wsock32, 'WSAAsyncGetHostByName');
2075
JMP [_WSAAsyncGetHostByName]
2080
_WSAAsyncGetHostByAddr: Pointer;
2082
function WSAAsyncGetHostByAddr;
2084
GetProcedureAddress(_WSAAsyncGetHostByAddr, wsock32, 'WSAAsyncGetHostByAddr');
2088
JMP [_WSAAsyncGetHostByAddr]
2093
_WSACancelAsyncRequest: Pointer;
2095
function WSACancelAsyncRequest;
2097
GetProcedureAddress(_WSACancelAsyncRequest, wsock32, 'WSACancelAsyncRequest');
2101
JMP [_WSACancelAsyncRequest]
2106
_WSAAsyncSelect: Pointer;
2108
function WSAAsyncSelect;
2110
GetProcedureAddress(_WSAAsyncSelect, wsock32, 'WSAAsyncSelect');
2114
JMP [_WSAAsyncSelect]
2119
_WSARecvEx: Pointer;
2123
GetProcedureAddress(_WSARecvEx, wsock32, 'WSARecvEx');
2132
_TransmitFile: Pointer;
2134
function TransmitFile;
2136
GetProcedureAddress(_TransmitFile, wsock32, 'TransmitFile');
2149
GetProcedureAddress(_AcceptEx, wsock32, 'AcceptEx');
2158
_GetAcceptExSockaddrs: Pointer;
2160
procedure GetAcceptExSockaddrs;
2162
GetProcedureAddress(_GetAcceptExSockaddrs, wsock32, 'GetAcceptExSockaddrs');
2166
JMP [_GetAcceptExSockaddrs]
2172
function __WSAFDIsSet; external wsock32 name '__WSAFDIsSet';
2173
function accept; external wsock32 name 'accept';
2174
function bind; external wsock32 name 'bind';
2175
function closesocket; external wsock32 name 'closesocket';
2176
function connect; external wsock32 name 'connect';
2177
function ioctlsocket; external wsock32 name 'ioctlsocket';
2178
function getpeername; external wsock32 name 'getpeername';
2179
function getsockname; external wsock32 name 'getsockname';
2180
function getsockopt; external wsock32 name 'getsockopt';
2181
function htonl; external wsock32 name 'htonl';
2182
function htons; external wsock32 name 'htons';
2183
function inet_addr; external wsock32 name 'inet_addr';
2184
function inet_ntoa; external wsock32 name 'inet_ntoa';
2185
function listen; external wsock32 name 'listen';
2186
function ntohl; external wsock32 name 'ntohl';
2187
function ntohs; external wsock32 name 'ntohs';
2188
function recv; external wsock32 name 'recv';
2189
function recvfrom; external wsock32 name 'recvfrom';
2190
function select; external wsock32 name 'select';
2191
function send; external wsock32 name 'send';
2192
function sendto; external wsock32 name 'sendto';
2193
function setsockopt; external wsock32 name 'setsockopt';
2194
function shutdown; external wsock32 name 'shutdown';
2195
function socket; external wsock32 name 'socket';
2196
function gethostbyaddr; external wsock32 name 'gethostbyaddr';
2197
function gethostbyname; external wsock32 name 'gethostbyname';
2198
function gethostname; external wsock32 name 'gethostname';
2199
function getservbyport; external wsock32 name 'getservbyport';
2200
function getservbyname; external wsock32 name 'getservbyname';
2201
function getprotobynumber; external wsock32 name 'getprotobynumber';
2202
function getprotobyname; external wsock32 name 'getprotobyname';
2203
function WSAStartup; external wsock32 name 'WSAStartup';
2204
function WSACleanup; external wsock32 name 'WSACleanup';
2205
procedure WSASetLastError; external wsock32 name 'WSASetLastError';
2206
function WSAGetLastError; external wsock32 name 'WSAGetLastError';
2207
function WSAIsBlocking; external wsock32 name 'WSAIsBlocking';
2208
function WSAUnhookBlockingHook; external wsock32 name 'WSAUnhookBlockingHook';
2209
function WSASetBlockingHook; external wsock32 name 'WSASetBlockingHook';
2210
function WSACancelBlockingCall; external wsock32 name 'WSACancelBlockingCall';
2211
function WSAAsyncGetServByName; external wsock32 name 'WSAAsyncGetServByName';
2212
function WSAAsyncGetServByPort; external wsock32 name 'WSAAsyncGetServByPort';
2213
function WSAAsyncGetProtoByName; external wsock32 name 'WSAAsyncGetProtoByName';
2214
function WSAAsyncGetProtoByNumber; external wsock32 name 'WSAAsyncGetProtoByNumber';
2215
function WSAAsyncGetHostByName; external wsock32 name 'WSAAsyncGetHostByName';
2216
function WSAAsyncGetHostByAddr; external wsock32 name 'WSAAsyncGetHostByAddr';
2217
function WSACancelAsyncRequest; external wsock32 name 'WSACancelAsyncRequest';
2218
function WSAAsyncSelect; external wsock32 name 'WSAAsyncSelect';
2219
function WSARecvEx; external wsock32 name 'WSARecvEx';
2220
function TransmitFile; external wsock32 name 'TransmitFile';
2221
function AcceptEx; external wsock32 name 'AcceptEx';
2222
procedure GetAcceptExSockaddrs; external wsock32 name 'GetAcceptExSockaddrs';
2224
{$ENDIF DYNAMIC_LINK}