netdb.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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(const char*);
  19. struct hostent* gethostbyaddr(const void* 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();
  27. struct servent* getservbyname(const char* name, const char* protocol);
  28. struct servent* getservbyport(int port, const char* protocol);
  29. void setservent(int stay_open);
  30. void endservent();
  31. struct protoent {
  32. char* p_name;
  33. char** p_aliases;
  34. int p_proto;
  35. };
  36. void endprotoent();
  37. struct protoent* getprotobyname(const char* name);
  38. struct protoent* getprotobynumber(int proto);
  39. struct protoent* getprotoent();
  40. void setprotoent(int stay_open);
  41. extern int h_errno;
  42. #define HOST_NOT_FOUND 101
  43. #define NO_DATA 102
  44. #define NO_RECOVERY 103
  45. #define TRY_AGAIN 104
  46. struct addrinfo {
  47. int ai_flags;
  48. int ai_family;
  49. int ai_socktype;
  50. int ai_protocol;
  51. socklen_t ai_addrlen;
  52. struct sockaddr* ai_addr;
  53. char* ai_canonname;
  54. struct addrinfo* ai_next;
  55. };
  56. #define EAI_ADDRFAMILY 1
  57. #define EAI_AGAIN 2
  58. #define EAI_BADFLAGS 3
  59. #define EAI_FAIL 4
  60. #define EAI_FAMILY 5
  61. #define EAI_MEMORY 6
  62. #define EAI_NODATA 7
  63. #define EAI_NONAME 8
  64. #define EAI_SERVICE 9
  65. #define EAI_SOCKTYPE 10
  66. #define EAI_SYSTEM 11
  67. #define EAI_OVERFLOW 12
  68. #define AI_PASSIVE 0x0001
  69. #define AI_CANONNAME 0x0002
  70. #define AI_NUMERICHOST 0x0004
  71. #define AI_NUMERICSERV 0x0008
  72. #define AI_V4MAPPED 0x0010
  73. #define AI_ALL 0x0020
  74. #define AI_ADDRCONFIG 0x0040
  75. #define NI_MAXHOST 1025
  76. #define NI_MAXSERV 32
  77. #define NI_NUMERICHOST 1
  78. #define NI_NUMERICSERV 2
  79. #define NI_NAMEREQD 3
  80. int getaddrinfo(const char* __restrict node, const char* __restrict service, const struct addrinfo* __restrict hints, struct addrinfo** __restrict res);
  81. void freeaddrinfo(struct addrinfo* res);
  82. const char* gai_strerror(int errcode);
  83. int getnameinfo(const struct sockaddr* __restrict addr, socklen_t addrlen, char* __restrict host, socklen_t hostlen, char* __restrict serv, socklen_t servlen, int flags);
  84. __END_DECLS