diff --git a/src/async/codec.rs b/src/async/codec.rs index 07b2b55a..49a2359f 100644 --- a/src/async/codec.rs +++ b/src/async/codec.rs @@ -14,7 +14,6 @@ use std::io; -use byteorder::{NativeEndian, NetworkEndian, WriteBytesExt}; use bytes::{BufMut, Bytes, BytesMut}; use tokio_util::codec::{Decoder, Encoder}; @@ -54,6 +53,7 @@ impl PacketProtocol { } #[cfg(target_os = "windows")] + #[allow(dead_code)] fn into_pi_field(self) -> Result { unimplemented!() } @@ -134,17 +134,22 @@ impl Encoder for TunPacketCodec { fn encode(&mut self, item: TunPacket, dst: &mut BytesMut) -> Result<(), Self::Error> { dst.reserve(item.get_bytes().len() + 4); match item { - TunPacket(proto, bytes) if self.0 => { - // build the packet information header comprising of 2 u16 - // fields: flags and protocol. - let mut buf = Vec::::with_capacity(4); - - // flags is always 0 - buf.write_u16::(0)?; - // write the protocol as network byte order - buf.write_u16::(proto.into_pi_field()?)?; - - dst.put_slice(&buf); + TunPacket(_proto, bytes) if self.0 => { + #[cfg(unix)] + { + use byteorder::{NativeEndian, NetworkEndian, WriteBytesExt}; + + // build the packet information header comprising of 2 u16 + // fields: flags and protocol. + let mut buf = Vec::::with_capacity(4); + + // flags is always 0 + buf.write_u16::(0)?; + // write the protocol as network byte order + buf.write_u16::(_proto.into_pi_field()?)?; + + dst.put_slice(&buf); + } dst.put(bytes); } TunPacket(_, bytes) => dst.put(bytes),