#include "in-addr-util.h"
#include "logarithm.h"
#include "macro.h"
+#include "memory-util.h"
#include "parse-util.h"
#include "random-util.h"
#include "stdio-util.h"
bool in6_addr_is_null(const struct in6_addr *a) {
assert(a);
- return IN6_IS_ADDR_UNSPECIFIED(a);
+ return eqzero(a->in6_u.u6_addr32);
}
int in_addr_is_null(int family, const union in_addr_union *u) {
bool in6_addr_is_link_local(const struct in6_addr *a) {
assert(a);
- return IN6_IS_ADDR_LINKLOCAL(a);
+ return (a->in6_u.u6_addr32[0] & htobe32(0xffc00000)) == htobe32(0xfe800000);
}
int in_addr_is_link_local(int family, const union in_addr_union *u) {
bool in6_addr_is_multicast(const struct in6_addr *a) {
assert(a);
- return IN6_IS_ADDR_MULTICAST(a);
+ return a->in6_u.u6_addr8[0] == 0xff;
}
int in_addr_is_multicast(int family, const union in_addr_union *u) {
!in4_addr_is_localhost(a);
}
+static bool in6_addr_is_loopback(const struct in6_addr *a) {
+ return memcmp(a, &(struct in6_addr) IN6ADDR_LOOPBACK_INIT, sizeof(struct in6_addr)) == 0;
+}
+
int in_addr_is_localhost(int family, const union in_addr_union *u) {
assert(u);
return in4_addr_is_localhost(&u->in);
if (family == AF_INET6)
- return IN6_IS_ADDR_LOOPBACK(&u->in6);
+ return in6_addr_is_loopback(&u->in6);
return -EAFNOSUPPORT;
}
return be32toh(u->in.s_addr) == UINT32_C(0x7F000001);
if (family == AF_INET6)
- return IN6_IS_ADDR_LOOPBACK(&u->in6);
+ return in6_addr_is_loopback(&u->in6);
return -EAFNOSUPPORT;
}
assert(a);
assert(b);
- return IN6_ARE_ADDR_EQUAL(a, b);
+ return memcmp(a, b, sizeof(struct in6_addr)) == 0;
}
int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b) {
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <linux/if.h>
+
+#define IF_NAMESIZE 16
+
+extern unsigned int if_nametoindex(const char *__ifname) __THROW;
+extern char *if_indextoname(unsigned int __ifindex, char __ifname[IF_NAMESIZE]) __THROW;
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <linux/in.h>
+#include <linux/in6.h>
+#include <linux/ipv6.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <sys/socket.h>
+
+#define INET_ADDRSTRLEN 16
+#define INET6_ADDRSTRLEN 46
+
+extern const struct in6_addr in6addr_any; /* :: */
+extern const struct in6_addr in6addr_loopback; /* ::1 */
+#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
+#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
+
+typedef uint32_t in_addr_t;
if (is_router) {
mreq = (struct ipv6_mreq) {
.ipv6mr_multiaddr = IN6_ADDR_ALL_ROUTERS_MULTICAST,
- .ipv6mr_interface = ifindex,
+ .ipv6mr_ifindex = ifindex,
};
ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filter);
} else {
mreq = (struct ipv6_mreq) {
.ipv6mr_multiaddr = IN6_ADDR_ALL_NODES_MULTICAST,
- .ipv6mr_interface = ifindex,
+ .ipv6mr_ifindex = ifindex,
};
ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filter);
ICMP6_FILTER_SETPASS(ND_NEIGHBOR_ADVERT, &filter);
if (r < 0)
return r;
- r = setsockopt_int(s, SOL_IPV6, IPV6_RECVHOPLIMIT, true);
+ r = setsockopt_int(s, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, true);
if (r < 0)
return r;
assert(!(msg.msg_flags & MSG_TRUNC));
- int *hops = CMSG_FIND_DATA(&msg, SOL_IPV6, IPV6_HOPLIMIT, int);
+ int *hops = CMSG_FIND_DATA(&msg, IPPROTO_IPV6, IPV6_HOPLIMIT, int);
if (hops && *hops != 255)
return -EMULTIHOP;
} else if (s->family == AF_INET6) {
struct ipv6_mreq mreq = {
.ipv6mr_multiaddr = in6,
- .ipv6mr_interface = s->link->ifindex,
+ .ipv6mr_ifindex = s->link->ifindex,
};
if (s->protocol == DNS_PROTOCOL_LLMNR)