fix compile errors in gatunad
- io::last_os_error() -> io::Error::last_os_error() - MacAddr(mac.0) -> MacAddr(mac.octets()) for pnet 0.35 - cast htons() result to c_int for libc::socket protocol arg - mark read as mut in spawn_pump
This commit is contained in:
+14
-10
@@ -68,7 +68,7 @@ fn lookup_mac(iface: &str) -> io::Result<MacAddr> {
|
||||
for ni in pnet_datalink::interfaces() {
|
||||
if ni.name == iface {
|
||||
if let Some(mac) = ni.mac {
|
||||
return Ok(MacAddr(mac.0));
|
||||
return Ok(MacAddr(mac.octets()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,20 +81,24 @@ fn lookup_mac(iface: &str) -> io::Result<MacAddr> {
|
||||
impl Link {
|
||||
pub fn open(iface: &str) -> io::Result<Link> {
|
||||
unsafe {
|
||||
let fd = libc::socket(libc::AF_PACKET, libc::SOCK_RAW, htons(libc::ETH_P_ALL as u16));
|
||||
let fd = libc::socket(
|
||||
libc::AF_PACKET,
|
||||
libc::SOCK_RAW,
|
||||
htons(libc::ETH_P_ALL as u16) as libc::c_int,
|
||||
);
|
||||
if fd < 0 {
|
||||
return Err(io::last_os_error());
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
|
||||
// Non-blocking for AsyncFd.
|
||||
let flags = libc::fcntl(fd, libc::F_GETFL);
|
||||
if flags < 0 {
|
||||
let e = io::last_os_error();
|
||||
let e = io::Error::last_os_error();
|
||||
libc::close(fd);
|
||||
return Err(e);
|
||||
}
|
||||
if libc::fcntl(fd, libc::F_SETFL, flags | libc::O_NONBLOCK) < 0 {
|
||||
let e = io::last_os_error();
|
||||
let e = io::Error::last_os_error();
|
||||
libc::close(fd);
|
||||
return Err(e);
|
||||
}
|
||||
@@ -111,7 +115,7 @@ impl Link {
|
||||
};
|
||||
let ifindex = libc::if_nametoindex(ciface.as_ptr());
|
||||
if ifindex == 0 {
|
||||
let e = io::last_os_error();
|
||||
let e = io::Error::last_os_error();
|
||||
libc::close(fd);
|
||||
return Err(e);
|
||||
}
|
||||
@@ -127,7 +131,7 @@ impl Link {
|
||||
std::mem::size_of::<libc::sockaddr_ll>() as libc::socklen_t,
|
||||
);
|
||||
if r < 0 {
|
||||
let e = io::last_os_error();
|
||||
let e = io::Error::last_os_error();
|
||||
libc::close(fd);
|
||||
return Err(e);
|
||||
}
|
||||
@@ -146,7 +150,7 @@ impl Link {
|
||||
std::mem::size_of::<libc::sock_fprog>() as libc::socklen_t,
|
||||
);
|
||||
if r < 0 {
|
||||
let e = io::last_os_error();
|
||||
let e = io::Error::last_os_error();
|
||||
libc::close(fd);
|
||||
return Err(e);
|
||||
}
|
||||
@@ -191,7 +195,7 @@ impl Link {
|
||||
)
|
||||
};
|
||||
if n < 0 {
|
||||
return Err(io::last_os_error());
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
// Skip frames we transmitted (AF_PACKET with ETH_P_ALL loops them back).
|
||||
if sll.sll_pkttype == libc::PACKET_OUTGOING {
|
||||
@@ -239,7 +243,7 @@ impl Link {
|
||||
)
|
||||
};
|
||||
if r < 0 {
|
||||
return Err(io::last_os_error());
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ pub async fn write_to_session(
|
||||
/// 1480-byte chunks and emits DATA frames. On EOF/error sends CLOSE and
|
||||
/// removes the session from the store.
|
||||
pub fn spawn_pump(
|
||||
read: OwnedReadHalf,
|
||||
mut read: OwnedReadHalf,
|
||||
session_id: u32,
|
||||
peer_mac: MacAddr,
|
||||
tx: TxChan,
|
||||
|
||||
Reference in New Issue
Block a user