netdb.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <sys/cdefs.h>
  8. #include <sys/types.h>
  9. __BEGIN_DECLS
  10. struct hostent {
  11. char* h_name;
  12. char** h_aliases;
  13. int h_addrtype;
  14. int h_length;
  15. char** h_addr_list;
  16. #define h_addr h_addr_list[0]
  17. };
  18. struct hostent* gethostbyname(char const*);
  19. struct hostent* gethostbyaddr(void const* addr, socklen_t len, int type);
  20. struct servent {
  21. char* s_name;
  22. char** s_aliases;
  23. int s_port;
  24. char* s_proto;
  25. };
  26. struct servent* getservent(void);
  27. struct servent* getservbyname(char const* name, char const* protocol);
  28. struct servent* getservbyport(int port, char const* protocol);
  29. void setservent(int stay_open);
  30. void endservent(void);
  31. struct protoent {
  32. char* p_name;
  33. char** p_aliases;
  34. int p_proto;
  35. };
  36. void endprotoent(void);
  37. struct protoent* getprotobyname(char const* name);
  38. struct protoent* getprotobynumber(int proto);
  39. struct protoent* getprotoent(void);
  40. void setprotoent(int stay_open);
  41. #ifdef NO_TLS
  42. extern int h_errno;
  43. #else
  44. extern __thread int h_errno;
  45. #endif
  46. #define HOST_NOT_FOUND 101
  47. #define NO_DATA 102
  48. #define NO_ADDRESS NO_DATA
  49. #define NO_RECOVERY 103
  50. #define TRY_AGAIN 104
  51. struct addrinfo {
  52. int ai_flags;
  53. int ai_family;
  54. int ai_socktype;
  55. int ai_protocol;
  56. socklen_t ai_addrlen;
  57. struct sockaddr* ai_addr;
  58. char* ai_canonname;
  59. struct addrinfo* ai_next;
  60. };
  61. #define EAI_ADDRFAMILY 1
  62. #define EAI_AGAIN 2
  63. #define EAI_BADFLAGS 3
  64. #define EAI_FAIL 4
  65. #define EAI_FAMILY 5
  66. #define EAI_MEMORY 6
  67. #define EAI_NODATA 7
  68. #define EAI_NONAME 8
  69. #define EAI_SERVICE 9
  70. #define EAI_SOCKTYPE 10
  71. #define EAI_SYSTEM 11
  72. #define EAI_OVERFLOW 12
  73. #define AI_PASSIVE 0x0001
  74. #define AI_CANONNAME 0x0002
  75. #define AI_NUMERICHOST 0x0004
  76. #define AI_NUMERICSERV 0x0008
  77. #define AI_V4MAPPED 0x0010
  78. #define AI_ALL 0x0020
  79. #define AI_ADDRCONFIG 0x0040
  80. #define NI_MAXHOST 1025
  81. #define NI_MAXSERV 32
  82. #define NI_NUMERICHOST (1 << 0)
  83. #define NI_NUMERICSERV (1 << 1)
  84. #define NI_NAMEREQD (1 << 2)
  85. #define NI_NOFQDN (1 << 3)
  86. #define NI_DGRAM (1 << 4)
  87. int getaddrinfo(char const* __restrict node, char const* __restrict service, const struct addrinfo* __restrict hints, struct addrinfo** __restrict res);
  88. void freeaddrinfo(struct addrinfo* res);
  89. char const* gai_strerror(int errcode);
  90. int getnameinfo(const struct sockaddr* __restrict addr, socklen_t addrlen, char* __restrict host, socklen_t hostlen, char* __restrict serv, socklen_t servlen, int flags);
  91. void herror(char const* s);
  92. char const* hstrerror(int err);
  93. __END_DECLS