sgx_socket.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _SGX_SOCKET_H
  6. #define _SGX_SOCKET_H
  7. #include "sgx_file.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define SOL_SOCKET 1
  12. #define SO_TYPE 3
  13. #define SO_LINGER 13
  14. #define SOCK_STREAM 1
  15. #define SOCK_DGRAM 2
  16. #define MSG_OOB 0x0001
  17. #define MSG_PEEK 0x0002
  18. #define MSG_DONTROUTE 0x0004
  19. #define MSG_CTRUNC 0x0008
  20. #define MSG_PROXY 0x0010
  21. #define MSG_TRUNC 0x0020
  22. #define MSG_DONTWAIT 0x0040
  23. #define MSG_EOR 0x0080
  24. #define MSG_WAITALL 0x0100
  25. #define MSG_FIN 0x0200
  26. #define MSG_SYN 0x0400
  27. #define MSG_CONFIRM 0x0800
  28. #define MSG_RST 0x1000
  29. #define MSG_ERRQUEUE 0x2000
  30. #define MSG_NOSIGNAL 0x4000
  31. #define MSG_MORE 0x8000
  32. #define MSG_WAITFORONE 0x10000
  33. #define MSG_BATCH 0x40000
  34. #define MSG_FASTOPEN 0x20000000
  35. #define MSG_CMSG_CLOEXEC 0x40000000
  36. #define SHUT_RD 0
  37. #define SHUT_WR 1
  38. #define SHUT_RDWR 2
  39. /* Address families. */
  40. #define AF_INET 2 /* IP protocol family. */
  41. #define AF_INET6 10 /* IP version 6. */
  42. /* Standard well-defined IP protocols. */
  43. #define IPPROTO_TCP 6 /* Transmission Control Protocol. */
  44. /* Types of sockets. */
  45. #define SOCK_DGRAM \
  46. 2 /* Connectionless, unreliable datagrams of fixed maximum length. */
  47. struct msghdr {
  48. void *msg_name;
  49. socklen_t msg_namelen;
  50. struct iovec *msg_iov;
  51. int msg_iovlen;
  52. void *msg_control;
  53. socklen_t msg_controllen;
  54. int msg_flags;
  55. };
  56. /* Internet address. */
  57. struct in_addr {
  58. uint32_t s_addr;
  59. };
  60. typedef struct in_addr in_addr_t;
  61. /* Structure describing an Internet socket address. */
  62. #define __SOCK_SIZE__ 16 /* sizeof(struct sockaddr) */
  63. struct sockaddr_in {
  64. uint16_t sin_family;
  65. uint16_t sin_port; /* Port number. */
  66. struct in_addr sin_addr; /* Internet address. */
  67. /* Pad to size of `struct sockaddr'. */
  68. unsigned char__pad[__SOCK_SIZE__ - sizeof(uint16_t) - sizeof(uint16_t)
  69. - sizeof(struct in_addr)];
  70. };
  71. /* Structure used to manipulate the SO_LINGER option. */
  72. struct linger {
  73. int l_onoff; /* Nonzero to linger on close. */
  74. int l_linger; /* Time to linger. */
  75. };
  76. /* Structure describing a generic socket address. */
  77. struct sockaddr {
  78. unsigned short int sa_family; /* Common data: address family and length. */
  79. char sa_data[14]; /* Address data. */
  80. };
  81. uint32_t
  82. ntohl(uint32_t value);
  83. uint32_t
  84. htonl(uint32_t value);
  85. uint16_t
  86. htons(uint16_t value);
  87. int
  88. socket(int domain, int type, int protocol);
  89. int
  90. getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
  91. ssize_t
  92. sendmsg(int sockfd, const struct msghdr *msg, int flags);
  93. ssize_t
  94. recvmsg(int sockfd, struct msghdr *msg, int flags);
  95. int
  96. shutdown(int sockfd, int how);
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #endif /* end of _SGX_SOCKET_H */