Blame socket/sys/socket.h

Packit 6c4009
/* Declarations of socket constants, types, and functions.
Packit 6c4009
   Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef	_SYS_SOCKET_H
Packit 6c4009
#define	_SYS_SOCKET_H	1
Packit 6c4009
Packit 6c4009
#include <features.h>
Packit 6c4009
Packit 6c4009
__BEGIN_DECLS
Packit 6c4009
Packit 6c4009
#include <bits/types/struct_iovec.h>
Packit 6c4009
#define	__need_size_t
Packit 6c4009
#include <stddef.h>
Packit 6c4009
Packit 6c4009
/* This operating system-specific header file defines the SOCK_*, PF_*,
Packit 6c4009
   AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr',
Packit 6c4009
   `struct msghdr', and `struct linger' types.  */
Packit 6c4009
#include <bits/socket.h>
Packit 6c4009
Packit 6c4009
#ifdef __USE_MISC
Packit 6c4009
# include <bits/types/struct_osockaddr.h>
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* The following constants should be used for the second parameter of
Packit 6c4009
   `shutdown'.  */
Packit 6c4009
enum
Packit 6c4009
{
Packit 6c4009
  SHUT_RD = 0,		/* No more receptions.  */
Packit 6c4009
#define SHUT_RD		SHUT_RD
Packit 6c4009
  SHUT_WR,		/* No more transmissions.  */
Packit 6c4009
#define SHUT_WR		SHUT_WR
Packit 6c4009
  SHUT_RDWR		/* No more receptions or transmissions.  */
Packit 6c4009
#define SHUT_RDWR	SHUT_RDWR
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* This is the type we use for generic socket address arguments.
Packit 6c4009
Packit 6c4009
   With GCC 2.7 and later, the funky union causes redeclarations or
Packit 6c4009
   uses with any of the listed types to be allowed without complaint.
Packit 6c4009
   G++ 2.7 does not support transparent unions so there we want the
Packit 6c4009
   old-style declaration, too.  */
Packit 6c4009
#if defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU
Packit 6c4009
# define __SOCKADDR_ARG		struct sockaddr *__restrict
Packit 6c4009
# define __CONST_SOCKADDR_ARG	const struct sockaddr *
Packit 6c4009
#else
Packit 6c4009
/* Add more `struct sockaddr_AF' types here as necessary.
Packit 6c4009
   These are all the ones I found on NetBSD and Linux.  */
Packit 6c4009
# define __SOCKADDR_ALLTYPES \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_at) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_ax25) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_dl) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_eon) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_in) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_in6) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_inarp) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_ipx) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_iso) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_ns) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_un) \
Packit 6c4009
  __SOCKADDR_ONETYPE (sockaddr_x25)
Packit 6c4009
Packit 6c4009
# define __SOCKADDR_ONETYPE(type) struct type *__restrict __##type##__;
Packit 6c4009
typedef union { __SOCKADDR_ALLTYPES
Packit 6c4009
	      } __SOCKADDR_ARG __attribute__ ((__transparent_union__));
Packit 6c4009
# undef __SOCKADDR_ONETYPE
Packit 6c4009
# define __SOCKADDR_ONETYPE(type) const struct type *__restrict __##type##__;
Packit 6c4009
typedef union { __SOCKADDR_ALLTYPES
Packit 6c4009
	      } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
Packit 6c4009
# undef __SOCKADDR_ONETYPE
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#ifdef __USE_GNU
Packit 6c4009
/* For `recvmmsg' and `sendmmsg'.  */
Packit 6c4009
struct mmsghdr
Packit 6c4009
  {
Packit 6c4009
    struct msghdr msg_hdr;	/* Actual message header.  */
Packit 6c4009
    unsigned int msg_len;	/* Number of received or sent bytes for the
Packit 6c4009
				   entry.  */
Packit 6c4009
  };
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Create a new socket of type TYPE in domain DOMAIN, using
Packit 6c4009
   protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
