From 863171105dbe3d873db4548b49b331310e41bf7b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 2 May 2025 09:49:37 -0600 Subject: [PATCH] Move htonl, htons, ntohl, ntohs to netinet/in.h to support more packages --- src/header/arpa_inet/mod.rs | 26 +------------------------- src/header/netdb/lookup.rs | 3 +-- src/header/netdb/mod.rs | 4 ++-- src/header/netinet_in/mod.rs | 24 ++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/header/arpa_inet/mod.rs b/src/header/arpa_inet/mod.rs index 848b8022ed..7f041fe290 100644 --- a/src/header/arpa_inet/mod.rs +++ b/src/header/arpa_inet/mod.rs @@ -14,24 +14,12 @@ use crate::{ c_str::CStr, header::{ errno::*, - netinet_in::{in_addr, in_addr_t, INADDR_NONE}, + netinet_in::{in_addr, in_addr_t, ntohl, INADDR_NONE}, sys_socket::{constants::*, socklen_t}, }, platform::{self, types::*}, }; -/// See . -#[no_mangle] -pub extern "C" fn htonl(hostlong: uint32_t) -> uint32_t { - hostlong.to_be() -} - -/// See . -#[no_mangle] -pub extern "C" fn htons(hostshort: uint16_t) -> uint16_t { - hostshort.to_be() -} - /// See . /// /// # Deprecated @@ -197,15 +185,3 @@ pub unsafe extern "C" fn inet_pton(af: c_int, src: *const c_char, dst: *mut c_vo } } } - -/// See . -#[no_mangle] -pub extern "C" fn ntohl(netlong: uint32_t) -> uint32_t { - u32::from_be(netlong) -} - -/// See . -#[no_mangle] -pub extern "C" fn ntohs(netshort: uint16_t) -> uint16_t { - u16::from_be(netshort) -} diff --git a/src/header/netdb/lookup.rs b/src/header/netdb/lookup.rs index 4656015932..8a17c3d656 100644 --- a/src/header/netdb/lookup.rs +++ b/src/header/netdb/lookup.rs @@ -8,9 +8,8 @@ use core::mem; use crate::platform::{types::*, Pal, Sys}; use crate::header::{ - arpa_inet::htons, errno::*, - netinet_in::{in_addr, sockaddr_in, IPPROTO_UDP}, + netinet_in::{htons, in_addr, sockaddr_in, IPPROTO_UDP}, sys_socket::{ self, constants::{AF_INET, SOCK_DGRAM}, diff --git a/src/header/netdb/mod.rs b/src/header/netdb/mod.rs index 295f78ca14..6cf1d16246 100644 --- a/src/header/netdb/mod.rs +++ b/src/header/netdb/mod.rs @@ -15,10 +15,10 @@ use crate::{ c_str::{CStr, CString}, error::ResultExt, header::{ - arpa_inet::{htons, inet_aton, ntohl}, + arpa_inet::inet_aton, errno::*, fcntl::O_RDONLY, - netinet_in::{in_addr, sockaddr_in, sockaddr_in6}, + netinet_in::{htons, in_addr, ntohl, sockaddr_in, sockaddr_in6}, stdlib::atoi, strings::strcasecmp, sys_socket::{constants::AF_INET, sa_family_t, sockaddr, socklen_t}, diff --git a/src/header/netinet_in/mod.rs b/src/header/netinet_in/mod.rs index 1be3771d47..f134cb7d3a 100644 --- a/src/header/netinet_in/mod.rs +++ b/src/header/netinet_in/mod.rs @@ -175,3 +175,27 @@ pub static in6addr_any: in6_addr = in6_addr { pub static in6addr_loopback: in6_addr = in6_addr { s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], }; + +/// See . +#[no_mangle] +pub extern "C" fn htonl(hostlong: uint32_t) -> uint32_t { + hostlong.to_be() +} + +/// See . +#[no_mangle] +pub extern "C" fn htons(hostshort: uint16_t) -> uint16_t { + hostshort.to_be() +} + +/// See . +#[no_mangle] +pub extern "C" fn ntohl(netlong: uint32_t) -> uint32_t { + u32::from_be(netlong) +} + +/// See . +#[no_mangle] +pub extern "C" fn ntohs(netshort: uint16_t) -> uint16_t { + u16::from_be(netshort) +}