Skip to content

Commit d5610e7

Browse files
committedJul 23, 2017
Determine MTU in TapInterface instead of hardcoding 1536.
1 parent c5fc8f7 commit d5610e7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎src/phy/sys/tap_interface.rs

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ impl TapInterfaceDesc {
3030
ifreq_ioctl(self.lower, &mut self.ifreq, imp::TUNSETIFF).map(|_| ())
3131
}
3232

33+
pub fn interface_mtu(&mut self) -> io::Result<usize> {
34+
let lower = unsafe {
35+
let lower = libc::socket(libc::AF_INET, libc::SOCK_DGRAM, libc::IPPROTO_IP);
36+
if lower == -1 { return Err(io::Error::last_os_error()) }
37+
lower
38+
};
39+
40+
ifreq_ioctl(lower, &mut self.ifreq, imp::SIOCGIFMTU).map(|mtu| mtu as usize)
41+
}
42+
3343
fn wait(&mut self, ms: u32) -> io::Result<bool> {
3444
unsafe {
3545
let mut readfds = mem::uninitialized::<libc::fd_set>();

‎src/phy/tap_interface.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ impl TapInterface {
2222
pub fn new(name: &str) -> io::Result<TapInterface> {
2323
let mut lower = sys::TapInterfaceDesc::new(name)?;
2424
lower.attach_interface()?;
25+
let mtu = lower.interface_mtu()?;
2526
Ok(TapInterface {
2627
lower: Rc::new(RefCell::new(lower)),
27-
mtu: 1536 // FIXME: get the real value somehow
28+
mtu: mtu
2829
})
2930
}
3031
}

0 commit comments

Comments
 (0)
Please sign in to comment.