in.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <Kernel/API/POSIX/sys/socket.h>
  8. #include <Kernel/API/POSIX/sys/types.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. typedef uint32_t in_addr_t;
  13. #define INADDR_ANY ((in_addr_t)0)
  14. #define INADDR_NONE ((in_addr_t)-1)
  15. #define INADDR_LOOPBACK 0x7f000001
  16. #define INADDR_BROADCAST 0xffffffff
  17. #define IN_LOOPBACKNET 127
  18. #define IP_TOS 1
  19. #define IP_TTL 2
  20. #define IP_MULTICAST_LOOP 3
  21. #define IP_ADD_MEMBERSHIP 4
  22. #define IP_DROP_MEMBERSHIP 5
  23. #define IP_MULTICAST_IF 6
  24. #define IP_MULTICAST_TTL 7
  25. #define IP_BLOCK_SOURCE 8
  26. #define IP_UNBLOCK_SOURCE 9
  27. #define IP_OPTIONS 10
  28. #define IPTOS_LOWDELAY 16
  29. #define IPTOS_THROUGHPUT 8
  30. #define IPTOS_RELIABILITY 4
  31. /* Make sure these don't overlap with any other IPv4 and IPv6 options */
  32. #define MCAST_JOIN_SOURCE_GROUP 100
  33. #define MCAST_LEAVE_SOURCE_GROUP 101
  34. #define IPPORT_RESERVED 1024
  35. #define IPPORT_USERRESERVED 5000
  36. typedef uint16_t in_port_t;
  37. struct in_addr {
  38. uint32_t s_addr;
  39. };
  40. struct sockaddr_in {
  41. sa_family_t sin_family;
  42. in_port_t sin_port;
  43. struct in_addr sin_addr;
  44. char sin_zero[8];
  45. };
  46. struct ip_mreq {
  47. struct in_addr imr_multiaddr;
  48. struct in_addr imr_interface;
  49. };
  50. struct group_source_req {
  51. uint32_t gsr_interface;
  52. struct sockaddr_storage gsr_group;
  53. struct sockaddr_storage gsr_source;
  54. };
  55. struct ip_mreq_source {
  56. struct in_addr imr_multiaddr;
  57. struct in_addr imr_sourceaddr;
  58. struct in_addr imr_interface;
  59. };
  60. #define IPV6_UNICAST_HOPS 1
  61. #define IPV6_MULTICAST_HOPS 2
  62. #define IPV6_MULTICAST_LOOP 3
  63. #define IPV6_MULTICAST_IF 4
  64. #define IPV6_ADD_MEMBERSHIP 5
  65. #define IPV6_DROP_MEMBERSHIP 6
  66. #define IP_ADD_SOURCE_MEMBERSHIP 7
  67. #define IP_DROP_SOURCE_MEMBERSHIP 8
  68. #define IPV6_V6ONLY 9
  69. #define IPV6_JOIN_GROUP 5
  70. #define IPV6_LEAVE_GROUP 6
  71. struct in6_addr {
  72. uint8_t s6_addr[16];
  73. };
  74. #define IN6ADDR_ANY_INIT \
  75. { \
  76. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  77. }
  78. #define IN6ADDR_LOOPBACK_INIT \
  79. { \
  80. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 \
  81. }
  82. extern const struct in6_addr in6addr_any;
  83. extern const struct in6_addr in6addr_loopback;
  84. struct sockaddr_in6 {
  85. sa_family_t sin6_family; // AF_INET6.
  86. in_port_t sin6_port; // Port number.
  87. uint32_t sin6_flowinfo; // IPv6 traffic class and flow information.
  88. struct in6_addr sin6_addr; // IPv6 address.
  89. uint32_t sin6_scope_id; // Set of interfaces for a scop
  90. };
  91. struct ipv6_mreq {
  92. struct in6_addr ipv6mr_multiaddr;
  93. uint32_t ipv6mr_interface;
  94. };
  95. #ifdef __cplusplus
  96. }
  97. #endif