verify netinet_in header includes

This commit is contained in:
auronandace
2026-03-25 10:50:01 +00:00
parent 186dc66818
commit d826d1fdc2
9 changed files with 79 additions and 35 deletions
+9 -7
View File
@@ -3,18 +3,20 @@
# Spec quotations relating to includes:
# - "The <arpa/inet.h> header shall define the in_port_t and in_addr_t types as described in <netinet/in.h> and the socklen_t type as defined in <sys/socket.h>."
# - "The <arpa/inet.h> header shall define the in_addr structure as described in <netinet/in.h>."
# - "The <arpa/inet.h> header shall define the INET_ADDRSTRLEN [IP6] and INET6_ADDRSTRLEN macros as described in <netinet/in.h>."
# - "The <arpa/inet.h> header shall define the INET_ADDRSTRLEN and INET6_ADDRSTRLEN macros as described in <netinet/in.h>."
# - "The <arpa/inet.h> header shall define the uint32_t and uint16_t types as described in <inttypes.h>."
# - "Inclusion of the <arpa/inet.h> header may also make visible all symbols from <netinet/in.h> and <inttypes.h>."
#
# features.h included for #[deprecated] annotation
sys_includes = [
"inttypes.h",
"netinet/in.h",
"features.h"
]
# Possible cycle between arpa/inet.h and netinet/in.h solved by:
# - including netinet/in.h in arpa/inet.h
# - splitting out functions (htonl, htons, ntohl, ntohs) into bits/arpainet.h
#
# netinet/in.h brings in sys/types.h which brings in features.h (needed for #[deprecated] annotation)
# bits/arpainet.h brings in inttypes.h
sys_includes = ["netinet/in.h"]
include_guard = "_ARPA_INET_H"
after_includes = """
#include <bits/arpainet.h> // for htonl, htons, ntohl, ntohs
#include <bits/socklen-t.h> // for socklen_t
"""
language = "C"
+2 -25
View File
@@ -10,6 +10,7 @@ use core::{
use crate::{
c_str::CStr,
header::{
bits_arpainet::ntohl,
bits_socklen_t::socklen_t,
errno::{EAFNOSUPPORT, ENOSPC},
netinet_in::{INADDR_NONE, in_addr, in_addr_t},
@@ -17,7 +18,7 @@ use crate::{
},
platform::{
self,
types::{c_char, c_int, c_void, uint16_t, uint32_t},
types::{c_char, c_int, c_void},
},
raw_cell::RawCell,
};
@@ -231,27 +232,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>.
#[unsafe(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>.
#[unsafe(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>.
#[unsafe(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>.
#[unsafe(no_mangle)]
pub extern "C" fn ntohs(netshort: uint16_t) -> uint16_t {
u16::from_be(netshort)
}
+19
View File
@@ -0,0 +1,19 @@
# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/arpa_inet.h.html
#
# The arpa/inet header should define the following functions:
# - htonl
# - htons
# - ntohl
# - ntohs
#
# They are also meant to be available in the netinet/in header.
# The arpa/inet and netinet/in headers both say that they may include each other which creates a cycle.
# To break the cycle we include netinet/in in the arpa/inet header and split out the above functions.
#
# include inttypes.h to get uint16_t and uint32_t
sys_includes = ["inttypes.h"]
include_guard = "_RELIBC_BITS_ARPAINET_H"
language = "C"
style = "Tag"
no_includes = true
cpp_compat = true
+25
View File
@@ -0,0 +1,25 @@
use crate::platform::types::{uint16_t, uint32_t};
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html>.
#[unsafe(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>.
#[unsafe(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>.
#[unsafe(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>.
#[unsafe(no_mangle)]
pub extern "C" fn ntohs(netshort: uint16_t) -> uint16_t {
u16::from_be(netshort)
}
+1
View File
@@ -4,6 +4,7 @@ pub mod _aio;
pub mod _fenv;
pub mod arpa_inet;
pub mod assert;
pub mod bits_arpainet;
#[path = "bits_locale-t/mod.rs"]
pub mod bits_locale_t;
pub mod bits_pthread;
+1 -1
View File
@@ -10,7 +10,7 @@ use crate::{
};
use crate::header::{
arpa_inet::htons,
bits_arpainet::htons,
bits_socklen_t::socklen_t,
bits_time::timespec,
errno::*,
+2 -1
View File
@@ -12,7 +12,8 @@ use crate::{
c_str::{CStr, CString},
error::ResultExt,
header::{
arpa_inet::{htons, inet_aton, ntohl},
arpa_inet::inet_aton,
bits_arpainet::{htons, ntohl},
bits_socklen_t::socklen_t,
errno::*,
fcntl::O_RDONLY,
+20
View File
@@ -1,4 +1,24 @@
# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html
#
# Spec quotations relating to includes:
# - "The <netinet/in.h> header shall define in_port_t Equivalent to the type uint16_t as described in <inttypes.h>."
# - "The <netinet/in.h> header shall define in_addr_t Equivalent to the type uint32_t as described in <inttypes.h>."
# - "The <netinet/in.h> header shall define the sa_family_t type as described in <sys/socket.h>."
# - "The <netinet/in.h> header shall define the uint8_t and uint32_t types as described in <inttypes.h>."
# - "Inclusion of the <netinet/in.h> header may also make visible all symbols from <inttypes.h> and <sys/socket.h>."
# - "The htonl(), htons(), ntohl(), and ntohs() functions shall be available as described in <arpa/inet.h>."
# - "Inclusion of the <netinet/in.h> header may also make visible all symbols from <arpa/inet.h>."
#
# Possible cycle between arpa/inet.h and netinet/in.h solved by:
# - including netinet/in.h in arpa/inet.h
# - splitting out functions (htonl, htons, ntohl, ntohs) into bits/arpainet.h
#
# sys/types.h needed for c_int and c_char
# bits/arpainet.h brings in inttypes.h
sys_includes = ["sys/types.h", "sys/socket.h"]
after_includes = """
#include <bits/arpainet.h> // for htonl, htons, ntohl, ntohs
"""
include_guard = "_NETINET_IN_H"
trailer = "#include <bits/netinet/in.h>"
language = "C"
-1
View File
@@ -1,6 +1,5 @@
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>