socketsh.inc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 linux}
  26. { For setsockoptions(2) }
  27. SOL_SOCKET = 1;
  28. SO_DEBUG = 1;
  29. SO_REUSEADDR= 2;
  30. SO_TYPE = 3;
  31. SO_ERROR = 4;
  32. SO_DONTROUTE= 5;
  33. SO_BROADCAST= 6;
  34. SO_SNDBUF = 7;
  35. SO_RCVBUF = 8;
  36. SO_KEEPALIVE= 9;
  37. SO_OOBINLINE= 10;
  38. SO_NO_CHECK = 11;
  39. SO_PRIORITY = 12;
  40. SO_LINGER = 13;
  41. SO_BSDCOMPAT= 14;
  42. { To add : SO_REUSEPORT 15 }
  43. SO_PASSCRED= 16;
  44. SO_PEERCRED= 17;
  45. SO_RCVLOWAT= 18;
  46. SO_SNDLOWAT= 19;
  47. SO_RCVTIMEO= 20;
  48. SO_SNDTIMEO= 21;
  49. { Security levels - as per NRL IPv6 - don't actually do anything }
  50. SO_SECURITY_AUTHENTICATION = 22;
  51. SO_SECURITY_ENCRYPTION_TRANSPORT= 23;
  52. SO_SECURITY_ENCRYPTION_NETWORK = 24;
  53. SO_BINDTODEVICE= 25;
  54. { Socket filtering }
  55. SO_ATTACH_FILTER= 26;
  56. SO_DETACH_FILTER= 27;
  57. SO_PEERNAME = 28;
  58. {$endif}
  59. const
  60. { Two constants to determine whether part of soket is for in or output }
  61. S_IN = 0;
  62. S_OUT = 1;
  63. Type
  64. TSockAddr = packed Record
  65. family:word; { was byte, fixed }
  66. data :array [0..13] of char;
  67. end;
  68. TInetSockAddr = packed Record
  69. family:Word;
  70. port :Word;
  71. addr :Cardinal;
  72. pad :array [1..8] of byte; { to get to the size of sockaddr... }
  73. end;
  74. TSockArray = Array[1..2] of Longint;
  75. Var
  76. SocketError:Longint;
  77. {Basic Socket Functions}
  78. Function Socket(Domain,SocketType,Protocol:Longint):Longint;
  79. Function Send(Sock:Longint;Var Addr;AddrLen,Flags:Longint):Longint;
  80. Function Recv(Sock:Longint;Var Addr;AddrLen,Flags:Longint):Longint;
  81. Function Bind(Sock:Longint;Var Addr;AddrLen:Longint):Boolean;
  82. Function Listen (Sock,MaxConnect:Longint):Boolean;
  83. Function Accept(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;
  84. Function Connect(Sock:Longint;Var Addr;Addrlen:Longint):boolean;
  85. Function Shutdown(Sock:Longint;How:Longint):Longint;
  86. Function GetSocketName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;
  87. Function GetPeerName(Sock:Longint;Var Addr;Var Addrlen:Longint):Longint;
  88. Function SetSocketOptions(Sock,Level,OptName:Longint;Var OptVal;optlen:longint):Longint;
  89. Function GetSocketOptions(Sock,Level,OptName:Longint;Var OptVal;optlen:longint):Longint;
  90. Function SocketPair(Domain,SocketType,Protocol:Longint;var Pair:TSockArray):Longint;
  91. {Text Support}
  92. Procedure Sock2Text(Sock:Longint;Var SockIn,SockOut:Text);
  93. {Untyped File Support}
  94. Procedure Sock2File(Sock:Longint;Var SockIn,SockOut:File);
  95. {Better Pascal Calling, Overloaded Functions!}
  96. Function Accept(Sock:longint;var addr:TInetSockAddr;var SockIn,SockOut:File):Boolean;
  97. Function Accept(Sock:longint;var addr:TInetSockAddr;var SockIn,SockOut:text):Boolean;
  98. Function Connect(Sock:longint;const addr:TInetSockAddr;var SockIn,SockOut:text):Boolean;
  99. Function Connect(Sock:longint;const addr:TInetSockAddr;var SockIn,SockOut:file):Boolean;
  100. {
  101. $Log$
  102. Revision 1.6 2000-06-02 17:30:43 marco
  103. * added some constants for getsocketoptions under a linux define.
  104. Allows server example to work ok.
  105. Revision 1.5 2000/02/09 16:59:31 peter
  106. * truncated log
  107. Revision 1.4 2000/01/07 16:41:36 daniel
  108. * copyright 2000
  109. Revision 1.3 2000/01/07 16:32:25 daniel
  110. * copyright 2000 added
  111. }