sal_netdb.h 3.2 KB

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