Packit 6c4009
   Returns a file descriptor for the new socket, or -1 for errors.  */
Packit 6c4009
extern int socket (int __domain, int __type, int __protocol) __THROW;
Packit 6c4009
Packit 6c4009
/* Create two new sockets, of type TYPE in domain DOMAIN and using
Packit 6c4009
   protocol PROTOCOL, which are connected to each other, and put file
Packit 6c4009
   descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
Packit 6c4009
   one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
Packit 6c4009
extern int socketpair (int __domain, int __type, int __protocol,
Packit 6c4009
		       int __fds[2]) __THROW;
Packit 6c4009
Packit 6c4009
/* Give the socket FD the local address ADDR (which is LEN bytes long).  */
Packit 6c4009
extern int bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
Packit 6c4009
     __THROW;
Packit 6c4009
Packit 6c4009
/* Put the local address of FD into *ADDR and its length in *LEN.  */
Packit 6c4009
extern int getsockname (int __fd, __SOCKADDR_ARG __addr,
Packit 6c4009
			socklen_t *__restrict __len) __THROW;
Packit 6c4009
Packit 6c4009
/* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
Packit 6c4009
   For connectionless socket types, just set the default address to send to
Packit 6c4009
   and the only address from which to accept transmissions.
Packit 6c4009
   Return 0 on success, -1 for errors.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
extern int connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
Packit 6c4009
Packit 6c4009
/* Put the address of the peer connected to socket FD into *ADDR
Packit 6c4009
   (which is *LEN bytes long), and its actual length into *LEN.  */
Packit 6c4009
extern int getpeername (int __fd, __SOCKADDR_ARG __addr,
Packit 6c4009
			socklen_t *__restrict __len) __THROW;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Send N bytes of BUF to socket FD.  Returns the number sent or -1.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
extern ssize_t send (int __fd, const void *__buf, size_t __n, int __flags);
Packit 6c4009
Packit 6c4009
/* Read N bytes into BUF from socket FD.
Packit 6c4009
   Returns the number read or -1 for errors.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
extern ssize_t recv (int __fd, void *__buf, size_t __n, int __flags);
Packit 6c4009
Packit 6c4009
/* Send N bytes of BUF on socket FD to peer at address ADDR (which is
Packit 6c4009
   ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
extern ssize_t sendto (int __fd, const void *__buf, size_t __n,
Packit 6c4009
		       int __flags, __CONST_SOCKADDR_ARG __addr,
Packit 6c4009
		       socklen_t __addr_len);
Packit 6c4009
Packit 6c4009
/* Read N bytes into BUF through socket FD.
Packit 6c4009
   If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
Packit 6c4009
   the sender, and store the actual size of the address in *ADDR_LEN.
Packit 6c4009
   Returns the number of bytes read or -1 for errors.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
extern ssize_t recvfrom (int __fd, void *__restrict __buf, size_t __n,
Packit 6c4009
			 int __flags, __SOCKADDR_ARG __addr,
Packit 6c4009
			 socklen_t *__restrict __addr_len);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Send a message described MESSAGE on socket FD.
Packit 6c4009
   Returns the number of bytes sent, or -1 for errors.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
extern ssize_t sendmsg (int __fd, const struct msghdr *__message,
Packit 6c4009
			int __flags);
Packit 6c4009
Packit 6c4009
#ifdef __USE_GNU
Packit 6c4009
/* Send a VLEN messages as described by VMESSAGES to socket FD.
Packit 6c4009
   Returns the number of datagrams successfully written or -1 for errors.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
extern int sendmmsg (int __fd, struct mmsghdr *__vmessages,
Packit 6c4009
		     unsigned int __vlen, int __flags);
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Receive a message as described by MESSAGE from socket FD.
Packit 6c4009
   Returns the number of bytes read or -1 for errors.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
extern ssize_t recvmsg (int __fd, struct msghdr *__message, int __flags);
Packit 6c4009
Packit 6c4009
#ifdef __USE_GNU
Packit 6c4009
/* Receive up to VLEN messages as described by VMESSAGES from socket FD.
Packit 6c4009
   Returns the number of messages received or -1 for errors.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
extern int recvmmsg (int __fd, struct mmsghdr *__vmessages,
Packit 6c4009
		     unsigned int __vlen, int __flags,
Packit 6c4009
		     struct timespec *__tmo);
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
Packit 6c4009
   into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
Packit 6c4009
   actual length.  Returns 0 on success, -1 for errors.  */
