sal_netdb.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-05-24 ChenYong First version
  9. */
  10. #ifndef SAL_NETDB_H__
  11. #define SAL_NETDB_H__
  12. #include <sal_socket.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define EAI_NONAME 200
  17. #define EAI_SERVICE 201
  18. #define EAI_FAIL 202
  19. #define EAI_MEMORY 203
  20. #define EAI_FAMILY 204
  21. #define HOST_NOT_FOUND 210
  22. #define NO_DATA 211
  23. #define NO_RECOVERY 212
  24. #define TRY_AGAIN 213
  25. #define AI_PASSIVE 0x01
  26. #define AI_CANONNAME 0x02
  27. #define AI_NUMERICHOST 0x04
  28. #define AI_NUMERICSERV 0x08
  29. #define AI_V4MAPPED 0x10
  30. #define AI_ALL 0x20
  31. #define AI_ADDRCONFIG 0x40
  32. /* input flags for structure addrinfo */
  33. #define AI_PASSIVE 0x01
  34. #define AI_CANONNAME 0x02
  35. #define AI_NUMERICHOST 0x04
  36. #define AI_NUMERICSERV 0x08
  37. #define AI_V4MAPPED 0x10
  38. #define AI_ALL 0x20
  39. #define AI_ADDRCONFIG 0x40
  40. #define DNS_MAX_NAME_LENGTH 256
  41. struct hostent {
  42. char *h_name; /* Official name of the host. */
  43. char **h_aliases; /* A pointer to an array of pointers to alternative host names,
  44. terminated by a null pointer. */
  45. int h_addrtype; /* Address type. */
  46. int h_length; /* The length, in bytes, of the address. */
  47. char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
  48. network byte order) for the host, terminated by a null pointer. */
  49. #define h_addr h_addr_list[0] /* for backward compatibility */
  50. };
  51. struct addrinfo {
  52. int ai_flags; /* Input flags. */
  53. int ai_family; /* Address family of socket. */
  54. int ai_socktype; /* Socket type. */
  55. int ai_protocol; /* Protocol of socket. */
  56. socklen_t ai_addrlen; /* Length of socket address. */
  57. struct sockaddr *ai_addr; /* Socket address of socket. */
  58. char *ai_canonname; /* Canonical name of service location. */
  59. struct addrinfo *ai_next; /* Pointer to next in list. */
  60. };
  61. struct hostent *sal_gethostbyname(const char *name);
  62. int sal_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
  63. size_t buflen, struct hostent **result, int *h_errnop);
  64. void sal_freeaddrinfo(struct addrinfo *ai);
  65. int sal_getaddrinfo(const char *nodename,
  66. const char *servname,
  67. const struct addrinfo *hints,
  68. struct addrinfo **res);
  69. #ifdef __cplusplus
  70. }
  71. #endif
  72. #endif /* SAL_NETDB_H__ */