1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
Index: erbium-net/Cargo.toml
===================================================================
--- erbium-net.orig/Cargo.toml
+++ erbium-net/Cargo.toml
@@ -44,8 +44,8 @@ version = "0.8"
features = ["tokio_socket"]
[dependencies.nix]
-version = "0.26"
-features = ["net"]
+version = "0.27"
+features = ["net", "uio", "fs"]
[dependencies.tokio]
version = "1.8.4"
Index: erbium-net/src/raw.rs
===================================================================
--- erbium-net.orig/src/raw.rs
+++ erbium-net/src/raw.rs
@@ -21,6 +21,8 @@ use nix::sys::socket;
use std::io;
use std::os::unix::io::AsRawFd;
use std::os::unix::io::RawFd;
+use std::os::fd::BorrowedFd;
+use std::os::fd::AsFd;
use tokio::io::unix::AsyncFd;
use crate::{addr::NetAddr, udp};
@@ -74,6 +76,12 @@ impl AsRawFd for RawSocket {
}
}
+impl AsFd for RawSocket {
+ fn as_fd(&self) -> BorrowedFd<'_> {
+ unsafe { BorrowedFd::borrow_raw(self.fd.as_raw_fd()) }
+ }
+}
+
impl RawSocket {
pub fn new(protocol: EthProto) -> Result<Self> {
Ok(Self {
@@ -113,7 +121,7 @@ impl RawSocket {
opt: O,
val: &O::Val,
) -> Result<()> {
- nix::sys::socket::setsockopt(self.as_raw_fd(), opt, val).map_err(|e| e.into())
+ nix::sys::socket::setsockopt(self, opt, val).map_err(|e| e.into())
}
}
@@ -128,6 +136,12 @@ impl AsRawFd for CookedRawSocket {
}
}
+impl AsFd for CookedRawSocket {
+ fn as_fd(&self) -> BorrowedFd<'_> {
+ unsafe { BorrowedFd::borrow_raw(self.fd.as_raw_fd()) }
+ }
+}
+
impl CookedRawSocket {
pub fn new(protocol: EthProto) -> Result<Self> {
Ok(Self {
@@ -167,7 +181,7 @@ impl CookedRawSocket {
opt: O,
val: &O::Val,
) -> Result<()> {
- nix::sys::socket::setsockopt(self.as_raw_fd(), opt, val).map_err(|e| e.into())
+ nix::sys::socket::setsockopt(self, opt, val).map_err(|e| e.into())
}
}
@@ -182,6 +196,12 @@ impl AsRawFd for Raw6Socket {
}
}
+impl AsFd for Raw6Socket {
+ fn as_fd(&self) -> BorrowedFd<'_> {
+ unsafe { BorrowedFd::borrow_raw(self.fd.as_raw_fd()) }
+ }
+}
+
impl Raw6Socket {
pub fn new(protocol: IpProto) -> Result<Self> {
Ok(Self {
@@ -221,7 +241,7 @@ impl Raw6Socket {
opt: O,
val: &O::Val,
) -> Result<()> {
- nix::sys::socket::setsockopt(self.as_raw_fd(), opt, val).map_err(|e| e.into())
+ nix::sys::socket::setsockopt(self, opt, val).map_err(|e| e.into())
}
}
@@ -236,6 +256,13 @@ impl AsRawFd for Raw4Socket {
}
}
+impl AsFd for Raw4Socket {
+ fn as_fd(&self) -> BorrowedFd<'_> {
+ unsafe { BorrowedFd::borrow_raw(self.fd.as_raw_fd()) }
+ }
+}
+
+
impl Raw4Socket {
pub fn new(protocol: IpProto) -> Result<Self> {
Ok(Self {
@@ -275,6 +302,6 @@ impl Raw4Socket {
opt: O,
val: &O::Val,
) -> Result<()> {
- nix::sys::socket::setsockopt(fd, opt, val).map_err(|e| e.into())
+ nix::sys::socket::setsockopt(unsafe { &BorrowedFd::borrow_raw(fd) }, opt, val).map_err(|e| e.into())
}
}
Index: erbium-net/src/udp.rs
===================================================================
--- erbium-net.orig/src/udp.rs
+++ erbium-net/src/udp.rs
@@ -28,6 +28,7 @@ use std::convert::TryFrom;
use std::io;
use std::net;
use std::os::unix::io::AsRawFd as _;
+use std::os::fd::BorrowedFd;
use tokio::io::unix::AsyncFd;
use nix::libc;
@@ -104,7 +105,7 @@ impl UdpSocket {
pub fn set_opt_ipv4_packet_info(&self, b: bool) -> Result<(), io::Error> {
nix::sys::socket::setsockopt(
- self.fd.get_ref().as_raw_fd(),
+ unsafe { &BorrowedFd::borrow_raw(self.fd.get_ref().as_raw_fd()) },
nix::sys::socket::sockopt::Ipv4PacketInfo,
&b,
)
@@ -113,7 +114,7 @@ impl UdpSocket {
pub fn set_opt_ipv6_packet_info(&self, b: bool) -> Result<(), io::Error> {
nix::sys::socket::setsockopt(
- self.fd.get_ref().as_raw_fd(),
+ unsafe { &BorrowedFd::borrow_raw(self.fd.get_ref().as_raw_fd()) },
nix::sys::socket::sockopt::Ipv6RecvPacketInfo,
&b,
)
@@ -122,7 +123,7 @@ impl UdpSocket {
pub fn set_opt_reuse_port(&self, b: bool) -> Result<(), io::Error> {
nix::sys::socket::setsockopt(
- self.fd.get_ref().as_raw_fd(),
+ unsafe { &BorrowedFd::borrow_raw(self.fd.get_ref().as_raw_fd()) },
nix::sys::socket::sockopt::ReusePort,
&b,
)
|