socketsh.inc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. Const
  12. { Socket Types }
  13. SOCK_STREAM = 1; { stream (connection) socket }
  14. SOCK_DGRAM = 2; { datagram (conn.less) socket }
  15. SOCK_RAW = 3; { raw socket }
  16. SOCK_RDM = 4; { reliably-delivered message }
  17. SOCK_SEQPACKET = 5; { sequential packet socket }
  18. AF_UNSPEC = 0;
  19. AF_UNIX = 1; { Unix domain sockets }
  20. AF_INET = 2; { Internet IP Protocol }
  21. { Protocol Families }
  22. PF_UNSPEC = AF_UNSPEC;
  23. PF_UNIX = AF_UNIX;
  24. PF_INET = AF_INET;
  25. {$Ifdef Unix}
  26. {$ifndef BSD}
  27. { For setsockoptions(2) }
  28. SOL_SOCKET = 1;
  29. SO_DEBUG = 1;
  30. SO_REUSEADDR= 2;
  31. SO_TYPE = 3;
  32. SO_ERROR = 4;
  33. SO_DONTROUTE= 5;
  34. SO_BROADCAST= 6;
  35. SO_SNDBUF = 7;
  36. SO_RCVBUF = 8;
  37. SO_KEEPALIVE= 9;
  38. SO_OOBINLINE= 10;
  39. SO_NO_CHECK = 11;
  40. SO_PRIORITY = 12;
  41. SO_LINGER = 13;
  42. SO_BSDCOMPAT= 14;
  43. { To add : SO_REUSEPORT 15 }
  44. SO_PASSCRED= 16;
  45. SO_PEERCRED= 17;
  46. SO_RCVLOWAT= 18;
  47. SO_SNDLOWAT= 19;
  48. SO_RCVTIMEO= 20;
  49. SO_SNDTIMEO= 21;
  50. { Security levels - as per NRL IPv6 - don't actually do anything }
  51. SO_SECURITY_AUTHENTICATION = 22;
  52. SO_SECURITY_ENCRYPTION_TRANSPORT= 23;
  53. SO_SECURITY_ENCRYPTION_NETWORK = 24;
  54. SO_BINDTODEVICE= 25;
  55. { Socket filtering }
  56. SO_ATTACH_FILTER= 26;
  57. SO_DETACH_FILTER= 27;
  58. SO_PEERNAME = 28;
  59. {$ELSE}
  60. SOL_SOCKET = $FFFF;
  61. SO_DEBUG =$0001; { turn on debugging info recording }
  62. SO_ACCEPTCONN =$0002; { socket has had listen() }
  63. SO_REUSEADDR =$0004; { allow local address reuse }
  64. SO_KEEPALIVE =$0008; { keep connections alive }
  65. SO_DONTROUTE =$0010; { just use interface addresses }
  66. SO_BROADCAST =$0020; { permit sending of broadcast msgs }
  67. SO_USELOOPBACK =$0040; { bypass hardware when possible }
  68. SO_LINGER =$0080; { linger on close if data present }
  69. SO_OOBINLINE =$0100; { leave received OOB data in line }
  70. SO_REUSEPORT =$0200; { allow local address & port reuse }
  71. SO_TIMESTAMP =$0400; { timestamp received dgram traffic }
  72. {
  73. * Additional options, not kept in so_options.
  74. }
  75. SO_SNDBUF =$1001; { send buffer size }
  76. SO_RCVBUF =$1002; { receive buffer size }
  77. SO_SNDLOWAT =$1003; { send low-water mark }
  78. SO_RCVLOWAT =$1004; { receive low-water mark }
  79. SO_SNDTIMEO =$1005; { send timeout }
  80. SO_RCVTIMEO =$1006; { receive timeout }
  81. SO_ERROR =$1007; { get error status and clear }
  82. SO_TYPE =$1008; { get socket type }
  83. SHUT_RD =0; { shut down the reading side }
  84. SHUT_WR =1; { shut down the writing side }
  85. SHUT_RDWR =2; { shut down both sides }
  86. {$endif}
  87. {$ENDIF}
  88. const
  89. { Two constants to determine whether part of soket is for in or output }
  90. S_IN = 0;
  91. S_OUT = 1;
  92. Type
  93. TSockAddr = packed Record
  94. {$ifdef BSD}
  95. len : byte;
  96. family:byte;
  97. {$ELSE}
  98. family:word; { was byte, fixed }
  99. {$ENDIF}
  100. data :array [0..13] of char;
  101. end;
  102. TInetSockAddr = packed Record
  103. family:Word;
  104. port :Word;
  105. addr :Cardinal;
  106. pad :array [1..8] of byte; { to get to the size of sockaddr... }
  107. end;
  108. TSockArray = Array[1..2] of Longint;
  109. Var
  110. SocketError:Longint;
  111. {Basic Socket Functions}
  112. Function Socket(Domain,SocketType,Protocol:Longint):Longint;
  113. Function Send(Sock:Longint;Const Buf;BufLen,Flags:Longint):Longint;
  114. Function Recv(Sock:Longint;Var Buf;BufLen,Flags:Longint):Longint;
  115. Function Bind(Sock:Longint;Const Addr;AddrLen:Longint):Boolean;
  116. Function Listen (Sock,MaxConnect:Longint):Boolean;
  117. Function Accept(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;
  118. Function Connect(Sock:Longint;Const Addr;Addrlen:Longint):boolean;
  119. Function Shutdown(Sock:Longint;How:Longint):Longint;
  120. Function GetSocketName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;
  121. Function GetPeerName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;
  122. Function SetSocketOptions(Sock,Level,OptName:Longint;Const OptVal;optlen:longint):Longint;
  123. Function GetSocketOptions(Sock,Level,OptName:Longint;Var OptVal;Var optlen:longint):Longint;
  124. Function SocketPair(Domain,SocketType,Protocol:Longint;var Pair:TSockArray):Longint;
  125. {Text Support}
  126. Procedure Sock2Text(Sock:Longint;Var SockIn,SockOut:Text);
  127. {Untyped File Support}
  128. Procedure Sock2File(Sock:Longint;Var SockIn,SockOut:File);
  129. {Better Pascal Calling, Overloaded Functions!}
  130. Function Accept(Sock:longint;var addr:TInetSockAddr;var SockIn,SockOut:File):Boolean;
  131. Function Accept(Sock:longint;var addr:TInetSockAddr;var SockIn,SockOut:text):Boolean;
  132. Function Connect(Sock:longint;const addr:TInetSockAddr;var SockIn,SockOut:text):Boolean;
  133. Function Connect(Sock:longint;const addr:TInetSockAddr;var SockIn,SockOut:file):Boolean;
  134. {
  135. $Log$
  136. Revision 1.6 2001-06-06 21:58:24 peter
  137. * Win32 fixes for Makefile so it doesn't require sh.exe
  138. Revision 1.5 2001/06/04 11:43:51 peter
  139. * Formal const to var fixes
  140. * Hexstr(int64) added
  141. Revision 1.4 2000/11/13 13:40:04 marco
  142. * Renamefest
  143. Revision 1.3 2000/09/11 14:53:14 marco
  144. * FreeBSD adjustments patched in from fixes branch
  145. Revision 1.1.2.1 2000/09/10 16:12:05 marco
  146. BSD SO_ constants added
  147. Revision 1.1 2000/07/13 06:30:48 michael
  148. + Initial import
  149. Revision 1.7 2000/06/19 13:31:46 michael
  150. + Corrected GetSocketOptions
  151. Revision 1.6 2000/06/02 17:30:43 marco
  152. * added some constants for getsocketoptions under a linux define.
  153. Allows server example to work ok.
  154. Revision 1.5 2000/02/09 16:59:31 peter
  155. * truncated log
  156. Revision 1.4 2000/01/07 16:41:36 daniel
  157. * copyright 2000
  158. Revision 1.3 2000/01/07 16:32:25 daniel
  159. * copyright 2000 added
  160. }