diff --git a/src/header/arpa_inet/cbindgen.toml b/src/header/arpa_inet/cbindgen.toml index a493276286..a6b683dde2 100644 --- a/src/header/arpa_inet/cbindgen.toml +++ b/src/header/arpa_inet/cbindgen.toml @@ -3,7 +3,7 @@ # Spec quotations relating to includes: # - "The header shall define the in_port_t and in_addr_t types as described in and the socklen_t type as defined in ." # - "The header shall define the in_addr structure as described in ." -# - "The header shall define the INET_ADDRSTRLEN [IP6]  and INET6_ADDRSTRLEN  macros as described in ." +# - "The header shall define the INET_ADDRSTRLEN [IP6] and INET6_ADDRSTRLEN macros as described in ." # - "The header shall define the uint32_t and uint16_t types as described in ." # - "Inclusion of the header may also make visible all symbols from and ." # diff --git a/src/header/arpa_inet/mod.rs b/src/header/arpa_inet/mod.rs index 8ab7f8bfe6..abab965675 100644 --- a/src/header/arpa_inet/mod.rs +++ b/src/header/arpa_inet/mod.rs @@ -12,12 +12,12 @@ use crate::{ header::{ bits_socklen_t::socklen_t, errno::{EAFNOSUPPORT, ENOSPC}, - netinet_in::{INADDR_NONE, in_addr, in_addr_t, ntohl}, + netinet_in::{INADDR_NONE, in_addr, in_addr_t}, sys_socket::constants::AF_INET, }, platform::{ self, - types::{c_char, c_int, c_void}, + types::{c_char, c_int, c_void, uint16_t, uint32_t}, }, raw_cell::RawCell, }; @@ -231,3 +231,27 @@ pub unsafe extern "C" fn inet_pton(af: c_int, src: *const c_char, dst: *mut c_vo } } } + +/// See . +#[unsafe(no_mangle)] +pub extern "C" fn htonl(hostlong: uint32_t) -> uint32_t { + hostlong.to_be() +} + +/// See . +#[unsafe(no_mangle)] +pub extern "C" fn htons(hostshort: uint16_t) -> uint16_t { + hostshort.to_be() +} + +/// See . +#[unsafe(no_mangle)] +pub extern "C" fn ntohl(netlong: uint32_t) -> uint32_t { + u32::from_be(netlong) +} + +/// See . +#[unsafe(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 51d29702f1..627d39c7b6 100644 --- a/src/header/netdb/lookup.rs +++ b/src/header/netdb/lookup.rs @@ -10,10 +10,11 @@ use crate::{ }; use crate::header::{ + arpa_inet::htons, bits_socklen_t::socklen_t, bits_time::timespec, errno::*, - netinet_in::{IPPROTO_UDP, htons, in_addr, sockaddr_in}, + netinet_in::{IPPROTO_UDP, in_addr, sockaddr_in}, sys_socket::{ self, constants::{AF_INET, SOCK_DGRAM}, diff --git a/src/header/netdb/mod.rs b/src/header/netdb/mod.rs index 13ef149a79..4e7b30f7b8 100644 --- a/src/header/netdb/mod.rs +++ b/src/header/netdb/mod.rs @@ -12,11 +12,11 @@ use crate::{ c_str::{CStr, CString}, error::ResultExt, header::{ - arpa_inet::inet_aton, + arpa_inet::{htons, inet_aton, ntohl}, bits_socklen_t::socklen_t, errno::*, fcntl::O_RDONLY, - netinet_in::{htons, in_addr, ntohl, sockaddr_in, sockaddr_in6}, + netinet_in::{in_addr, sockaddr_in, sockaddr_in6}, stdlib::atoi, strings::strcasecmp, sys_socket::{constants::AF_INET, sa_family_t, sockaddr}, diff --git a/src/header/netinet_in/mod.rs b/src/header/netinet_in/mod.rs index 2a7b6edf91..4a45b8d7d2 100644 --- a/src/header/netinet_in/mod.rs +++ b/src/header/netinet_in/mod.rs @@ -6,7 +6,7 @@ use crate::{ header::sys_socket::{sa_family_t, sockaddr_storage}, - platform::types::{c_char, c_int, uint16_t, uint32_t}, + platform::types::{c_char, c_int}, }; /// See . @@ -175,27 +175,3 @@ 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 . -#[unsafe(no_mangle)] -pub extern "C" fn htonl(hostlong: uint32_t) -> uint32_t { - hostlong.to_be() -} - -/// See . -#[unsafe(no_mangle)] -pub extern "C" fn htons(hostshort: uint16_t) -> uint16_t { - hostshort.to_be() -} - -/// See . -#[unsafe(no_mangle)] -pub extern "C" fn ntohl(netlong: uint32_t) -> uint32_t { - u32::from_be(netlong) -} - -/// See . -#[unsafe(no_mangle)] -pub extern "C" fn ntohs(netshort: uint16_t) -> uint16_t { - u16::from_be(netshort) -} diff --git a/tests/sys_socket/recvfrom.c b/tests/sys_socket/recvfrom.c index 2b57597280..f4975aeafd 100644 --- a/tests/sys_socket/recvfrom.c +++ b/tests/sys_socket/recvfrom.c @@ -1,5 +1,6 @@ #include +#include #include #include