Skip to content

Commit 35e4786

Browse files
committed
feat: add memoffset package and update nix dependency features; refactor TunAsyncDevice methods
1 parent 41985c6 commit 35e4786

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocol/raw/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ windows-sys = { version = "0.61.2", features = [
3737
] }
3838

3939
[target.'cfg(unix)'.dependencies]
40-
nix = "0.31.0"
40+
nix = { version = "0.31.0", features = ["net"] }
4141

4242
[features]
4343
default = []

protocol/raw/src/device/unix.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tokio_smoltcp::{
1313
smoltcp::{phy::Checksum, wire::IpAddress},
1414
};
1515
use tokio_util::codec::Framed;
16-
use tun_crate::{create_as_async, Configuration, Device, TunPacket, TunPacketCodec};
16+
use tun_crate::{create_as_async, AbstractDevice, Configuration, TunPacketCodec};
1717

1818
pub struct TunAsyncDevice {
1919
device_name: String,
@@ -37,11 +37,11 @@ pub fn get_tun(cfg: TunTapSetup) -> Result<TunAsyncDevice> {
3737
.up();
3838

3939
if let Some(name) = &cfg.name {
40-
config.name(name);
40+
config.tun_name(name);
4141
}
4242

4343
let dev = create_as_async(&config).map_err(map_other)?;
44-
let device_name = dev.get_ref().name().to_string();
44+
let device_name = dev.tun_name().map_err(map_other)?;
4545
let dev = dev.into_framed();
4646

4747
tracing::info!("tun created: {}", device_name);
@@ -68,7 +68,8 @@ impl Stream for TunAsyncDevice {
6868
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
6969
let p = ready!(self.dev.poll_next_unpin(cx));
7070

71-
Poll::Ready(p.map(|i| i.map(|p| p.get_bytes().to_vec())))
71+
// TunPacketCodec yields Vec<u8>
72+
Poll::Ready(p.map(|i| i.map(|p| p)))
7273
}
7374
}
7475

@@ -80,7 +81,7 @@ impl Sink<Packet> for TunAsyncDevice {
8081
}
8182

8283
fn start_send(mut self: Pin<&mut Self>, item: Packet) -> Result<(), Self::Error> {
83-
self.dev.start_send_unpin(TunPacket::new(item))
84+
self.dev.start_send_unpin(item)
8485
}
8586

8687
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {

rd-std/src/builtin/local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl LocalNetConfig {
142142
return Err(io::Error::last_os_error().into());
143143
}
144144

145-
socket.bind_device_by_index(std::num::NonZeroU32::new(idx))?;
145+
socket.bind_device_by_index_v4(std::num::NonZeroU32::new(idx))?;
146146
}
147147
}
148148

0 commit comments

Comments
 (0)