1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-05 09:17:44 +03:00

icmp6: shorten code a bit

This commit is contained in:
Yu Watanabe 2021-10-19 20:32:40 +09:00
parent ea51deb188
commit 113e124f9b

View File

@ -34,16 +34,17 @@ static int icmp6_bind_router_message(const struct icmp6_filter *filter,
_cleanup_close_ int s = -1; _cleanup_close_ int s = -1;
int r; int r;
assert(filter);
assert(mreq);
s = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, IPPROTO_ICMPV6); s = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, IPPROTO_ICMPV6);
if (s < 0) if (s < 0)
return -errno; return -errno;
r = setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, filter, sizeof(*filter)); if (setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, filter, sizeof(*filter)) < 0)
if (r < 0)
return -errno; return -errno;
r = setsockopt(s, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq, sizeof(*mreq)); if (setsockopt(s, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq, sizeof(*mreq)) < 0)
if (r < 0)
return -errno; return -errno;
/* RFC 3315, section 6.7, bullet point 2 may indicate that an /* RFC 3315, section 6.7, bullet point 2 may indicate that an
@ -131,15 +132,13 @@ int icmp6_send_router_solicitation(int s, const struct ether_addr *ether_addr) {
.msg_iov = &iov, .msg_iov = &iov,
.msg_iovlen = 1, .msg_iovlen = 1,
}; };
int r;
assert(s >= 0); assert(s >= 0);
assert(ether_addr); assert(ether_addr);
rs.rs_opt_mac = *ether_addr; rs.rs_opt_mac = *ether_addr;
r = sendmsg(s, &msg, 0); if (sendmsg(s, &msg, 0) < 0)
if (r < 0)
return -errno; return -errno;
return 0; return 0;