No functional change, just refactoring.
}
static void test_with_icmp6_packet(const uint8_t *data, size_t size) {
- static const struct sockaddr_in6 dst = {
- .sin6_family = AF_INET6,
- .sin6_addr = IN6_ADDR_ALL_ROUTERS_MULTICAST,
- };
-
_cleanup_close_pair_ int fd_pair[2] = EBADF_PAIR;
_cleanup_(icmp6_packet_unrefp) ICMP6Packet *packet = NULL;
_cleanup_set_free_ Set *options = NULL;
if (ndisc_parse_options(packet, &options) < 0)
return;
- if (ndisc_send(fd_pair[1], &dst, icmp6_packet_get_header(packet), options, /* timestamp = */ 0) < 0)
+ if (ndisc_send(fd_pair[1], &IN6_ADDR_ALL_ROUTERS_MULTICAST,
+ icmp6_packet_get_header(packet), options, /* timestamp = */ 0) < 0)
return;
packet = icmp6_packet_unref(packet);
return test_fd[is_router];
}
-int icmp6_send(int fd, const struct sockaddr_in6 *dst, const struct iovec *iov, size_t n_iov) {
+int icmp6_send(int fd, const struct in6_addr *dst, const struct iovec *iov, size_t n_iov) {
return writev(fd, iov, n_iov);
}
return TAKE_FD(s);
}
-int icmp6_send(int fd, const struct sockaddr_in6 *dst, const struct iovec *iov, size_t n_iov) {
+int icmp6_send(int fd, const struct in6_addr *dst, const struct iovec *iov, size_t n_iov) {
+ struct sockaddr_in6 sa = {
+ .sin6_family = AF_INET6,
+ .sin6_addr = *ASSERT_PTR(dst),
+ };
struct msghdr msg = {
- .msg_name = (struct sockaddr_in6*) dst,
+ .msg_name = &sa,
.msg_namelen = sizeof(struct sockaddr_in6),
.msg_iov = (struct iovec*) iov,
.msg_iovlen = n_iov,
};
+ assert(fd >= 0);
+
if (sendmsg(fd, &msg, 0) < 0)
return -errno;
} } } )
int icmp6_bind(int ifindex, bool is_router);
-int icmp6_send(int fd, const struct sockaddr_in6 *dst, const struct iovec *iov, size_t n_iov);
+int icmp6_send(int fd, const struct in6_addr *dst, const struct iovec *iov, size_t n_iov);
int icmp6_receive(
int fd,
void *buffer,
return 0;
}
-int ndisc_send(int fd, const struct sockaddr_in6 *dst, const struct icmp6_hdr *hdr, Set *options, usec_t timestamp) {
+int ndisc_send(int fd, const struct in6_addr *dst, const struct icmp6_hdr *hdr, Set *options, usec_t timestamp) {
int r;
assert(fd >= 0);
return ndisc_option_add_prefix64_internal(options, 0, prefixlen, prefix, lifetime, valid_until);
}
-int ndisc_send(int fd, const struct sockaddr_in6 *dst, const struct icmp6_hdr *hdr, Set *options, usec_t timestamp);
+int ndisc_send(int fd, const struct in6_addr *dst, const struct icmp6_hdr *hdr, Set *options, usec_t timestamp);
}
static int ndisc_send_router_solicitation(sd_ndisc *nd) {
- static const struct sockaddr_in6 dst = {
- .sin6_family = AF_INET6,
- .sin6_addr = IN6_ADDR_ALL_ROUTERS_MULTICAST,
- };
static const struct nd_router_solicit header = {
.nd_rs_type = ND_ROUTER_SOLICIT,
};
return r;
}
- return ndisc_send(nd->fd, &dst, &header.nd_rs_hdr, options, USEC_INFINITY);
+ return ndisc_send(nd->fd, &IN6_ADDR_ALL_ROUTERS_MULTICAST, &header.nd_rs_hdr, options, USEC_INFINITY);
}
static usec_t ndisc_timeout_compute_random(usec_t val) {
return r;
}
- struct sockaddr_in6 dst_sockaddr = {
- .sin6_family = AF_INET6,
- .sin6_addr = arg_dest.in6,
- };
-
- return ndisc_send(fd, &dst_sockaddr, hdr, options, now(CLOCK_BOOTTIME));
+ return ndisc_send(fd, &arg_dest.in6, hdr, options, now(CLOCK_BOOTTIME));
}
static int send_router_solicit(int fd) {