netdb.h 3.9 KB

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