This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
EvilWorks.APi.WInsock2.pas
2625 lines (2218 loc) · 88.6 KB
/
EvilWorks.APi.WInsock2.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// EvilLibrary by Vedran Vuk 2010-2012
//
// Name: EvilWorks.Api.Winsock2
// Description: Winsock2 header file, because embarcadero's is, naturally, incomplete.
// Also some extra utilities, all self contained and lightweight.
// File last change date: September 14th. 2012
// File version: Dev 0.0.0
// Licence: Free.
//
unit EvilWorks.Api.Winsock2;
interface
uses
WinApi.Windows;
{$ALIGN OFF}
// Define the current Winsock version. To build an earlier Winsock version
// application redefine this value prior to including Winsock2.h
const
WINSOCK_VERSION = $0202;
WINSOCK2_DLL = 'ws2_32.dll';
type
u_char = Byte;
u_short = Word;
u_int = DWORD;
u_long = DWORD;
// The new type to be used in all instances which refer to sockets.
TSocket = u_int;
socklen_t = integer;
WSAEVENT = THandle;
PWSAEVENT = ^WSAEVENT;
LPWSAEVENT = PWSAEVENT;
{$IFDEF UNICODE}
PMBChar = PWideChar;
{$ELSE}
PMBChar = PAnsiChar;
{$ENDIF}
const
FD_SETSIZE = 64;
type
PFDSet = ^TFDSet;
TFDSet = packed record
fd_count: u_int;
fd_array: array [0 .. FD_SETSIZE - 1] of TSocket;
end;
PTimeVal = ^TTimeVal;
TTimeVal = packed record
tv_sec: Longint;
tv_usec: Longint;
end;
timeval = TTimeVal;
const
IOCPARM_MASK = $7F;
IOC_VOID = $20000000;
IOC_OUT = $40000000;
IOC_IN = $80000000;
IOC_INOUT = (IOC_IN or IOC_OUT);
// get # bytes to read
FIONREAD = IOC_OUT or (SizeOf(Longint) shl 16) or (Ord('f') shl 8) or 127;
// set/clear non-blocking i/o
FIONBIO = IOC_IN or (SizeOf(Longint) shl 16) or (Ord('f') shl 8) or 126;
// set/clear async i/o
FIOASYNC = IOC_IN or (SizeOf(Longint) shl 16) or (Ord('f') shl 8) or 125;
// Socket I/O Controls
// set high watermark
SIOCSHIWAT = IOC_IN or (SizeOf(Longint) shl 16) or (Ord('s') shl 8);
// get high watermark
SIOCGHIWAT = IOC_OUT or (SizeOf(Longint) shl 16) or (Ord('s') shl 8) or 1;
// set low watermark
SIOCSLOWAT = IOC_IN or (SizeOf(Longint) shl 16) or (Ord('s') shl 8) or 2;
// get low watermark
SIOCGLOWAT = IOC_OUT or (SizeOf(Longint) shl 16) or (Ord('s') shl 8) or 3;
// at oob mark?
SIOCATMARK = IOC_OUT or (SizeOf(Longint) shl 16) or (Ord('s') shl 8) or 7;
// 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
PHostEnt = ^THostEnt;
THostEnt = packed record
h_name: PAnsiChar; // official name of host
h_aliases: ^PAnsiChar; // alias list
h_addrtype: Smallint; // host address type
h_length: Smallint; // length of address
case Byte of
0:
(h_addr_list: ^PAnsiChar); // list of addresses
1:
(h_addr: ^PAnsiChar); // address, for backward compat
end;
// It is assumed here that a network number
// fits in 32 bits.
PNetEnt = ^TNetEnt;
TNetEnt = packed record
n_name: PAnsiChar; // official name of net
n_aliases: ^PAnsiChar; // alias list
n_addrtype: Smallint; // net address type
n_net: u_long; // network #
end;
PServEnt = ^TServEnt;
TServEnt = packed record
s_name: PAnsiChar; // official service name
s_aliases: ^PAnsiChar; // alias list
s_port: Smallint; // protocol to use
s_proto: PAnsiChar; // port #
end;
PProtoEnt = ^TProtoEnt;
TProtoEnt = packed record
p_name: PAnsiChar; // official protocol name
p_aliases: ^PAnsiChar; // alias list
p_proto: Smallint; // protocol #
end;
// Constants and structures defined by the internet system,
// Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
const
// Protocols
IPPROTO_IP = 0; // dummy for IP
IPPROTO_ICMP = 1; // control message protocol
IPPROTO_IGMP = 2; // group management protocol
IPPROTO_GGP = 3; // gateway^2 (deprecated)
IPPROTO_TCP = 6; // TCP
IPPROTO_PUP = 12; // pup
IPPROTO_UDP = 17; // UDP - user datagram protocol
IPPROTO_IDP = 22; // xns idp
IPPROTO_ND = 77; // UNOFFICIAL net disk proto
IPPROTO_RAW = 255; // raw IP packet
IPPROTO_MAX = 256;
// Port/socket numbers: network standard functions
IPPORT_ECHO = 7;
IPPORT_DISCARD = 9;
IPPORT_SYSTAT = 11;
IPPORT_DAYTIME = 13;
IPPORT_NETSTAT = 15;
IPPORT_FTP = 21;
IPPORT_TELNET = 23;
IPPORT_SMTP = 25;
IPPORT_TIMESERVER = 37;
IPPORT_NAMESERVER = 42;
IPPORT_WHOIS = 43;
IPPORT_MTP = 57;
// Port/socket numbers: host specific functions
IPPORT_TFTP = 69;
IPPORT_RJE = 77;
IPPORT_FINGER = 79;
IPPORT_TTYLINK = 87;
IPPORT_SUPDUP = 95;
// UNIX TCP sockets
IPPORT_EXECSERVER = 512;
IPPORT_LOGINSERVER = 513;
IPPORT_CMDSERVER = 514;
IPPORT_EFSSERVER = 520;
// UNIX UDP sockets
IPPORT_BIFFUDP = 512;
IPPORT_WHOSERVER = 513;
IPPORT_ROUTESERVER = 520;
// Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root).
IPPORT_RESERVED = 1024;
// Link numbers
IMPLINK_IP = 155;
IMPLINK_LOWEXPER = 156;
IMPLINK_HIGHEXPER = 158;
TF_DISCONNECT = $01;
TF_REUSE_SOCKET = $02;
TF_WRITE_BEHIND = $04;
// This is used instead of -1, since the TSocket type is unsigned.
INVALID_SOCKET = TSocket(not (0));
SOCKET_ERROR = - 1;
// The following may be used in place of the address family, socket type, or
// protocol in a call to WSASocket to indicate that the corresponding value
// should be taken from the supplied WSAPROTOCOL_INFO structure instead of the
// parameter itself.
FROM_PROTOCOL_INFO = - 1;
// Types
SOCK_STREAM = 1; { stream socket }
SOCK_DGRAM = 2; { datagram socket }
SOCK_RAW = 3; { raw-protocol interface }
SOCK_RDM = 4; { reliably-delivered message }
SOCK_SEQPACKET = 5; { sequenced packet stream }
// Option flags per-socket.
SO_DEBUG = $0001; // turn on debugging info recording
SO_ACCEPTCONN = $0002; // socket has had listen()
SO_REUSEADDR = $0004; // allow local address reuse
SO_KEEPALIVE = $0008; // keep connections alive
SO_DONTROUTE = $0010; // just use interface addresses
SO_BROADCAST = $0020; // permit sending of broadcast msgs
SO_USELOOPBACK = $0040; // bypass hardware when possible
SO_LINGER = $0080; // linger on close if data present
SO_OOBINLINE = $0100; // leave received OOB data in line
SO_DONTLINGER = not SO_LINGER;
SO_EXCLUSIVEADDRUSE = not SO_REUSEADDR; // disallow local address reuse
// Additional options.
SO_SNDBUF = $1001; // send buffer size
SO_RCVBUF = $1002; // receive buffer size
SO_SNDLOWAT = $1003; // send low-water mark
SO_RCVLOWAT = $1004; // receive low-water mark
SO_SNDTIMEO = $1005; // send timeout
SO_RCVTIMEO = $1006; // receive timeout
SO_ERROR = $1007; // get error status and clear
SO_TYPE = $1008; // get socket type
// Options for connect and disconnect data and options.
// Used only by non-TCP/IP transports such as DECNet, OSI TP4, etc.
SO_CONNDATA = $7000;
SO_CONNOPT = $7001;
SO_DISCDATA = $7002;
SO_DISCOPT = $7003;
SO_CONNDATALEN = $7004;
SO_CONNOPTLEN = $7005;
SO_DISCDATALEN = $7006;
SO_DISCOPTLEN = $7007;
// Option for opening sockets for synchronous access.
SO_OPENTYPE = $7008;
SO_SYNCHRONOUS_ALERT = $10;
SO_SYNCHRONOUS_NONALERT = $20;
// Other NT-specific options.
SO_MAXDG = $7009;
SO_MAXPATHDG = $700A;
SO_UPDATE_ACCEPT_CONTEXT = $700B;
SO_UPDATE_CONNECT_CONTEXT = $7010;
SO_CONNECT_TIME = $700C;
// TCP options.
TCP_NODELAY = $0001;
TCP_BSDURGENT = $7000;
// WinSock 2 extension -- new options
SO_GROUP_ID = $2001; // ID of a socket group
SO_GROUP_PRIORITY = $2002; // the relative priority within a group
SO_MAX_MSG_SIZE = $2003; // maximum message size
SO_Protocol_InfoA = $2004; // WSAPROTOCOL_INFOA structure
SO_Protocol_InfoW = $2005; // WSAPROTOCOL_INFOW structure
{$IFDEF UNICODE}
SO_Protocol_Info = SO_Protocol_InfoW;
{$ELSE}
SO_Protocol_Info = SO_Protocol_InfoA;
{$ENDIF}
PVD_CONFIG = $3001; // configuration info for service provider
SO_CONDITIONAL_ACCEPT = $3002; // enable true conditional accept:
// connection is not ack-ed to the
// other side until conditional
// function returns CF_ACCEPT
// Address families.
AF_UNSPEC = 0; // unspecified
AF_UNIX = 1; // local to host (pipes, portals)
AF_INET = 2; // Internet protocol Version 4: UDP, TCP, etc.
AF_IMPLINK = 3; // arpanet imp addresses
AF_PUP = 4; // pup protocols: e.g. BSP
AF_CHAOS = 5; // mit CHAOS protocols
AF_IPX = 6; // IPX and SPX
AF_NS = AF_IPX; // XEROX NS protocols
AF_ISO = 7; // ISO protocols
AF_OSI = AF_ISO; // OSI is ISO
AF_ECMA = 8; // european computer manufacturers
AF_DATAKIT = 9; // datakit protocols
AF_CCITT = 10; // CCITT protocols, X.25 etc
AF_SNA = 11; // IBM SNA
AF_DECnet = 12; // DECnet
AF_DLI = 13; // Direct data link interface
AF_LAT = 14; // LAT
AF_HYLINK = 15; // NSC Hyperchannel
AF_APPLETALK = 16; // AppleTalk
AF_NETBIOS = 17; // NetBios-style addresses
AF_VOICEVIEW = 18; // VoiceView
AF_FIREFOX = 19; // FireFox
AF_UNKNOWN1 = 20; // Somebody is using this!
AF_BAN = 21; // Banyan
AF_ATM = 22; // Native ATM Services
AF_INET6 = 23; // Internet protocol Version 6
AF_CLUSTER = 24; // Microsoft Wolfpack
AF_12844 = 25; // IEEE 1284.4 WG AF
AF_IRDA = 26; // IrDA
AF_NETDES = 28; // Network Designers OSI & gateway enabled protocols
AF_MAX = 29;
// Protocol families, same as address families for now.
PF_UNSPEC = AF_UNSPEC;
PF_UNIX = AF_UNIX;
PF_INET = AF_INET;
PF_IMPLINK = AF_IMPLINK;
PF_PUP = AF_PUP;
PF_CHAOS = AF_CHAOS;
PF_NS = AF_NS;
PF_IPX = AF_IPX;
PF_ISO = AF_ISO;
PF_OSI = AF_OSI;
PF_ECMA = AF_ECMA;
PF_DATAKIT = AF_DATAKIT;
PF_CCITT = AF_CCITT;
PF_SNA = AF_SNA;
PF_DECnet = AF_DECnet;
PF_DLI = AF_DLI;
PF_LAT = AF_LAT;
PF_HYLINK = AF_HYLINK;
PF_APPLETALK = AF_APPLETALK;
PF_VOICEVIEW = AF_VOICEVIEW;
PF_FIREFOX = AF_FIREFOX;
PF_UNKNOWN1 = AF_UNKNOWN1;
PF_BAN = AF_BAN;
PF_ATM = AF_ATM;
PF_INET6 = AF_INET6;
PF_MAX = AF_MAX;
WSAID_CONNECTEX: TGUID = (D1: $25A207B9; D2: $DDF3; D3: $4660; D4: ($8E, $E9, $76, $E5, $8C, $74, $06, $3E));
WSAID_TRANSMITFILE: TGUID = (D1: $B5367DF0; D2: $CBAC; D3: $11CF; D4: ($95, $CA, $00, $80, $5F, $48, $A1, $92));
//
// Flags used in "hints" argument to getaddrinfo()
// - AI_ADDRCONFIG is supported starting with Vista
// - default is AI_ADDRCONFIG ON whether the flag is set or not
// because the performance penalty in not having ADDRCONFIG in
// the multi-protocol stack environment is severe;
// this defaulting may be disabled by specifying the AI_ALL flag,
// in that case AI_ADDRCONFIG must be EXPLICITLY specified to
// enable ADDRCONFIG behavior
//
AI_PASSIVE = $00000001; // Socket address will be used in bind() call
AI_CANONNAME = $00000002; // Return canonical name in first ai_canonname
AI_NUMERICHOST = $00000004; // Nodename must be a numeric address string
AI_NUMERICSERV = $00000008; // Servicename must be a numeric port number
AI_ALL = $00000100; // Query both IP6 and IP4 with AI_V4MAPPED
AI_ADDRCONFIG = $00000400; // Resolution only if global address configured
AI_V4MAPPED = $00000800; // On v6 failure, query v4 and convert to V4MAPPED format
AI_NON_AUTHORITATIVE = $00004000; // LUP_NON_AUTHORITATIVE
AI_SECURE = $00008000; // LUP_SECURE
AI_RETURN_PREFERRED_NAMES = $00010000; // LUP_RETURN_PREFERRED_NAMES
AI_FQDN = $00020000; // Return the FQDN in ai_canonname
AI_FILESERVER = $00040000; // Resolving fileserver name resolution
type
// IPv4 Address
SunB = packed record
s_b1, s_b2, s_b3, s_b4: u_char;
end;
SunW = packed record
s_w1, s_w2: u_short;
end;
in_addr = packed record
case integer of
0:
(S_un_b: SunB);
1:
(S_un_w: SunW);
2:
(S_addr: u_long);
end;
TInAddr = in_addr;
PInAddr = ^TInAddr;
// IPv6 address
in6_addr = packed record
case integer of
0:
(Bytes: array [0 .. 15] of Byte);
1:
(Words: array [0 .. 7] of Word);
end;
TIn6Addr = in6_addr;
PIn6Addr = ^TIn6Addr;
in_addr6 = in6_addr;
// Structure used by kernel to store most addresses.
TSockAddrIn = packed record
case integer of
0:
(sin_family: u_short;
sin_port: u_short;
sin_addr: TInAddr;
sin_zero: array [0 .. 7] of Char);
1:
(sa_family: u_short;
sa_data: array [0 .. 13] of Char)
end;
PSockAddrIn = ^TSockAddrIn;
TSockAddr = TSockAddrIn;
PSockAddr = ^TSockAddr;
SOCKADDR = TSockAddr;
SOCKADDR_IN = TSockAddrIn;
TSockAddrIn6 = packed record
sin6_family: short;
sin6_port: u_short;
sin6_flowinfo: u_long;
sin6_addr: in6_addr;
sin6_scope_id: u_long;
end;
PSockAddrIn6 = ^TSockAddrIn6;
SOCKADDR_IN6 = TSockAddrIn6;
// Structure used by kernel to pass protocol information in raw sockets.
PSockProto = ^TSockProto;
TSockProto = packed record
sp_family: u_short;
sp_protocol: u_short;
end;
// Structure used for manipulating linger option.
PLinger = ^TLinger;
TLinger = packed record
l_onoff: u_short;
l_linger: u_short;
end;
PADDRINFOA = ^ADDRINFOA;
PPADDRINFOA = ^PADDRINFOA;
ADDRINFOA = record
ai_flags: integer;
ai_family: integer;
ai_socktype: integer;
ai_protocol: integer;
ai_addrlen: cardinal; // size_t
AI_CANONNAME: PAnsiChar;
ai_addr: PSockAddr;
ai_next: PADDRINFOA;
end;
TAddrInfoA = ADDRINFOA;
PADDRINFOW = ^ADDRINFOW;
PPADDRINFOW = ^PADDRINFOW;
ADDRINFOW = record
ai_flags: integer;
ai_family: integer;
ai_socktype: integer;
ai_protocol: integer;
ai_addrlen: cardinal; // size_t
AI_CANONNAME: PWideChar;
ai_addr: PSockAddr;
ai_next: PADDRINFOW;
end;
TAddrInfoW = ADDRINFOW;
{$IFDEF UNICODE}
addrinfo = ADDRINFOW;
TAddrInfo = TAddrInfoW;
PAddrInfo = PADDRINFOW;
PPAddrInfo = PPADDRINFOW;
{$ELSE}
addrinfo = ADDRINFOA;
TAddrInfo = TAddrInfoA;
PAddrInfo = PADDRINFOA;
PPAddrInfo = PPADDRINFOA;
{$ENDIF}
const
INADDR_ANY = $00000000;
INADDR_LOOPBACK = $7F000001;
INADDR_BROADCAST = $FFFFFFFF;
INADDR_NONE = $FFFFFFFF;
ADDR_ANY = INADDR_ANY;
SOL_SOCKET = $FFFF; // options for socket level
MSG_OOB = $1; // process out-of-band data
MSG_PEEK = $2; // peek at incoming message
MSG_DONTROUTE = $4; // send without using routing tables
MSG_WAITALL = $8; // do not complete until packet is completely filled
MSG_PARTIAL = $8000; // partial send or recv for message xport
// WinSock 2 extension -- new flags for WSASend(), WSASendTo(), WSARecv() and WSARecvFrom()
MSG_INTERRUPT = $10; // send/recv in the interrupt context
MSG_MAXIOVLEN = 16;
// Define constant based on rfc883, used by gethostbyxxxx() calls.
MAXGETHOSTSTRUCT = 1024;
// Maximum queue length specifiable by listen.
SOMAXCONN = $7FFFFFFF;
// WinSock 2 extension -- bit values and indices for FD_XXX network events
FD_READ_BIT = 0;
FD_WRITE_BIT = 1;
FD_OOB_BIT = 2;
FD_ACCEPT_BIT = 3;
FD_CONNECT_BIT = 4;
FD_CLOSE_BIT = 5;
FD_QOS_BIT = 6;
FD_GROUP_QOS_BIT = 7;
FD_MAX_EVENTS = 8;
FD_READ = (1 shl FD_READ_BIT);
FD_WRITE = (1 shl FD_WRITE_BIT);
FD_OOB = (1 shl FD_OOB_BIT);
FD_ACCEPT = (1 shl FD_ACCEPT_BIT);
FD_CONNECT = (1 shl FD_CONNECT_BIT);
FD_CLOSE = (1 shl FD_CLOSE_BIT);
FD_QOS = (1 shl FD_QOS_BIT);
FD_GROUP_QOS = (1 shl FD_GROUP_QOS_BIT);
FD_ALL_EVENTS = (1 shl FD_MAX_EVENTS) - 1;
// All Windows Sockets error constants are biased by WSABASEERR from the "normal"
WSABASEERR = 10000;
// Windows Sockets definitions of regular Microsoft C error constants
WSAEINTR = WSABASEERR + 4;
WSAEBADF = WSABASEERR + 9;
WSAEACCES = WSABASEERR + 13;
WSAEFAULT = WSABASEERR + 14;
WSAEINVAL = WSABASEERR + 22;
WSAEMFILE = WSABASEERR + 24;
// Windows Sockets definitions of regular Berkeley error constants
WSAEWOULDBLOCK = WSABASEERR + 35;
WSAEINPROGRESS = WSABASEERR + 36;
WSAEALREADY = WSABASEERR + 37;
WSAENOTSOCK = WSABASEERR + 38;
WSAEDESTADDRREQ = WSABASEERR + 39;
WSAEMSGSIZE = WSABASEERR + 40;
WSAEPROTOTYPE = WSABASEERR + 41;
WSAENOPROTOOPT = WSABASEERR + 42;
WSAEPROTONOSUPPORT = WSABASEERR + 43;
WSAESOCKTNOSUPPORT = WSABASEERR + 44;
WSAEOPNOTSUPP = WSABASEERR + 45;
WSAEPFNOSUPPORT = WSABASEERR + 46;
WSAEAFNOSUPPORT = WSABASEERR + 47;
WSAEADDRINUSE = WSABASEERR + 48;
WSAEADDRNOTAVAIL = WSABASEERR + 49;
WSAENETDOWN = WSABASEERR + 50;
WSAENETUNREACH = WSABASEERR + 51;
WSAENETRESET = WSABASEERR + 52;
WSAECONNABORTED = WSABASEERR + 53;
WSAECONNRESET = WSABASEERR + 54;
WSAENOBUFS = WSABASEERR + 55;
WSAEISCONN = WSABASEERR + 56;
WSAENOTCONN = WSABASEERR + 57;
WSAESHUTDOWN = WSABASEERR + 58;
WSAETOOMANYREFS = WSABASEERR + 59;
WSAETIMEDOUT = WSABASEERR + 60;
WSAECONNREFUSED = WSABASEERR + 61;
WSAELOOP = WSABASEERR + 62;
WSAENAMETOOLONG = WSABASEERR + 63;
WSAEHOSTDOWN = WSABASEERR + 64;
WSAEHOSTUNREACH = WSABASEERR + 65;
WSAENOTEMPTY = WSABASEERR + 66;
WSAEPROCLIM = WSABASEERR + 67;
WSAEUSERS = WSABASEERR + 68;
WSAEDQUOT = WSABASEERR + 69;
WSAESTALE = WSABASEERR + 70;
WSAEREMOTE = WSABASEERR + 71;
// Extended Windows Sockets error constant definitions
WSASYSNOTREADY = WSABASEERR + 91;
WSAVERNOTSUPPORTED = WSABASEERR + 92;
WSANOTINITIALISED = WSABASEERR + 93;
WSAEDISCON = WSABASEERR + 101;
WSAENOMORE = WSABASEERR + 102;
WSAECANCELLED = WSABASEERR + 103;
WSAEINVALIDPROCTABLE = WSABASEERR + 104;
WSAEINVALIDPROVIDER = WSABASEERR + 105;
WSAEPROVIDERFAILEDINIT = WSABASEERR + 106;
WSASYSCALLFAILURE = WSABASEERR + 107;
WSASERVICE_NOT_FOUND = WSABASEERR + 108;
WSATYPE_NOT_FOUND = WSABASEERR + 109;
WSA_E_NO_MORE = WSABASEERR + 110;
WSA_E_CANCELLED = WSABASEERR + 111;
WSAEREFUSED = WSABASEERR + 112;
{ Error return codes from gethostbyname() and gethostbyaddr()
(when using the resolver). Note that these errors are
retrieved via WSAGetLastError() and must therefore follow
the rules for avoiding clashes with error numbers from
specific implementations or language run-time systems.
For this reason the codes are based at WSABASEERR+1001.
Note also that [WSA]NO_ADDRESS is defined only for
compatibility purposes. }
// Authoritative Answer: Host not found
WSAHOST_NOT_FOUND = WSABASEERR + 1001;
HOST_NOT_FOUND = WSAHOST_NOT_FOUND;
// Non-Authoritative: Host not found, or SERVERFAIL
WSATRY_AGAIN = WSABASEERR + 1002;
TRY_AGAIN = WSATRY_AGAIN;
// Non recoverable errors, FORMERR, REFUSED, NOTIMP
WSANO_RECOVERY = WSABASEERR + 1003;
NO_RECOVERY = WSANO_RECOVERY;
// Valid name, no data record of requested type
WSANO_DATA = WSABASEERR + 1004;
NO_DATA = WSANO_DATA;
// no address, look for MX record
WSANO_ADDRESS = WSANO_DATA;
NO_ADDRESS = WSANO_ADDRESS;
// Define QOS related error return codes
WSA_QOS_RECEIVERS = WSABASEERR + 1005; // at least one Reserve has arrived
WSA_QOS_SENDERS = WSABASEERR + 1006; // at least one Path has arrived
WSA_QOS_NO_SENDERS = WSABASEERR + 1007; // there are no senders
WSA_QOS_NO_RECEIVERS = WSABASEERR + 1008; // there are no receivers
WSA_QOS_REQUEST_CONFIRMED = WSABASEERR + 1009; // Reserve has been confirmed
WSA_QOS_ADMISSION_FAILURE = WSABASEERR + 1010; // error due to lack of resources
WSA_QOS_POLICY_FAILURE = WSABASEERR + 1011; // rejected for administrative reasons - bad credentials
WSA_QOS_BAD_STYLE = WSABASEERR + 1012; // unknown or conflicting style
WSA_QOS_BAD_OBJECT = WSABASEERR + 1013;
// problem with some part of the filterspec or providerspecific buffer in general
WSA_QOS_TRAFFIC_CTRL_ERROR = WSABASEERR + 1014; // problem with some part of the flowspec
WSA_QOS_GENERIC_ERROR = WSABASEERR + 1015; // general error
WSA_QOS_ESERVICETYPE = WSABASEERR + 1016; // invalid service type in flowspec
WSA_QOS_EFLOWSPEC = WSABASEERR + 1017; // invalid flowspec
WSA_QOS_EPROVSPECBUF = WSABASEERR + 1018; // invalid provider specific buffer
WSA_QOS_EFILTERSTYLE = WSABASEERR + 1019; // invalid filter style
WSA_QOS_EFILTERTYPE = WSABASEERR + 1020; // invalid filter type
WSA_QOS_EFILTERCOUNT = WSABASEERR + 1021; // incorrect number of filters
WSA_QOS_EOBJLENGTH = WSABASEERR + 1022; // invalid object length
WSA_QOS_EFLOWCOUNT = WSABASEERR + 1023; // incorrect number of flows
WSA_QOS_EUNKOWNPSOBJ = WSABASEERR + 1024; // unknown object in provider specific buffer
WSA_QOS_EPOLICYOBJ = WSABASEERR + 1025; // invalid policy object in provider specific buffer
WSA_QOS_EFLOWDESC = WSABASEERR + 1026; // invalid flow descriptor in the list
WSA_QOS_EPSFLOWSPEC = WSABASEERR + 1027; // inconsistent flow spec in provider specific buffer
WSA_QOS_EPSFILTERSPEC = WSABASEERR + 1028; // invalid filter spec in provider specific buffer
WSA_QOS_ESDMODEOBJ = WSABASEERR + 1029; // invalid shape discard mode object in provider specific buffer
WSA_QOS_ESHAPERATEOBJ = WSABASEERR + 1030; // invalid shaping rate object in provider specific buffer
WSA_QOS_RESERVED_PETYPE = WSABASEERR + 1031; // reserved policy element in provider specific buffer
{ WinSock 2 extension -- new error codes and type definition }
WSA_IO_PENDING = ERROR_IO_PENDING;
WSA_IO_INCOMPLETE = ERROR_IO_INCOMPLETE;
WSA_INVALID_HANDLE = ERROR_INVALID_HANDLE;
WSA_INVALID_PARAMETER = ERROR_INVALID_PARAMETER;
WSA_NOT_ENOUGH_MEMORY = ERROR_NOT_ENOUGH_MEMORY;
WSA_OPERATION_ABORTED = ERROR_OPERATION_ABORTED;
WSA_INVALID_EVENT = WSAEVENT(nil);
WSA_MAXIMUM_WAIT_EVENTS = MAXIMUM_WAIT_OBJECTS;
WSA_WAIT_FAILED = $FFFFFFFF;
WSA_WAIT_EVENT_0 = WAIT_OBJECT_0;
WSA_WAIT_IO_COMPLETION = WAIT_IO_COMPLETION;
WSA_WAIT_TIMEOUT = WAIT_TIMEOUT;
WSA_INFINITE = INFINITE;
{ Windows Sockets errors redefined as regular Berkeley error constants.
These are commented out in Windows NT to avoid conflicts with errno.h.
Use the WSA constants instead. }
EWOULDBLOCK = WSAEWOULDBLOCK;
EINPROGRESS = WSAEINPROGRESS;
EALREADY = WSAEALREADY;
ENOTSOCK = WSAENOTSOCK;
EDESTADDRREQ = WSAEDESTADDRREQ;
EMSGSIZE = WSAEMSGSIZE;
EPROTOTYPE = WSAEPROTOTYPE;
ENOPROTOOPT = WSAENOPROTOOPT;
EPROTONOSUPPORT = WSAEPROTONOSUPPORT;
ESOCKTNOSUPPORT = WSAESOCKTNOSUPPORT;
EOPNOTSUPP = WSAEOPNOTSUPP;
EPFNOSUPPORT = WSAEPFNOSUPPORT;
EAFNOSUPPORT = WSAEAFNOSUPPORT;
EADDRINUSE = WSAEADDRINUSE;
EADDRNOTAVAIL = WSAEADDRNOTAVAIL;
ENETDOWN = WSAENETDOWN;
ENETUNREACH = WSAENETUNREACH;
ENETRESET = WSAENETRESET;
ECONNABORTED = WSAECONNABORTED;
ECONNRESET = WSAECONNRESET;
ENOBUFS = WSAENOBUFS;
EISCONN = WSAEISCONN;
ENOTCONN = WSAENOTCONN;
ESHUTDOWN = WSAESHUTDOWN;
ETOOMANYREFS = WSAETOOMANYREFS;
ETIMEDOUT = WSAETIMEDOUT;
ECONNREFUSED = WSAECONNREFUSED;
ELOOP = WSAELOOP;
ENAMETOOLONG = WSAENAMETOOLONG;
EHOSTDOWN = WSAEHOSTDOWN;
EHOSTUNREACH = WSAEHOSTUNREACH;
ENOTEMPTY = WSAENOTEMPTY;
EPROCLIM = WSAEPROCLIM;
EUSERS = WSAEUSERS;
EDQUOT = WSAEDQUOT;
ESTALE = WSAESTALE;
EREMOTE = WSAEREMOTE;
WSADESCRIPTION_LEN = 256;
WSASYS_STATUS_LEN = 128;
type
PWSAData = ^TWSAData;
TWSAData = packed record
wVersion: Word;
wHighVersion: Word;
szDescription: array [0 .. WSADESCRIPTION_LEN] of AnsiChar;
szSystemStatus: array [0 .. WSASYS_STATUS_LEN] of AnsiChar;
iMaxSockets: Word;
iMaxUdpDg: Word;
lpVendorInfo: PAnsiChar;
end;
{ WSAOVERLAPPED = Record
Internal: LongInt;
InternalHigh: LongInt;
Offset: LongInt;
OffsetHigh: LongInt;
hEvent: WSAEVENT;
end; }
WSAOVERLAPPED = TOverlapped;
TWSAOverlapped = WSAOVERLAPPED;
PWSAOverlapped = ^WSAOVERLAPPED;
LPWSAOVERLAPPED = PWSAOverlapped;
{ WinSock 2 extension -- WSABUF and QOS struct, include qos.h }
{ to pull in FLOWSPEC and related definitions }
WSABUF = packed record
len: u_long; { the length of the buffer }
buf: pointer; { the pointer to the buffer }
end { WSABUF };
PWSABUF = ^WSABUF;
LPWSABUF = PWSABUF;
TServiceType = Longint;
TFlowSpec = packed record
TokenRate, // In Bytes/sec
TokenBucketSize, // In Bytes
PeakBandwidth, // In Bytes/sec
Latency, // In microseconds
DelayVariation: Longint; // In microseconds
ServiceType: TServiceType;
MaxSduSize, MinimumPolicedSize: Longint; // In Bytes
end;
PFlowSpec = ^TFlowSpec;
QOS = packed record
SendingFlowspec: TFlowSpec; { the flow spec for data sending }
ReceivingFlowspec: TFlowSpec; { the flow spec for data receiving }
ProviderSpecific: WSABUF; { additional provider specific stuff }
end;
TQualityOfService = QOS;
PQOS = ^QOS;
LPQOS = PQOS;
const
SERVICETYPE_NOTRAFFIC = $00000000; // No data in this direction
SERVICETYPE_BESTEFFORT = $00000001; // Best Effort
SERVICETYPE_CONTROLLEDLOAD = $00000002; // Controlled Load
SERVICETYPE_GUARANTEED = $00000003; // Guaranteed
SERVICETYPE_NETWORK_UNAVAILABLE = $00000004; // Used to notify change to user
SERVICETYPE_GENERAL_INFORMATION = $00000005; // corresponds to "General Parameters" defined by IntServ
SERVICETYPE_NOCHANGE = $00000006;
// used to indicate that the flow spec contains no change from any previous one
// to turn on immediate traffic control, OR this flag with the ServiceType field in teh FLOWSPEC
SERVICE_IMMEDIATE_TRAFFIC_CONTROL = $80000000;
// WinSock 2 extension -- manifest constants for return values of the condition function
CF_ACCEPT = $0000;
CF_REJECT = $0001;
CF_DEFER = $0002;
// WinSock 2 extension -- manifest constants for shutdown()
SD_RECEIVE = $00;
SD_SEND = $01;
SD_BOTH = $02;
// WinSock 2 extension -- data type and manifest constants for socket groups
SG_UNCONSTRAINED_GROUP = $01;
SG_CONSTRAINED_GROUP = $02;
type
GROUP = DWORD;
// WinSock 2 extension -- data type for WSAEnumNetworkEvents()
TWSANetworkEvents = record
lNetworkEvents: Longint;
iErrorCode: array [0 .. FD_MAX_EVENTS - 1] of integer;
end;
PWSANetworkEvents = ^TWSANetworkEvents;
LPWSANetworkEvents = PWSANetworkEvents;
// WinSock 2 extension -- WSAPROTOCOL_INFO structure
{$IFNDEF ver130}
TGUID = packed record
D1: Longint;
D2: Word;
D3: Word;
D4: array [0 .. 7] of Byte;
end;
PGUID = ^TGUID;
{$ENDIF}
LPGUID = PGUID;
// WinSock 2 extension -- WSAPROTOCOL_INFO manifest constants
const
MAX_PROTOCOL_CHAIN = 7;
BASE_PROTOCOL = 1;
LAYERED_PROTOCOL = 0;
WSAPROTOCOL_LEN = 255;
type
TWSAProtocolChain = record
ChainLen: integer; // the length of the chain,
// length = 0 means layered protocol,
// length = 1 means base protocol,
// length > 1 means protocol chain
ChainEntries: array [0 .. MAX_PROTOCOL_CHAIN - 1] of Longint; // a list of dwCatalogEntryIds
end;
type
TWSAProtocol_InfoA = record
dwServiceFlags1: Longint;
dwServiceFlags2: Longint;
dwServiceFlags3: Longint;
dwServiceFlags4: Longint;
dwProviderFlags: Longint;
ProviderId: TGUID;
dwCatalogEntryId: Longint;
ProtocolChain: TWSAProtocolChain;
iVersion: integer;
iAddressFamily: integer;
iMaxSockAddr: integer;
iMinSockAddr: integer;
iSocketType: integer;
iProtocol: integer;
iProtocolMaxOffset: integer;
iNetworkByteOrder: integer;
iSecurityScheme: integer;
dwMessageSize: Longint;
dwProviderReserved: Longint;
szProtocol: array [0 .. WSAPROTOCOL_LEN + 1 - 1] of Char;
end { TWSAProtocol_InfoA };
PWSAProtocol_InfoA = ^TWSAProtocol_InfoA;
LPWSAProtocol_InfoA = PWSAProtocol_InfoA;
TWSAProtocol_InfoW = record
dwServiceFlags1: Longint;
dwServiceFlags2: Longint;
dwServiceFlags3: Longint;
dwServiceFlags4: Longint;
dwProviderFlags: Longint;
ProviderId: TGUID;
dwCatalogEntryId: Longint;
ProtocolChain: TWSAProtocolChain;
iVersion: integer;
iAddressFamily: integer;
iMaxSockAddr: integer;
iMinSockAddr: integer;
iSocketType: integer;
iProtocol: integer;
iProtocolMaxOffset: integer;
iNetworkByteOrder: integer;
iSecurityScheme: integer;
dwMessageSize: Longint;
dwProviderReserved: Longint;
szProtocol: array [0 .. WSAPROTOCOL_LEN + 1 - 1] of WideChar;
end { TWSAProtocol_InfoW };
PWSAProtocol_InfoW = ^TWSAProtocol_InfoW;
LPWSAProtocol_InfoW = PWSAProtocol_InfoW;
{$IFDEF UNICODE}
WSAProtocol_Info = TWSAProtocol_InfoW;
TWSAProtocol_Info = TWSAProtocol_InfoW;
PWSAProtocol_Info = PWSAProtocol_InfoW;
LPWSAProtocol_Info = PWSAProtocol_InfoW;
{$ELSE}
WSAProtocol_Info = TWSAProtocol_InfoA;
TWSAProtocol_Info = TWSAProtocol_InfoA;
PWSAProtocol_Info = PWSAProtocol_InfoA;
LPWSAProtocol_Info = PWSAProtocol_InfoA;
{$ENDIF}
const
// Flag bit definitions for dwProviderFlags
PFL_MULTIPLE_PROTO_ENTRIES = $00000001;
PFL_RECOMMENDED_PROTO_ENTRY = $00000002;
PFL_HIDDEN = $00000004;
PFL_MATCHES_PROTOCOL_ZERO = $00000008;
// Flag bit definitions for dwServiceFlags1
XP1_CONNECTIONLESS = $00000001;
XP1_GUARANTEED_DELIVERY = $00000002;
XP1_GUARANTEED_ORDER = $00000004;
XP1_MESSAGE_ORIENTED = $00000008;
XP1_PSEUDO_STREAM = $00000010;
XP1_GRACEFUL_CLOSE = $00000020;
XP1_EXPEDITED_DATA = $00000040;
XP1_CONNECT_DATA = $00000080;
XP1_DISCONNECT_DATA = $00000100;
XP1_SUPPORT_BROADCAST = $00000200;
XP1_SUPPORT_MULTIPOINT = $00000400;
XP1_MULTIPOINT_CONTROL_PLANE = $00000800;
XP1_MULTIPOINT_DATA_PLANE = $00001000;
XP1_QOS_SUPPORTED = $00002000;
XP1_INTERRUPT = $00004000;
XP1_UNI_SEND = $00008000;
XP1_UNI_RECV = $00010000;
XP1_IFS_HANDLES = $00020000;
XP1_PARTIAL_MESSAGE = $00040000;
BIGENDIAN = $0000;
LITTLEENDIAN = $0001;
SECURITY_PROTOCOL_NONE = $0000;
// WinSock 2 extension -- manifest constants for WSAJoinLeaf()
JL_SENDER_ONLY = $01;
JL_RECEIVER_ONLY = $02;
JL_BOTH = $04;
// WinSock 2 extension -- manifest constants for WSASocket()
WSA_FLAG_OVERLAPPED = $01;
WSA_FLAG_MULTIPOINT_C_ROOT = $02;
WSA_FLAG_MULTIPOINT_C_LEAF = $04;
WSA_FLAG_MULTIPOINT_D_ROOT = $08;
WSA_FLAG_MULTIPOINT_D_LEAF = $10;
// WinSock 2 extension -- manifest constants for WSAIoctl()
IOC_UNIX = $00000000;