sal_netdb.h 2.6 KB

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