From bbd3d5c2a0b1ac1831023936bf89c1eb294a04ed Mon Sep 17 00:00:00 2001 From: shellrow Date: Sun, 9 Nov 2025 16:26:06 +0900 Subject: [PATCH 1/5] chore: replace non-ASCII symbols --- nex-core/src/ip.rs | 2 +- nex-packet/src/icmpv6.rs | 48 ++++++++++++++++++++-------------------- nex-packet/src/tcp.rs | 16 +++++++------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/nex-core/src/ip.rs b/nex-core/src/ip.rs index 0aecf41..42893ff 100644 --- a/nex-core/src/ip.rs +++ b/nex-core/src/ip.rs @@ -56,7 +56,7 @@ pub fn is_global_ipv6(ipv6_addr: &Ipv6Addr) -> bool { // Drone Remote ID Protocol Entity Tags (DETs) Prefix (`2001:30::/28`)` || matches!(ipv6_addr.segments(), [0x2001, b, _, _, _, _, _, _] if b >= 0x20 && b <= 0x3F) )) - // 6to4 (`2002::/16`) – it's not explicitly documented as globally reachable, + // 6to4 (`2002::/16`) - it's not explicitly documented as globally reachable, // IANA says N/A. || matches!(ipv6_addr.segments(), [0x2002, _, _, _, _, _, _, _]) || is_documentation_ipv6(ipv6_addr) diff --git a/nex-packet/src/icmpv6.rs b/nex-packet/src/icmpv6.rs index da71766..308aa07 100644 --- a/nex-packet/src/icmpv6.rs +++ b/nex-packet/src/icmpv6.rs @@ -647,15 +647,15 @@ pub mod ndp { } } - /// Neighbor Discovery Option Types [RFC 4861 § 4.6] + /// Neighbor Discovery Option Types [RFC 4861 Section 4.6] /// - /// [RFC 4861 § 4.6]: https://tools.ietf.org/html/rfc4861#section-4.6 + /// [RFC 4861 Section 4.6]: https://tools.ietf.org/html/rfc4861#section-4.6 #[allow(non_snake_case)] #[allow(non_upper_case_globals)] pub mod NdpOptionTypes { use super::NdpOptionType; - /// Source Link-Layer Address Option [RFC 4861 § 4.6.1] + /// Source Link-Layer Address Option [RFC 4861 Section 4.6.1] /// /// ```text /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -663,10 +663,10 @@ pub mod ndp { /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// ``` /// - /// [RFC 4861 § 4.6.1]: https://tools.ietf.org/html/rfc4861#section-4.6.1 + /// [RFC 4861 Section 4.6.1]: https://tools.ietf.org/html/rfc4861#section-4.6.1 pub const SourceLLAddr: NdpOptionType = NdpOptionType(1); - /// Target Link-Layer Address Option [RFC 4861 § 4.6.1] + /// Target Link-Layer Address Option [RFC 4861 Section 4.6.1] /// /// ```text /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -674,10 +674,10 @@ pub mod ndp { /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// ``` /// - /// [RFC 4861 § 4.6.1]: https://tools.ietf.org/html/rfc4861#section-4.6.1 + /// [RFC 4861 Section 4.6.1]: https://tools.ietf.org/html/rfc4861#section-4.6.1 pub const TargetLLAddr: NdpOptionType = NdpOptionType(2); - /// Prefix Information Option [RFC 4861 § 4.6.2] + /// Prefix Information Option [RFC 4861 Section 4.6.2] /// /// ```text /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -699,10 +699,10 @@ pub mod ndp { /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// ``` /// - /// [RFC 4861 § 4.6.2]: https://tools.ietf.org/html/rfc4861#section-4.6.2 + /// [RFC 4861 Section 4.6.2]: https://tools.ietf.org/html/rfc4861#section-4.6.2 pub const PrefixInformation: NdpOptionType = NdpOptionType(3); - /// Redirected Header Option [RFC 4861 § 4.6.3] + /// Redirected Header Option [RFC 4861 Section 4.6.3] /// /// ```text /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -716,10 +716,10 @@ pub mod ndp { /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// ``` /// - /// [RFC 4861 § 4.6.3]: https://tools.ietf.org/html/rfc4861#section-4.6.3 + /// [RFC 4861 Section 4.6.3]: https://tools.ietf.org/html/rfc4861#section-4.6.3 pub const RedirectedHeader: NdpOptionType = NdpOptionType(4); - /// MTU Option [RFC 4861 § 4.6.4] + /// MTU Option [RFC 4861 Section 4.6.4] /// /// ```text /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -729,11 +729,11 @@ pub mod ndp { /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// ``` /// - /// [RFC 4861 § 4.6.4]: https://tools.ietf.org/html/rfc4861#section-4.6.4 + /// [RFC 4861 Section 4.6.4]: https://tools.ietf.org/html/rfc4861#section-4.6.4 pub const MTU: NdpOptionType = NdpOptionType(5); } - /// Neighbor Discovery Option [RFC 4861 § 4.6] + /// Neighbor Discovery Option [RFC 4861 Section 4.6] /// /// ```text /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -743,7 +743,7 @@ pub mod ndp { /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /// ``` /// - /// [RFC 4861 § 4.6]: https://tools.ietf.org/html/rfc4861#section-4.6 + /// [RFC 4861 Section 4.6]: https://tools.ietf.org/html/rfc4861#section-4.6 #[derive(Clone, Debug, PartialEq, Eq)] pub struct NdpOptionPacket { pub option_type: NdpOptionType, @@ -827,7 +827,7 @@ pub mod ndp { /// Calculate a length of a `NdpOption`'s payload. - /// Router Solicitation Message [RFC 4861 § 4.1] + /// Router Solicitation Message [RFC 4861 Section 4.1] /// /// ```text /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -838,7 +838,7 @@ pub mod ndp { /// | Options ... /// ``` /// - /// [RFC 4861 § 4.1]: https://tools.ietf.org/html/rfc4861#section-4.1 + /// [RFC 4861 Section 4.1]: https://tools.ietf.org/html/rfc4861#section-4.1 #[derive(Clone, Debug, PartialEq, Eq)] pub struct RouterSolicitPacket { pub header: Icmpv6Header, @@ -998,7 +998,7 @@ pub mod ndp { pub const OtherConf: u8 = 0b01000000; } - /// Router Advertisement Message Format [RFC 4861 § 4.2] + /// Router Advertisement Message Format [RFC 4861 Section 4.2] /// /// ```text /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -1014,7 +1014,7 @@ pub mod ndp { /// +-+-+-+-+-+-+-+-+-+-+-+- /// ``` /// - /// [RFC 4861 § 4.2]: https://tools.ietf.org/html/rfc4861#section-4.2 + /// [RFC 4861 Section 4.2]: https://tools.ietf.org/html/rfc4861#section-4.2 #[derive(Clone, Debug, PartialEq, Eq)] pub struct RouterAdvertPacket { pub header: Icmpv6Header, @@ -1190,7 +1190,7 @@ pub mod ndp { } } - /// Neighbor Solicitation Message Format [RFC 4861 § 4.3] + /// Neighbor Solicitation Message Format [RFC 4861 Section 4.3] /// /// ```text /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -1210,7 +1210,7 @@ pub mod ndp { /// +-+-+-+-+-+-+-+-+-+-+-+- /// ``` /// - /// [RFC 4861 § 4.3]: https://tools.ietf.org/html/rfc4861#section-4.3 + /// [RFC 4861 Section 4.3]: https://tools.ietf.org/html/rfc4861#section-4.3 #[derive(Clone, Debug, PartialEq, Eq)] pub struct NeighborSolicitPacket { pub header: Icmpv6Header, @@ -1397,7 +1397,7 @@ pub mod ndp { pub const Override: u8 = 0b00100000; } - /// Neighbor Advertisement Message Format [RFC 4861 § 4.4] + /// Neighbor Advertisement Message Format [RFC 4861 Section 4.4] /// /// ```text /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -1417,7 +1417,7 @@ pub mod ndp { /// +-+-+-+-+-+-+-+-+-+-+-+- /// ``` /// - /// [RFC 4861 § 4.4]: https://tools.ietf.org/html/rfc4861#section-4.4 + /// [RFC 4861 Section 4.4]: https://tools.ietf.org/html/rfc4861#section-4.4 #[derive(Clone, Debug, PartialEq, Eq)] pub struct NeighborAdvertPacket { pub header: Icmpv6Header, @@ -1606,7 +1606,7 @@ pub mod ndp { } } - /// Redirect Message Format [RFC 4861 § 4.5] + /// Redirect Message Format [RFC 4861 Section 4.5] /// /// ```text /// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -1634,7 +1634,7 @@ pub mod ndp { /// +-+-+-+-+-+-+-+-+-+-+-+- /// ``` /// - /// [RFC 4861 § 4.5]: https://tools.ietf.org/html/rfc4861#section-4.5 + /// [RFC 4861 Section 4.5]: https://tools.ietf.org/html/rfc4861#section-4.5 #[derive(Clone, Debug, PartialEq, Eq)] pub struct RedirectPacket { pub header: Icmpv6Header, diff --git a/nex-packet/src/tcp.rs b/nex-packet/src/tcp.rs index d0e62bc..d4b5983 100644 --- a/nex-packet/src/tcp.rs +++ b/nex-packet/src/tcp.rs @@ -242,29 +242,29 @@ impl TcpOptionKind { #[allow(non_snake_case)] #[allow(non_upper_case_globals)] pub mod TcpFlags { - /// CWR – Congestion Window Reduced (CWR) flag is set by the sending + /// CWR - Congestion Window Reduced (CWR) flag is set by the sending /// host to indicate that it received a TCP segment with the ECE flag set /// and had responded in congestion control mechanism. pub const CWR: u8 = 0b10000000; - /// ECE – ECN-Echo has a dual role, depending on the value of the + /// ECE - ECN-Echo has a dual role, depending on the value of the /// SYN flag. It indicates: /// If the SYN flag is set (1), that the TCP peer is ECN capable. /// If the SYN flag is clear (0), that a packet with Congestion Experienced /// flag set (ECN=11) in IP header received during normal transmission. pub const ECE: u8 = 0b01000000; - /// URG – indicates that the Urgent pointer field is significant. + /// URG - indicates that the Urgent pointer field is significant. pub const URG: u8 = 0b00100000; - /// ACK – indicates that the Acknowledgment field is significant. + /// ACK - indicates that the Acknowledgment field is significant. /// All packets after the initial SYN packet sent by the client should have this flag set. pub const ACK: u8 = 0b00010000; - /// PSH – Push function. Asks to push the buffered data to the receiving application. + /// PSH - Push function. Asks to push the buffered data to the receiving application. pub const PSH: u8 = 0b00001000; - /// RST – Reset the connection. + /// RST - Reset the connection. pub const RST: u8 = 0b00000100; - /// SYN – Synchronize sequence numbers. Only the first packet sent from each end + /// SYN - Synchronize sequence numbers. Only the first packet sent from each end /// should have this flag set. pub const SYN: u8 = 0b00000010; - /// FIN – No more data from sender. + /// FIN - No more data from sender. pub const FIN: u8 = 0b00000001; } From c0fc71601a50815b01a4dc2786a408f95aae93cc Mon Sep 17 00:00:00 2001 From: shellrow Date: Sun, 9 Nov 2025 16:40:59 +0900 Subject: [PATCH 2/5] Upgrade to Rust 2024 edition --- Cargo.toml | 2 +- examples/async_dump.rs | 24 ++++++++++++------------ examples/async_icmp_socket.rs | 2 +- examples/dump.rs | 24 ++++++++++++------------ nex-datalink/src/bindings/bpf.rs | 2 +- nex-packet/src/dns.rs | 6 +++--- nex-packet/src/packet.rs | 6 +++--- nex-sys/src/unix.rs | 12 ++++++------ 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7422655..bfbe76d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ [workspace.package] version = "0.23.2" -edition = "2021" +edition = "2024" authors = ["shellrow "] [workspace.dependencies] diff --git a/examples/async_dump.rs b/examples/async_dump.rs index ff58247..4046172 100644 --- a/examples/async_dump.rs +++ b/examples/async_dump.rs @@ -96,7 +96,7 @@ fn handle_ethernet_frame(ethernet: EthernetPacket) { } fn handle_arp_packet(packet: Bytes) { - if let Some(arp) = ArpPacket::from_bytes(packet) { + match ArpPacket::from_bytes(packet) { Some(arp) => { println!( "ARP packet: {}({}) > {}({}); operation: {:?}", arp.header.sender_hw_addr, @@ -105,35 +105,35 @@ fn handle_arp_packet(packet: Bytes) { arp.header.target_proto_addr, arp.header.operation ); - } else { + } _ => { println!("Malformed ARP Packet"); - } + }} } fn handle_ipv4_packet(packet: Bytes) { - if let Some(ipv4) = Ipv4Packet::from_bytes(packet) { + match Ipv4Packet::from_bytes(packet) { Some(ipv4) => { handle_transport_protocol( IpAddr::V4(ipv4.header.source), IpAddr::V4(ipv4.header.destination), ipv4.header.next_level_protocol, ipv4.payload, ); - } else { + } _ => { println!("Malformed IPv4 Packet"); - } + }} } fn handle_ipv6_packet(packet: Bytes) { - if let Some(ipv6) = Ipv6Packet::from_bytes(packet) { + match Ipv6Packet::from_bytes(packet) { Some(ipv6) => { handle_transport_protocol( IpAddr::V6(ipv6.header.source), IpAddr::V6(ipv6.header.destination), ipv6.header.next_header, ipv6.payload, ); - } else { + } _ => { println!("Malformed IPv6 Packet"); - } + }} } fn handle_transport_protocol( @@ -162,7 +162,7 @@ fn handle_transport_protocol( } fn handle_tcp_packet(source: IpAddr, destination: IpAddr, packet: Bytes) { - if let Some(tcp) = TcpPacket::from_bytes(packet) { + match TcpPacket::from_bytes(packet) { Some(tcp) => { println!( "TCP Packet: {}:{} > {}:{}; length: {}", source, @@ -171,9 +171,9 @@ fn handle_tcp_packet(source: IpAddr, destination: IpAddr, packet: Bytes) { tcp.header.destination, tcp.total_len(), ); - } else { + } _ => { println!("Malformed TCP Packet"); - } + }} } fn handle_udp_packet(source: IpAddr, destination: IpAddr, packet: Bytes) { diff --git a/examples/async_icmp_socket.rs b/examples/async_icmp_socket.rs index 93fa3cc..89f39af 100644 --- a/examples/async_icmp_socket.rs +++ b/examples/async_icmp_socket.rs @@ -87,7 +87,7 @@ async fn main() -> std::io::Result<()> { let mut handles = Vec::new(); for i in 1u8..=254 { let addr = Ipv4Addr::new(parts[0], parts[1], parts[2], i); - let id: u16 = thread_rng().gen(); + let id: u16 = thread_rng().r#gen(); let seq: u16 = 1; let socket = socket.clone(); let replies = replies.clone(); diff --git a/examples/dump.rs b/examples/dump.rs index 8075bc1..babcd9e 100644 --- a/examples/dump.rs +++ b/examples/dump.rs @@ -119,7 +119,7 @@ fn handle_ethernet_frame(ethernet: EthernetPacket) { } fn handle_arp_packet(packet: Bytes) { - if let Some(arp) = ArpPacket::from_bytes(packet) { + match ArpPacket::from_bytes(packet) { Some(arp) => { println!( "ARP packet: {}({}) > {}({}); operation: {:?}", arp.header.sender_hw_addr, @@ -128,35 +128,35 @@ fn handle_arp_packet(packet: Bytes) { arp.header.target_proto_addr, arp.header.operation ); - } else { + } _ => { println!("Malformed ARP Packet"); - } + }} } fn handle_ipv4_packet(packet: Bytes) { - if let Some(ipv4) = Ipv4Packet::from_bytes(packet) { + match Ipv4Packet::from_bytes(packet) { Some(ipv4) => { handle_transport_protocol( IpAddr::V4(ipv4.header.source), IpAddr::V4(ipv4.header.destination), ipv4.header.next_level_protocol, ipv4.payload, ); - } else { + } _ => { println!("Malformed IPv4 Packet"); - } + }} } fn handle_ipv6_packet(packet: Bytes) { - if let Some(ipv6) = Ipv6Packet::from_bytes(packet) { + match Ipv6Packet::from_bytes(packet) { Some(ipv6) => { handle_transport_protocol( IpAddr::V6(ipv6.header.source), IpAddr::V6(ipv6.header.destination), ipv6.header.next_header, ipv6.payload, ); - } else { + } _ => { println!("Malformed IPv6 Packet"); - } + }} } fn handle_transport_protocol( @@ -185,7 +185,7 @@ fn handle_transport_protocol( } fn handle_tcp_packet(source: IpAddr, destination: IpAddr, packet: Bytes) { - if let Some(tcp) = TcpPacket::from_bytes(packet) { + match TcpPacket::from_bytes(packet) { Some(tcp) => { println!( "TCP Packet: {}:{} > {}:{}; length: {}", source, @@ -194,9 +194,9 @@ fn handle_tcp_packet(source: IpAddr, destination: IpAddr, packet: Bytes) { tcp.header.destination, tcp.total_len(), ); - } else { + } _ => { println!("Malformed TCP Packet"); - } + }} } fn handle_udp_packet(source: IpAddr, destination: IpAddr, packet: Bytes) { diff --git a/nex-datalink/src/bindings/bpf.rs b/nex-datalink/src/bindings/bpf.rs index 6f1fd73..dc53470 100644 --- a/nex-datalink/src/bindings/bpf.rs +++ b/nex-datalink/src/bindings/bpf.rs @@ -142,6 +142,6 @@ pub struct bpf_hdr { } #[cfg(not(windows))] -extern "C" { +unsafe extern "C" { pub fn ioctl(d: libc::c_int, request: libc::c_ulong, ...) -> libc::c_int; } diff --git a/nex-packet/src/dns.rs b/nex-packet/src/dns.rs index 33d214f..6d33227 100644 --- a/nex-packet/src/dns.rs +++ b/nex-packet/src/dns.rs @@ -1056,11 +1056,11 @@ impl Packet for DnsPacket { fn parse_responses(count: usize, buf: &mut &[u8]) -> Option> { let mut packets = Vec::with_capacity(count); for _ in 0..count { - if let Some(pkt) = DnsResponsePacket::from_buf_mut(buf) { + match DnsResponsePacket::from_buf_mut(buf) { Some(pkt) => { packets.push(pkt); - } else { + } _ => { break; - } + }} } Some(packets) } diff --git a/nex-packet/src/packet.rs b/nex-packet/src/packet.rs index 665aa39..52fe9e4 100644 --- a/nex-packet/src/packet.rs +++ b/nex-packet/src/packet.rs @@ -143,12 +143,12 @@ impl<'a, P: Packet> GenericMutablePacket<'a, P> { } fn lengths(&self) -> (usize, usize) { - if let Some(packet) = P::from_buf(self.packet()) { + match P::from_buf(self.packet()) { Some(packet) => { let header_len = packet.header_len(); let payload_len = packet.payload_len(); (header_len, payload_len) - } else { + } _ => { (self.buffer.len(), 0) - } + }} } } diff --git a/nex-sys/src/unix.rs b/nex-sys/src/unix.rs index a6c7e97..9706e25 100644 --- a/nex-sys/src/unix.rs +++ b/nex-sys/src/unix.rs @@ -29,9 +29,9 @@ pub const AF_INET6: libc::c_int = libc::AF_INET6; pub use libc::{IFF_BROADCAST, IFF_LOOPBACK, IFF_MULTICAST, IFF_POINTOPOINT, IFF_UP}; -pub unsafe fn close(sock: CSocket) { +pub unsafe fn close(sock: CSocket) { unsafe { let _ = libc::close(sock); -} +}} fn ntohs(u: u16) -> u16 { u16::from_be(u) @@ -115,9 +115,9 @@ pub unsafe fn sendto( flags: libc::c_int, addr: *const SockAddr, addrlen: SockLen, -) -> CouldFail { +) -> CouldFail { unsafe { libc::sendto(socket, buf, len, flags, addr, addrlen) -} +}} pub unsafe fn recvfrom( socket: CSocket, @@ -126,9 +126,9 @@ pub unsafe fn recvfrom( flags: libc::c_int, addr: *mut SockAddr, addrlen: *mut SockLen, -) -> CouldFail { +) -> CouldFail { unsafe { libc::recvfrom(socket, buf, len, flags, addr, addrlen) -} +}} #[inline] pub fn retry(f: &mut F) -> libc::ssize_t From 3a1bdb08ed28c3c7ecbece483c8704c8a40a49e9 Mon Sep 17 00:00:00 2001 From: shellrow <81893184+shellrow@users.noreply.github.com> Date: Sun, 9 Nov 2025 16:48:26 +0900 Subject: [PATCH 3/5] run cargo fix --edition on Windows Upgrade to Rust 2024 edition --- nex-datalink/src/bindings/windows.rs | 2 +- nex-sys/src/windows.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/nex-datalink/src/bindings/windows.rs b/nex-datalink/src/bindings/windows.rs index ef5f803..ea11767 100644 --- a/nex-datalink/src/bindings/windows.rs +++ b/nex-datalink/src/bindings/windows.rs @@ -51,7 +51,7 @@ pub fn to_npf_name(name: &str) -> String { #[link(name = "Packet")] #[allow(improper_ctypes)] -extern "C" { +unsafe extern "C" { // from Packet32.h pub fn PacketSendPacket(AdapterObject: LPADAPTER, pPacket: LPPACKET, Sync: BOOLEAN) -> BOOLEAN; pub fn PacketReceivePacket( diff --git a/nex-sys/src/windows.rs b/nex-sys/src/windows.rs index 472aaa0..013dc2e 100644 --- a/nex-sys/src/windows.rs +++ b/nex-sys/src/windows.rs @@ -22,9 +22,9 @@ pub type SockAddrFamily6 = ws::ADDRESS_FAMILY; pub type InAddr = ws::IN_ADDR; pub type In6Addr = ws::IN6_ADDR; -pub unsafe fn close(sock: CSocket) { +pub unsafe fn close(sock: CSocket) { unsafe { let _ = ws::closesocket(sock); -} +}} pub unsafe fn sendto( socket: CSocket, @@ -33,9 +33,9 @@ pub unsafe fn sendto( flags: libc::c_int, to: *const SockAddr, tolen: SockLen, -) -> CouldFail { +) -> CouldFail { unsafe { ws::sendto(socket, buf as *const u8, len, flags, to, tolen) -} +}} pub unsafe fn recvfrom( socket: CSocket, @@ -44,9 +44,9 @@ pub unsafe fn recvfrom( flags: libc::c_int, addr: *mut SockAddr, addrlen: *mut SockLen, -) -> CouldFail { +) -> CouldFail { unsafe { ws::recvfrom(socket, buf as *mut u8, len, flags, addr, addrlen) -} +}} #[inline] pub fn retry(f: &mut F) -> libc::c_int From ca36ee8d22224007a321c43a0ebfc6efe11d6a12 Mon Sep 17 00:00:00 2001 From: shellrow Date: Sun, 9 Nov 2025 16:53:33 +0900 Subject: [PATCH 4/5] Format code with cargo fmt --- examples/arp.rs | 2 +- examples/async_datalink.rs | 2 +- examples/async_dump.rs | 102 +++++++++++++++------------ examples/async_icmp_socket.rs | 4 +- examples/dump.rs | 100 ++++++++++++++------------ examples/icmp_socket.rs | 2 +- examples/mutable_chaining.rs | 6 +- examples/ndp.rs | 2 +- nex-datalink/src/async_io/bpf.rs | 2 +- nex-datalink/src/async_io/wpcap.rs | 2 +- nex-datalink/src/bindings/windows.rs | 2 +- nex-packet/src/arp.rs | 2 +- nex-packet/src/builder/ndp.rs | 2 +- nex-packet/src/builder/udp.rs | 2 +- nex-packet/src/dns.rs | 13 ++-- nex-packet/src/gre.rs | 2 +- nex-packet/src/icmpv6.rs | 10 +-- nex-packet/src/packet.rs | 15 ++-- nex-packet/src/tcp.rs | 2 +- nex-packet/src/util.rs | 2 +- nex-socket/src/icmp/async_impl.rs | 2 +- nex-socket/src/icmp/sync_impl.rs | 2 +- nex-socket/src/tcp/sync_impl.rs | 4 +- nex-sys/src/unix.rs | 20 +++--- nex-sys/src/windows.rs | 20 +++--- 25 files changed, 176 insertions(+), 148 deletions(-) diff --git a/examples/arp.rs b/examples/arp.rs index 64df91a..2cc1b84 100644 --- a/examples/arp.rs +++ b/examples/arp.rs @@ -8,7 +8,7 @@ use nex::datalink; use nex::datalink::Channel::Ethernet; -use nex::net::interface::{get_interfaces, Interface}; +use nex::net::interface::{Interface, get_interfaces}; use nex::net::mac::MacAddr; use nex::packet::builder::ethernet::EthernetPacketBuilder; use nex::packet::ethernet::EtherType; diff --git a/examples/async_datalink.rs b/examples/async_datalink.rs index 0b60f40..77805c9 100644 --- a/examples/async_datalink.rs +++ b/examples/async_datalink.rs @@ -13,8 +13,8 @@ use nex::packet::frame::{Frame, ParseOption}; use nex::packet::icmp::IcmpType; use nex::packet::icmpv6::Icmpv6Type; use nex_core::interface::Interface; -use nex_datalink::async_io::{async_channel, AsyncChannel}; use nex_datalink::Config; +use nex_datalink::async_io::{AsyncChannel, async_channel}; use nex_packet::ip::IpNextProtocol; use nex_packet::ipv4::Ipv4Flags; use nex_packet::packet::Packet; diff --git a/examples/async_dump.rs b/examples/async_dump.rs index 4046172..7084615 100644 --- a/examples/async_dump.rs +++ b/examples/async_dump.rs @@ -14,8 +14,8 @@ use nex::packet::ipv6::Ipv6Packet; use nex::packet::packet::Packet; use nex::packet::tcp::TcpPacket; use nex::packet::udp::UdpPacket; -use nex_datalink::async_io::{async_channel, AsyncChannel}; use nex_datalink::Config; +use nex_datalink::async_io::{AsyncChannel, async_channel}; use nex_packet::ethernet::EthernetHeader; use nex_packet::{icmp, icmpv6}; use std::net::IpAddr; @@ -96,44 +96,53 @@ fn handle_ethernet_frame(ethernet: EthernetPacket) { } fn handle_arp_packet(packet: Bytes) { - match ArpPacket::from_bytes(packet) { Some(arp) => { - println!( - "ARP packet: {}({}) > {}({}); operation: {:?}", - arp.header.sender_hw_addr, - arp.header.sender_proto_addr, - arp.header.target_hw_addr, - arp.header.target_proto_addr, - arp.header.operation - ); - } _ => { - println!("Malformed ARP Packet"); - }} + match ArpPacket::from_bytes(packet) { + Some(arp) => { + println!( + "ARP packet: {}({}) > {}({}); operation: {:?}", + arp.header.sender_hw_addr, + arp.header.sender_proto_addr, + arp.header.target_hw_addr, + arp.header.target_proto_addr, + arp.header.operation + ); + } + _ => { + println!("Malformed ARP Packet"); + } + } } fn handle_ipv4_packet(packet: Bytes) { - match Ipv4Packet::from_bytes(packet) { Some(ipv4) => { - handle_transport_protocol( - IpAddr::V4(ipv4.header.source), - IpAddr::V4(ipv4.header.destination), - ipv4.header.next_level_protocol, - ipv4.payload, - ); - } _ => { - println!("Malformed IPv4 Packet"); - }} + match Ipv4Packet::from_bytes(packet) { + Some(ipv4) => { + handle_transport_protocol( + IpAddr::V4(ipv4.header.source), + IpAddr::V4(ipv4.header.destination), + ipv4.header.next_level_protocol, + ipv4.payload, + ); + } + _ => { + println!("Malformed IPv4 Packet"); + } + } } fn handle_ipv6_packet(packet: Bytes) { - match Ipv6Packet::from_bytes(packet) { Some(ipv6) => { - handle_transport_protocol( - IpAddr::V6(ipv6.header.source), - IpAddr::V6(ipv6.header.destination), - ipv6.header.next_header, - ipv6.payload, - ); - } _ => { - println!("Malformed IPv6 Packet"); - }} + match Ipv6Packet::from_bytes(packet) { + Some(ipv6) => { + handle_transport_protocol( + IpAddr::V6(ipv6.header.source), + IpAddr::V6(ipv6.header.destination), + ipv6.header.next_header, + ipv6.payload, + ); + } + _ => { + println!("Malformed IPv6 Packet"); + } + } } fn handle_transport_protocol( @@ -162,18 +171,21 @@ fn handle_transport_protocol( } fn handle_tcp_packet(source: IpAddr, destination: IpAddr, packet: Bytes) { - match TcpPacket::from_bytes(packet) { Some(tcp) => { - println!( - "TCP Packet: {}:{} > {}:{}; length: {}", - source, - tcp.header.source, - destination, - tcp.header.destination, - tcp.total_len(), - ); - } _ => { - println!("Malformed TCP Packet"); - }} + match TcpPacket::from_bytes(packet) { + Some(tcp) => { + println!( + "TCP Packet: {}:{} > {}:{}; length: {}", + source, + tcp.header.source, + destination, + tcp.header.destination, + tcp.total_len(), + ); + } + _ => { + println!("Malformed TCP Packet"); + } + } } fn handle_udp_packet(source: IpAddr, destination: IpAddr, packet: Bytes) { diff --git a/examples/async_icmp_socket.rs b/examples/async_icmp_socket.rs index 89f39af..fb55e85 100644 --- a/examples/async_icmp_socket.rs +++ b/examples/async_icmp_socket.rs @@ -4,14 +4,14 @@ //! Example: async_icmp_socket 192.168.1 use bytes::Bytes; -use nex::net::interface::{get_interfaces, Interface}; +use nex::net::interface::{Interface, get_interfaces}; use nex_packet::builder::icmp::IcmpPacketBuilder; use nex_packet::icmp::echo_reply::EchoReplyPacket; use nex_packet::icmp::{self, IcmpPacket, IcmpType}; use nex_packet::ipv4::Ipv4Packet; use nex_packet::packet::Packet; use nex_socket::icmp::{AsyncIcmpSocket, IcmpConfig, IcmpKind}; -use rand::{thread_rng, Rng}; +use rand::{Rng, thread_rng}; use std::collections::HashMap; use std::env; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; diff --git a/examples/dump.rs b/examples/dump.rs index babcd9e..1169d44 100644 --- a/examples/dump.rs +++ b/examples/dump.rs @@ -119,44 +119,53 @@ fn handle_ethernet_frame(ethernet: EthernetPacket) { } fn handle_arp_packet(packet: Bytes) { - match ArpPacket::from_bytes(packet) { Some(arp) => { - println!( - "ARP packet: {}({}) > {}({}); operation: {:?}", - arp.header.sender_hw_addr, - arp.header.sender_proto_addr, - arp.header.target_hw_addr, - arp.header.target_proto_addr, - arp.header.operation - ); - } _ => { - println!("Malformed ARP Packet"); - }} + match ArpPacket::from_bytes(packet) { + Some(arp) => { + println!( + "ARP packet: {}({}) > {}({}); operation: {:?}", + arp.header.sender_hw_addr, + arp.header.sender_proto_addr, + arp.header.target_hw_addr, + arp.header.target_proto_addr, + arp.header.operation + ); + } + _ => { + println!("Malformed ARP Packet"); + } + } } fn handle_ipv4_packet(packet: Bytes) { - match Ipv4Packet::from_bytes(packet) { Some(ipv4) => { - handle_transport_protocol( - IpAddr::V4(ipv4.header.source), - IpAddr::V4(ipv4.header.destination), - ipv4.header.next_level_protocol, - ipv4.payload, - ); - } _ => { - println!("Malformed IPv4 Packet"); - }} + match Ipv4Packet::from_bytes(packet) { + Some(ipv4) => { + handle_transport_protocol( + IpAddr::V4(ipv4.header.source), + IpAddr::V4(ipv4.header.destination), + ipv4.header.next_level_protocol, + ipv4.payload, + ); + } + _ => { + println!("Malformed IPv4 Packet"); + } + } } fn handle_ipv6_packet(packet: Bytes) { - match Ipv6Packet::from_bytes(packet) { Some(ipv6) => { - handle_transport_protocol( - IpAddr::V6(ipv6.header.source), - IpAddr::V6(ipv6.header.destination), - ipv6.header.next_header, - ipv6.payload, - ); - } _ => { - println!("Malformed IPv6 Packet"); - }} + match Ipv6Packet::from_bytes(packet) { + Some(ipv6) => { + handle_transport_protocol( + IpAddr::V6(ipv6.header.source), + IpAddr::V6(ipv6.header.destination), + ipv6.header.next_header, + ipv6.payload, + ); + } + _ => { + println!("Malformed IPv6 Packet"); + } + } } fn handle_transport_protocol( @@ -185,18 +194,21 @@ fn handle_transport_protocol( } fn handle_tcp_packet(source: IpAddr, destination: IpAddr, packet: Bytes) { - match TcpPacket::from_bytes(packet) { Some(tcp) => { - println!( - "TCP Packet: {}:{} > {}:{}; length: {}", - source, - tcp.header.source, - destination, - tcp.header.destination, - tcp.total_len(), - ); - } _ => { - println!("Malformed TCP Packet"); - }} + match TcpPacket::from_bytes(packet) { + Some(tcp) => { + println!( + "TCP Packet: {}:{} > {}:{}; length: {}", + source, + tcp.header.source, + destination, + tcp.header.destination, + tcp.total_len(), + ); + } + _ => { + println!("Malformed TCP Packet"); + } + } } fn handle_udp_packet(source: IpAddr, destination: IpAddr, packet: Bytes) { diff --git a/examples/icmp_socket.rs b/examples/icmp_socket.rs index a666057..375ff54 100644 --- a/examples/icmp_socket.rs +++ b/examples/icmp_socket.rs @@ -3,7 +3,7 @@ //! Usage: icmp_socket use bytes::Bytes; -use nex::net::interface::{get_interfaces, Interface}; +use nex::net::interface::{Interface, get_interfaces}; use nex_packet::builder::icmp::IcmpPacketBuilder; use nex_packet::builder::icmpv6::Icmpv6PacketBuilder; use nex_packet::icmp::IcmpPacket; diff --git a/examples/mutable_chaining.rs b/examples/mutable_chaining.rs index db53b4b..3fb826e 100644 --- a/examples/mutable_chaining.rs +++ b/examples/mutable_chaining.rs @@ -2,12 +2,12 @@ use nex::net::mac::MacAddr; use nex::packet::ethernet::{ - EtherType, EthernetPacket, MutableEthernetPacket, ETHERNET_HEADER_LEN, + ETHERNET_HEADER_LEN, EtherType, EthernetPacket, MutableEthernetPacket, }; use nex::packet::ip::IpNextProtocol; -use nex::packet::ipv4::{self, Ipv4Packet, MutableIpv4Packet, IPV4_HEADER_LEN}; +use nex::packet::ipv4::{self, IPV4_HEADER_LEN, Ipv4Packet, MutableIpv4Packet}; use nex::packet::packet::{MutablePacket, Packet}; -use nex::packet::udp::{self, MutableUdpPacket, UdpPacket, UDP_HEADER_LEN}; +use nex::packet::udp::{self, MutableUdpPacket, UDP_HEADER_LEN, UdpPacket}; use std::net::Ipv4Addr; fn main() { diff --git a/examples/ndp.rs b/examples/ndp.rs index bc376d2..060bd24 100644 --- a/examples/ndp.rs +++ b/examples/ndp.rs @@ -8,7 +8,7 @@ use nex::datalink; use nex::datalink::Channel::Ethernet; -use nex::net::interface::{get_interfaces, Interface}; +use nex::net::interface::{Interface, get_interfaces}; use nex::net::mac::MacAddr; use nex::packet::builder::ethernet::EthernetPacketBuilder; use nex::packet::builder::ipv6::Ipv6PacketBuilder; diff --git a/nex-datalink/src/async_io/bpf.rs b/nex-datalink/src/async_io/bpf.rs index bf351ad..c06039b 100644 --- a/nex-datalink/src/async_io/bpf.rs +++ b/nex-datalink/src/async_io/bpf.rs @@ -1,8 +1,8 @@ //! Asynchronous raw datalink support for BSD BPF devices. +use crate::Config; use crate::async_io::{AsyncChannel, AsyncRawSender}; use crate::bindings::bpf; -use crate::Config; use futures_core::stream::Stream; use nex_core::interface::Interface; use nex_sys; diff --git a/nex-datalink/src/async_io/wpcap.rs b/nex-datalink/src/async_io/wpcap.rs index 37ae0bd..465e5c5 100644 --- a/nex-datalink/src/async_io/wpcap.rs +++ b/nex-datalink/src/async_io/wpcap.rs @@ -1,8 +1,8 @@ //! Asynchronous raw datalink support for Windows using the Npcap / WinPcap library. +use crate::Config; use crate::async_io::{AsyncChannel, AsyncRawSender}; use crate::bindings::{bpf, windows}; -use crate::Config; use futures_core::stream::Stream; use nex_core::interface::Interface; use std::cmp; diff --git a/nex-datalink/src/bindings/windows.rs b/nex-datalink/src/bindings/windows.rs index ea11767..940ccf7 100644 --- a/nex-datalink/src/bindings/windows.rs +++ b/nex-datalink/src/bindings/windows.rs @@ -2,9 +2,9 @@ #![allow(non_snake_case)] #![allow(dead_code)] -use windows_sys::core::PCWSTR; use windows_sys::Win32::Foundation::{BOOLEAN, HANDLE}; use windows_sys::Win32::System::IO::OVERLAPPED; +use windows_sys::core::PCWSTR; #[repr(C)] pub struct _ADAPTER; diff --git a/nex-packet/src/arp.rs b/nex-packet/src/arp.rs index e3bf32a..ec0126c 100644 --- a/nex-packet/src/arp.rs +++ b/nex-packet/src/arp.rs @@ -1,7 +1,7 @@ //! ARP packet abstraction. use crate::{ - ethernet::{EtherType, ETHERNET_HEADER_LEN}, + ethernet::{ETHERNET_HEADER_LEN, EtherType}, packet::{MutablePacket, Packet}, }; diff --git a/nex-packet/src/builder/ndp.rs b/nex-packet/src/builder/ndp.rs index 24fce2f..d40a072 100644 --- a/nex-packet/src/builder/ndp.rs +++ b/nex-packet/src/builder/ndp.rs @@ -1,5 +1,5 @@ use crate::icmpv6::ndp::{NdpOptionPacket, NdpOptionTypes, NeighborSolicitPacket}; -use crate::icmpv6::{self, checksum, Icmpv6Header, Icmpv6Packet, Icmpv6Type}; +use crate::icmpv6::{self, Icmpv6Header, Icmpv6Packet, Icmpv6Type, checksum}; use crate::packet::Packet; use bytes::Bytes; use nex_core::mac::MacAddr; diff --git a/nex-packet/src/builder/udp.rs b/nex-packet/src/builder/udp.rs index 9b219f4..eed3c8b 100644 --- a/nex-packet/src/builder/udp.rs +++ b/nex-packet/src/builder/udp.rs @@ -1,7 +1,7 @@ use std::net::IpAddr; use crate::packet::Packet; -use crate::udp::{UdpHeader, UdpPacket, UDP_HEADER_LEN}; +use crate::udp::{UDP_HEADER_LEN, UdpHeader, UdpPacket}; use bytes::Bytes; /// Builder for constructing UDP packets diff --git a/nex-packet/src/dns.rs b/nex-packet/src/dns.rs index 6d33227..ae1d3fd 100644 --- a/nex-packet/src/dns.rs +++ b/nex-packet/src/dns.rs @@ -1056,11 +1056,14 @@ impl Packet for DnsPacket { fn parse_responses(count: usize, buf: &mut &[u8]) -> Option> { let mut packets = Vec::with_capacity(count); for _ in 0..count { - match DnsResponsePacket::from_buf_mut(buf) { Some(pkt) => { - packets.push(pkt); - } _ => { - break; - }} + match DnsResponsePacket::from_buf_mut(buf) { + Some(pkt) => { + packets.push(pkt); + } + _ => { + break; + } + } } Some(packets) } diff --git a/nex-packet/src/gre.rs b/nex-packet/src/gre.rs index 0bab76a..2100a7b 100644 --- a/nex-packet/src/gre.rs +++ b/nex-packet/src/gre.rs @@ -2,7 +2,7 @@ use crate::packet::{GenericMutablePacket, Packet}; use bytes::{Buf, Bytes}; -use nex_core::bitfield::{u1, u16be, u3, u32be, u5}; +use nex_core::bitfield::{u1, u3, u5, u16be, u32be}; /// GRE (Generic Routing Encapsulation) Packet. /// diff --git a/nex-packet/src/icmpv6.rs b/nex-packet/src/icmpv6.rs index 308aa07..bf911c5 100644 --- a/nex-packet/src/icmpv6.rs +++ b/nex-packet/src/icmpv6.rs @@ -611,7 +611,7 @@ pub mod ndp { use bytes::Bytes; use nex_core::bitfield::{self, u24be, u32be}; - use crate::icmpv6::{Icmpv6Code, Icmpv6Header, Icmpv6Packet, Icmpv6Type, ICMPV6_HEADER_LEN}; + use crate::icmpv6::{ICMPV6_HEADER_LEN, Icmpv6Code, Icmpv6Header, Icmpv6Packet, Icmpv6Type}; use crate::packet::Packet; use std::net::Ipv6Addr; @@ -817,11 +817,7 @@ pub mod ndp { pub fn option_payload_length(&self) -> usize { //let len = option.get_length(); let len = self.payload.len(); - if len > 0 { - ((len * 8) - 2) as usize - } else { - 0 - } + if len > 0 { ((len * 8) - 2) as usize } else { 0 } } } @@ -2446,7 +2442,7 @@ pub mod echo_reply { mod echo_tests { use super::*; use crate::icmpv6::{ - echo_reply::EchoReplyPacket, echo_request::EchoRequestPacket, Icmpv6Code, Icmpv6Type, + Icmpv6Code, Icmpv6Type, echo_reply::EchoReplyPacket, echo_request::EchoRequestPacket, }; #[test] diff --git a/nex-packet/src/packet.rs b/nex-packet/src/packet.rs index 52fe9e4..9bf1296 100644 --- a/nex-packet/src/packet.rs +++ b/nex-packet/src/packet.rs @@ -143,12 +143,13 @@ impl<'a, P: Packet> GenericMutablePacket<'a, P> { } fn lengths(&self) -> (usize, usize) { - match P::from_buf(self.packet()) { Some(packet) => { - let header_len = packet.header_len(); - let payload_len = packet.payload_len(); - (header_len, payload_len) - } _ => { - (self.buffer.len(), 0) - }} + match P::from_buf(self.packet()) { + Some(packet) => { + let header_len = packet.header_len(); + let payload_len = packet.payload_len(); + (header_len, payload_len) + } + _ => (self.buffer.len(), 0), + } } } diff --git a/nex-packet/src/tcp.rs b/nex-packet/src/tcp.rs index d4b5983..12f160e 100644 --- a/nex-packet/src/tcp.rs +++ b/nex-packet/src/tcp.rs @@ -9,7 +9,7 @@ use std::net::Ipv6Addr; use std::net::{IpAddr, Ipv4Addr}; use bytes::{Buf, BufMut, Bytes, BytesMut}; -use nex_core::bitfield::{u16be, u32be, u4}; +use nex_core::bitfield::{u4, u16be, u32be}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; diff --git a/nex-packet/src/util.rs b/nex-packet/src/util.rs index d488143..32ed338 100644 --- a/nex-packet/src/util.rs +++ b/nex-packet/src/util.rs @@ -4,8 +4,8 @@ use crate::ip::IpNextProtocol; use nex_core::bitfield::u16be; use core::convert::TryInto; -use core::u16; use core::u8; +use core::u16; use std::net::{Ipv4Addr, Ipv6Addr}; /// Convert a value to a byte array. diff --git a/nex-socket/src/icmp/async_impl.rs b/nex-socket/src/icmp/async_impl.rs index e56bf06..a0d121e 100644 --- a/nex-socket/src/icmp/async_impl.rs +++ b/nex-socket/src/icmp/async_impl.rs @@ -1,5 +1,5 @@ -use crate::icmp::{IcmpConfig, IcmpKind, IcmpSocketType}; use crate::SocketFamily; +use crate::icmp::{IcmpConfig, IcmpKind, IcmpSocketType}; use socket2::{Domain, Protocol, Socket, Type as SockType}; use std::io; use std::net::{SocketAddr, UdpSocket as StdUdpSocket}; diff --git a/nex-socket/src/icmp/sync_impl.rs b/nex-socket/src/icmp/sync_impl.rs index 0c028c0..46e4105 100644 --- a/nex-socket/src/icmp/sync_impl.rs +++ b/nex-socket/src/icmp/sync_impl.rs @@ -1,5 +1,5 @@ -use crate::icmp::{IcmpConfig, IcmpKind, IcmpSocketType}; use crate::SocketFamily; +use crate::icmp::{IcmpConfig, IcmpKind, IcmpSocketType}; use socket2::{Domain, Protocol, Socket, Type as SockType}; use std::io; use std::net::{SocketAddr, UdpSocket}; diff --git a/nex-socket/src/tcp/sync_impl.rs b/nex-socket/src/tcp/sync_impl.rs index e648b72..3d88526 100644 --- a/nex-socket/src/tcp/sync_impl.rs +++ b/nex-socket/src/tcp/sync_impl.rs @@ -9,7 +9,7 @@ use crate::tcp::TcpConfig; use std::os::fd::AsRawFd; #[cfg(unix)] -use nix::poll::{poll, PollFd, PollFlags}; +use nix::poll::{PollFd, PollFlags, poll}; /// Low level synchronous TCP socket. #[derive(Debug)] @@ -164,7 +164,7 @@ impl TcpSocket { use std::mem::size_of; use std::os::windows::io::AsRawSocket; use windows_sys::Win32::Networking::WinSock::{ - getsockopt, WSAPoll, POLLWRNORM, SOCKET, SOCKET_ERROR, SOL_SOCKET, SO_ERROR, WSAPOLLFD, + POLLWRNORM, SO_ERROR, SOCKET, SOCKET_ERROR, SOL_SOCKET, WSAPOLLFD, WSAPoll, getsockopt, }; let sock = self.socket.as_raw_socket() as SOCKET; diff --git a/nex-sys/src/unix.rs b/nex-sys/src/unix.rs index 9706e25..4aaab23 100644 --- a/nex-sys/src/unix.rs +++ b/nex-sys/src/unix.rs @@ -29,9 +29,11 @@ pub const AF_INET6: libc::c_int = libc::AF_INET6; pub use libc::{IFF_BROADCAST, IFF_LOOPBACK, IFF_MULTICAST, IFF_POINTOPOINT, IFF_UP}; -pub unsafe fn close(sock: CSocket) { unsafe { - let _ = libc::close(sock); -}} +pub unsafe fn close(sock: CSocket) { + unsafe { + let _ = libc::close(sock); + } +} fn ntohs(u: u16) -> u16 { u16::from_be(u) @@ -115,9 +117,9 @@ pub unsafe fn sendto( flags: libc::c_int, addr: *const SockAddr, addrlen: SockLen, -) -> CouldFail { unsafe { - libc::sendto(socket, buf, len, flags, addr, addrlen) -}} +) -> CouldFail { + unsafe { libc::sendto(socket, buf, len, flags, addr, addrlen) } +} pub unsafe fn recvfrom( socket: CSocket, @@ -126,9 +128,9 @@ pub unsafe fn recvfrom( flags: libc::c_int, addr: *mut SockAddr, addrlen: *mut SockLen, -) -> CouldFail { unsafe { - libc::recvfrom(socket, buf, len, flags, addr, addrlen) -}} +) -> CouldFail { + unsafe { libc::recvfrom(socket, buf, len, flags, addr, addrlen) } +} #[inline] pub fn retry(f: &mut F) -> libc::ssize_t diff --git a/nex-sys/src/windows.rs b/nex-sys/src/windows.rs index 013dc2e..069e610 100644 --- a/nex-sys/src/windows.rs +++ b/nex-sys/src/windows.rs @@ -22,9 +22,11 @@ pub type SockAddrFamily6 = ws::ADDRESS_FAMILY; pub type InAddr = ws::IN_ADDR; pub type In6Addr = ws::IN6_ADDR; -pub unsafe fn close(sock: CSocket) { unsafe { - let _ = ws::closesocket(sock); -}} +pub unsafe fn close(sock: CSocket) { + unsafe { + let _ = ws::closesocket(sock); + } +} pub unsafe fn sendto( socket: CSocket, @@ -33,9 +35,9 @@ pub unsafe fn sendto( flags: libc::c_int, to: *const SockAddr, tolen: SockLen, -) -> CouldFail { unsafe { - ws::sendto(socket, buf as *const u8, len, flags, to, tolen) -}} +) -> CouldFail { + unsafe { ws::sendto(socket, buf as *const u8, len, flags, to, tolen) } +} pub unsafe fn recvfrom( socket: CSocket, @@ -44,9 +46,9 @@ pub unsafe fn recvfrom( flags: libc::c_int, addr: *mut SockAddr, addrlen: *mut SockLen, -) -> CouldFail { unsafe { - ws::recvfrom(socket, buf as *mut u8, len, flags, addr, addrlen) -}} +) -> CouldFail { + unsafe { ws::recvfrom(socket, buf as *mut u8, len, flags, addr, addrlen) } +} #[inline] pub fn retry(f: &mut F) -> libc::c_int From 82189914615ead80fea217806dbb9d609b524b5b Mon Sep 17 00:00:00 2001 From: shellrow Date: Sun, 9 Nov 2025 16:55:44 +0900 Subject: [PATCH 5/5] Bump version to 0.24.0 --- Cargo.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bfbe76d..b8dbd8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,16 +10,16 @@ members = [ ] [workspace.package] -version = "0.23.2" +version = "0.24.0" edition = "2024" authors = ["shellrow "] [workspace.dependencies] -nex-core = { version = "0.23.2", path = "nex-core" } -nex-datalink = { version = "0.23.2", path = "nex-datalink" } -nex-packet = { version = "0.23.2", path = "nex-packet" } -nex-sys = { version = "0.23.2", path = "nex-sys" } -nex-socket = { version = "0.23.2", path = "nex-socket" } +nex-core = { version = "0.24.0", path = "nex-core" } +nex-datalink = { version = "0.24.0", path = "nex-datalink" } +nex-packet = { version = "0.24.0", path = "nex-packet" } +nex-sys = { version = "0.24.0", path = "nex-sys" } +nex-socket = { version = "0.24.0", path = "nex-socket" } serde = { version = "1" } libc = "0.2" netdev = { version = "0.39" }