sal_netdb.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * File : sal_netdb.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2018-05-24 ChenYong First version
  23. */
  24. #ifndef SAL_NETDB_H__
  25. #define SAL_NETDB_H__
  26. #include <sal_socket.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #define EAI_NONAME 200
  31. #define EAI_SERVICE 201
  32. #define EAI_FAIL 202
  33. #define EAI_MEMORY 203
  34. #define EAI_FAMILY 204
  35. #define HOST_NOT_FOUND 210
  36. #define NO_DATA 211
  37. #define NO_RECOVERY 212
  38. #define TRY_AGAIN 213
  39. #define AI_PASSIVE 0x01
  40. #define AI_CANONNAME 0x02
  41. #define AI_NUMERICHOST 0x04
  42. #define AI_NUMERICSERV 0x08
  43. #define AI_V4MAPPED 0x10
  44. #define AI_ALL 0x20
  45. #define AI_ADDRCONFIG 0x40
  46. /* input flags for structure addrinfo */
  47. #define AI_PASSIVE 0x01
  48. #define AI_CANONNAME 0x02
  49. #define AI_NUMERICHOST 0x04
  50. #define AI_NUMERICSERV 0x08
  51. #define AI_V4MAPPED 0x10
  52. #define AI_ALL 0x20
  53. #define AI_ADDRCONFIG 0x40
  54. #define DNS_MAX_NAME_LENGTH 256
  55. struct hostent {
  56. char *h_name; /* Official name of the host. */
  57. char **h_aliases; /* A pointer to an array of pointers to alternative host names,
  58. terminated by a null pointer. */
  59. int h_addrtype; /* Address type. */
  60. int h_length; /* The length, in bytes, of the address. */
  61. char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
  62. network byte order) for the host, terminated by a null pointer. */
  63. #define h_addr h_addr_list[0] /* for backward compatibility */
  64. };
  65. struct addrinfo {
  66. int ai_flags; /* Input flags. */
  67. int ai_family; /* Address family of socket. */
  68. int ai_socktype; /* Socket type. */
  69. int ai_protocol; /* Protocol of socket. */
  70. socklen_t ai_addrlen; /* Length of socket address. */
  71. struct sockaddr *ai_addr; /* Socket address of socket. */
  72. char *ai_canonname; /* Canonical name of service location. */
  73. struct addrinfo *ai_next; /* Pointer to next in list. */
  74. };
  75. struct hostent *sal_gethostbyname(const char *name);
  76. int sal_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
  77. size_t buflen, struct hostent **result, int *h_errnop);
  78. void sal_freeaddrinfo(struct addrinfo *ai);
  79. int sal_getaddrinfo(const char *nodename,
  80. const char *servname,
  81. const struct addrinfo *hints,
  82. struct addrinfo **res);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif /* SAL_NETDB_H__ */