socket.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) 2019 Linaro Limited
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_
  7. #define ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_
  8. #include <sys/types.h>
  9. #include <net/socket.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. static inline int socket(int family, int type, int proto)
  14. {
  15. return zsock_socket(family, type, proto);
  16. }
  17. static inline int socketpair(int family, int type, int proto, int sv[2])
  18. {
  19. return zsock_socketpair(family, type, proto, sv);
  20. }
  21. #define SHUT_RD ZSOCK_SHUT_RD
  22. #define SHUT_WR ZSOCK_SHUT_WR
  23. #define SHUT_RDWR ZSOCK_SHUT_RDWR
  24. #define MSG_PEEK ZSOCK_MSG_PEEK
  25. #define MSG_TRUNC ZSOCK_MSG_TRUNC
  26. #define MSG_DONTWAIT ZSOCK_MSG_DONTWAIT
  27. #define MSG_WAITALL ZSOCK_MSG_WAITALL
  28. static inline int shutdown(int sock, int how)
  29. {
  30. return zsock_shutdown(sock, how);
  31. }
  32. static inline int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
  33. {
  34. return zsock_bind(sock, addr, addrlen);
  35. }
  36. static inline int connect(int sock, const struct sockaddr *addr,
  37. socklen_t addrlen)
  38. {
  39. return zsock_connect(sock, addr, addrlen);
  40. }
  41. static inline int listen(int sock, int backlog)
  42. {
  43. return zsock_listen(sock, backlog);
  44. }
  45. static inline int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
  46. {
  47. return zsock_accept(sock, addr, addrlen);
  48. }
  49. static inline ssize_t send(int sock, const void *buf, size_t len, int flags)
  50. {
  51. return zsock_send(sock, buf, len, flags);
  52. }
  53. static inline ssize_t recv(int sock, void *buf, size_t max_len, int flags)
  54. {
  55. return zsock_recv(sock, buf, max_len, flags);
  56. }
  57. static inline ssize_t sendto(int sock, const void *buf, size_t len, int flags,
  58. const struct sockaddr *dest_addr,
  59. socklen_t addrlen)
  60. {
  61. return zsock_sendto(sock, buf, len, flags, dest_addr, addrlen);
  62. }
  63. static inline ssize_t sendmsg(int sock, const struct msghdr *message,
  64. int flags)
  65. {
  66. return zsock_sendmsg(sock, message, flags);
  67. }
  68. static inline ssize_t recvfrom(int sock, void *buf, size_t max_len, int flags,
  69. struct sockaddr *src_addr, socklen_t *addrlen)
  70. {
  71. return zsock_recvfrom(sock, buf, max_len, flags, src_addr, addrlen);
  72. }
  73. static inline int getsockopt(int sock, int level, int optname,
  74. void *optval, socklen_t *optlen)
  75. {
  76. return zsock_getsockopt(sock, level, optname, optval, optlen);
  77. }
  78. static inline int setsockopt(int sock, int level, int optname,
  79. const void *optval, socklen_t optlen)
  80. {
  81. return zsock_setsockopt(sock, level, optname, optval, optlen);
  82. }
  83. static inline int getsockname(int sock, struct sockaddr *addr,
  84. socklen_t *addrlen)
  85. {
  86. return zsock_getsockname(sock, addr, addrlen);
  87. }
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif /* ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_ */