Skip to content

Commit 7cccca8

Browse files
ETKNeilsunfishcode
authored andcommitted
Add ipv6 multicast hops support
1 parent 19eab8e commit 7cccca8

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

src/backend/libc/net/syscalls.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,24 @@ pub(crate) mod sockopt {
701701
getsockopt(fd, c::IPPROTO_IPV6 as _, c::IPV6_MULTICAST_LOOP).map(to_bool)
702702
}
703703

704+
#[inline]
705+
pub(crate) fn set_ipv6_multicast_hops(
706+
fd: BorrowedFd<'_>,
707+
multicast_hops: u32,
708+
) -> io::Result<()> {
709+
setsockopt(
710+
fd,
711+
c::IPPROTO_IP as _,
712+
c::IPV6_MULTICAST_LOOP,
713+
multicast_hops,
714+
)
715+
}
716+
717+
#[inline]
718+
pub(crate) fn get_ipv6_multicast_hops(fd: BorrowedFd<'_>) -> io::Result<u32> {
719+
getsockopt(fd, c::IPPROTO_IP as _, c::IPV6_MULTICAST_LOOP)
720+
}
721+
704722
#[inline]
705723
pub(crate) fn set_ip_add_membership(
706724
fd: BorrowedFd<'_>,

src/backend/linux_raw/net/syscalls.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,24 @@ pub(crate) mod sockopt {
11311131
getsockopt(fd, c::IPPROTO_IPV6 as _, c::IPV6_MULTICAST_LOOP).map(to_bool)
11321132
}
11331133

1134+
#[inline]
1135+
pub(crate) fn set_ipv6_multicast_hops(
1136+
fd: BorrowedFd<'_>,
1137+
multicast_hops: u32,
1138+
) -> io::Result<()> {
1139+
setsockopt(
1140+
fd,
1141+
c::IPPROTO_IP as _,
1142+
c::IPV6_MULTICAST_LOOP,
1143+
multicast_hops,
1144+
)
1145+
}
1146+
1147+
#[inline]
1148+
pub(crate) fn get_ipv6_multicast_hops(fd: BorrowedFd<'_>) -> io::Result<u32> {
1149+
getsockopt(fd, c::IPPROTO_IP as _, c::IPV6_MULTICAST_LOOP)
1150+
}
1151+
11341152
#[inline]
11351153
pub(crate) fn set_ip_add_membership(
11361154
fd: BorrowedFd<'_>,

src/net/sockopt.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,50 @@ pub fn get_ipv6_multicast_loop<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
445445
backend::net::syscalls::sockopt::get_ipv6_multicast_loop(fd.as_fd())
446446
}
447447

448+
/// `setsockopt(fd, IPPROTO_IP, IPV6_MULTICAST_HOPS, multicast_hops)`
449+
///
450+
/// # References
451+
/// - [POSIX `setsockopt`]
452+
/// - [POSIX `netinet/in.h`]
453+
/// - [Linux `setsockopt`]
454+
/// - [Linux `ipv6`]
455+
/// - [Winsock2 `setsockopt`]
456+
/// - [Winsock2 `IPPROTO_IPV6` options]
457+
///
458+
/// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
459+
/// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
460+
/// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html
461+
/// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html
462+
/// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
463+
/// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
464+
#[inline]
465+
#[doc(alias = "IP_MULTICAST_TTL")]
466+
pub fn set_ipv6_multicast_hops<Fd: AsFd>(fd: Fd, multicast_hops: u32) -> io::Result<()> {
467+
backend::net::syscalls::sockopt::set_ipv6_multicast_hops(fd.as_fd(), multicast_hops)
468+
}
469+
470+
/// `getsockopt(fd, IPPROTO_IP, IPV6_MULTICAST_HOPS)`
471+
///
472+
/// # References
473+
/// - [POSIX `getsockopt`]
474+
/// - [POSIX `netinet/in.h`]
475+
/// - [Linux `getsockopt`]
476+
/// - [Linux `ipv6`]
477+
/// - [Winsock2 `getsockopt`]
478+
/// - [Winsock2 `IPPROTO_IPV6` options]
479+
///
480+
/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
481+
/// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
482+
/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
483+
/// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html
484+
/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
485+
/// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
486+
#[inline]
487+
#[doc(alias = "IP_MULTICAST_TTL")]
488+
pub fn get_ipv6_multicast_hops<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
489+
backend::net::syscalls::sockopt::get_ipv6_multicast_hops(fd.as_fd())
490+
}
491+
448492
/// `setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, multiaddr, interface)`
449493
///
450494
/// # References

0 commit comments

Comments
 (0)