sockets.pp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. unit Sockets;
  11. Interface
  12. {$ifdef Unix}
  13. Uses UnixType;
  14. {$endif}
  15. {$ifdef FreeBSD}
  16. {$DEFINE SOCK_HAS_SINLEN} // BSD definition of scoketaddr
  17. {$endif}
  18. {$ifdef Darwin}
  19. {$DEFINE SOCK_HAS_SINLEN} // BSD definition of scoketaddr
  20. {$endif}
  21. {$i unxsockh.inc}
  22. {$i socketsh.inc}
  23. type
  24. TUnixSockAddr = packed Record
  25. {$ifdef SOCK_HAS_SINLEN}
  26. sa_len : cuchar;
  27. {$endif}
  28. family : sa_family_t;
  29. path:array[0..107] of char; //104 total for freebsd.
  30. end;
  31. { unix socket specific functions }
  32. Procedure Str2UnixSockAddr(const addr:string;var t:TUnixSockAddr;var len:longint);
  33. Function Bind(Sock:longint;const addr:string):boolean;
  34. Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:text):Boolean;
  35. Function Connect(Sock:longint;const addr:string;var SockIn,SockOut:file):Boolean;
  36. Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:text):Boolean;
  37. Function Accept(Sock:longint;var addr:string;var SockIn,SockOut:File):Boolean;
  38. //function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint; maybelibc
  39. //function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint; maybelibc
  40. //function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint; maybelibc
  41. Implementation
  42. Uses BaseUnix,{$ifndef FPC_USE_LIBC}SysCall{$else}initc{$endif};
  43. { Include filerec and textrec structures }
  44. {$i filerec.inc}
  45. {$i textrec.inc}
  46. {******************************************************************************
  47. Kernel Socket Callings
  48. ******************************************************************************}
  49. {$ifndef FPC_USE_LIBC}
  50. {$i unixsock.inc}
  51. {$else}
  52. {$i stdsock.inc}
  53. {$endif}
  54. {$i sockovl.inc}
  55. {$i sockets.inc}
  56. end.