in.h 2.2 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 <bits/stdint.h>
  8. #include <sys/cdefs.h>
  9. #include <sys/socket.h>
  10. __BEGIN_DECLS
  11. typedef uint32_t in_addr_t;
  12. in_addr_t inet_addr(const char*);
  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. struct in6_addr {
  62. uint8_t s6_addr[16];
  63. };
  64. #define IN6ADDR_ANY_INIT \
  65. { \
  66. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  67. }
  68. extern struct in6_addr in6addr_any;
  69. struct sockaddr_in6 {
  70. sa_family_t sin6_family; // AF_INET6.
  71. in_port_t sin6_port; // Port number.
  72. uint32_t sin6_flowinfo; // IPv6 traffic class and flow information.
  73. struct in6_addr sin6_addr; // IPv6 address.
  74. uint32_t sin6_scope_id; // Set of interfaces for a scop
  75. };
  76. struct ipv6_mreq {
  77. struct in6_addr ipv6mr_multiaddr;
  78. uint32_t ipv6mr_interface;
  79. };
  80. __END_DECLS