Move htonl, htons, ntohl, ntohs to netinet/in.h to support more packages

This commit is contained in:
Jeremy Soller
2025-05-02 09:49:37 -06:00
parent 58572ceefc
commit 863171105d
4 changed files with 28 additions and 29 deletions
+1 -25
View File
@@ -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 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub extern "C" fn htonl(hostlong: uint32_t) -> uint32_t {
hostlong.to_be()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub extern "C" fn htons(hostshort: uint16_t) -> uint16_t {
hostshort.to_be()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_addr.html>.
///
/// # Deprecated
@@ -197,15 +185,3 @@ pub unsafe extern "C" fn inet_pton(af: c_int, src: *const c_char, dst: *mut c_vo
}
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub extern "C" fn ntohl(netlong: uint32_t) -> uint32_t {
u32::from_be(netlong)
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub extern "C" fn ntohs(netshort: uint16_t) -> uint16_t {
u16::from_be(netshort)
}
+1 -2
View File
@@ -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},
+2 -2
View File
@@ -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},
+24
View File
@@ -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 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub extern "C" fn htonl(hostlong: uint32_t) -> uint32_t {
hostlong.to_be()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub extern "C" fn htons(hostshort: uint16_t) -> uint16_t {
hostshort.to_be()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub extern "C" fn ntohl(netlong: uint32_t) -> uint32_t {
u32::from_be(netlong)
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[no_mangle]
pub extern "C" fn ntohs(netshort: uint16_t) -> uint16_t {
u16::from_be(netshort)
}