home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !unixlib / source / clib / sys / h / socket < prev    next >
Encoding:
Text File  |  2004-09-05  |  10.6 KB  |  273 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/sys/socket.h,v $
  4.  * $Date: 2004/01/14 23:16:58 $
  5.  * $Revision: 1.7 $
  6.  * $State: Exp $
  7.  * $Author: joty $
  8.  *
  9.  ***************************************************************************/
  10.  
  11. /*
  12.  * File taken from glibc 2.2.5.
  13.  * Following changes were made:
  14.  *  - Changed "#include <features.h>" into "#include <unixlib/features.h>"
  15.  *  - Added __opensock() internal function definition.
  16.  *  - Added the prototypes for the SWI veneers.
  17.  *  - Added SOMAXCONN constant.
  18.  */
  19.  
  20. /* Declarations of socket constants, types, and functions.
  21.    Copyright (C) 1991,92,1994-1999,2000,2001 Free Software Foundation, Inc.
  22.    This file is part of the GNU C Library.
  23.  
  24.    The GNU C Library is free software; you can redistribute it and/or
  25.    modify it under the terms of the GNU Lesser General Public
  26.    License as published by the Free Software Foundation; either
  27.    version 2.1 of the License, or (at your option) any later version.
  28.  
  29.    The GNU C Library is distributed in the hope that it will be useful,
  30.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  31.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  32.    Lesser General Public License for more details.
  33.  
  34.    You should have received a copy of the GNU Lesser General Public
  35.    License along with the GNU C Library; if not, write to the Free
  36.    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  37.    02111-1307 USA.  */
  38.  
  39. #ifndef    __SYS_SOCKET_H
  40. #define    __SYS_SOCKET_H    1
  41.  
  42. #include <unixlib/features.h>
  43.  
  44. __BEGIN_DECLS
  45.  
  46. #include <sys/uio.h>
  47. #define    __need_size_t
  48. #include <stddef.h>
  49.  
  50.  
  51. /* This operating system-specific header file defines the SOCK_*, PF_*,
  52.    AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr',
  53.    `struct msghdr', and `struct linger' types.  */
  54. #include <bits/socket.h>
  55.  
  56. #ifdef __USE_BSD
  57. /* This is the 4.3 BSD `struct sockaddr' format, which is used as wire
  58.    format in the grotty old 4.3 `talk' protocol.  */
  59. struct osockaddr
  60.   {
  61.     unsigned short int sa_family;
  62.     unsigned char sa_data[14];
  63.   };
  64. #endif
  65.  
  66. /* Maximum queue length for listen() calls.  */
  67. #define SOMAXCONN   128
  68.  
  69. /* The following constants should be used for the second parameter of
  70.    `shutdown'.  */
  71. enum
  72. {
  73.   SHUT_RD = 0,        /* No more receptions.  */
  74. #define SHUT_RD        SHUT_RD
  75.   SHUT_WR,        /* No more transmissions.  */
  76. #define SHUT_WR        SHUT_WR
  77.   SHUT_RDWR        /* No more receptions or transmissions.  */
  78. #define SHUT_RDWR    SHUT_RDWR
  79. };
  80.  
  81. /* This is the type we use for generic socket address arguments.
  82.  
  83.    With GCC 2.7 and later, the funky union causes redeclarations or
  84.    uses with any of the listed types to be allowed without complaint.
  85.    G++ 2.7 does not support transparent unions so there we want the
  86.    old-style declaration, too.  */
  87. #if defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU
  88. # define __SOCKADDR_ARG        struct sockaddr *__restrict
  89. # define __CONST_SOCKADDR_ARG    __const struct sockaddr *
  90. #else
  91. /* Add more `struct sockaddr_AF' types here as necessary.
  92.    These are all the ones I found on NetBSD and Linux.  */
  93. # define __SOCKADDR_ALLTYPES \
  94.   __SOCKADDR_ONETYPE (sockaddr) \
  95.   __SOCKADDR_ONETYPE (sockaddr_at) \
  96.   __SOCKADDR_ONETYPE (sockaddr_ax25) \
  97.   __SOCKADDR_ONETYPE (sockaddr_dl) \
  98.   __SOCKADDR_ONETYPE (sockaddr_eon) \
  99.   __SOCKADDR_ONETYPE (sockaddr_in) \
  100.   __SOCKADDR_ONETYPE (sockaddr_in6) \
  101.   __SOCKADDR_ONETYPE (sockaddr_inarp) \
  102.   __SOCKADDR_ONETYPE (sockaddr_ipx) \
  103.   __SOCKADDR_ONETYPE (sockaddr_iso) \
  104.   __SOCKADDR_ONETYPE (sockaddr_ns) \
  105.   __SOCKADDR_ONETYPE (sockaddr_un) \
  106.   __SOCKADDR_ONETYPE (sockaddr_x25)
  107.  
  108. # define __SOCKADDR_ONETYPE(type) struct type *__restrict __##type##__;
  109. typedef union { __SOCKADDR_ALLTYPES
  110.           } __SOCKADDR_ARG __attribute__ ((__transparent_union__));
  111. # undef __SOCKADDR_ONETYPE
  112. # define __SOCKADDR_ONETYPE(type) __const struct type *__restrict __##type##__;
  113. typedef union { __SOCKADDR_ALLTYPES
  114.           } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
  115. # undef __SOCKADDR_ONETYPE
  116. #endif
  117.  
  118.  
  119. /* Create a new socket of type TYPE in domain DOMAIN, using
  120.    protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
  121.    Returns a file descriptor for the new socket, or -1 for errors.  */
  122. extern int socket (int __domain, int __type, int __protocol) __THROW;
  123.  
  124. /* Create two new sockets, of type TYPE in domain DOMAIN and using
  125.    protocol PROTOCOL, which are connected to each other, and put file
  126.    descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
  127.    one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
  128. extern int socketpair (int __domain, int __type, int __protocol,
  129.                int __fds[2]) __THROW;
  130.  
  131. /* Give the socket FD the local address ADDR (which is LEN bytes long).  */
  132. extern int bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
  133.      __THROW;
  134.  
  135. /* Put the local address of FD into *ADDR and its length in *LEN.  */
  136. extern int getsockname (int __fd, __SOCKADDR_ARG __addr,
  137.             socklen_t *__restrict __len) __THROW;
  138.  
  139. /* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
  140.    For connectionless socket types, just set the default address to send to
  141.    and the only address from which to accept transmissions.
  142.    Return 0 on success, -1 for errors.  */
  143. extern int connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
  144.      __THROW;
  145.  
  146. /* Put the address of the peer connected to socket FD into *ADDR
  147.    (which is *LEN bytes long), and its actual length into *LEN.  */
  148. extern int getpeername (int __fd, __SOCKADDR_ARG __addr,
  149.             socklen_t *__restrict __len) __THROW;
  150.  
  151.  
  152. /* Send N bytes of BUF to socket FD.  Returns the number sent or -1.  */
  153. extern ssize_t send (int __fd, __const void *__buf, size_t __n, int __flags)
  154.      __THROW;
  155.  
  156. /* Read N bytes into BUF from socket FD.
  157.    Returns the number read or -1 for errors.  */
  158. extern ssize_t recv (int __fd, void *__buf, size_t __n, int __flags)
  159.      __THROW;
  160.  
  161. /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
  162.    ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.  */
  163. extern ssize_t sendto (int __fd, __const void *__buf, size_t __n,
  164.                int __flags, __CONST_SOCKADDR_ARG __addr,
  165.                socklen_t __addr_len) __THROW;
  166.  
  167. /* Read N bytes into BUF through socket FD.
  168.    If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
  169.    the sender, and store the actual size of the address in *ADDR_LEN.
  170.    Returns the number of bytes read or -1 for errors.  */
  171. extern ssize_t recvfrom (int __fd, void *__restrict __buf, size_t __n, int __flags,
  172.              __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len)
  173.      __THROW;
  174.  
  175.  
  176. /* Send a message described MESSAGE on socket FD.
  177.    Returns the number of bytes sent, or -1 for errors.  */
  178. extern ssize_t sendmsg (int __fd, __const struct msghdr *__message, int __flags)
  179.      __THROW;
  180.  
  181. /* Receive a message as described by MESSAGE from socket FD.
  182.    Returns the number of bytes read or -1 for errors.  */
  183. extern ssize_t recvmsg (int __fd, struct msghdr *__message, int __flags)
  184.      __THROW;
  185.  
  186.  
  187. /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
  188.    into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
  189.    actual length.  Returns 0 on success, -1 for errors.  */
  190. extern int getsockopt (int __fd, int __level, int __optname,
  191.                void *__restrict __optval,
  192.                socklen_t *__restrict __optlen) __THROW;
  193.  
  194. /* Set socket FD's option OPTNAME at protocol level LEVEL
  195.    to *OPTVAL (which is OPTLEN bytes long).
  196.    Returns 0 on success, -1 for errors.  */
  197. extern int setsockopt (int __fd, int __level, int __optname,
  198.                __const void *__optval, socklen_t __optlen) __THROW;
  199.  
  200.  
  201. /* Prepare to accept connections on socket FD.
  202.    N connection requests will be queued before further requests are refused.
  203.    Returns 0 on success, -1 for errors.  */
  204. extern int listen (int __fd, int __n) __THROW;
  205.  
  206. /* Await a connection on socket FD.
  207.    When a connection arrives, open a new socket to communicate with it,
  208.    set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
  209.    peer and *ADDR_LEN to the address's actual length, and return the
  210.    new socket's descriptor, or -1 for errors.  */
  211. extern int accept (int __fd, __SOCKADDR_ARG __addr,
  212.            socklen_t *__restrict __addr_len)
  213.      __THROW;
  214.  
  215. /* Shut down all or part of the connection open on socket FD.
  216.    HOW determines what to shut down:
  217.      SHUT_RD   = No more receptions;
  218.      SHUT_WR   = No more transmissions;
  219.      SHUT_RDWR = No more receptions or transmissions.
  220.    Returns 0 on success, -1 for errors.  */
  221. extern int shutdown (int __fd, int __how) __THROW;
  222.  
  223.  
  224. #ifdef __USE_XOPEN2K
  225. /* Determine wheter socket is at a out-of-band mark.  */
  226. extern int sockatmark (int __fd) __THROW;
  227. #endif
  228.  
  229.  
  230. #ifdef __USE_MISC
  231. /* FDTYPE is S_IFSOCK or another S_IF* macro defined in <sys/stat.h>;
  232.    returns 1 if FD is open on an object of the indicated type, 0 if not,
  233.    or -1 for errors (setting errno).  */
  234. extern int isfdtype (int __fd, int __fdtype) __THROW;
  235. #endif
  236.  
  237. #ifdef __UNIXLIB_INTERNALS
  238. /* Direct SWI veneers: */
  239. extern int _socket (int __domain, int __type, int __protocol);
  240. extern int _bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
  241. extern int _listen (int __fd, int __n);
  242. extern int _accept (int __fd, __SOCKADDR_ARG __addr,
  243.             socklen_t *__restrict __addr_len);
  244. extern int _connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
  245. extern ssize_t _recv (int __fd, void *__buf, size_t __n, int __flags);
  246. extern ssize_t _recvfrom (int __fd, void *__restrict __buf, size_t __n, int __flags,
  247.               __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len);
  248. extern ssize_t _recvmsg (int __fd, struct msghdr *__message, int __flags);
  249. extern ssize_t _send (int __fd, __const void *__buf, size_t __n, int __flags);
  250. extern ssize_t _sendto (int __fd, __const void *__buf, size_t __n,
  251.                 int __flags, __CONST_SOCKADDR_ARG __addr,
  252.                 socklen_t __addr_len);
  253. extern ssize_t _sendmsg (int __fd, __const struct msghdr *__message, int __flags);
  254. extern int _shutdown (int __fd, int __how);
  255. extern int _setsockopt (int __fd, int __level, int __optname,
  256.                 __const void *__optval, socklen_t __optlen);
  257. extern int _getsockopt (int __fd, int __level, int __optname,
  258.                 void *__restrict __optval,
  259.                 socklen_t *__restrict __optlen);
  260. extern int _getsockname (int __fd, __SOCKADDR_ARG __addr,
  261.              socklen_t *__restrict __len);
  262. extern int _getpeername (int __fd, __SOCKADDR_ARG __addr,
  263.              socklen_t *__restrict __len);
  264.  
  265. /* Return a socket of any type.  The socket can be used in subsequent
  266.    ioctl calls to talk to the kernel.  */
  267. extern int __opensock (void) internal_function;
  268. #endif
  269.  
  270. __END_DECLS
  271.  
  272. #endif /* sys/socket.h */
  273.