use ip6 feature flag for IPv6 related definitions
as a consequence, some unit tests have to be fixed, too
This commit is contained in:
+11
-3
@@ -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::<sockaddr_in>() as socklen_t {
|
||||
unsafe { drop(Box::from_raw(bai.ai_addr.cast::<sockaddr_in>())) };
|
||||
} else if bai.ai_addrlen == mem::size_of::<sockaddr_in6>() as socklen_t {
|
||||
unsafe { drop(Box::from_raw(bai.ai_addr.cast::<sockaddr_in6>())) };
|
||||
} else {
|
||||
#[cfg(feature = "ip6")]
|
||||
if bai.ai_addrlen == mem::size_of::<sockaddr_in6>() as socklen_t {
|
||||
unsafe { drop(Box::from_raw(bai.ai_addr.cast::<sockaddr_in6>())) };
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ pub struct in_addr {
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[cfg(feature = "ip6")]
|
||||
#[repr(C)]
|
||||
pub struct in6_addr {
|
||||
pub s6_addr: [u8; 16],
|
||||
@@ -39,6 +40,7 @@ pub struct sockaddr_in {
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
pub const INET_ADDRSTRLEN: c_int = 16;
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[cfg(feature = "ip6")]
|
||||
pub const IPPROTO_IPV6: u8 = 41;
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
pub const IPPROTO_RAW: u8 = 0xff;
|
||||
@@ -91,20 +96,29 @@ pub const IPPROTO_MAX: u8 = 0xff;
|
||||
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man7/ip.7.html>.
|
||||
pub const IP_TTL: c_int = 2;
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[cfg(feature = "ip6")]
|
||||
pub const IPV6_UNICAST_HOPS: c_int = 16;
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[cfg(feature = "ip6")]
|
||||
pub const IPV6_MULTICAST_IF: c_int = 17;
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[cfg(feature = "ip6")]
|
||||
pub const IPV6_MULTICAST_HOPS: c_int = 18;
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[cfg(feature = "ip6")]
|
||||
pub const IPV6_V6ONLY: c_int = 26;
|
||||
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man7/ip.7.html>.
|
||||
pub const IP_MULTICAST_IF: c_int = 32;
|
||||
@@ -166,12 +180,14 @@ pub struct group_source_req {
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html>.
|
||||
#[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],
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
//}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -18,7 +18,8 @@ struct signal {
|
||||
int signum;
|
||||
};
|
||||
|
||||
void handler() {
|
||||
void handler(int sig) {
|
||||
(void) sig;
|
||||
handler_called = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
volatile sig_atomic_t handler_called = false;
|
||||
|
||||
void handler() {
|
||||
void handler(int sig) {
|
||||
(void) sig;
|
||||
handler_called = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user