home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / main / BBS / D32_01.ZIP / W32SOCK.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-06-26  |  14.8 KB  |  201 lines

  1. unit W32sock;
  2. {&Orgname+}
  3. (*
  4. **
  5. ** WINDOWS TCP/IP routines
  6. **
  7. ** Copyright (c) 1998 by Thomas W. Mueller
  8. **
  9. ** Created : 24-Oct-1998
  10. ** Last update : 24-Oct-1998
  11. **
  12. **
  13. *)
  14.  
  15. (*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-*)
  16.  INTERFACE
  17. (*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-*)
  18.  
  19. uses
  20.   Windows,
  21.   SockDef;
  22.  
  23. type
  24.   u_char = Char;
  25.   u_short = Word;
  26.   u_int = Integer;
  27.   u_long = Longint;
  28.  
  29. { Socket function prototypes }
  30.  
  31. function accept(_s: ULONG; _addr: pSockAddr; _addrlen: PInteger): ULONG;                                  stdcall;
  32. function bind(_s: ULONG; _addr: pSockAddr; _namelen: Integer): Integer;                                   stdcall;
  33. function connect(_s: ULONG; _name: pSockAddr; _namelen: Integer): Integer;                                stdcall;
  34. function closesocket(s: ULONG): Integer;                                                                  stdcall;
  35. function select(nfds: Integer; readfds, writefds, exceptfds: PFDSet;
  36.   timeout: PTimeVal): Longint;                                                                            stdcall;
  37. function ioctlsocket(_s: ULONG; _cmd: Longint; var _arg: ULONG): Integer;                                 stdcall;
  38. function getpeername(_s: ULONG; _name: pSockAddr; var _namelen: Integer): Integer;                        stdcall;
  39. function getsockname(_s: ULONG; _name: pSockAddr; var _namelen: Integer): Integer;                        stdcall;
  40. function getsockopt(_s: ULONG; _level, _optname: Integer; _optval: PChar; var _optlen: Integer): Integer; stdcall;
  41. function htonl(_hostlong: ULONG): ULONG;                                                                  stdcall;
  42. function htons(_hostshort: Integer): Integer;                                                             stdcall;
  43. function inet_addr(_cp: PChar): ULONG;                                                                    stdcall;
  44. function inet_ntoa(_inaddr: tIn_Addr): PChar;                                                             stdcall;
  45. function listen(_s: ULONG; _backlog: Integer): Integer;                                                   stdcall;
  46. function ntohl(_netlong: ULONG): ULONG;                                                                   stdcall;
  47. function ntohs(_netshort: Integer): Integer;                                                              stdcall;
  48. function recv(_s: ULONG; _Buf: pointer; _len, _flags: Integer): Integer;                                  stdcall;
  49.  
  50. function recvfrom(s: ULONG; _Buf: pointer; _len, _flags: Integer;
  51.                   var _from: TSockAddr; var _fromlen: Integer): Integer;                                  stdcall;
  52. function send(_s: ULONG; _Buf: pointer; _len, _flags: Integer): Integer;                                  stdcall;
  53. function sendto(_s: ULONG; _Buf: pointer; _len, _flags: Integer; var _addrto: TSockAddr;
  54.                 _tolen: Integer): Integer;                                                                stdcall;
  55. function setsockopt(_s: ULONG; _level, _optname: Integer; _optval: PChar;
  56.                     _optlen: Integer): Integer;                                                           stdcall;
  57. function shutdown(_s: ULONG; _how: Integer): Integer;                                                     stdcall;
  58. function socket(_af, _struct, _protocol: Integer): ULONG;                                                 stdcall;
  59.  
  60. function gethostbyaddr(_addr: Pointer; _len, _struct: Integer): PHostEnt;                                 stdcall;
  61. function gethostbyname(_name: PChar): PHostEnt;                                                           stdcall;
  62. function gethostname(_name: PChar; _len: Integer): Integer;                                               stdcall;
  63. function getservbyport(_port: Integer; _proto: PChar): PServEnt;                                          stdcall;
  64. function getservbyname(_name, _proto: PChar): PServEnt;                                                   stdcall;
  65. function getprotobynumber(_proto: Integer): PProtoEnt;                                                    stdcall;
  66. function getprotobyname(_name: PChar): PProtoEnt;                                                         stdcall;
  67.  
  68. function WSAStartup(wVersionRequired: word; var WSData: TWSAData): Integer;               stdcall;
  69. function WSACleanup: Integer;                                                             stdcall;
  70. procedure WSASetLastError(iError: Integer);                                               stdcall;
  71. function WSAGetLastError: Integer;                                                        stdcall;
  72. function WSAIsBlocking: BOOL;                                                             stdcall;
  73. function WSAUnhookBlockingHook: Integer;                                                  stdcall;
  74. function WSASetBlockingHook(lpBlockFunc: TFarProc): TFarProc;                             stdcall;
  75. function WSACancelBlockingCall: Integer;                                                  stdcall;
  76. function WSAAsyncGetServByName(HWindow: HWND; wMsg: u_int;
  77.   name, proto, buf: PChar; buflen: Integer): THandle;                                     stdcall;
  78. function WSAAsyncGetServByPort( HWindow: HWND; wMsg, port: u_int;
  79.   proto, buf: PChar; buflen: Integer): THandle;                                           stdcall;
  80. function WSAAsyncGetProtoByName(HWindow: HWND; wMsg: u_int;
  81.   name, buf: PChar; buflen: Integer): THandle;                                            stdcall;
  82. function WSAAsyncGetProtoByNumber(HWindow: HWND; wMsg: u_int; number: Integer;
  83.   buf: PChar; buflen: Integer): THandle;                                                  stdcall;
  84. function WSAAsyncGetHostByName(HWindow: HWND; wMsg: u_int;
  85.   name, buf: PChar; buflen: Integer): THandle;                                            stdcall;
  86. function WSAAsyncGetHostByAddr(HWindow: HWND; wMsg: u_int; addr: PChar;
  87.   len, struct: Integer; buf: PChar; buflen: Integer): THandle;                            stdcall;
  88. function WSACancelAsyncRequest(hAsyncTaskHandle: THandle): Integer;                       stdcall;
  89. function WSAAsyncSelect(s: ULONG; HWindow: HWND; wMsg: u_int; lEvent: Longint): Integer;  stdcall;
  90. function WSARecvEx(s: ULONG; var buf; len: Integer; var flags: Integer): Integer;         stdcall;
  91.  
  92. function WSAMakeSyncReply(Buflen, Error: Word): Longint;
  93. function WSAMakeSelectReply(Event, Error: Word): Longint;
  94. function WSAGetAsyncBuflen(Param: Longint): Word;
  95. function WSAGetAsyncError(Param: Longint): Word;
  96. function WSAGetSelectEvent(Param: Longint): Word;
  97. function WSAGetSelectError(Param: Longint): Word;
  98.  
  99. (*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-*)
  100.  IMPLEMENTATION
  101. (*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-+-*-*)
  102.  
  103. const
  104.   winsocket = 'wsock32.dll';
  105.  
  106. function WSAMakeSyncReply(Buflen, Error: Word): Longint;
  107. begin
  108.   WSAMakeSyncReply:= MakeLong(Buflen, Error);
  109. end;
  110.  
  111. function WSAMakeSelectReply(Event, Error: Word): Longint;
  112. begin
  113.   WSAMakeSelectReply:= MakeLong(Event, Error);
  114. end;
  115.  
  116. function WSAGetAsyncBuflen(Param: Longint): Word;
  117. begin
  118.   WSAGetAsyncBuflen:= LOWORD(Param);
  119. end;
  120.  
  121. function WSAGetAsyncError(Param: Longint): Word;
  122. begin
  123.   WSAGetAsyncError:= HIWORD(Param);
  124. end;
  125.  
  126. function WSAGetSelectEvent(Param: Longint): Word;
  127. begin
  128.   WSAGetSelectEvent:= LOWORD(Param);
  129. end;
  130.  
  131. function WSAGetSelectError(Param: Longint): Word;
  132. begin
  133.   WSAGetSelectError:= HIWORD(Param);
  134. end;
  135.  
  136. function accept(_s: ULONG; _addr: pSockAddr; _addrlen: PInteger): ULONG;                                    external    winsocket name 'accept';
  137. function bind(_s: ULONG; _addr: pSockAddr; _namelen: Integer): Integer;                                     external    winsocket name 'bind';
  138. function connect(_s: ULONG; _name: pSockAddr; _namelen: Integer): Integer;                                  external    winsocket name 'connect';
  139. function closesocket(s: ULONG): Integer;                                                                    external    winsocket name 'closesocket';
  140. function select(nfds: Integer; readfds, writefds, exceptfds: PFDSet;
  141.   timeout: PTimeVal): Longint;                                                                              external    winsocket name 'select';
  142. function ioctlsocket(_s: ULONG; _cmd: Longint; var _arg: ULONG): Integer;                                   external    winsocket name 'ioctlsocket';
  143. function getpeername(_s: ULONG; _name: pSockAddr; var _namelen: Integer): Integer;                          external    winsocket name 'getpeername';
  144. function getsockname(_s: ULONG; _name: pSockAddr; var _namelen: Integer): Integer;                          external    winsocket name 'getsockname';
  145. function getsockopt(_s: ULONG; _level, _optname: Integer; _optval: PChar; var _optlen: Integer): Integer;   external    winsocket name 'getsockopt';
  146. function htonl(_hostlong: ULONG): ULONG;                                                                    external    winsocket name 'htonl';
  147. function htons(_hostshort: Integer): Integer;                                                               external    winsocket name 'htons';
  148. function inet_addr(_cp: PChar): ULONG;                                                                      external    winsocket name 'inet_addr';
  149. function inet_ntoa(_inaddr: tIn_Addr): PChar;                                                               external    winsocket name 'inet_ntoa';
  150. function listen(_s: ULONG; _backlog: Integer): Integer;                                                     external    winsocket name 'listen';
  151. function ntohl(_netlong: ULONG): ULONG;                                                                     external    winsocket name 'ntohl';
  152. function ntohs(_netshort: Integer): Integer;                                                                external    winsocket name 'ntohs';
  153. function recv(_s: ULONG; _Buf: pointer; _len, _flags: Integer): Integer;                                    external    winsocket name 'recv';
  154.  
  155.  
  156. function recvfrom(s: ULONG; _Buf: pointer; _len, _flags: Integer;
  157.                   var _from: TSockAddr; var _fromlen: Integer): Integer;                                    external    winsocket name 'recvfrom';
  158. function send(_s: ULONG; _Buf: pointer; _len, _flags: Integer): Integer;                                    external    winsocket name 'send';
  159. function sendto(_s: ULONG; _Buf: pointer; _len, _flags: Integer; var _addrto: TSockAddr;
  160.                 _tolen: Integer): Integer;                                                                  external    winsocket name 'sendto';
  161. function setsockopt(_s: ULONG; _level, _optname: Integer; _optval: PChar;
  162.                     _optlen: Integer): Integer;                                                             external    winsocket name 'setsockopt';
  163. function shutdown(_s: ULONG; _how: Integer): Integer;                                                       external    winsocket name 'shutdown';
  164. function socket(_af, _struct, _protocol: Integer): ULONG;                                                   external    winsocket name 'socket';
  165.  
  166.  
  167. function gethostbyaddr(_addr: Pointer; _len, _struct: Integer): PHostEnt;                                 external    winsocket name 'gethostbyaddr';
  168. function gethostbyname(_name: PChar): PHostEnt;                                                           external    winsocket name 'gethostbyname';
  169. function gethostname(_name: PChar; _len: Integer): Integer;                                               external    winsocket name 'gethostname';
  170. function getservbyport(_port: Integer; _proto: PChar): PServEnt;                                          external    winsocket name 'getservbyport';
  171. function getservbyname(_name, _proto: PChar): PServEnt;                                                   external    winsocket name 'getservbyname';
  172. function getprotobynumber(_proto: Integer): PProtoEnt;                                                    external    winsocket name 'getprotobynumber';
  173. function getprotobyname(_name: PChar): PProtoEnt;                                                         external    winsocket name 'getprotobyname';
  174.  
  175.  
  176. function WSAStartup(wVersionRequired: word; var WSData: TWSAData): Integer;                external   winsocket name 'WSAStartup';
  177. function WSACleanup: Integer;                                                              external   winsocket name 'WSACleanup';
  178. procedure WSASetLastError(iError: Integer);                                                external   winsocket name 'WSASetLastError';
  179. function WSAGetLastError: Integer;                                                         external   winsocket name 'WSAGetLastError';
  180. function WSAIsBlocking: BOOL;                                                              external   winsocket name 'WSAIsBlocking';
  181. function WSAUnhookBlockingHook: Integer;                                                   external   winsocket name 'WSAUnhookBlockingHook';
  182. function WSASetBlockingHook(lpBlockFunc: TFarProc): TFarProc;                              external   winsocket name 'WSASetBlockingHook';
  183. function WSACancelBlockingCall: Integer;                                                   external   winsocket name 'WSACancelBlockingCall';
  184. function WSAAsyncGetServByName(HWindow: HWND; wMsg: u_int;
  185.   name, proto, buf: PChar; buflen: Integer): THandle;                                      external   winsocket name 'WSAAsyncGetServByName';
  186. function WSAAsyncGetServByPort( HWindow: HWND; wMsg, port: u_int;
  187.   proto, buf: PChar; buflen: Integer): THandle;                                            external   winsocket name 'WSAAsyncGetServByPort';
  188. function WSAAsyncGetProtoByName(HWindow: HWND; wMsg: u_int;
  189.   name, buf: PChar; buflen: Integer): THandle;                                             external   winsocket name 'WSAAsyncGetProtoByName';
  190. function WSAAsyncGetProtoByNumber(HWindow: HWND; wMsg: u_int; number: Integer;
  191.   buf: PChar; buflen: Integer): THandle;                                                   external   winsocket name 'WSAAsyncGetProtoByNumber';
  192. function WSAAsyncGetHostByName(HWindow: HWND; wMsg: u_int;
  193.   name, buf: PChar; buflen: Integer): THandle;                                             external   winsocket name 'WSAAsyncGetHostByName';
  194. function WSAAsyncGetHostByAddr(HWindow: HWND; wMsg: u_int; addr: PChar;
  195.   len, struct: Integer; buf: PChar; buflen: Integer): THandle;                             external   winsocket name 'WSAAsyncGetHostByAddr';
  196. function WSACancelAsyncRequest(hAsyncTaskHandle: THandle): Integer;                        external   winsocket name 'WSACancelAsyncRequest';
  197. function WSAAsyncSelect(s: ULONG; HWindow: HWND; wMsg: u_int; lEvent: Longint): Integer;   external   winsocket name 'WSAAsyncSelect';
  198. function WSARecvEx(s: ULONG; var buf; len: Integer; var flags: Integer): Integer;          external   winsocket name 'WSARecvEx';
  199.  
  200. end. { unit. W32SOCK }
  201.