-
Notifications
You must be signed in to change notification settings - Fork 275
Closed
Description
ttl and set_ttl methods return an error on IPv6 sockets.
Current implementations are limited to IPv4 only:
pub fn ttl(&self) -> io::Result<u32> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IP, sys::IP_TTL).map(|ttl| ttl as u32)
}
}
}and
pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {
unsafe { setsockopt(self.as_raw(), sys::IPPROTO_IP, sys::IP_TTL, ttl as c_int) }
}For IPv6 address family the proper implementations should be like
pub fn ttl(&self) -> io::Result<u32> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IPV6, sys::IP_TTL).map(|ttl| ttl as u32)
}
}
}and
pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {
unsafe { setsockopt(self.as_raw(), sys::IPPROTO_IPV6, sys::IP_TTL, ttl as c_int) }
}Unfortunately, I haven't found a reliable way to get the address family/domain of the socket instance, something like
pub fn domain(&self) -> io::Result<Domain>
So the possible solutions are:
- To implement
Socket::domainmethod, which is very system-dependent and may include:
Socket::local_addrcheck, which may fail for unbound sockets on some systems- Using
getsockoptwithSO_DOMAINoption, which is not available on some systems.
- Add methods like
Socket::ttl_v6andSocket::set_ttl_v6- and leave the problem of detecting the proper address family to a library user.
Metadata
Metadata
Assignees
Labels
No labels