netdb.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef _NETDB_H
  2. #define _NETDB_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  7. #define __NEED_size_t
  8. #endif
  9. #define __NEED_socklen_t
  10. #define __NEED_uint32_t
  11. #include <bits/alltypes.h>
  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 *, const char *, const struct addrinfo *, struct addrinfo **);
  48. void freeaddrinfo (struct addrinfo *);
  49. int getnameinfo (const struct sockaddr *, socklen_t, char *, socklen_t, char *, 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)
  100. const char *hstrerror(int);
  101. struct hostent *gethostbyname (const char *);
  102. int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
  103. int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
  104. struct hostent *gethostbyname2(const char *, int);
  105. struct hostent *gethostbyaddr (const void *, socklen_t, int);
  106. int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
  107. int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
  108. int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
  109. #ifdef __GNUC__
  110. __attribute__((const))
  111. #endif
  112. int *__h_errno_location(void);
  113. #define h_errno (*__h_errno_location())
  114. #define EAI_NODATA -5
  115. #define EAI_ADDRFAMILY -9
  116. #define EAI_INPROGRESS -100
  117. #define EAI_CANCELED -101
  118. #define EAI_NOTCANCELED -102
  119. #define EAI_ALLDONE -103
  120. #define EAI_INTR -104
  121. #define EAI_IDN_ENCODE -105
  122. #define NI_MAXHOST 255
  123. #define NI_MAXSERV 32
  124. #define HOST_NOT_FOUND 1
  125. #define TRY_AGAIN 2
  126. #define NO_RECOVERY 3
  127. #define NO_DATA 4
  128. #endif
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif