netdb.h 3.9 KB

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