1
{****************************************************************************
4
This file is part of the Free Pascal run time library.
5
Copyrigth (c) 2003 by Yuri Prokushev (prokushev@freemail.ru)
7
This file corresponds to version 1.1 of the Windows Sockets
10
See the file COPYING.FPC, included in this distribution,
11
for details about the copyright.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
****************************************************************************}
28
// The new type to be used in all instances which refer to sockets.
36
// Select uses arrays of TSockets. These macros manipulate such
37
// arrays. FD_SETSIZE may be defined by the user before including
38
// this file, but the default here should be >= 64.
40
// CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
41
// INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
47
fd_count: Word; // how many are SET?
48
fd_array: Array[0..FD_SETSIZE-1] of TSocket; // an array of TSockets
54
Function __WSAFDIsSet(a: TSocket;var b: fdset): Longint; cdecl;
55
external 'PMWSock' name '__WSAFDIsSet';
56
Function __WSAFDIsSet_(s:TSocket; var FDSet:TFDSet): Longint; cdecl;
57
external 'PMWSock' name '__WSAFDIsSet';
58
Function __WSAFDIsSet2_(s:TSocket; var FDSet:TFDSet): boolean; cdecl;
59
external 'PMWSock' name '__WSAFDIsSet';
61
Function FD_ISSET2(a: TSocket;var b: fdset): Longint; cdecl;
62
external 'PMWSock' name '__WSAFDIsSet';
64
Function FD_ISSET(a: TSocket;var b: fdset): boolean; cdecl;
65
external 'PMWSock' name '__WSAFDIsSet';
67
Procedure FD_CLR(ASocket: TSocket; var aset: fdset);
68
Procedure FD_SET(Socket:TSocket; var FDSet:TFDSet);
70
// Structure used in select() call, taken from the BSD file sys/time.h.
73
tv_sec: LongInt; // seconds
74
tv_usec: LongInt; // and microseconds
80
{ found no reference to this type in c header files and here. AlexS }
81
{ minutes west of Greenwich }
82
{ type of dst correction }
84
tz_minuteswest : longint;
88
PTimeZone = ^TTimeZone;
90
// Operations on timevals.
91
// timercmp does not work for >= or <=.
93
Function timerisset(tvp: timeval): Boolean;
94
//Function timercmp(tvp, uvp, cmp);
95
Procedure timerclear(var tvp: timeval);
97
// Commands for ioctlsocket(), taken from the BSD file fcntl.h.
99
// Ioctl's have the command encoded in the lower word,
100
// and the size of any in or out parameters in the upper
101
// word. The high 2 bits of the upper word are used
102
// to encode the in/out status of the parameter; for now
103
// we restrict parameters to at most 128 bytes.
106
IOCPARM_MASK = $7f; // parameters must be < 128 bytes
107
IOC_VOID = $20000000; // no parameters
108
IOC_OUT = $40000000; // copy out parameters
109
IOC_IN = longint ($80000000); // copy in parameters
110
IOC_INOUT = IOC_IN or IOC_OUT; // 0x20000000 distinguishes new &
113
// get # bytes to read
114
FIONREAD=(IOC_OUT or ((Longint (sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 127);
115
// set/clear non-blocking i/o
116
FIONBIO=(IOC_IN or ((Longint(sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 126);
117
// set/clear async i/o
118
FIOASYNC=(IOC_IN or ((Longint(sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('f') shl 8) or 125);
120
// Socket I/O Controls
122
// set high watermark
123
SIOCSHIWAT=(IOC_IN or ((Longint(sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 0);
124
// get high watermark
125
SIOCGHIWAT=(IOC_OUT or ((Longint (sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 1);
127
SIOCSLOWAT=(IOC_IN or ((Longint(sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 2);
129
SIOCGLOWAT=(IOC_OUT or ((Longint (sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 3);
131
SIOCATMARK=(IOC_OUT or ((Longint (sizeof(Cardinal)) and IOCPARM_MASK) shl 16) or (Ord('s') shl 8) or 7);
133
// Structures returned by network data base library, taken from the
134
// BSD file netdb.h. All addresses are supplied in host order, and
135
// returned in network order (suitable for use in system calls).
139
h_name: PChar; // official name of host
140
h_aliases: PPChar; // alias list
141
h_addrtype: LongInt; // host address type
142
h_length: LongInt; // length of address
144
0: (h_addr_list: ppchar); // list of addresses from name server
145
1: (h_addr: ppchar) // address, for backward compatiblity
150
// It is assumed here that a network number
154
n_name: PChar; // official name of net
155
n_aliases: PPChar; // alias list
156
n_addrtype: Longint; // net address type
157
n_net: Cardinal; // network #
164
s_name: PChar; // official service name
165
s_aliases: PPChar; // alias list
166
s_port: LongInt; // port #
167
s_proto: PChar; // protocol to use
173
p_name: PChar; // official protocol name
174
p_aliases: PPChar; // alias list
175
p_proto: LongInt; // protocol #
177
TProtoEnt = protoent;
180
// Constants and structures defined by the internet system,
181
// Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
185
IPPROTO_IP =0; // dummy for IP
186
IPPROTO_ICMP =1; // control message protocol
187
IPPROTO_GGP =2; // gateway^2 (deprecated)
188
IPPROTO_TCP =6; // tcp
189
IPPROTO_PUP =12; // pup
190
IPPROTO_UDP =17; // user datagram protocol
191
IPPROTO_IDP =22; // xns idp
192
IPPROTO_ND =77; // UNOFFICIAL net disk proto
193
IPPROTO_RAW =255; // raw IP packet
196
// Port/socket numbers: network standard functions
206
IPPORT_TIMESERVER =37;
207
IPPORT_NAMESERVER =42;
211
// Port/socket numbers: host specific functions
221
IPPORT_EXECSERVER =512;
222
IPPORT_LOGINSERVER =513;
223
IPPORT_CMDSERVER =514;
224
IPPORT_EFSSERVER =520;
229
IPPORT_WHOSERVER =513;
230
IPPORT_ROUTESERVER =520;
233
// Ports < IPPORT_RESERVED are reserved for
234
// privileged processes (e.g. root).
236
IPPORT_RESERVED =1024;
241
IMPLINK_LOWEXPER =156;
242
IMPLINK_HIGHEXPER =158;
244
// Internet address (old style... should be updated)
249
1:(S_un_b:record s_b1,s_b2,s_b3,s_b4: Byte; end;);
250
2:(s_un_w:record s_w1,s_w2: Word; end;);
251
3:(s_addr: Cardinal);
256
{$define s_addr:=in_addr.S_addr} // can be used for most tcp & ip code
257
{$define s_host:=in_addr.S_un_b.s_b2} // host on imp
258
{$define s_net:=in_addr.S_un_b.s_b1} // network
259
{$define s_imp:=in_addr.S_un_w.s_w2} // imp
260
{$define s_impno:=in_addr.S_un_b.s_b4} // imp #
261
{$define s_lh:=in_addr.S_un_b.s_b3} // logical host
263
// Definitions of bits in internet address integers.
264
// On subnets, the decomposition of addresses to host and net parts
265
// is done according to subnet mask, not the masks here.
267
{$define IN_CLASSA(i):=((Longint(i) and $80000000) = 0)}
268
IN_CLASSA_NET =$ff000000;
269
IN_CLASSA_NSHIFT =24;
270
IN_CLASSA_HOST =$00ffffff;
273
{$define IN_CLASSB(i):=((Longint(i) and $c0000000) = $80000000)}
274
IN_CLASSB_NET =$ffff0000;
275
IN_CLASSB_NSHIFT =16;
276
IN_CLASSB_HOST =$0000ffff;
277
IN_CLASSB_MAX =65536;
279
{$define IN_CLASSC(i):=((Longint(i) and $e0000000) = $c0000000)}
280
IN_CLASSC_NET =$ffffff00;
282
IN_CLASSC_HOST =$000000ff;
284
INADDR_ANY =$00000000;
285
INADDR_LOOPBACK =$7f000001;
286
INADDR_BROADCAST =$ffffffff;
287
INADDR_NONE =$ffffffff;
289
// Socket address, internet style.
294
0 : ( (* equals to sockaddr_in, size is 16 byte *)
295
sin_family : SmallInt; (* 2 byte *)
296
sin_port : Word; (* 2 byte *)
297
sin_addr : TInAddr; (* 4 byte *)
298
sin_zero : array[0..8-1] of char; (* 8 byte *)
300
1 : ((* equals to sockaddr, size is 16 byte *)
301
sa_family : Smallint; (* 2 byte *)
302
sa_data : array[0..14-1] of char; (* 14 byte *)
305
TSockAddrIn = sockaddr_in;
306
PSockAddrIn = ^TSockAddrIn;
307
TSockAddr = sockaddr_in;
308
PSockAddr = ^TSockAddr;
311
WSADESCRIPTION_LEN =256;
312
WSASYS_STATUS_LEN =128;
318
szDescription: array[0..WSADESCRIPTION_LEN] of Char;
319
szSystemStatus: array[0..WSASYS_STATUS_LEN] of Char;
322
// in OS/2 no such entry
323
// pad1 : SmallInt; { 2 byte, ofs 394 } { ensure right packaging }
330
// Options for use with [gs]etsockopt at the IP level.
333
IP_OPTIONS =1; // set/get IP per-packet options
336
IP_MULTICAST_TTL = 3;
337
IP_MULTICAST_LOOP = 4;
338
IP_ADD_MEMBERSHIP = 5;
339
IP_DROP_MEMBERSHIP = 6;
340
IP_DEFAULT_MULTICAST_TTL = 1;
341
IP_DEFAULT_MULTICAST_LOOP = 1;
342
IP_MAX_MEMBERSHIPS = 20;
346
imr_multiaddr : in_addr;
347
imr_interface : in_addr;
350
// Definitions related to sockets: types, address families, options,
351
// taken from the BSD file sys/socket.h.
353
// This is used instead of -1, since the
354
// TSocket type is unsigned.
362
SOCK_STREAM =1; // stream socket
363
SOCK_DGRAM =2; // datagram socket
364
SOCK_RAW =3; // raw-protocol interface
365
SOCK_RDM =4; // reliably-delivered message
366
SOCK_SEQPACKET =5; // sequenced packet stream
368
// Option flags per-socket.
371
SO_DEBUG =$0001; // turn on debugging info recording
372
SO_ACCEPTCONN =$0002; // socket has had listen()
373
SO_REUSEADDR =$0004; // allow local address reuse
374
SO_KEEPALIVE =$0008; // keep connections alive
375
SO_DONTROUTE =$0010; // just use interface addresses
376
SO_BROADCAST =$0020; // permit sending of broadcast msgs
377
SO_USELOOPBACK =$0040; // bypass hardware when possible
378
SO_LINGER =$0080; // linger on close if data present
379
SO_OOBINLINE =$0100; // leave received OOB data in line
380
SO_DONTLINGER =NOT SO_LINGER; // dont linger
382
// Additional options.
384
SO_SNDBUF =$1001; // send buffer size
385
SO_RCVBUF =$1002; // receive buffer size
386
SO_SNDLOWAT =$1003; // send low-water mark
387
SO_RCVLOWAT =$1004; // receive low-water mark
388
SO_SNDTIMEO =$1005; // send timeout
389
SO_RCVTIMEO =$1006; // receive timeout
390
SO_ERROR =$1007; // get error status and clear
391
SO_TYPE =$1008; // get socket type
394
Options for connect and disconnect data and options. Used only by
395
non-TCP/IP transports such as DECNet, OSI TP4, etc.
401
SO_CONNDATALEN = $7004;
402
SO_CONNOPTLEN = $7005;
403
SO_DISCDATALEN = $7006;
404
SO_DISCOPTLEN = $7007;
407
Option for opening sockets for synchronous access.
410
SO_SYNCHRONOUS_ALERT = $10;
411
SO_SYNCHRONOUS_NONALERT = $20;
414
Other NT-specific options.
417
SO_MAXPATHDG = $700A;
418
SO_UPDATE_ACCEPT_CONTEXT = $700B;
419
SO_CONNECT_TIME = $700C;
425
TCP_BSDURGENT = $7000;
430
AF_UNSPEC =0; // unspecified
431
AF_UNIX =1; // local to host (pipes, portals)
432
AF_INET =2; // internetwork: UDP, TCP, etc.
433
AF_IMPLINK =3; // arpanet imp addresses
434
AF_PUP =4; // pup protocols: e.g. BSP
435
AF_CHAOS =5; // mit CHAOS protocols
436
AF_NS =6; // XEROX NS protocols
437
AF_ISO =7; // ISO protocols
438
AF_OSI =AF_ISO; // OSI is ISO
439
AF_ECMA =8; // european computer manufacturers
440
AF_DATAKIT =9; // datakit protocols
441
AF_CCITT =10; // CCITT protocols, X.25 etc
442
AF_SNA =11; // IBM SNA
443
AF_DECnet =12; // DECnet
444
AF_DLI =13; // Direct data link interface
446
AF_HYLINK =15; // NSC Hyperchannel
447
AF_APPLETALK =16; // AppleTalk
448
AF_NETBIOS =17; // NetBios-style addresses
453
{ Somebody is using this! }
460
// Structure used by kernel to store most
465
sa_family:Word; // address family
466
sa_data:Array[0..13] of char; // up to 14 bytes of direct address
469
// Structure used by kernel to pass protocol
470
// information in raw sockets.
473
sp_family:Word; // address family
474
sp_protocol:Word; // protocol
477
TSockProto = sockproto;
478
PSockProto = ^TSockProto;
481
// Protocol families, same as address families for now.
484
PF_UNSPEC =AF_UNSPEC;
487
PF_IMPLINK =AF_IMPLINK;
494
PF_DATAKIT =AF_DATAKIT;
497
PF_DECnet =AF_DECnet;
500
PF_HYLINK =AF_HYLINK;
501
PF_APPLETALK =AF_APPLETALK;
503
PF_FIREFOX = AF_FIREFOX;
504
PF_UNKNOWN1 = AF_UNKNOWN1;
509
// Structure used for manipulating linger option.
513
l_onoff:LongInt; // option on/off
514
l_linger:LongInt; // linger time
519
// Level number for (get/set)sockopt() to apply to socket itself.
522
SOL_SOCKET =$ffff; // options for socket level
524
// Maximum queue length specifiable by listen.
528
MSG_OOB =1; // process out-of-band data
529
MSG_PEEK =2; // peek at incoming message
530
MSG_DONTROUTE =4; // send without using routing tables
533
// Define constant based on rfc883, used by gethostbyxxxx() calls.
535
MAXGETHOSTSTRUCT =1024;
536
MAXHOSTNAMELEN = MAXGETHOSTSTRUCT;
538
// Define flags to be used with the WSAAsyncSelect() call.
547
// All Windows Sockets error constants are biased by WSABASEERR from
553
// Windows Sockets definitions of regular Microsoft C error constants
555
WSAEINTR =(WSABASEERR+4);
556
WSAEBADF =(WSABASEERR+9);
557
WSAEACCES =(WSABASEERR+13);
558
WSAEFAULT =(WSABASEERR+14);
559
WSAEINVAL =(WSABASEERR+22);
560
WSAEMFILE =(WSABASEERR+24);
562
// Windows Sockets definitions of regular Berkeley error constants
564
WSAEWOULDBLOCK =(WSABASEERR+35);
565
WSAEINPROGRESS =(WSABASEERR+36);
566
WSAEALREADY =(WSABASEERR+37);
567
WSAENOTSOCK =(WSABASEERR+38);
568
WSAEDESTADDRREQ =(WSABASEERR+39);
569
WSAEMSGSIZE =(WSABASEERR+40);
570
WSAEPROTOTYPE =(WSABASEERR+41);
571
WSAENOPROTOOPT =(WSABASEERR+42);
572
WSAEPROTONOSUPPORT =(WSABASEERR+43);
573
WSAESOCKTNOSUPPORT =(WSABASEERR+44);
574
WSAEOPNOTSUPP =(WSABASEERR+45);
575
WSAEPFNOSUPPORT =(WSABASEERR+46);
576
WSAEAFNOSUPPORT =(WSABASEERR+47);
577
WSAEADDRINUSE =(WSABASEERR+48);
578
WSAEADDRNOTAVAIL =(WSABASEERR+49);
579
WSAENETDOWN =(WSABASEERR+50);
580
WSAENETUNREACH =(WSABASEERR+51);
581
WSAENETRESET =(WSABASEERR+52);
582
WSAECONNABORTED =(WSABASEERR+53);
583
WSAECONNRESET =(WSABASEERR+54);
584
WSAENOBUFS =(WSABASEERR+55);
585
WSAEISCONN =(WSABASEERR+56);
586
WSAENOTCONN =(WSABASEERR+57);
587
WSAESHUTDOWN =(WSABASEERR+58);
588
WSAETOOMANYREFS =(WSABASEERR+59);
589
WSAETIMEDOUT =(WSABASEERR+60);
590
WSAECONNREFUSED =(WSABASEERR+61);
591
WSAELOOP =(WSABASEERR+62);
592
WSAENAMETOOLONG =(WSABASEERR+63);
593
WSAEHOSTDOWN =(WSABASEERR+64);
594
WSAEHOSTUNREACH =(WSABASEERR+65);
595
WSAENOTEMPTY =(WSABASEERR+66);
596
WSAEPROCLIM =(WSABASEERR+67);
597
WSAEUSERS =(WSABASEERR+68);
598
WSAEDQUOT =(WSABASEERR+69);
599
WSAESTALE =(WSABASEERR+70);
600
WSAEREMOTE =(WSABASEERR+71);
601
WSAEDISCON = WSABASEERR + 101;
603
// Extended Windows Sockets error constant definitions
605
WSASYSNOTREADY =(WSABASEERR+91);
606
WSAVERNOTSUPPORTED =(WSABASEERR+92);
607
WSANOTINITIALISED =(WSABASEERR+93);
609
// Error return codes from gethostbyname() and gethostbyaddr()
610
// (when using the resolver). Note that these errors are
611
// retrieved via WSAGetLastError() and must therefore follow
612
// the rules for avoiding clashes with error numbers from
613
// specific implementations or language run-time systems.
614
// For this reason the codes are based at WSABASEERR+1001.
615
// Note also that [WSA]NO_ADDRESS is defined only for
616
// compatibility purposes.
618
{$define h_errno:=WSAGetLastError()}
620
// Authoritative Answer: Host not found
622
WSAHOST_NOT_FOUND =(WSABASEERR+1001);
623
HOST_NOT_FOUND =WSAHOST_NOT_FOUND;
625
// Non-Authoritative: Host not found, or SERVERFAIL
627
WSATRY_AGAIN =(WSABASEERR+1002);
628
TRY_AGAIN =WSATRY_AGAIN;
630
// Non recoverable errors, FORMERR, REFUSED, NOTIMP
632
WSANO_RECOVERY =(WSABASEERR+1003);
633
NO_RECOVERY =WSANO_RECOVERY;
635
// Valid name, no data record of requested type
637
WSANO_DATA =(WSABASEERR+1004);
640
// no address, look for MX record
642
WSANO_ADDRESS =WSANO_DATA;
643
NO_ADDRESS =WSANO_ADDRESS;
645
// Windows Sockets errors redefined as regular Berkeley error constants
648
EWOULDBLOCK =WSAEWOULDBLOCK;
649
EINPROGRESS =WSAEINPROGRESS;
650
EALREADY =WSAEALREADY;
651
ENOTSOCK =WSAENOTSOCK;
652
EDESTADDRREQ =WSAEDESTADDRREQ;
653
EMSGSIZE =WSAEMSGSIZE;
654
EPROTOTYPE =WSAEPROTOTYPE;
655
ENOPROTOOPT =WSAENOPROTOOPT;
656
EPROTONOSUPPORT =WSAEPROTONOSUPPORT;
657
ESOCKTNOSUPPORT =WSAESOCKTNOSUPPORT;
658
EOPNOTSUPP =WSAEOPNOTSUPP;
659
EPFNOSUPPORT =WSAEPFNOSUPPORT;
660
EAFNOSUPPORT =WSAEAFNOSUPPORT;
661
EADDRINUSE =WSAEADDRINUSE;
662
EADDRNOTAVAIL =WSAEADDRNOTAVAIL;
663
ENETDOWN =WSAENETDOWN;
664
ENETUNREACH =WSAENETUNREACH;
665
ENETRESET =WSAENETRESET;
666
ECONNABORTED =WSAECONNABORTED;
667
ECONNRESET =WSAECONNRESET;
670
ENOTCONN =WSAENOTCONN;
671
ESHUTDOWN =WSAESHUTDOWN;
672
ETOOMANYREFS =WSAETOOMANYREFS;
673
ETIMEDOUT =WSAETIMEDOUT;
674
ECONNREFUSED =WSAECONNREFUSED;
676
ENAMETOOLONG =WSAENAMETOOLONG;
677
EHOSTDOWN =WSAEHOSTDOWN;
678
EHOSTUNREACH =WSAEHOSTUNREACH;
679
ENOTEMPTY =WSAENOTEMPTY;
680
EPROCLIM =WSAEPROCLIM;
687
TF_REUSE_SOCKET = $02;
688
TF_WRITE_BEHIND = $04;
691
Options for use with [gs]etsockopt at the IP level.
698
_TRANSMIT_FILE_BUFFERS = record
700
HeadLength : Cardinal;
702
TailLength : Cardinal;
704
TRANSMIT_FILE_BUFFERS = _TRANSMIT_FILE_BUFFERS;
705
TTransmitFileBuffers = _TRANSMIT_FILE_BUFFERS;
706
PTransmitFileBuffers = ^TTransmitFileBuffers;
708
// Socket function prototypes
710
Function accept(s: TSocket; Var addr; Var addrlen: LongInt): TSocket; cdecl;
711
external 'PMWSock' name 'accept';
712
Function accept(s:TSocket; addr: PSockAddr; addrlen : PLongint) : TSocket; cdecl;
713
external 'PMWSock' name 'accept';
714
Function accept(s:TSocket; addr: PSockAddr; var addrlen : Longint) : TSocket; cdecl;
715
external 'PMWSock' name 'accept';
717
Function bind(s: TSocket; Const addr; namelen: LongInt): LongInt; cdecl;
718
external 'PMWSock' name 'bind';
719
Function bind(s:TSocket; addr: PSockaddr;namelen: Longint): Longint; cdecl;
720
external 'PMWSock' name 'bind';
722
Function closesocket(s: TSocket): LongInt; cdecl;
723
external 'PMWSock' name 'closesocket';
725
Function connect(s: TSocket; Const name: sockaddr; namelen: LongInt): LongInt; cdecl;
726
external 'PMWSock' name 'connect';
727
Function connect(s:TSocket; addr:PSockAddr; namelen: Longint): Longint; cdecl;
728
external 'PMWSock' name 'connect';
730
Function ioctlsocket(s: TSocket; cmd: LongInt; Var argp: Cardinal): LongInt; cdecl;
731
external 'PMWSock' name 'ioctlsocket';
732
Function ioctlsocket(s: TSocket; cmd: longint; var arg:longint): Longint; cdecl;
733
external 'PMWSock' name 'ioctlsocket';
734
Function ioctlsocket(s: TSocket; cmd: longint; argp: PCardinal): Longint; cdecl;
735
external 'PMWSock' name 'ioctlsocket';
737
Function getpeername(s: TSocket; Var name: sockaddr; Var nameLen: LongInt): LongInt; cdecl;
738
external 'PMWSock' name 'getpeername';
740
Function getsockname(s: TSocket;Var name: sockaddr; Var namelen: LongInt): LongInt; cdecl;
741
external 'PMWSock' name 'getsockname';
743
Function getsockopt(s: TSocket; level, optname: LongInt;Var optval; Var optlen: LongInt): LongInt; cdecl;
744
external 'PMWSock' name 'getsockopt';
745
Function getsockopt(s: TSocket; level: Longint; optname: Longint; optval:pchar;var optlen: Longint): Longint; cdecl;
746
external 'PMWSock' name 'getsockopt';
748
Function htonl(hostlong: Cardinal): Cardinal; cdecl;
749
external 'PMWSock' name 'htonl';
751
Function htons(hostshort: Word): Word; cdecl;
752
external 'PMWSock' name 'htons';
754
Function inet_addr(cp: pchar): Cardinal; cdecl;
755
external 'PMWSock' name 'inet_addr';
757
Function inet_ntoa(Var _in: in_addr): PChar; cdecl;
758
external 'PMWSock' name 'inet_ntoa';
759
Function inet_ntoa(i: PInAddr): pchar; cdecl;
760
external 'PMWSock' name 'inet_ntoa';
762
Function listen(s: TSocket; backlog: LongInt): LongInt; cdecl;
763
external 'PMWSock' name 'listen';
765
Function ntohl(netlong: Cardinal): Cardinal; cdecl;
766
external 'PMWSock' name 'ntohl';
768
Function ntohs(netshort: Word): Word; cdecl;
769
external 'PMWSock' name 'ntohs';
771
Function recv(s: TSocket;Var Buf; len, flags: LongInt): LongInt; cdecl;
772
external 'PMWSock' name 'recv';
773
Function recv(s: TSocket; buf:pchar; len: Longint; flags: Longint): Longint; cdecl;
774
external 'PMWSock' name 'recv';
776
Function recvfrom(s: TSocket; Var Buf: PChar; len, flags:LongInt;
777
Var from: sockaddr; Var fromLen: LongInt): LongInt; cdecl;
778
external 'PMWSock' name 'recvfrom';
779
Function recvfrom(s: TSocket; buf:pchar; len: Longint; flags: Longint;
780
from: PSockAddr; fromlen: Longint): Longint; cdecl;
781
external 'PMWSock' name 'recvfrom';
782
Function recvfrom(s: TSocket; var buf; len: Longint; flags: Longint;
783
Const from: TSockAddr; var fromlen: Longint): Longint; cdecl;
784
external 'PMWSock' name 'recvfrom';
786
Function select(nfds: LongInt; Var readfds, writefds, exceptfds: fdset;
787
Const timeout: timeval): LongInt; cdecl;
788
external 'PMWSock' name 'select';
789
Function select(nfds: Longint; readfds, writefds, exceptfds : PFDSet;
790
timeout: PTimeVal): Longint; cdecl;
791
external 'PMWSock' name 'select';
793
Function send(s: TSocket; Const Buf: PChar; len, flags: LongInt): LongInt; cdecl;
794
external 'PMWSock' name 'send';
796
Function sendto(s: TSocket; Const Buf: PChar; len, flags: LongInt;
797
Const _to: sockaddr; tolen: LongInt): LongInt; cdecl;
798
external 'PMWSock' name 'sendto';
799
Function sendto(s: TSocket; buf: pchar; len: Longint; flags: Longint;
800
toaddr: PSockAddr; tolen: Longint): Longint; cdecl;
801
external 'PMWSock' name 'sendto';
803
Function setsockopt(s: TSocket; level: Longint; optname: Longint;
804
optval: pchar; optlen: Longint): Longint; cdecl;
805
external 'PMWSock' name 'setsockopt';
807
Function shutdown(s: TSocket; how: LongInt): LongInt; cdecl;
808
external 'PMWSock' name 'shutdown';
810
Function socket(af, typ, protocol: LongInt): TSocket; cdecl;
811
external 'PMWSock' name 'socket';
813
// Database function prototypes
815
Function gethostbyaddr(addr: pchar; len: Longint; t: Longint): PHostEnt; cdecl;
816
external 'PMWSock' name 'gethostbyaddr';
818
Function gethostbyname(name: pchar): PHostEnt; cdecl;
819
external 'PMWSock' name 'gethostbyname';
821
Function gethostname(name: pchar; namelen: Longint): Longint; cdecl;
822
external 'PMWSock' name 'gethostname';
824
Function getservbyport(port: Longint; proto: pchar): PServEnt; cdecl;
825
external 'PMWSock' name 'getservbyport';
827
Function getservbyname(name: pchar; proto: pchar): PServEnt; cdecl;
828
external 'PMWSock' name 'getservbyname';
830
Function getprotobynumber(proto: LongInt): pprotoent; cdecl;
831
external 'PMWSock' name 'getprotobynumber';
833
Function getprotobyname(name: pchar): PProtoEnt; cdecl;
834
external 'PMWSock' name 'getprotobyname';
836
// Microsoft Windows Extension function prototypes
838
Function WSAStartup(wVersionRequired: Word;Var aWSAData: WSAData): LongInt; cdecl;
839
external 'PMWSock' name 'WSAStartup';
841
Function WSACleanup: LongInt; cdecl;
842
external 'PMWSock' name 'WSACleanup';
844
Procedure WSASetLastError(iError: LongInt); cdecl;
845
external 'PMWSock' name 'WSASetLastError';
847
Function WSAGetLastError: LongInt; cdecl;
848
external 'PMWSock' name 'WSAGetLastError';
850
Function WSAIsBlocking: Longbool; cdecl;
851
external 'PMWSock' name 'WSAIsBlocking';
853
Function WSAUnhookBlockingHook: LongInt; cdecl;
854
external 'PMWSock' name 'WSAUnhookBlockingHook';
856
Function WSASetBlockingHook(lpBlockFunc: Pointer): Pointer; cdecl;
857
external 'PMWSock' name 'WSASetBlockingHook';
859
Function WSACancelBlockingCall: LongInt; cdecl;
860
external 'PMWSock' name 'WSACancelBlockingCall';
862
Function WSAAsyncGetServByName(hWnd: HWND; wMsg: Cardinal;
863
name: pchar; proto: pchar;
865
buflen: Longint): Cardinal; cdecl;
866
external 'PMWSock' name 'WSAAsyncGetServByName';
868
Function WSAAsyncGetServByPort(hWnd: HWND; wMsg: Cardinal;
870
proto: pchar; buf: pchar;
871
buflen: Longint): Cardinal; cdecl;
872
external 'PMWSock' name 'WSAAsyncGetServByPort';
874
Function WSAAsyncGetProtoByName(hWnd: HWND; wMsg: Cardinal;
875
name: pchar; buf: pchar;
876
buflen: Longint): Cardinal; cdecl;
877
external 'PMWSock' name 'WSAAsyncGetProtoByName';
879
Function WSAAsyncGetProtoByNumber(hWnd: HWND; wMsg: Cardinal;
882
buflen: Longint): Cardinal; cdecl;
883
external 'PMWSock' name 'WSAAsyncGetProtoByNumber';
885
Function WSAAsyncGetHostByName(hWnd: HWND; wMsg: Cardinal;
886
name: pchar; buf: pchar;
887
buflen: Longint): Cardinal; cdecl;
888
external 'PMWSock' name 'WSAAsyncGetHostByName';
890
Function WSAAsyncGetHostByAddr(hWnd: HWND; wMsg: Cardinal;
891
addr: pchar; len: Longint; t: Longint;
892
buf: pchar; buflen: Longint): Cardinal; cdecl;
893
external 'PMWSock' name 'WSAAsyncGetHostByAddr';
895
Function WSACancelAsyncRequest(hAsyncTaskHandle: Cardinal): LongInt; cdecl;
896
external 'PMWSock' name 'WSACancelAsyncRequest';
898
Function WSAAsyncSelect(s: TSocket; ahWnd: HWND; wMsg: Cardinal; lEvent: LongInt): Cardinal; cdecl;
899
external 'PMWSock' name 'WSAAsyncSelect';
901
// Windows message parameter composition and decomposition
904
// WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
905
// when constructing the response to a WSAAsyncGetXByY() routine.
907
Function WSAMakeAsyncReply(Buflen,Error:Word):dword;
908
// Seems to be error in rtl\win32\winsock.pp
909
Function WSAMakeSyncReply(Buflen,Error:Word):dword;
911
// WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
912
// when constructing the response to WSAAsyncSelect().
914
Function WSAMakeSelectReply(Event,Error:Word):dword;
916
// WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
917
// to extract the buffer length from the lParam in the response
918
// to a WSAGetXByY().
920
Function WSAGetAsyncBuflen(Param:dword):Word;
923
// WSAGETASYNCERROR is intended for use by the Windows Sockets application
924
// to extract the error code from the lParam in the response
925
// to a WSAGetXByY().
927
Function WSAGetAsyncError(Param:dword):Word;
929
// WSAGETSELECTEVENT is intended for use by the Windows Sockets application
930
// to extract the event code from the lParam in the response
931
// to a WSAAsyncSelect().
933
Function WSAGetSelectEvent(Param:dword):Word;
935
// WSAGETSELECTERROR is intended for use by the Windows Sockets application
936
// to extract the error code from the lParam in the response
937
// to a WSAAsyncSelect().
939
Function WSAGetSelectError(Param:dword):Word;
941
Procedure FD_ZERO(var aset: fdset);
943
// Following functions not found in PMWSock
945
function WSARecvEx(s:TSocket;var buf; len:tOS_INT; flags:ptOS_INT):tOS_INT;stdcall;
946
external winsockdll name 'WSARecvEx';
947
function TransmitFile(hSocket:TSocket; hFile:THandle; nNumberOfBytesToWrite:dword;
948
nNumberOfBytesPerSend:DWORD; lpOverlapped:POverlapped;
949
lpTransmitBuffers:PTransmitFileBuffers; dwReserved:dword):Bool;stdcall;
950
external winsockdll name 'TransmitFile';
952
function AcceptEx(sListenSocket,sAcceptSocket:TSocket;
953
lpOutputBuffer:Pointer; dwReceiveDataLength,dwLocalAddressLength,
954
dwRemoteAddressLength:dword; var lpdwBytesReceived:dword;
955
lpOverlapped:POverlapped):Bool;stdcall;
956
external winsockdll name 'AcceptEx';
958
procedure GetAcceptExSockaddrs(lpOutputBuffer:Pointer;
959
dwReceiveDataLength,dwLocalAddressLength,dwRemoteAddressLength:dword;
960
var LocalSockaddr:TSockAddr; var LocalSockaddrLength:tOS_INT;
961
var RemoteSockaddr:TSockAddr; var RemoteSockaddrLength:tOS_INT);stdcall;
962
external winsockdll name 'GetAcceptExSockaddrs';
967
Procedure FD_CLR(ASocket: TSocket; var aset: fdset);
972
while I <= aset.fd_count do
974
if (aset.fd_array[i] = ASocket) then
976
while (i < (aset.fd_count-1)) do
978
aset.fd_array[I]:=aset.fd_array[i+1];
988
Procedure FD_ZERO(var aset: fdset);
993
procedure FD_SET(Socket: TSocket; var FDSet: tfdset);
995
if FDSet.fd_count < FD_SETSIZE then
997
FDSet.fd_array[FDSet.fd_count] := Socket;
1002
Function MAKELONG(a,b : longint) : LONGINT;
1004
MAKELONG:=LONGINT((WORD(a)) or ((CARDINAL(WORD(b))) shl 16));
1007
Function WSAMakeAsyncReply(Buflen,Error:Word):dword;
1009
WSAMakeAsyncReply:=MakeLong(Buflen, Error);
1012
Function WSAMakeSyncReply(Buflen,Error:Word):dword;
1014
WSAMakeSyncReply:=WSAMakeAsyncReply(Buflen,Error);
1017
Function WSAMakeSelectReply(Event,Error:Word):dword;
1019
WSAMakeSelectReply:=MakeLong(Event,Error);
1022
Function WSAGetAsyncBuflen(Param:dword):Word;
1024
WSAGetAsyncBuflen:=lo(Param);
1027
Function WSAGetAsyncError(Param:dword):Word;
1029
WSAGetAsyncError:=hi(Param);
1032
Function WSAGetSelectEvent(Param:dword):Word;
1034
WSAGetSelectEvent:=lo(Param);
1037
Function WSAGetSelectError(Param:dword):Word;
1039
WSAGetSelectError:=hi(Param);
1042
Function timerisset(tvp: timeval): Boolean;
1044
TimerIsSet:=Boolean(tvp.tv_sec or tvp.tv_usec);
1048
Function timercmp(tvp, uvp, cmp): Boolean;
1050
((tvp)->tv_sec cmp (uvp)->tv_sec || \
1051
(tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
1055
Procedure timerclear(var tvp: timeval);