netdb.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef _NETDB_H
  2. #define _NETDB_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #if __STDC_VERSION__ >= 199901L
  7. #define __restrict restrict
  8. #elif !defined(__GNUC__)
  9. #define __restrict
  10. #endif
  11. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  12. #define __NEED_size_t
  13. #endif
  14. #define __NEED_socklen_t
  15. #define __NEED_uint32_t
  16. #include <bits/alltypes.h>
  17. struct addrinfo
  18. {
  19. int ai_flags;
  20. int ai_family;
  21. int ai_socktype;
  22. int ai_protocol;
  23. socklen_t ai_addrlen;
  24. struct sockaddr *ai_addr;
  25. char *ai_canonname;
  26. struct addrinfo *ai_next;
  27. };
  28. #define IPPORT_RESERVED 1024
  29. #define AI_PASSIVE 0x01
  30. #define AI_CANONNAME 0x02
  31. #define AI_NUMERICHOST 0x04
  32. #define AI_V4MAPPED 0x08
  33. #define AI_ALL 0x10
  34. #define AI_ADDRCONFIG 0x20
  35. #define AI_NUMERICSERV 0x400
  36. #define NI_NUMERICHOST 0x01
  37. #define NI_NUMERICSERV 0x02
  38. #define NI_NOFQDN 0x04
  39. #define NI_NAMEREQD 0x08
  40. #define NI_DGRAM 0x10
  41. /*#define NI_NUMERICSCOPE */
  42. #define EAI_BADFLAGS -1
  43. #define EAI_NONAME -2
  44. #define EAI_AGAIN -3
  45. #define EAI_FAIL -4
  46. #define EAI_FAMILY -6
  47. #define EAI_SOCKTYPE -7
  48. #define EAI_SERVICE -8
  49. #define EAI_MEMORY -10
  50. #define EAI_SYSTEM -11
  51. #define EAI_OVERFLOW -12
  52. int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict);
  53. void freeaddrinfo (struct addrinfo *);
  54. int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int);
  55. const char *gai_strerror(int);
  56. /* Legacy functions follow (marked OBsolete in SUS) */
  57. struct netent
  58. {
  59. char *n_name;
  60. char **n_aliases;
  61. int n_addrtype;
  62. uint32_t n_net;
  63. };
  64. struct hostent
  65. {
  66. char *h_name;
  67. char **h_aliases;
  68. int h_addrtype;
  69. int h_length;
  70. char **h_addr_list;
  71. };
  72. #define h_addr h_addr_list[0]
  73. struct servent
  74. {
  75. char *s_name;
  76. char **s_aliases;
  77. int s_port;
  78. char *s_proto;
  79. };
  80. struct protoent
  81. {
  82. char *p_name;
  83. char **p_aliases;
  84. int p_proto;
  85. };
  86. void sethostent (int);
  87. void endhostent (void);
  88. struct hostent *gethostent (void);
  89. void setnetent (int);
  90. void endnetent (void);
  91. struct netent *getnetent (void);
  92. struct netent *getnetbyaddr (uint32_t, int);
  93. struct netent *getnetbyname (const char *);
  94. void setservent (int);
  95. void endservent (void);
  96. struct servent *getservent (void);
  97. struct servent *getservbyname (const char *, const char *);
  98. struct servent *getservbyport (int, const char *);
  99. void setprotoent (int);
  100. void endprotoent (void);
  101. struct protoent *getprotoent (void);
  102. struct protoent *getprotobyname (const char *);
  103. struct protoent *getprotobynumber (int);
  104. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
  105. || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE < 200809L) \
  106. || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE < 700)
  107. struct hostent *gethostbyname (const char *);
  108. struct hostent *gethostbyaddr (const void *, socklen_t, int);
  109. #ifdef __GNUC__
  110. __attribute__((const))
  111. #endif
  112. int *__h_errno_location(void);
  113. #define h_errno (*__h_errno_location())
  114. #define HOST_NOT_FOUND 1
  115. #define TRY_AGAIN 2
  116. #define NO_RECOVERY 3
  117. #define NO_DATA 4
  118. #endif
  119. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  120. const char *hstrerror(int);
  121. int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
  122. int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
  123. struct hostent *gethostbyname2(const char *, int);
  124. int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
  125. int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
  126. int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
  127. #define EAI_NODATA -5
  128. #define EAI_ADDRFAMILY -9
  129. #define EAI_INPROGRESS -100
  130. #define EAI_CANCELED -101
  131. #define EAI_NOTCANCELED -102
  132. #define EAI_ALLDONE -103
  133. #define EAI_INTR -104
  134. #define EAI_IDN_ENCODE -105
  135. #define NI_MAXHOST 255
  136. #define NI_MAXSERV 32
  137. #endif
  138. #ifdef __cplusplus
  139. }
  140. #endif
  141. #endif