in.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 IN_LOOPBACKNET 127
  17. #define IP_TTL 2
  18. #define IP_MULTICAST_LOOP 3
  19. #define IP_ADD_MEMBERSHIP 4
  20. #define IP_DROP_MEMBERSHIP 5
  21. #define IP_MULTICAST_IF 6
  22. #define IP_MULTICAST_TTL 7
  23. /* Make sure these don't overlap with any other IPv4 and IPv6 options */
  24. #define MCAST_JOIN_SOURCE_GROUP 100
  25. #define MCAST_LEAVE_SOURCE_GROUP 101
  26. #define IPPORT_RESERVED 1024
  27. #define IPPORT_USERRESERVED 5000
  28. typedef uint16_t in_port_t;
  29. struct in_addr {
  30. uint32_t s_addr;
  31. };
  32. struct sockaddr_in {
  33. sa_family_t sin_family;
  34. in_port_t sin_port;
  35. struct in_addr sin_addr;
  36. char sin_zero[8];
  37. };
  38. struct ip_mreq {
  39. struct in_addr imr_multiaddr;
  40. struct in_addr imr_interface;
  41. };
  42. struct group_source_req {
  43. uint32_t gsr_interface;
  44. struct sockaddr_storage gsr_group;
  45. struct sockaddr_storage gsr_source;
  46. };
  47. struct ip_mreq_source {
  48. struct in_addr imr_multiaddr;
  49. struct in_addr imr_sourceaddr;
  50. struct in_addr imr_interface;
  51. };
  52. #define IPV6_UNICAST_HOPS 1
  53. #define IPV6_MULTICAST_HOPS 2
  54. #define IPV6_MULTICAST_LOOP 3
  55. #define IPV6_MULTICAST_IF 4
  56. #define IPV6_ADD_MEMBERSHIP 5
  57. #define IPV6_DROP_MEMBERSHIP 6
  58. #define IP_ADD_SOURCE_MEMBERSHIP 7
  59. #define IP_DROP_SOURCE_MEMBERSHIP 8
  60. #define IPV6_V6ONLY 9
  61. #define IPV6_JOIN_GROUP 5
  62. #define IPV6_LEAVE_GROUP 6
  63. struct in6_addr {
  64. uint8_t s6_addr[16];
  65. };
  66. #define IN6ADDR_ANY_INIT \
  67. { \
  68. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  69. }
  70. extern struct in6_addr in6addr_any;
  71. struct sockaddr_in6 {
  72. sa_family_t sin6_family; // AF_INET6.
  73. in_port_t sin6_port; // Port number.
  74. uint32_t sin6_flowinfo; // IPv6 traffic class and flow information.
  75. struct in6_addr sin6_addr; // IPv6 address.
  76. uint32_t sin6_scope_id; // Set of interfaces for a scop
  77. };
  78. struct ipv6_mreq {
  79. struct in6_addr ipv6mr_multiaddr;
  80. uint32_t ipv6mr_interface;
  81. };
  82. #ifdef __cplusplus
  83. }
  84. #endif