/libc/include/sys/socket.h

https://gitlab.com/abidin24/sortix · C Header · 189 lines · 133 code · 30 blank · 26 comment · 0 complexity · 06d97187debd823485a27305c932a9d0 MD5 · raw file

  1. /*
  2. * Copyright (c) 2013, 2014 Jonas 'Sortie' Termansen.
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. *
  16. * sys/socket.h
  17. * Main sockets header.
  18. */
  19. #ifndef _SYS_SOCKET_H
  20. #define _SYS_SOCKET_H 1
  21. #include <sys/cdefs.h>
  22. #include <sys/__/types.h>
  23. #include <sortix/socket.h>
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #ifndef __socklen_t_defined
  28. #define __socklen_t_defined
  29. typedef __socklen_t socklen_t;
  30. #endif
  31. #ifndef __size_t_defined
  32. #define __size_t_defined
  33. #define __need_size_t
  34. #include <stddef.h>
  35. #endif
  36. #ifndef __ssize_t_defined
  37. #define __ssize_t_defined
  38. typedef __ssize_t ssize_t;
  39. #endif
  40. #ifndef __sa_family_t_defined
  41. #define __sa_family_t_defined
  42. typedef unsigned short int sa_family_t;
  43. #endif
  44. #ifdef __cplusplus
  45. } /* extern "C" */
  46. #endif
  47. #include <sortix/uio.h>
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. struct sockaddr
  52. {
  53. sa_family_t sa_family;
  54. char sa_data[16 - sizeof(sa_family_t)];
  55. };
  56. #define __ss_aligntype unsigned long int
  57. #define _SS_SIZE 128
  58. #define _SS_PADSIZE (_SS_SIZE - (2 * sizeof (__ss_aligntype)))
  59. struct sockaddr_storage
  60. {
  61. sa_family_t ss_family;
  62. __ss_aligntype __ss_align;
  63. char __ss_padding[_SS_PADSIZE];
  64. };
  65. struct msghdr
  66. {
  67. void* msg_name;
  68. socklen_t msg_namelen;
  69. struct iovec* msg_iov;
  70. int msg_iovlen;
  71. void* msg_control;
  72. socklen_t msg_controllen;
  73. int msg_flags;
  74. };
  75. struct cmsghdr
  76. {
  77. socklen_t cmsg_len;
  78. int cmsg_level;
  79. int cmsg_type;
  80. };
  81. #define SCM_RIGHTS 1
  82. /* TODO: CMSG_DATA(cmsg) */
  83. /* TODO: CMSG_NXTHDR(cmsg) */
  84. /* TODO: CMSH_FIRSTHDR(cmsg) */
  85. struct linger
  86. {
  87. int l_onoff;
  88. int l_linger;
  89. };
  90. #define SOL_SOCKET 0
  91. /* #define IPPROTO_* constants follow numerically. */
  92. /* Options at the SOL_SOCKET socket level. */
  93. #define SO_ACCEPTCONN 1
  94. #define SO_BROADCAST 2
  95. #define SO_DEBUG 3
  96. #define SO_DONTROUTE 4
  97. #define SO_ERROR 5
  98. #define SO_KEEPALIVE 6
  99. #define SO_LINGER 7
  100. #define SO_OOBINLINE 8
  101. #define SO_RCVBUF 9
  102. #define SO_RCVLOWAT 10
  103. #define SO_RCVTIMEO 11
  104. #define SO_REUSEADDR 12
  105. #define SO_SNDBUF 13
  106. #define SO_SNDLOWAT 14
  107. #define SO_SNDTIMEO 15
  108. #define SO_TYPE 16
  109. #define SOMAXCONN 5
  110. #define MSG_CTRUNC (1<<0)
  111. #define MSG_DONTROUTE (1<<1)
  112. #define MSG_EOR (1<<2)
  113. #define MSG_OOB (1<<3)
  114. #define MSG_NOSIGNAL (1<<4)
  115. #define MSG_PEEK (1<<5)
  116. #define MSG_TRUNC (1<<6)
  117. #define MSG_WAITALL (1<<7)
  118. #define MSG_DONTWAIT (1<<8)
  119. #define MSG_CMSG_CLOEXEC (1<<9)
  120. #define AF_UNSPEC 0
  121. #define AF_INET 1
  122. #define AF_INET6 2
  123. #define AF_UNIX 3
  124. /* TODO: POSIX doesn't specifiy these and it is a bit of a BSD-ism, but they
  125. appear to be used in some software (such as GNU wget). */
  126. #define PF_UNSPEC AF_UNSPEC
  127. #define PF_INET AF_INET
  128. #define PF_INET6 AF_INET6
  129. #define PF_UNIX AF_UNIX
  130. #define AF_LOCAL AF_UNIX
  131. #define PF_LOCAL PF_UNIX
  132. /* TODO: Nicely wrap this in an enum, as in glibc's header? */
  133. #define SHUT_RD (1 << 0)
  134. #define SHUT_WR (1 << 1)
  135. #define SHUT_RDWR (SHUT_RD | SHUT_WR)
  136. int accept4(int, struct sockaddr* __restrict, socklen_t* __restrict, int);
  137. int accept(int, struct sockaddr* __restrict, socklen_t* __restrict);
  138. int bind(int, const struct sockaddr*, socklen_t);
  139. int connect(int, const struct sockaddr*, socklen_t);
  140. int getpeername(int, struct sockaddr* __restrict, socklen_t* __restrict);
  141. int getsockname(int, struct sockaddr* __restrict, socklen_t* __restrict);
  142. int getsockopt(int, int, int, void* __restrict, socklen_t* __restrict);
  143. int listen(int, int);
  144. ssize_t recv(int, void*, size_t, int);
  145. ssize_t recvfrom(int, void* __restrict, size_t, int,
  146. struct sockaddr* __restrict, socklen_t* __restrict);
  147. ssize_t recvmsg(int, struct msghdr*, int);
  148. ssize_t send(int, const void*, size_t, int);
  149. ssize_t sendmsg(int, const struct msghdr*, int);
  150. ssize_t sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t);
  151. int setsockopt(int, int, int, const void*, socklen_t);
  152. int shutdown(int, int);
  153. int sockatmark(int);
  154. int socket(int, int, int);
  155. int socketpair(int, int, int, int[2]);
  156. #ifdef __cplusplus
  157. } /* extern "C" */
  158. #endif
  159. #endif