JwaMSWSock.pas
上传用户:davidchvip
上传日期:2009-07-28
资源大小:1749k
文件大小:20k
源码类别:

Windows编程

开发平台:

Delphi

  1. {******************************************************************************}
  2. {                                                                       }
  3. { Winsock2 Options and Extensions API interface Unit for Object Pascal         }
  4. {                                                                       }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft          }
  6. { Corporation. All Rights Reserved.                                            }
  7. {                 }
  8. { The original file is: mswsock.h, released June 2000. The original Pascal     }
  9. { code is: MSWSock.pas, released December 2000. The initial developer of the   }
  10. { Pascal code is Marcel van Brakel (brakelm@chello.nl).                        }
  11. {                                                                              }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001            }
  13. { Marcel van Brakel. All Rights Reserved.                                      }
  14. {                 }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI)        }
  16. {                }
  17. { You may retrieve the latest version of this file at the Project JEDI home    }
  18. { page, located at http://delphi-jedi.org or my personal homepage located at   }
  19. { http://members.chello.nl/m.vanbrakel2                                        }
  20. {                }
  21. { The contents of this file are used with permission, subject to the Mozilla   }
  22. { Public License Version 1.1 (the "License"); you may not use this file except }
  23. { in compliance with the License. You may obtain a copy of the License at      }
  24. { http://www.mozilla.org/MPL/MPL-1.1.html                                      }
  25. {                                                                              }
  26. { Software distributed under the License is distributed on an "AS IS" basis,   }
  27. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  28. { the specific language governing rights and limitations under the License.    }
  29. {                                                                              }
  30. { Alternatively, the contents of this file may be used under the terms of the  }
  31. { GNU Lesser General Public License (the  "LGPL License"), in which case the   }
  32. { provisions of the LGPL License are applicable instead of those above.        }
  33. { If you wish to allow use of your version of this file only under the terms   }
  34. { of the LGPL License and not to allow others to use your version of this file }
  35. { under the MPL, indicate your decision by deleting  the provisions above and  }
  36. { replace  them with the notice and other provisions required by the LGPL      }
  37. { License.  If you do not delete the provisions above, a recipient may use     }
  38. { your version of this file under either the MPL or the LGPL License.          }
  39. {                 }
  40. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  41. {                 }
  42. {******************************************************************************}
  43. unit JwaMSWSock;
  44. {$WEAKPACKAGEUNIT}
  45. {$HPPEMIT ''}
  46. {$HPPEMIT '#include "mswsock.h"'}
  47. {$HPPEMIT ''}
  48. {$I WINDEFINES.INC}
  49. interface
  50. uses
  51.   JwaWinType, JwaWinBase, JwaWinSock2;
  52. //
  53. // Options for connect and disconnect data and options.  Used only by
  54. // non-TCP/IP transports such as DECNet, OSI TP4, etc.
  55. //
  56. const
  57.   SO_CONNDATA                = $7000;
  58.   {$EXTERNALSYM SO_CONNDATA}
  59.   SO_CONNOPT                 = $7001;
  60.   {$EXTERNALSYM SO_CONNOPT}
  61.   SO_DISCDATA                = $7002;
  62.   {$EXTERNALSYM SO_DISCDATA}
  63.   SO_DISCOPT                 = $7003;
  64.   {$EXTERNALSYM SO_DISCOPT}
  65.   SO_CONNDATALEN             = $7004;
  66.   {$EXTERNALSYM SO_CONNDATALEN}
  67.   SO_CONNOPTLEN              = $7005;
  68.   {$EXTERNALSYM SO_CONNOPTLEN}
  69.   SO_DISCDATALEN             = $7006;
  70.   {$EXTERNALSYM SO_DISCDATALEN}
  71.   SO_DISCOPTLEN              = $7007;
  72.   {$EXTERNALSYM SO_DISCOPTLEN}
  73. //
  74. // Option for opening sockets for synchronous access.
  75. //
  76. const
  77.   SO_OPENTYPE                = $7008;
  78.   {$EXTERNALSYM SO_OPENTYPE}
  79.   SO_SYNCHRONOUS_ALERT       = $10;
  80.   {$EXTERNALSYM SO_SYNCHRONOUS_ALERT}
  81.   SO_SYNCHRONOUS_NONALERT    = $20;
  82.   {$EXTERNALSYM SO_SYNCHRONOUS_NONALERT}
  83. //
  84. // Other NT-specific options.
  85. //
  86. const
  87.   SO_MAXDG                   = $7009;
  88.   {$EXTERNALSYM SO_MAXDG}
  89.   SO_MAXPATHDG               = $700A;
  90.   {$EXTERNALSYM SO_MAXPATHDG}
  91.   SO_UPDATE_ACCEPT_CONTEXT   = $700B;
  92.   {$EXTERNALSYM SO_UPDATE_ACCEPT_CONTEXT}
  93.   SO_CONNECT_TIME            = $700C;
  94.   {$EXTERNALSYM SO_CONNECT_TIME}
  95.   SO_UPDATE_CONNECT_CONTEXT  = $7010;
  96.   {$EXTERNALSYM SO_UPDATE_CONNECT_CONTEXT}
  97. //
  98. // TCP options.
  99. //
  100. const
  101.   TCP_BSDURGENT              = $7000;
  102.   {$EXTERNALSYM TCP_BSDURGENT}
  103. //
  104. // MS Transport Provider IOCTL to control
  105. // reporting PORT_UNREACHABLE messages
  106. // on UDP sockets via recv/WSARecv/etc.
  107. // Path TRUE in input buffer to enable (default if supported),
  108. // FALSE to disable.
  109. //
  110.   SIO_UDP_CONNRESET          = IOC_IN or IOC_VENDOR or 12;
  111.   {$EXTERNALSYM SIO_UDP_CONNRESET}
  112. //
  113. // Microsoft extended APIs.
  114. //
  115. function WSARecvEx(s: TSocket; buf: PChar; len: Integer; var flags: Integer): Integer; stdcall;
  116. {$EXTERNALSYM WSARecvEx}
  117. type
  118.   _TRANSMIT_FILE_BUFFERS = record
  119.     Head: LPVOID;
  120.     HeadLength: DWORD;
  121.     Tail: LPVOID;
  122.     TailLength: DWORD;
  123.   end;
  124.   {$EXTERNALSYM _TRANSMIT_FILE_BUFFERS}
  125.   TRANSMIT_FILE_BUFFERS = _TRANSMIT_FILE_BUFFERS;
  126.   {$EXTERNALSYM TRANSMIT_FILE_BUFFERS}
  127.   PTRANSMIT_FILE_BUFFERS = ^TRANSMIT_FILE_BUFFERS;
  128.   {$EXTERNALSYM PTRANSMIT_FILE_BUFFERS}
  129.   LPTRANSMIT_FILE_BUFFERS = ^TRANSMIT_FILE_BUFFERS;
  130.   {$EXTERNALSYM LPTRANSMIT_FILE_BUFFERS}
  131.   TTransmitFileBuffers = TRANSMIT_FILE_BUFFERS;
  132.   PTransmitFileBuffers = LPTRANSMIT_FILE_BUFFERS;
  133. const
  134.   TF_DISCONNECT         = $01;
  135.   {$EXTERNALSYM TF_DISCONNECT}
  136.   TF_REUSE_SOCKET       = $02;
  137.   {$EXTERNALSYM TF_REUSE_SOCKET}
  138.   TF_WRITE_BEHIND       = $04;
  139.   {$EXTERNALSYM TF_WRITE_BEHIND}
  140.   TF_USE_DEFAULT_WORKER = $00;
  141.   {$EXTERNALSYM TF_USE_DEFAULT_WORKER}
  142.   TF_USE_SYSTEM_THREAD  = $10;
  143.   {$EXTERNALSYM TF_USE_SYSTEM_THREAD}
  144.   TF_USE_KERNEL_APC     = $20;
  145.   {$EXTERNALSYM TF_USE_KERNEL_APC}
  146. function TransmitFile(hSocket: TSocket; hFile: HANDLE; nNumberOfBytesToWrite,
  147.   nNumberOfBytesPerSend: DWORD; lpOverlapped: POVERLAPPED;
  148.   lpTransmitBuffers: LPTRANSMIT_FILE_BUFFERS; dwReserved: DWORD): BOOL; stdcall;
  149. {$EXTERNALSYM TransmitFile}
  150. function AcceptEx(sListenSocket, sAcceptSocket: TSocket; lpOutputBuffer: LPVOID;
  151.   dwReceiveDataLength, dwLocalAddressLength, dwRemoteAddressLength: DWORD;
  152.   var lpdwBytesReceived: DWORD; lpOverlapped: POVERLAPPED): BOOL; stdcall;
  153. {$EXTERNALSYM AcceptEx}
  154. procedure GetAcceptExSockaddrs(lpOutputBuffer: LPVOID; dwReceiveDataLength,
  155.   dwLocalAddressLength, dwRemoteAddressLength: DWORD; var LocalSockaddr: LPSOCKADDR;
  156.   var LocalSockaddrLength: Integer; RemoteSockaddr: LPSOCKADDR;
  157.   var RemoteSockaddrLength: Integer); stdcall;
  158. {$EXTERNALSYM GetAcceptExSockaddrs}
  159. //
  160. // "QueryInterface" versions of the above APIs.
  161. //
  162. type
  163.   LPFN_TRANSMITFILE = function (hSocket: TSocket; hFile: HANDLE; nNumberOfBytesToWrite,
  164.     nNumberOfBytesPerSend: DWORD; lpOverlapped: POVERLAPPED;
  165.     lpTransmitBuffers: LPTRANSMIT_FILE_BUFFERS; dwReserved: DWORD): BOOL; stdcall;
  166.   {$EXTERNALSYM LPFN_TRANSMITFILE}
  167.   TFnTransmitFile = LPFN_TRANSMITFILE;
  168. const
  169.   WSAID_TRANSMITFILE: TGUID = (
  170.     D1:$b5367df0; D2:$cbac; D3:$11cf; D4:($95, $ca, $00, $80, $5f, $48, $a1, $92));
  171.   {$EXTERNALSYM WSAID_TRANSMITFILE}
  172. type
  173.   LPFN_ACCEPTEX = function (sListenSocket, sAcceptSocket: TSocket; lpOutputBuffer: LPVOID;
  174.     dwReceiveDataLength, dwLocalAddressLength, dwRemoteAddressLength: DWORD;
  175.     var lpdwBytesReceived: DWORD; lpOverlapped: POVERLAPPED): BOOL; stdcall;
  176.   {$EXTERNALSYM LPFN_ACCEPTEX}
  177.   TFnAcceptEx = LPFN_ACCEPTEX;
  178. const
  179.   WSAID_ACCEPTEX: TGUID = (
  180.     D1:$b5367df1; D2:$cbac; D3:$11cf; D4:($95, $ca, $00, $80, $5f, $48, $a1, $92));
  181.   {$EXTERNALSYM WSAID_ACCEPTEX}
  182. type
  183.   LPFN_GETACCEPTEXSOCKADDRS = procedure (lpOutputBuffer: LPVOID; dwReceiveDataLength,
  184.     dwLocalAddressLength, dwRemoteAddressLength: DWORD; var LocalSockaddr: LPSOCKADDR;
  185.     var LocalSockaddrLength: Integer; var RemoteSockaddr: LPSOCKADDR;
  186.     var RemoteSockaddrLength: Integer); stdcall;
  187.   {$EXTERNALSYM LPFN_GETACCEPTEXSOCKADDRS}
  188.   TFnGetAcceptExSockAddrs = LPFN_GETACCEPTEXSOCKADDRS;
  189. const
  190.   WSAID_GETACCEPTEXSOCKADDRS: TGUID = (
  191.     D1: $b5367df2; D2:$cbac; D3:$11cf; D4:($95, $ca, $00, $80, $5f, $48, $a1, $92));
  192.   {$EXTERNALSYM WSAID_GETACCEPTEXSOCKADDRS}
  193.   TP_ELEMENT_MEMORY  = 1;
  194.   {$EXTERNALSYM TP_ELEMENT_MEMORY}
  195.   TP_ELEMENT_FILE    = 2;
  196.   {$EXTERNALSYM TP_ELEMENT_FILE}
  197.   TP_ELEMENT_EOP     = 4;
  198.   {$EXTERNALSYM TP_ELEMENT_EOP}
  199. type
  200.   _TRANSMIT_PACKETS_ELEMENT = record
  201.     dwElFlags: ULONG;
  202.     cLength: ULONG;
  203.     case Integer of
  204.       0: (
  205.         nFileOffset: LARGE_INTEGER;
  206.         hFile: HANDLE);
  207.       1: (
  208.         pBuffer: LPVOID);
  209.   end;
  210.   {$EXTERNALSYM _TRANSMIT_PACKETS_ELEMENT}
  211.   TRANSMIT_PACKETS_ELEMENT = _TRANSMIT_PACKETS_ELEMENT;
  212.   {$EXTERNALSYM TRANSMIT_PACKETS_ELEMENT}
  213.   PTRANSMIT_PACKETS_ELEMENT = ^TRANSMIT_PACKETS_ELEMENT;
  214.   {$EXTERNALSYM PTRANSMIT_PACKETS_ELEMENT}
  215.   LPTRANSMIT_PACKETS_ELEMENT = ^TRANSMIT_PACKETS_ELEMENT;
  216.   {$EXTERNALSYM LPTRANSMIT_PACKETS_ELEMENT}
  217.   TTransmitPacketElement = TRANSMIT_PACKETS_ELEMENT;
  218.   PTransmitPacketElement = PTRANSMIT_PACKETS_ELEMENT;
  219. const
  220.   TP_DISCONNECT         = TF_DISCONNECT;
  221.   {$EXTERNALSYM TP_DISCONNECT}
  222.   TP_REUSE_SOCKET       = TF_REUSE_SOCKET;
  223.   {$EXTERNALSYM TP_REUSE_SOCKET}
  224.   TP_USE_DEFAULT_WORKER = TF_USE_DEFAULT_WORKER;
  225.   {$EXTERNALSYM TP_USE_DEFAULT_WORKER}
  226.   TP_USE_SYSTEM_THREAD  = TF_USE_SYSTEM_THREAD;
  227.   {$EXTERNALSYM TP_USE_SYSTEM_THREAD}
  228.   TP_USE_KERNEL_APC     = TF_USE_KERNEL_APC;
  229.   {$EXTERNALSYM TP_USE_KERNEL_APC}
  230. type
  231.   LPFN_TRANSMITPACKETS = function (Socket: TSocket; lpPacketArray: LPTRANSMIT_PACKETS_ELEMENT; ElementCount: DWORD;
  232.     nSendSize: DWORD; lpOverlapped: LPOVERLAPPED; dwFlags: DWORD): BOOL; stdcall;
  233.   {$EXTERNALSYM LPFN_TRANSMITPACKETS}
  234. const
  235.   WSAID_TRANSMITPACKETS: TGUID = (
  236.     D1: $d9689da0; D2:$1f90; D3:$11d3; D4:($99, $71, $00, $c0, $4f, $68, $c8, $76));
  237.   {$EXTERNALSYM WSAID_TRANSMITPACKETS}
  238. type
  239.   LPFN_CONNECTEX = function (s: TSocket; name: PSockAddr; namelen: Integer; lpSendBuffer: PVOID; dwSendDataLength: DWORD;
  240.     lpdwBytesSent: LPDWORD; lpOverlapped: LPOVERLAPPED): BOOL; stdcall;
  241.   {$EXTERNALSYM LPFN_CONNECTEX}
  242. const
  243.   WSAID_CONNECTEX: TGUID = (
  244.     D1: $25a207b9; D2:$ddf3; D3:$4660; D4:($8e, $e9, $76, $e5, $8c, $74, $06, $3e));
  245.   {$EXTERNALSYM WSAID_CONNECTEX}
  246. type
  247.   LPFN_DISCONNECTEX = function (s: TSocket; lpOverlapped: LPOVERLAPPED; dwFlags: DWORD; dwReserved: DWORD): BOOL; stdcall;
  248.   {$EXTERNALSYM LPFN_DISCONNECTEX}
  249. const
  250.   WSAID_DISCONNECTEX: TGUID = (
  251.     D1: $7fda2e11; D2:$8630; D3:$436f; D4:($a0, $31, $f5, $36, $a6, $ee, $c1, $57));
  252.   {$EXTERNALSYM WSAID_DISCONNECTEX}
  253.   DE_REUSE_SOCKET = TF_REUSE_SOCKET;
  254.   {$EXTERNALSYM DE_REUSE_SOCKET}
  255.   
  256. //
  257. // Network-location awareness -- Name registration values for use
  258. // with WSASetService and other structures.
  259. //
  260. // {6642243A-3BA8-4aa6-BAA5-2E0BD71FDD83}
  261.   NLA_NAMESPACE_GUID: TGUID = (
  262.     D1: $6642243a; D2:$3ba8; D3:$4aa6; D4:($ba, $a5, $2e, $0b, $d7, $1f, $dd, $83));
  263.   {$EXTERNALSYM NLA_NAMESPACE_GUID}
  264. // {6642243A-3BA8-4aa6-BAA5-2E0BD71FDD83}
  265.   NLA_SERVICE_CLASS_GUID: TGUID = (
  266.     D1: $37e515; D2:$b5c9; D3:$4a43; D4:($ba, $da, $8b, $48, $a8, $7a, $d2, $39));
  267.   {$EXTERNALSYM NLA_SERVICE_CLASS_GUID}
  268.   NLA_ALLUSERS_NETWORK  = $00000001;
  269.   {$EXTERNALSYM NLA_ALLUSERS_NETWORK}
  270.   NLA_FRIENDLY_NAME     = $00000002;
  271.   {$EXTERNALSYM NLA_FRIENDLY_NAME}
  272. type
  273.   _NLA_BLOB_DATA_TYPE = (
  274.     NLA_RAW_DATA,
  275.     NLA_INTERFACE,
  276.     NLA_802_1X_LOCATION,
  277.     NLA_CONNECTIVITY,
  278.     NLA_ICS);
  279.   {$EXTERNALSYM _NLA_BLOB_DATA_TYPE}
  280.   NLA_BLOB_DATA_TYPE = _NLA_BLOB_DATA_TYPE;
  281.   {$EXTERNALSYM NLA_BLOB_DATA_TYPE}
  282.   PNLA_BLOB_DATA_TYPE = ^NLA_BLOB_DATA_TYPE;
  283.   {$EXTERNALSYM PNLA_BLOB_DATA_TYPE}
  284.   TNlaBlobDataType = NLA_BLOB_DATA_TYPE;
  285.   PNlaBlobDataType = PNLA_BLOB_DATA_TYPE;
  286.   _NLA_CONNECTIVITY_TYPE = (
  287.     NLA_NETWORK_AD_HOC,
  288.     NLA_NETWORK_MANAGED,
  289.     NLA_NETWORK_UNMANAGED,
  290.     NLA_NETWORK_UNKNOWN);
  291.   {$EXTERNALSYM _NLA_CONNECTIVITY_TYPE}
  292.   NLA_CONNECTIVITY_TYPE = _NLA_CONNECTIVITY_TYPE;
  293.   {$EXTERNALSYM NLA_CONNECTIVITY_TYPE}
  294.   PNLA_CONNECTIVITY_TYPE = ^NLA_CONNECTIVITY_TYPE;
  295.   {$EXTERNALSYM PNLA_CONNECTIVITY_TYPE}
  296.   TNlaConnectivityType = NLA_CONNECTIVITY_TYPE;
  297.   PNlaConnectivityType = PNLA_CONNECTIVITY_TYPE;
  298.   _NLA_INTERNET = (
  299.     NLA_INTERNET_UNKNOWN,
  300.     NLA_INTERNET_NO,
  301.     NLA_INTERNET_YES);
  302.   {$EXTERNALSYM _NLA_INTERNET}
  303.   NLA_INTERNET = _NLA_INTERNET;
  304.   {$EXTERNALSYM NLA_INTERNET}
  305.   PNLA_INTERNET = ^NLA_INTERNET;
  306.   {$EXTERNALSYM PNLA_INTERNET}
  307.   TNlaInternet = NLA_INTERNET;
  308.   PNlaInternet = PNLA_INTERNET;  
  309.   _NLA_BLOB = record
  310.     header: record
  311.       type_: NLA_BLOB_DATA_TYPE;
  312.       dwSize: DWORD;
  313.       nextOffset: DWORD;
  314.     end;
  315.     case Integer of
  316.       0: (
  317.         // header.type -> NLA_RAW_DATA
  318.         rawData: array [0..0] of CHAR);
  319.       1: (
  320.         // header.type -> NLA_INTERFACE
  321.         dwType: DWORD;
  322.         dwSpeed: DWORD;
  323.         adapterName: array [0..0] of CHAR);
  324.       2: (
  325.         // header.type -> NLA_802_1X_LOCATION
  326.         information: array [0..0] of CHAR);
  327.       3: (
  328.         // header.type -> NLA_CONNECTIVITY
  329.         type_: NLA_CONNECTIVITY_TYPE;
  330.         internet: NLA_INTERNET);
  331.       4: (
  332.         // header.type -> NLA_ICS
  333.         remote: record
  334.           speed: DWORD;
  335.           type_: DWORD;
  336.           state: DWORD;
  337.           machineName: array [0..255] of WCHAR;
  338.           sharedAdapterName: array [0..255] of WCHAR;
  339.         end);
  340.   end;
  341.   {$EXTERNALSYM _NLA_BLOB}
  342.   NLA_BLOB = _NLA_BLOB;
  343.   {$EXTERNALSYM NLA_BLOB}
  344.   PNLA_BLOB = ^NLA_BLOB;
  345.   {$EXTERNALSYM PNLA_BLOB}
  346.   LPNLA_BLOB = ^NLA_BLOB;
  347.   {$EXTERNALSYM LPNLA_BLOB}
  348.   TNlaBlob = NLA_BLOB;
  349.   PNlaBlob = PNLA_BLOB;  
  350.   _WSAMSG = record
  351.     name: LPSOCKADDR;          // Remote address
  352.     namelen: INT;              // Remote address length
  353.     lpBuffers: LPWSABUF;       // Data buffer array
  354.     dwBufferCount: DWORD;      // Number of elements in the array
  355.     Control: WSABUF;           // Control buffer
  356.     dwFlags: DWORD;            // Flags
  357.   end;
  358.   {$EXTERNALSYM _WSAMSG}
  359.   WSAMSG = _WSAMSG;
  360.   {$EXTERNALSYM WSAMSG}
  361.   PWSAMSG = ^WSAMSG;
  362.   {$EXTERNALSYM PWSAMSG}
  363.   LPWSAMSG = ^WSAMSG;
  364.   {$EXTERNALSYM LPWSAMSG}
  365.   TWsaMsg = WSAMSG;
  366. //
  367. // Layout of ancillary data objects in the control buffer
  368. //
  369.   _WSACMSGHDR = record
  370.     cmsg_len: SIZE_T;
  371.     cmsg_level: INT;
  372.     cmsg_type: INT;
  373.     // followed by UCHAR cmsg_data[]
  374.   end;
  375.   {$EXTERNALSYM _WSACMSGHDR}
  376.   WSACMSGHDR = _WSACMSGHDR;
  377.   {$EXTERNALSYM WSACMSGHDR}
  378.   PWSACMSGHDR = ^WSACMSGHDR;
  379.   {$EXTERNALSYM PWSACMSGHDR}
  380.   LPWSACMSGHDR = ^WSACMSGHDR;
  381.   {$EXTERNALSYM LPWSACMSGHDR}
  382.   TWsaCMsgHdr = WSACMSGHDR;
  383. //
  384. // Alignment macros for header and data members of
  385. // the control buffer.
  386. //
  387. { TODO
  388. #define WSA_CMSGHDR_ALIGN(length)                           
  389.             ( ((length) + TYPE_ALIGNMENT(WSACMSGHDR)-1) &   
  390.                 (~(TYPE_ALIGNMENT(WSACMSGHDR)-1)) )         
  391. #define WSA_CMSGDATA_ALIGN(length)                          
  392.             ( ((length) + MAX_NATURAL_ALIGNMENT-1) &        
  393.                 (~(MAX_NATURAL_ALIGNMENT-1)) )
  394. }
  395. //
  396. //  WSA_CMSG_FIRSTHDR
  397. //
  398. //  Returns a pointer to the first ancillary data object,
  399. //  or a null pointer if there is no ancillary data in the
  400. //  control buffer of the WSAMSG structure.
  401. //
  402. //  LPCMSGHDR
  403. //  WSA_CMSG_FIRSTHDR (
  404. //      LPWSAMSG    msg
  405. //      );
  406. //
  407. (* TODO
  408. #define WSA_CMSG_FIRSTHDR(msg) 
  409.     ( ((msg)->Control.len >= sizeof(WSACMSGHDR))            
  410.         ? (LPWSACMSGHDR)(msg)->Control.buf                  
  411.         : (LPWSACMSGHDR)NULL )
  412. *)
  413. //
  414. //  WSA_CMSG_NXTHDR
  415. //
  416. //  Returns a pointer to the next ancillary data object,
  417. //  or a null if there are no more data objects.
  418. //
  419. //  LPCMSGHDR
  420. //  WSA_CMSG_NEXTHDR (
  421. //      LPWSAMSG        msg,
  422. //      LPWSACMSGHDR    cmsg
  423. //      );
  424. //
  425. { TODO
  426. #define WSA_CMSG_NXTHDR(msg, cmsg)                          
  427.     ( ((cmsg) == NULL)                                      
  428.         ? WSA_CMSG_FIRSTHDR(msg)                            
  429.         : ( ( ((u_char *)(cmsg) +                           
  430.                     WSA_CMSGHDR_ALIGN((cmsg)->cmsg_len) +   
  431.                     sizeof(WSACMSGHDR) ) >                  
  432.                 (u_char *)((msg)->Control.buf) +            
  433.                     (msg)->Control.len )                    
  434.             ? (LPWSACMSGHDR)NULL                            
  435.             : (LPWSACMSGHDR)((u_char *)(cmsg) +             
  436.                 WSA_CMSGHDR_ALIGN((cmsg)->cmsg_len)) ) )
  437. }
  438. //
  439. //  WSA_CMSG_DATA
  440. //
  441. //  Returns a pointer to the first byte of data (what is referred
  442. //  to as the cmsg_data member though it is not defined in
  443. //  the structure).
  444. //
  445. //  u_char *
  446. //  WSA_CMSG_DATA (
  447. //      LPWSACMSGHDR   pcmsg
  448. //      );
  449. //
  450. { TODO
  451. #define WSA_CMSG_DATA(cmsg)             
  452.             ( (u_char *)(cmsg) + WSA_CMSGDATA_ALIGN(sizeof(WSACMSGHDR)) )
  453. }
  454. //
  455. //  WSA_CMSG_SPACE
  456. //
  457. //  Returns total size of an ancillary data object given
  458. //  the amount of data. Used to allocate the correct amount
  459. //  of space.
  460. //
  461. //  SIZE_T
  462. //  WSA_CMSG_SPACE (
  463. //      SIZE_T length
  464. //      );
  465. //
  466. { TODO
  467. #define WSA_CMSG_SPACE(length)  
  468.         (WSA_CMSGDATA_ALIGN(sizeof(WSACMSGHDR) + WSA_CMSGHDR_ALIGN(length)))
  469. }
  470. //
  471. //  WSA_CMSG_LEN
  472. //
  473. //  Returns the value to store in cmsg_len given the amount of data.
  474. //
  475. //  SIZE_T
  476. //  WSA_CMSG_LEN (
  477. //      SIZE_T length
  478. //  );
  479. //
  480. { TODO
  481. #define WSA_CMSG_LEN(length)    
  482.          (WSA_CMSGDATA_ALIGN(sizeof(WSACMSGHDR)) + length)
  483. }
  484. //
  485. // Definition for flags member of the WSAMSG structure
  486. // This is in addition to other MSG_xxx flags defined
  487. // for recv/recvfrom/send/sendto.
  488. //
  489. const
  490.   MSG_TRUNC     = $0100;
  491.   {$EXTERNALSYM MSG_TRUNC}
  492.   MSG_CTRUNC    = $0200;
  493.   {$EXTERNALSYM MSG_CTRUNC}
  494.   MSG_BCAST     = $0400;
  495.   {$EXTERNALSYM MSG_BCAST}
  496.   MSG_MCAST     = $0800;
  497.   {$EXTERNALSYM MSG_MCAST}
  498. type
  499.   LPFN_WSARECVMSG = function (s: TSocket; lpMsg: LPWSAMSG; lpdwNumberOfBytesRecvd: LPDWORD; lpOverlapped: LPWSAOVERLAPPED;
  500.     lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE): INT; stdcall;
  501.   {$EXTERNALSYM LPFN_WSARECVMSG}
  502. const
  503.   WSAID_WSARECVMSG: TGUID = (
  504.     D1: $f689d7c8; D2:$6f1f; D3:$436b; D4:($8a, $53, $e5, $4f, $e3, $51, $c3, $22));
  505.   {$EXTERNALSYM WSAID_WSARECVMSG}
  506. implementation
  507. const
  508.   mswsock_lib = 'mswsock.dll';
  509. {$IFDEF DYNAMIC_LINK}
  510. var
  511.   _WSARecvEx: Pointer;
  512. function WSARecvEx;
  513. begin
  514.   GetProcedureAddress(_WSARecvEx, mswsock_lib, 'WSARecvEx');
  515.   asm
  516.     mov esp, ebp
  517.     pop ebp
  518.     jmp [_WSARecvEx]
  519.   end;
  520. end;
  521. {$ELSE}
  522. function WSARecvEx; external mswsock_lib name 'WSARecvEx';
  523. {$ENDIF DYNAMIC_LINK}
  524. {$IFDEF DYNAMIC_LINK}
  525. var
  526.   _TransmitFile: Pointer;
  527. function TransmitFile;
  528. begin
  529.   GetProcedureAddress(_TransmitFile, mswsock_lib, 'TransmitFile');
  530.   asm
  531.     mov esp, ebp
  532.     pop ebp
  533.     jmp [_TransmitFile]
  534.   end;
  535. end;
  536. {$ELSE}
  537. function TransmitFile; external mswsock_lib name 'TransmitFile';
  538. {$ENDIF DYNAMIC_LINK}
  539. {$IFDEF DYNAMIC_LINK}
  540. var
  541.   _AcceptEx: Pointer;
  542. function AcceptEx;
  543. begin
  544.   GetProcedureAddress(_AcceptEx, mswsock_lib, 'AcceptEx');
  545.   asm
  546.     mov esp, ebp
  547.     pop ebp
  548.     jmp [_AcceptEx]
  549.   end;
  550. end;
  551. {$ELSE}
  552. function AcceptEx; external mswsock_lib name 'AcceptEx';
  553. {$ENDIF DYNAMIC_LINK}
  554. {$IFDEF DYNAMIC_LINK}
  555. var
  556.   _GetAcceptExSockaddrs: Pointer;
  557. procedure GetAcceptExSockaddrs;
  558. begin
  559.   GetProcedureAddress(_GetAcceptExSockaddrs, mswsock_lib, 'GetAcceptExSockaddrs');
  560.   asm
  561.     mov esp, ebp
  562.     pop ebp
  563.     jmp [_GetAcceptExSockaddrs]
  564.   end;
  565. end;
  566. {$ELSE}
  567. procedure GetAcceptExSockaddrs; external mswsock_lib name 'GetAcceptExSockaddrs';
  568. {$ENDIF DYNAMIC_LINK}
  569. end.