diff --git a/src/header/netdb/mod.rs b/src/header/netdb/mod.rs index c5964fbd3c..ea82382d45 100644 --- a/src/header/netdb/mod.rs +++ b/src/header/netdb/mod.rs @@ -17,7 +17,7 @@ use crate::{ bits_safamily_t::sa_family_t, errno::*, fcntl::O_RDONLY, - netinet_in::{in_addr, sockaddr_in, sockaddr_in6}, + netinet_in::{in_addr, sockaddr_in}, stdlib::atoi, strings::strcasecmp, sys_socket::{constants::AF_INET, sockaddr, socklen_t}, @@ -31,6 +31,9 @@ use crate::{ raw_cell::RawCell, }; +#[cfg(feature = "ip6")] +use crate::header::netinet_in::sockaddr_in6; + #[cfg(target_os = "linux")] #[path = "linux.rs"] pub mod sys; @@ -1058,9 +1061,14 @@ pub unsafe extern "C" fn freeaddrinfo(res: *mut addrinfo) { if !bai.ai_addr.is_null() { if bai.ai_addrlen == mem::size_of::() as socklen_t { unsafe { drop(Box::from_raw(bai.ai_addr.cast::())) }; - } else if bai.ai_addrlen == mem::size_of::() as socklen_t { - unsafe { drop(Box::from_raw(bai.ai_addr.cast::())) }; } else { + #[cfg(feature = "ip6")] + if bai.ai_addrlen == mem::size_of::() as socklen_t { + unsafe { drop(Box::from_raw(bai.ai_addr.cast::())) }; + } else { + todo_skip!(0, "freeaddrinfo: unknown ai_addrlen {}", bai.ai_addrlen); + } + #[cfg(not(feature = "ip6"))] todo_skip!(0, "freeaddrinfo: unknown ai_addrlen {}", bai.ai_addrlen); } } diff --git a/src/header/netinet_in/mod.rs b/src/header/netinet_in/mod.rs index 0e4ced5c15..a60c728af8 100644 --- a/src/header/netinet_in/mod.rs +++ b/src/header/netinet_in/mod.rs @@ -22,6 +22,7 @@ pub struct in_addr { } /// See . +#[cfg(feature = "ip6")] #[repr(C)] pub struct in6_addr { pub s6_addr: [u8; 16], @@ -39,6 +40,7 @@ pub struct sockaddr_in { /// See . #[repr(C)] +#[cfg(feature = "ip6")] pub struct sockaddr_in6 { pub sin6_family: sa_family_t, pub sin6_port: in_port_t, @@ -49,6 +51,7 @@ pub struct sockaddr_in6 { /// See . #[repr(C)] +#[cfg(feature = "ip6")] pub struct ipv6_mreq { pub ipv6mr_multiaddr: in6_addr, pub ipv6mr_interface: u32, @@ -58,6 +61,7 @@ pub struct ipv6_mreq { /// See . pub const INET_ADDRSTRLEN: c_int = 16; /// See . +#[cfg(feature = "ip6")] pub const INET6_ADDRSTRLEN: c_int = 46; // IP options @@ -82,6 +86,7 @@ pub const IPPROTO_UDP: u8 = 17; /// Non-POSIX. pub const IPPROTO_IDP: u8 = 22; /// See . +#[cfg(feature = "ip6")] pub const IPPROTO_IPV6: u8 = 41; /// See . pub const IPPROTO_RAW: u8 = 0xff; @@ -91,20 +96,29 @@ pub const IPPROTO_MAX: u8 = 0xff; /// Non-POSIX, see . pub const IP_TTL: c_int = 2; /// See . +#[cfg(feature = "ip6")] pub const IPV6_UNICAST_HOPS: c_int = 16; /// See . +#[cfg(feature = "ip6")] pub const IPV6_MULTICAST_IF: c_int = 17; /// See . +#[cfg(feature = "ip6")] pub const IPV6_MULTICAST_HOPS: c_int = 18; /// See . +#[cfg(feature = "ip6")] pub const IPV6_MULTICAST_LOOP: c_int = 19; /// Non-POSIX. +#[cfg(feature = "ip6")] pub const IPV6_ADD_MEMBERSHIP: c_int = 20; +#[cfg(feature = "ip6")] pub const IPV6_JOIN_GROUP: c_int = 20; /// Non-POSIX. +#[cfg(feature = "ip6")] pub const IPV6_DROP_MEMBERSHIP: c_int = 21; +#[cfg(feature = "ip6")] pub const IPV6_LEAVE_GROUP: c_int = 21; /// See . +#[cfg(feature = "ip6")] pub const IPV6_V6ONLY: c_int = 26; /// Non-POSIX, see . pub const IP_MULTICAST_IF: c_int = 32; @@ -166,12 +180,14 @@ pub struct group_source_req { /// See . #[unsafe(no_mangle)] +#[cfg(feature = "ip6")] pub static in6addr_any: in6_addr = in6_addr { s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], }; /// See . #[unsafe(no_mangle)] +#[cfg(feature = "ip6")] 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], }; diff --git a/tests/dirent/main.c b/tests/dirent/main.c index b524ed1e98..fcf2799cf4 100644 --- a/tests/dirent/main.c +++ b/tests/dirent/main.c @@ -19,6 +19,7 @@ int main(void) { for (char counter = 0; (entry = readdir(dir)); counter += 1) { puts(entry->d_name); + (void) counter; //if (counter == 4) { // tell = telldir(dir); //} diff --git a/tests/netdb/getaddrinfo.c b/tests/netdb/getaddrinfo.c index bdf694f75f..91af8fea59 100644 --- a/tests/netdb/getaddrinfo.c +++ b/tests/netdb/getaddrinfo.c @@ -9,10 +9,16 @@ #include "test_helpers.h" +#ifdef INET6_ADDRSTRLEN +#define _ADDRSTRLEN INET6_ADDRSTRLEN +#else +#define _ADDRSTRLEN INET_ADDRSTRLEN +#endif + int main(void) { struct addrinfo hints, *res; int errcode; - char addrstr[INET6_ADDRSTRLEN]; + char addrstr[_ADDRSTRLEN]; void *ptr; memset(&hints, 0, sizeof(hints)); @@ -40,7 +46,7 @@ int main(void) { ptr = NULL; } if (ptr) { - inet_ntop(res->ai_family, ptr, addrstr, INET6_ADDRSTRLEN); + inet_ntop(res->ai_family, ptr, addrstr, _ADDRSTRLEN); printf( "IPv%d address: %s (%s)\n", diff --git a/tests/signals/pthread_kill-self.c b/tests/signals/pthread_kill-self.c index e791473ffc..f7cb5d14f9 100644 --- a/tests/signals/pthread_kill-self.c +++ b/tests/signals/pthread_kill-self.c @@ -18,7 +18,8 @@ struct signal { int signum; }; -void handler() { +void handler(int sig) { + (void) sig; handler_called = 1; return; } diff --git a/tests/signals/sigpause-revert.c b/tests/signals/sigpause-revert.c index 3cf46964fd..dcf67c7fdb 100644 --- a/tests/signals/sigpause-revert.c +++ b/tests/signals/sigpause-revert.c @@ -14,7 +14,8 @@ volatile sig_atomic_t handler_called = false; -void handler() { +void handler(int sig) { + (void) sig; handler_called = true; return; } diff --git a/tests/signals/sigpause-suspend.c b/tests/signals/sigpause-suspend.c index ed2ab1d2a5..5b8de9db2a 100644 --- a/tests/signals/sigpause-suspend.c +++ b/tests/signals/sigpause-suspend.c @@ -19,10 +19,12 @@ volatile sig_atomic_t handler_called = 0; volatile atomic_bool completed = false; -void handler() { +void handler(int sig) { + (void) sig; handler_called = 1; return; } + void *b_thread_func(void *code_raw) { int *code = code_raw; printf("Pausing signal %s\n", strsignal(*code)); diff --git a/tests/sys_socket/getpeername.c b/tests/sys_socket/getpeername.c index 2a3acd1918..f2b758b9e7 100644 --- a/tests/sys_socket/getpeername.c +++ b/tests/sys_socket/getpeername.c @@ -2,8 +2,14 @@ #include "test_helpers.h" +#ifdef INET6_ADDRSTRLEN +#define _ADDRSTRLEN INET6_ADDRSTRLEN +#else +#define _ADDRSTRLEN INET_ADDRSTRLEN +#endif + void print_sockaddr(char *ctx, struct sockaddr *addr) { - char ip_string[INET6_ADDRSTRLEN]; + char ip_string[_ADDRSTRLEN]; void *raw_ip_addr; char *fam; in_port_t port; diff --git a/tests/wchar/mbsrtowcs.c b/tests/wchar/mbsrtowcs.c index 6db79da51a..91e6e0db66 100644 --- a/tests/wchar/mbsrtowcs.c +++ b/tests/wchar/mbsrtowcs.c @@ -20,6 +20,6 @@ void print_as_wide(const char* mbstr) } int main(void) { - const char* mbstr = u8"z\u00df\u6c34\U0001f34c"; // or u8"zß水🍌" + const char* mbstr = (const char*) u8"z\u00df\u6c34\U0001f34c"; // or u8"zß水🍌" print_as_wide(mbstr); }