Packit 6c4009
extern int getsockopt (int __fd, int __level, int __optname,
Packit 6c4009
		       void *__restrict __optval,
Packit 6c4009
		       socklen_t *__restrict __optlen) __THROW;
Packit 6c4009
Packit 6c4009
/* Set socket FD's option OPTNAME at protocol level LEVEL
Packit 6c4009
   to *OPTVAL (which is OPTLEN bytes long).
Packit 6c4009
   Returns 0 on success, -1 for errors.  */
Packit 6c4009
extern int setsockopt (int __fd, int __level, int __optname,
Packit 6c4009
		       const void *__optval, socklen_t __optlen) __THROW;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Prepare to accept connections on socket FD.
Packit 6c4009
   N connection requests will be queued before further requests are refused.
Packit 6c4009
   Returns 0 on success, -1 for errors.  */
Packit 6c4009
extern int listen (int __fd, int __n) __THROW;
Packit 6c4009
Packit 6c4009
/* Await a connection on socket FD.
Packit 6c4009
   When a connection arrives, open a new socket to communicate with it,
Packit 6c4009
   set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
Packit 6c4009
   peer and *ADDR_LEN to the address's actual length, and return the
Packit 6c4009
   new socket's descriptor, or -1 for errors.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
extern int accept (int __fd, __SOCKADDR_ARG __addr,
Packit 6c4009
		   socklen_t *__restrict __addr_len);
Packit 6c4009
Packit 6c4009
#ifdef __USE_GNU
Packit 6c4009
/* Similar to 'accept' but takes an additional parameter to specify flags.
Packit 6c4009
Packit 6c4009
   This function is a cancellation point and therefore not marked with
Packit 6c4009
   __THROW.  */
Packit 6c4009
extern int accept4 (int __fd, __SOCKADDR_ARG __addr,
Packit 6c4009
		    socklen_t *__restrict __addr_len, int __flags);
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Shut down all or part of the connection open on socket FD.
Packit 6c4009
   HOW determines what to shut down:
Packit 6c4009
     SHUT_RD   = No more receptions;
Packit 6c4009
     SHUT_WR   = No more transmissions;
Packit 6c4009
     SHUT_RDWR = No more receptions or transmissions.
Packit 6c4009
   Returns 0 on success, -1 for errors.  */
Packit 6c4009
extern int shutdown (int __fd, int __how) __THROW;
Packit 6c4009
Packit 6c4009
Packit 6c4009
#ifdef __USE_XOPEN2K
Packit 6c4009
/* Determine wheter socket is at a out-of-band mark.  */
Packit 6c4009
extern int sockatmark (int __fd) __THROW;
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
#ifdef __USE_MISC
Packit 6c4009
/* FDTYPE is S_IFSOCK or another S_IF* macro defined in <sys/stat.h>;
Packit 6c4009
   returns 1 if FD is open on an object of the indicated type, 0 if not,
Packit 6c4009
   or -1 for errors (setting errno).  */
Packit 6c4009
extern int isfdtype (int __fd, int __fdtype) __THROW;
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Define some macros helping to catch buffer overflows.  */
Packit 6c4009
#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
Packit 6c4009
# include <bits/socket2.h>
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
__END_DECLS
Packit 6c4009
Packit 6c4009
#endif /* sys/socket.h */