2
0

netdb.h 3.9 KB

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