sgx_socket.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /* Standard well-defined IP protocols. */
  42. #define IPPROTO_TCP 6 /* Transmission Control Protocol. */
  43. /* Types of sockets. */
  44. #define SOCK_DGRAM \
  45. 2 /* Connectionless, unreliable datagrams of fixed maximum length. */
  46. struct msghdr {
  47. void *msg_name;
  48. socklen_t msg_namelen;
  49. struct iovec *msg_iov;
  50. int msg_iovlen;
  51. void *msg_control;
  52. socklen_t msg_controllen;
  53. int msg_flags;
  54. };
  55. /* Internet address. */
  56. struct in_addr {
  57. uint32_t s_addr;
  58. };
  59. typedef struct in_addr in_addr_t;
  60. /* Structure describing an Internet socket address. */
  61. #define __SOCK_SIZE__ 16 /* sizeof(struct sockaddr) */
  62. struct sockaddr_in {
  63. uint16_t sin_family;
  64. uint16_t sin_port; /* Port number. */
  65. struct in_addr sin_addr; /* Internet address. */
  66. /* Pad to size of `struct sockaddr'. */
  67. unsigned char__pad[__SOCK_SIZE__ - sizeof(uint16_t) - sizeof(uint16_t)
  68. - sizeof(struct in_addr)];
  69. };
  70. /* Structure used to manipulate the SO_LINGER option. */
  71. struct linger {
  72. int l_onoff; /* Nonzero to linger on close. */
  73. int l_linger; /* Time to linger. */
  74. };
  75. /* Structure describing a generic socket address. */
  76. struct sockaddr {
  77. unsigned short int sa_family; /* Common data: address family and length. */
  78. char sa_data[14]; /* Address data. */
  79. };
  80. int
  81. socket(int domain, int type, int protocol);
  82. int
  83. getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
  84. ssize_t
  85. sendmsg(int sockfd, const struct msghdr *msg, int flags);
  86. ssize_t
  87. recvmsg(int sockfd, struct msghdr *msg, int flags);
  88. int
  89. shutdown(int sockfd, int how);
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. #endif /* end of _SGX_SOCKET_H */