Determine MTU in TapInterface instead of hardcoding 1536.
parent
94796a566b
commit
051169a49d
|
@ -30,6 +30,16 @@ impl TapInterfaceDesc {
|
|||
ifreq_ioctl(self.lower, &mut self.ifreq, imp::TUNSETIFF).map(|_| ())
|
||||
}
|
||||
|
||||
pub fn interface_mtu(&mut self) -> io::Result<usize> {
|
||||
let lower = unsafe {
|
||||
let lower = libc::socket(libc::AF_INET, libc::SOCK_DGRAM, libc::IPPROTO_IP);
|
||||
if lower == -1 { return Err(io::Error::last_os_error()) }
|
||||
lower
|
||||
};
|
||||
|
||||
ifreq_ioctl(lower, &mut self.ifreq, imp::SIOCGIFMTU).map(|mtu| mtu as usize)
|
||||
}
|
||||
|
||||
fn wait(&mut self, ms: u32) -> io::Result<bool> {
|
||||
unsafe {
|
||||
let mut readfds = mem::uninitialized::<libc::fd_set>();
|
||||
|
|
|
@ -22,9 +22,10 @@ impl TapInterface {
|
|||
pub fn new(name: &str) -> io::Result<TapInterface> {
|
||||
let mut lower = sys::TapInterfaceDesc::new(name)?;
|
||||
lower.attach_interface()?;
|
||||
let mtu = lower.interface_mtu()?;
|
||||
Ok(TapInterface {
|
||||
lower: Rc::new(RefCell::new(lower)),
|
||||
mtu: 1536 // FIXME: get the real value somehow
|
||||
mtu: mtu
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue