socket.inc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. (*
  2. $Id$
  3. ------------------------------------------------------------------------------
  4. DSWifi Project - socket emulation layer defines/prototypes (sys/socket.h)
  5. (C) 2005-2006 Stephen Stair - [email protected] - http://www.akkit.org
  6. ******************************************************************************
  7. DSWifi Lib and test materials are licenced under the MIT open source licence:
  8. Copyright (c) 2005-2006 Stephen Stair
  9. Permission is hereby granted, free of charge, to any person obtaining a copy of
  10. this software and associated documentation files (the "Software"), to deal in
  11. the Software without restriction, including without limitation the rights to
  12. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  13. of the Software, and to permit persons to whom the Software is furnished to do
  14. so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in all
  16. copies or substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. SOFTWARE.
  24. ******************************************************************************
  25. Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
  26. (http://www.freepascal.org)
  27. Copyright (C) 2006 Francesco Lombardi
  28. Check http://sourceforge.net/projects/libndsfpc for updates
  29. ------------------------------------------------------------------------------
  30. Comments:
  31. *)
  32. {$ifdef NDS_INTERFACE}
  33. const
  34. //#include <sys/time.h>
  35. SOL_SOCKET = $fff; (* options for socket level *)
  36. SOL_TCP = 6; (* TCP level *)
  37. PF_UNSPEC = 0;
  38. PF_INET = 2;
  39. PF_INET6 = 10;
  40. AF_UNSPEC = PF_UNSPEC;
  41. AF_INET = PF_INET;
  42. AF_INET6 = PF_INET6;
  43. SOCK_STREAM = 1;
  44. SOCK_DGRAM = 2;
  45. // need to sync FIO* values with commonly accepted ones sometime
  46. FIONBIO = 1;
  47. FIONREAD = 2;
  48. SOCKET_ERROR = -1;
  49. // send()/recv()/etc flags
  50. // at present, only MSG_PEEK is implemented though.
  51. MSG_WAITALL = $40000000;
  52. MSG_TRUNC = $20000000;
  53. MSG_PEEK = $10000000;
  54. MSG_OOB = $08000000;
  55. MSG_EOR = $04000000;
  56. MSG_DONTROUTE = $02000000;
  57. MSG_CTRUNC = $01000000;
  58. // shutdown() flags:
  59. SHUT_RD = 1;
  60. SHUT_WR = 2;
  61. SHUT_RDWR = 3;
  62. SO_DEBUG = $0001; (* turn on debugging info recording *)
  63. SO_ACCEPTCONN = $0002; (* socket has had listen() *)
  64. SO_REUSEADDR = $0004; (* allow local address reuse *)
  65. SO_KEEPALIVE = $0008; (* keep connections alive *)
  66. SO_DONTROUTE = $0010; (* just use interface addresses *)
  67. SO_BROADCAST = $0020; (* permit sending of broadcast msgs *)
  68. SO_USELOOPBACK = $0040; (* bypass hardware when possible *)
  69. SO_LINGER = $0080; (* linger on close if data present *)
  70. SO_OOBINLINE = $0100; (* leave received OOB data in line *)
  71. SO_REUSEPORT = $0200; (* allow local address & port reuse *)
  72. SO_DONTLINGER = not SO_LINGER;
  73. SO_SNDBUF = $1001; (* send buffer size *)
  74. SO_RCVBUF = $1002; (* receive buffer size *)
  75. SO_SNDLOWAT = $1003; (* send low-water mark *)
  76. SO_RCVLOWAT = $1004; (* receive low-water mark *)
  77. SO_SNDTIMEO = $1005; (* send timeout *)
  78. SO_RCVTIMEO = $1006; (* receive timeout *)
  79. SO_ERROR = $1007; (* get error status and clear *)
  80. SO_TYPE = $1008; (* get socket type *)
  81. type
  82. sockaddr = record
  83. _sa_family: cushort;
  84. sa_data: array [0..13] of AnsiChar;
  85. end;
  86. psockaddr = ^sockaddr;
  87. function socket(domain, _type, protocol: cint): cint; cdecl; external;
  88. function bind(socket: cint; {const} addr: psockaddr; addr_len: cint): cint; cdecl; external;
  89. function connect(socket: cint; {const} addr: psockaddr; addr_len: cint): cint; cdecl; external;
  90. function send(socket: cint; {const} data: pointer; sendlength, flags: cint): cint; cdecl; external;
  91. function recv(socket: cint; data: pointer; recvlength, flags: cint): cint; cdecl; external;
  92. function sendto(socket: cint; {const} data: pointer; sendlength, flags: cint; const addr: psockaddr; addr_len: cint): cint; cdecl; external;
  93. function recvfrom(socket: cint; data: pointer; recvlength, flags: cint; addr: psockaddr; addr_len: pcint): cint; cdecl; external;
  94. function listen(socket, max_connections: cint): cint; cdecl; external;
  95. function accept(socket: cint; addr: psockaddr; addr_len: pcint): cint; cdecl; external;
  96. function shutdown(socket, shutdown_type: cint): cint; cdecl; external;
  97. function closesocket(socket: cint): cint; cdecl; external;
  98. function ioctl(socket: cint; cmd: clong; arg: pointer): cint; cdecl; external;
  99. function setsockopt(socket, level, option_name: cint; const data: pointer; data_len: cint): cint; cdecl; external;
  100. function getsockopt(socket, level, option_name: cint; data: pointer; data_len: pcint): cint; cdecl; external;
  101. function getpeername(socket: cint; addr: psockaddr; addr_len: pcint): cint; cdecl; external;
  102. function getsockname(socket: cint; addr: psockaddr; addr_len: pcint): cint; cdecl; external;
  103. function gethostname(name: pcchar; {size_t} len: cuint): cint; cdecl; external;
  104. function sethostname(const name: pcchar; {size_t} len: cuint): cint; cdecl; external;
  105. function htons(num: cushort): cushort; cdecl; external;
  106. function htonl(num: culong): culong; cdecl; external;
  107. function ntohs(num: cushort): cushort; inline;
  108. function ntohl(num: culong): culong; inline;
  109. type
  110. fd_set = array [0..7] of clong;
  111. pfd_set = ^fd_set;
  112. timeval = packed record
  113. sec: clong;
  114. usec: clong;
  115. end;
  116. ptimeval = ^timeval;
  117. function select(nfds: cint; readfds, writefds, errorfds: pfd_set; timeout: ptimeval): cint; cdecl; external;
  118. {$endif NDS_INTERFACE}
  119. {$ifdef NDS_IMPLEMENTATION}
  120. function ntohs(num: cushort): cushort; inline;
  121. begin
  122. ntohs := htons(num);
  123. end;
  124. function ntohl(num: culong): culong; inline;
  125. begin
  126. ntohl := htonl(num);
  127. end;
  128. {$endif NDS_IMPLEMENTATION}