diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index d3fb2c3f..f932fa23 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -687,7 +687,9 @@ static void GetAllVarsImpl(const clang::Stmt *stmt, } if (auto *decl_ref = clang::dyn_cast(stmt)) { - vars.insert(decl_ref->getDecl()); + if (!clang::isa(decl_ref->getDecl())) { + vars.insert(decl_ref->getDecl()); + } } else if (auto *member = clang::dyn_cast(stmt)) { vars.insert(member->getMemberDecl()); GetAllVarsImpl(member->getBase(), vars); diff --git a/libcc2rs/src/libc_shims/ifaddrs.rs b/libcc2rs/src/libc_shims/ifaddrs.rs index 33446410..977d4f8b 100644 --- a/libcc2rs/src/libc_shims/ifaddrs.rs +++ b/libcc2rs/src/libc_shims/ifaddrs.rs @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use super::Sockaddr; +use super::{Sockaddr, SockaddrIn, SockaddrIn6, SockaddrStorage}; use crate::{ByteRepr, Ptr, Value}; use std::cell::RefCell; use std::rc::Rc; @@ -15,6 +15,41 @@ pub struct Ifaddrs { pub ifa_netmask: Value>, } +impl Ifaddrs { + pub fn from_interface_address(ifa: &nix::ifaddrs::InterfaceAddress) -> Self { + fn mk_addr(ss: Option<&nix::sys::socket::SockaddrStorage>) -> Ptr { + match ss { + None => Ptr::null(), + Some(a) => match (a.as_sockaddr_in(), a.as_sockaddr_in6()) { + (Some(v4), _) => { + let l = ::libc::sockaddr_in::from(*v4); + let st = Ptr::alloc(SockaddrStorage::default()); + st.reinterpret_cast::() + .write(SockaddrIn::from_libc(&l)); + st.reinterpret_cast::() + } + (None, Some(v6)) => { + let l = ::libc::sockaddr_in6::from(*v6); + let st = Ptr::alloc(SockaddrStorage::default()); + st.reinterpret_cast::() + .write(SockaddrIn6::from_libc(&l)); + st.reinterpret_cast::() + } + (None, None) => Ptr::null(), + }, + } + } + let node = Ifaddrs::default(); + let mut name = ifa.interface_name.clone().into_bytes(); + name.push(0); + *node.ifa_name.borrow_mut() = Ptr::alloc_array(name.into_boxed_slice()); + *node.ifa_flags.borrow_mut() = ifa.flags.bits() as u32; + *node.ifa_addr.borrow_mut() = mk_addr(ifa.address.as_ref()); + *node.ifa_netmask.borrow_mut() = mk_addr(ifa.netmask.as_ref()); + node + } +} + impl Clone for Ifaddrs { fn clone(&self) -> Self { Self { diff --git a/libcc2rs/src/libc_shims/socket.rs b/libcc2rs/src/libc_shims/socket.rs index 73012d70..954184e9 100644 --- a/libcc2rs/src/libc_shims/socket.rs +++ b/libcc2rs/src/libc_shims/socket.rs @@ -37,6 +37,90 @@ pub struct SockaddrStorage { pub __pad: Value>, } +impl SockaddrIn { + #[allow(clippy::unnecessary_cast)] + pub fn from_libc(l: &::libc::sockaddr_in) -> Self { + Self { + sin_family: Rc::new(RefCell::new(l.sin_family as u16)), + sin_port: Rc::new(RefCell::new(l.sin_port)), + sin_addr: Rc::new(RefCell::new(InAddr { + s_addr: Rc::new(RefCell::new(l.sin_addr.s_addr)), + })), + sin_zero: Rc::new(RefCell::new( + l.sin_zero + .iter() + .map(|&b| b as u8) + .collect::>() + .into_boxed_slice(), + )), + } + } + + pub fn from_ipv4(addr: &::std::net::Ipv4Addr, port: u16) -> Self { + let s = Self::default(); + *s.sin_family.borrow_mut() = ::libc::AF_INET as u16; + *s.sin_port.borrow_mut() = port.to_be(); + *s.sin_addr.borrow().s_addr.borrow_mut() = u32::from(*addr).to_be(); + s + } + + #[cfg(target_os = "linux")] + pub fn to_libc(&self) -> ::libc::sockaddr_in { + let mut sin_zero = [0u8; 8]; + sin_zero.copy_from_slice(&self.sin_zero.borrow()); + ::libc::sockaddr_in { + sin_family: *self.sin_family.borrow(), + sin_port: *self.sin_port.borrow(), + sin_addr: ::libc::in_addr { + s_addr: *self.sin_addr.borrow().s_addr.borrow(), + }, + sin_zero, + } + } +} + +impl SockaddrIn6 { + #[allow(clippy::unnecessary_cast)] + pub fn from_libc(l: &::libc::sockaddr_in6) -> Self { + Self { + sin6_family: Rc::new(RefCell::new(l.sin6_family as u16)), + sin6_port: Rc::new(RefCell::new(l.sin6_port)), + sin6_flowinfo: Rc::new(RefCell::new(l.sin6_flowinfo)), + sin6_addr: Rc::new(RefCell::new(In6Addr { + s6_addr: Rc::new(RefCell::new( + l.sin6_addr.s6_addr.to_vec().into_boxed_slice(), + )), + })), + sin6_scope_id: Rc::new(RefCell::new(l.sin6_scope_id)), + } + } + + pub fn from_ipv6(addr: &::std::net::Ipv6Addr, port: u16) -> Self { + let s = Self::default(); + *s.sin6_family.borrow_mut() = ::libc::AF_INET6 as u16; + *s.sin6_port.borrow_mut() = port.to_be(); + s.sin6_addr + .borrow() + .s6_addr + .borrow_mut() + .copy_from_slice(&addr.octets()); + s + } + + #[cfg(target_os = "linux")] + pub fn to_libc(&self) -> ::libc::sockaddr_in6 { + let mut s6_addr = [0u8; 16]; + s6_addr.copy_from_slice(&self.sin6_addr.borrow().s6_addr.borrow()); + ::libc::sockaddr_in6 { + sin6_family: *self.sin6_family.borrow(), + sin6_port: *self.sin6_port.borrow(), + sin6_flowinfo: *self.sin6_flowinfo.borrow(), + sin6_addr: ::libc::in6_addr { s6_addr }, + sin6_scope_id: *self.sin6_scope_id.borrow(), + } + } +} + impl Default for Sockaddr { fn default() -> Self { Self { diff --git a/rules/ifaddrs/tgt_refcount.rs b/rules/ifaddrs/tgt_refcount.rs index 152bb0df..90ddb02a 100644 --- a/rules/ifaddrs/tgt_refcount.rs +++ b/rules/ifaddrs/tgt_refcount.rs @@ -6,3 +6,47 @@ use libcc2rs::*; fn t1() -> libcc2rs::Ifaddrs { Default::default() } + +fn f1(a0: Ptr>) -> i32 { + let __out = a0.clone(); + match nix::ifaddrs::getifaddrs() { + Ok(__ifas) => { + let __list: Vec = __ifas.collect(); + let mut __next = Ptr::::null(); + for __ifa in __list.iter().rev() { + let __node = Ifaddrs::from_interface_address(__ifa); + *__node.ifa_next.borrow_mut() = __next.clone(); + __next = Ptr::alloc(__node); + } + __out.write(__next); + 0 + } + Err(__e) => { + libcc2rs::cpp2rust_errno().write(__e as i32); + -1 + } + } +} + +fn f2(a0: Ptr) { + let mut __cur = a0.clone(); + while !__cur.is_null() { + let __next = __cur.with(|__i| { + let __name = __i.ifa_name.borrow(); + if !__name.is_null() { + __name.delete_array(); + } + let __addr = __i.ifa_addr.borrow(); + if !__addr.is_null() { + __addr.delete(); + } + let __mask = __i.ifa_netmask.borrow(); + if !__mask.is_null() { + __mask.delete(); + } + (*__i.ifa_next.borrow()).clone() + }); + __cur.delete(); + __cur = __next; + } +} diff --git a/rules/netdb/tgt_refcount.rs b/rules/netdb/tgt_refcount.rs index 109eebf4..23e3d541 100644 --- a/rules/netdb/tgt_refcount.rs +++ b/rules/netdb/tgt_refcount.rs @@ -6,3 +6,108 @@ use libcc2rs::*; fn t1() -> libcc2rs::Addrinfo { Default::default() } + +fn f1(a0: Ptr, a1: Ptr, a2: Ptr, a3: Ptr>) -> i32 { + let __node = a0.clone(); + let __service = a1.clone(); + let __hints = a2.clone(); + let __out = a3.clone(); + let __family = if __hints.is_null() { + ::libc::AF_UNSPEC + } else { + __hints.with(|__h| *__h.ai_family.borrow()) + }; + let __socktype = if __hints.is_null() { + 0 + } else { + __hints.with(|__h| *__h.ai_socktype.borrow()) + }; + let __protocol = if __hints.is_null() { + 0 + } else { + __hints.with(|__h| *__h.ai_protocol.borrow()) + }; + let __port: u16 = if __service.is_null() { + 0 + } else { + __service.to_rust_string().parse().unwrap_or(0) + }; + let mut __addrs: Vec<::std::net::IpAddr> = Vec::new(); + if __node.is_null() { + if __family == ::libc::AF_INET6 { + __addrs.push(::std::net::IpAddr::V6(::std::net::Ipv6Addr::UNSPECIFIED)); + } else { + __addrs.push(::std::net::IpAddr::V4(::std::net::Ipv4Addr::UNSPECIFIED)); + } + } else { + let __host = __node.to_rust_string(); + match __host.parse::<::std::net::IpAddr>() { + Ok(__ip) => __addrs.push(__ip), + Err(_) => { + use ::std::net::ToSocketAddrs; + match (__host.as_str(), __port).to_socket_addrs() { + Ok(__it) => { + for __sa in __it { + __addrs.push(__sa.ip()); + } + } + Err(_) => {} + } + } + } + } + __addrs.retain(|__ip| match __family { + ::libc::AF_INET => __ip.is_ipv4(), + ::libc::AF_INET6 => __ip.is_ipv6(), + _ => true, + }); + if __addrs.is_empty() { + ::libc::EAI_NONAME + } else { + let mut __next = Ptr::::null(); + for __ip in __addrs.iter().rev() { + let __ai = Addrinfo::default(); + *__ai.ai_socktype.borrow_mut() = __socktype; + *__ai.ai_protocol.borrow_mut() = __protocol; + let __storage = Ptr::alloc(SockaddrStorage::default()); + match __ip { + ::std::net::IpAddr::V4(__v4) => { + *__ai.ai_family.borrow_mut() = ::libc::AF_INET; + *__ai.ai_addrlen.borrow_mut() = + ::std::mem::size_of::<::libc::sockaddr_in>() as u32; + __storage + .reinterpret_cast::() + .write(SockaddrIn::from_ipv4(__v4, __port)); + } + ::std::net::IpAddr::V6(__v6) => { + *__ai.ai_family.borrow_mut() = ::libc::AF_INET6; + *__ai.ai_addrlen.borrow_mut() = + ::std::mem::size_of::<::libc::sockaddr_in6>() as u32; + __storage + .reinterpret_cast::() + .write(SockaddrIn6::from_ipv6(__v6, __port)); + } + } + *__ai.ai_addr.borrow_mut() = __storage.reinterpret_cast::(); + *__ai.ai_next.borrow_mut() = __next.clone(); + __next = Ptr::alloc(__ai); + } + __out.write(__next); + 0 + } +} + +fn f2(a0: Ptr) { + let mut __cur = a0.clone(); + while !__cur.is_null() { + let __next = __cur.with(|__ai| { + let __addr = __ai.ai_addr.borrow(); + if !__addr.is_null() { + __addr.delete(); + } + (*__ai.ai_next.borrow()).clone() + }); + __cur.delete(); + __cur = __next; + } +} diff --git a/rules/socket/src.c b/rules/socket/src.c index 243e2463..95f63fd1 100644 --- a/rules/socket/src.c +++ b/rules/socket/src.c @@ -88,3 +88,11 @@ ssize_t f19(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) { return sendto(sockfd, buf, len, flags, dest_addr, addrlen); } + +int f20() { + return AF_INET; +} + +int f21() { + return AF_INET6; +} diff --git a/rules/socket/tgt_unsafe.rs b/rules/socket/tgt_unsafe.rs index 7b93c687..1af2d775 100644 --- a/rules/socket/tgt_unsafe.rs +++ b/rules/socket/tgt_unsafe.rs @@ -102,3 +102,11 @@ unsafe fn f19( ) -> isize { libc::sendto(a0, a1, a2, a3, a4, a5) } + +unsafe fn f20() -> i32 { + libc::AF_INET +} + +unsafe fn f21() -> i32 { + libc::AF_INET6 +} diff --git a/tests/unit/ifaddrs.c b/tests/unit/ifaddrs.c new file mode 100644 index 00000000..0b5e80a5 --- /dev/null +++ b/tests/unit/ifaddrs.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +#include + +int main(void) { + struct ifaddrs *list = NULL; + assert(getifaddrs(&list) == 0); + assert(list != NULL); + int found_loopback = 0; + struct ifaddrs *ifa; + for (ifa = list; ifa != NULL; ifa = ifa->ifa_next) { + assert(ifa->ifa_name != NULL); + if (ifa->ifa_addr == NULL) { + continue; + } + if (ifa->ifa_addr->sa_family != AF_INET) { + continue; + } + struct sockaddr_in *sin = (struct sockaddr_in *)ifa->ifa_addr; + unsigned char lo_be[4] = {127, 0, 0, 1}; + if (memcmp(&sin->sin_addr, lo_be, 4) == 0) { + found_loopback = 1; + assert(ifa->ifa_flags != 0); + assert(ifa->ifa_netmask != NULL); + struct sockaddr_in *mask = (struct sockaddr_in *)ifa->ifa_netmask; + unsigned char mask_be[4] = {255, 0, 0, 0}; + assert(memcmp(&mask->sin_addr, mask_be, 4) == 0); + } + } + assert(found_loopback); + freeifaddrs(list); + return 0; +} diff --git a/tests/unit/netdb.c b/tests/unit/netdb.c new file mode 100644 index 00000000..5003bf09 --- /dev/null +++ b/tests/unit/netdb.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include + +static void test_ipv4_literal(void) { + struct addrinfo hints; + hints.ai_flags = 0; + hints.ai_protocol = 0; + hints.ai_addrlen = 0; + hints.ai_addr = NULL; + hints.ai_canonname = NULL; + hints.ai_next = NULL; + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + struct addrinfo *res = NULL; + assert(getaddrinfo("127.0.0.1", "8080", &hints, &res) == 0); + assert(res != NULL); + assert(res->ai_family == AF_INET); + assert(res->ai_socktype == SOCK_STREAM); + assert(res->ai_addrlen == sizeof(struct sockaddr_in)); + assert(res->ai_addr != NULL); + struct sockaddr_in *sin = (struct sockaddr_in *)res->ai_addr; + assert(sin->sin_family == AF_INET); + unsigned char port_be[2] = {8080 / 256, 8080 % 256}; + assert(memcmp(&sin->sin_port, port_be, 2) == 0); + unsigned char addr_be[4] = {127, 0, 0, 1}; + assert(memcmp(&sin->sin_addr, addr_be, 4) == 0); + freeaddrinfo(res); +} + +static void test_ipv6_literal(void) { + struct addrinfo hints; + hints.ai_flags = 0; + hints.ai_protocol = 0; + hints.ai_addrlen = 0; + hints.ai_addr = NULL; + hints.ai_canonname = NULL; + hints.ai_next = NULL; + hints.ai_family = AF_INET6; + hints.ai_socktype = SOCK_STREAM; + struct addrinfo *res = NULL; + assert(getaddrinfo("::1", "443", &hints, &res) == 0); + assert(res != NULL); + assert(res->ai_family == AF_INET6); + assert(res->ai_addrlen == sizeof(struct sockaddr_in6)); + assert(res->ai_addr != NULL); + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)res->ai_addr; + assert(sin6->sin6_family == AF_INET6); + unsigned char port_be[2] = {443 / 256, 443 % 256}; + assert(memcmp(&sin6->sin6_port, port_be, 2) == 0); + unsigned char addr_be[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + assert(memcmp(&sin6->sin6_addr, addr_be, 16) == 0); + freeaddrinfo(res); +} + +static void test_null_hints(void) { + struct addrinfo *res = NULL; + assert(getaddrinfo("127.0.0.1", "80", NULL, &res) == 0); + assert(res != NULL); + assert(res->ai_family == AF_INET); + struct sockaddr_in *sin = (struct sockaddr_in *)res->ai_addr; + unsigned char addr_be[4] = {127, 0, 0, 1}; + assert(memcmp(&sin->sin_addr, addr_be, 4) == 0); + freeaddrinfo(res); +} + +int main(void) { + test_ipv4_literal(); + test_ipv6_literal(); + test_null_hints(); + return 0; +} diff --git a/tests/unit/out/refcount/enum_int_interop_c.rs b/tests/unit/out/refcount/enum_int_interop_c.rs index edb5e2f5..39f7a014 100644 --- a/tests/unit/out/refcount/enum_int_interop_c.rs +++ b/tests/unit/out/refcount/enum_int_interop_c.rs @@ -358,10 +358,8 @@ fn main_0() -> i32 { .offset((*idx.borrow()) as isize)), )); assert!( - ((({ - let _lhs = ((*(*(*pe.borrow()).upgrade().deref()).opt.borrow()) as u32).clone(); - _lhs == ((Option::OPT_A as i32) as u32) - }) as i32) + (((((*(*(*pe.borrow()).upgrade().deref()).opt.borrow()) as u32) + == ((Option::OPT_A as i32) as u32)) as i32) != 0) ); return 0; diff --git a/tests/unit/out/refcount/ifaddrs.rs b/tests/unit/out/refcount/ifaddrs.rs new file mode 100644 index 00000000..3e533a0b --- /dev/null +++ b/tests/unit/out/refcount/ifaddrs.rs @@ -0,0 +1,135 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let list: Value> = + Rc::new(RefCell::new(Ptr::::null())); + assert!( + ((({ + let __out = (list.as_pointer()).clone(); + match nix::ifaddrs::getifaddrs() { + Ok(__ifas) => { + let __list: Vec = __ifas.collect(); + let mut __next = Ptr::::null(); + for __ifa in __list.iter().rev() { + let __node = Ifaddrs::from_interface_address(__ifa); + *__node.ifa_next.borrow_mut() = __next.clone(); + __next = Ptr::alloc(__node); + } + __out.write(__next); + 0 + } + Err(__e) => { + libcc2rs::cpp2rust_errno().write(__e as i32); + -1 + } + } + } == 0) as i32) + != 0) + ); + assert!((((!((*list.borrow()).is_null())) as i32) != 0)); + let found_loopback: Value = Rc::new(RefCell::new(0)); + let ifa: Value> = + Rc::new(RefCell::new(Ptr::::null())); + (*ifa.borrow_mut()) = (*list.borrow()).clone(); + 'loop_: while (((!((*ifa.borrow()).is_null())) as i32) != 0) { + assert!( + (((!((*(*(*ifa.borrow()).upgrade().deref()).ifa_name.borrow()).is_null())) as i32) + != 0) + ); + if ((((*(*(*ifa.borrow()).upgrade().deref()).ifa_addr.borrow()).is_null()) as i32) != 0) { + let __rhs = (*(*(*ifa.borrow()).upgrade().deref()).ifa_next.borrow()).clone(); + (*ifa.borrow_mut()) = __rhs; + continue 'loop_; + } + if (((((*(*(*(*(*ifa.borrow()).upgrade().deref()).ifa_addr.borrow()) + .upgrade() + .deref()) + .sa_family + .borrow()) as i32) + != libc::AF_INET) as i32) + != 0) + { + let __rhs = (*(*(*ifa.borrow()).upgrade().deref()).ifa_next.borrow()).clone(); + (*ifa.borrow_mut()) = __rhs; + continue 'loop_; + } + let sin: Value> = Rc::new(RefCell::new( + (*(*(*ifa.borrow()).upgrade().deref()).ifa_addr.borrow()) + .reinterpret_cast::(), + )); + let lo_be: Value> = Rc::new(RefCell::new(Box::new([127_u8, 0_u8, 0_u8, 1_u8]))); + if ((((((*(*sin.borrow()).upgrade().deref()).sin_addr.as_pointer()) + as Ptr) + .to_any() + .memcmp( + &((lo_be.as_pointer() as Ptr) as Ptr).to_any(), + 4_usize, + ) + == 0) as i32) + != 0) + { + (*found_loopback.borrow_mut()) = 1; + assert!( + ((((*(*(*ifa.borrow()).upgrade().deref()).ifa_flags.borrow()) != 0_u32) as i32) + != 0) + ); + assert!( + (((!((*(*(*ifa.borrow()).upgrade().deref()).ifa_netmask.borrow()).is_null())) + as i32) + != 0) + ); + let mask: Value> = Rc::new(RefCell::new( + (*(*(*ifa.borrow()).upgrade().deref()).ifa_netmask.borrow()) + .reinterpret_cast::(), + )); + let mask_be: Value> = + Rc::new(RefCell::new(Box::new([255_u8, 0_u8, 0_u8, 0_u8]))); + assert!( + ((((((*(*mask.borrow()).upgrade().deref()).sin_addr.as_pointer()) + as Ptr) + .to_any() + .memcmp( + &((mask_be.as_pointer() as Ptr::) as Ptr::).to_any(), + 4_usize + ) + == 0) as i32) + != 0) + ); + } + let __rhs = (*(*(*ifa.borrow()).upgrade().deref()).ifa_next.borrow()).clone(); + (*ifa.borrow_mut()) = __rhs; + } + assert!(((*found_loopback.borrow()) != 0)); + { + let mut __cur = (*list.borrow()).clone(); + while !__cur.is_null() { + let __next = __cur.with(|__i| { + let __name = __i.ifa_name.borrow(); + if !__name.is_null() { + __name.delete_array(); + } + let __addr = __i.ifa_addr.borrow(); + if !__addr.is_null() { + __addr.delete(); + } + let __mask = __i.ifa_netmask.borrow(); + if !__mask.is_null() { + __mask.delete(); + } + (*__i.ifa_next.borrow()).clone() + }); + __cur.delete(); + __cur = __next; + } + }; + return 0; +} diff --git a/tests/unit/out/refcount/netdb.rs b/tests/unit/out/refcount/netdb.rs new file mode 100644 index 00000000..8aea22f4 --- /dev/null +++ b/tests/unit/out/refcount/netdb.rs @@ -0,0 +1,488 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn test_ipv4_literal_0() { + let hints: Value = Rc::new(RefCell::new(Default::default())); + (*(*hints.borrow()).ai_flags.borrow_mut()) = 0; + (*(*hints.borrow()).ai_protocol.borrow_mut()) = 0; + (*(*hints.borrow()).ai_addrlen.borrow_mut()) = 0_u32; + (*(*hints.borrow()).ai_addr.borrow_mut()) = Ptr::::null(); + (*(*hints.borrow()).ai_canonname.borrow_mut()) = Ptr::::null(); + (*(*hints.borrow()).ai_next.borrow_mut()) = Ptr::::null(); + (*(*hints.borrow()).ai_family.borrow_mut()) = libc::AF_INET; + (*(*hints.borrow()).ai_socktype.borrow_mut()) = libc::SOCK_STREAM; + let res: Value> = + Rc::new(RefCell::new(Ptr::::null())); + assert!( + ((({ + let __node = Ptr::from_string_literal(b"127.0.0.1").clone(); + let __service = Ptr::from_string_literal(b"8080").clone(); + let __hints = (hints.as_pointer()).clone(); + let __out = (res.as_pointer()).clone(); + let __family = if __hints.is_null() { + ::libc::AF_UNSPEC + } else { + __hints.with(|__h| *__h.ai_family.borrow()) + }; + let __socktype = if __hints.is_null() { + 0 + } else { + __hints.with(|__h| *__h.ai_socktype.borrow()) + }; + let __protocol = if __hints.is_null() { + 0 + } else { + __hints.with(|__h| *__h.ai_protocol.borrow()) + }; + let __port: u16 = if __service.is_null() { + 0 + } else { + __service.to_rust_string().parse().unwrap_or(0) + }; + let mut __addrs: Vec<::std::net::IpAddr> = Vec::new(); + if __node.is_null() { + if __family == ::libc::AF_INET6 { + __addrs.push(::std::net::IpAddr::V6(::std::net::Ipv6Addr::UNSPECIFIED)); + } else { + __addrs.push(::std::net::IpAddr::V4(::std::net::Ipv4Addr::UNSPECIFIED)); + } + } else { + let __host = __node.to_rust_string(); + match __host.parse::<::std::net::IpAddr>() { + Ok(__ip) => __addrs.push(__ip), + Err(_) => { + use ::std::net::ToSocketAddrs; + match (__host.as_str(), __port).to_socket_addrs() { + Ok(__it) => { + for __sa in __it { + __addrs.push(__sa.ip()); + } + } + Err(_) => {} + } + } + } + } + __addrs.retain(|__ip| match __family { + ::libc::AF_INET => __ip.is_ipv4(), + ::libc::AF_INET6 => __ip.is_ipv6(), + _ => true, + }); + if __addrs.is_empty() { + ::libc::EAI_NONAME + } else { + let mut __next = Ptr::::null(); + for __ip in __addrs.iter().rev() { + let __ai = Addrinfo::default(); + *__ai.ai_socktype.borrow_mut() = __socktype; + *__ai.ai_protocol.borrow_mut() = __protocol; + let __storage = Ptr::alloc(SockaddrStorage::default()); + match __ip { + ::std::net::IpAddr::V4(__v4) => { + *__ai.ai_family.borrow_mut() = ::libc::AF_INET; + *__ai.ai_addrlen.borrow_mut() = + ::std::mem::size_of::<::libc::sockaddr_in>() as u32; + __storage + .reinterpret_cast::() + .write(SockaddrIn::from_ipv4(__v4, __port)); + } + ::std::net::IpAddr::V6(__v6) => { + *__ai.ai_family.borrow_mut() = ::libc::AF_INET6; + *__ai.ai_addrlen.borrow_mut() = + ::std::mem::size_of::<::libc::sockaddr_in6>() as u32; + __storage + .reinterpret_cast::() + .write(SockaddrIn6::from_ipv6(__v6, __port)); + } + } + *__ai.ai_addr.borrow_mut() = __storage.reinterpret_cast::(); + *__ai.ai_next.borrow_mut() = __next.clone(); + __next = Ptr::alloc(__ai); + } + __out.write(__next); + 0 + } + } == 0) as i32) + != 0) + ); + assert!((((!((*res.borrow()).is_null())) as i32) != 0)); + assert!( + ((((*(*(*res.borrow()).upgrade().deref()).ai_family.borrow()) == libc::AF_INET) as i32) + != 0) + ); + assert!( + ((((*(*(*res.borrow()).upgrade().deref()).ai_socktype.borrow()) == libc::SOCK_STREAM) + as i32) + != 0) + ); + assert!( + (((((*(*(*res.borrow()).upgrade().deref()).ai_addrlen.borrow()) as usize) == 16usize) + as i32) + != 0) + ); + assert!( + (((!((*(*(*res.borrow()).upgrade().deref()).ai_addr.borrow()).is_null())) as i32) != 0) + ); + let sin: Value> = Rc::new(RefCell::new( + (*(*(*res.borrow()).upgrade().deref()).ai_addr.borrow()) + .reinterpret_cast::(), + )); + assert!( + (((((*(*(*sin.borrow()).upgrade().deref()).sin_family.borrow()) as i32) == libc::AF_INET) + as i32) + != 0) + ); + let port_be: Value> = Rc::new(RefCell::new(Box::new([ + ((8080 / 256) as u8), + ((8080 % 256) as u8), + ]))); + assert!( + ((((((*(*sin.borrow()).upgrade().deref()).sin_port.as_pointer()) as Ptr::) + .to_any() + .memcmp( + &((port_be.as_pointer() as Ptr::) as Ptr::).to_any(), + 2_usize + ) + == 0) as i32) + != 0) + ); + let addr_be: Value> = Rc::new(RefCell::new(Box::new([127_u8, 0_u8, 0_u8, 1_u8]))); + assert!( + ((((((*(*sin.borrow()).upgrade().deref()).sin_addr.as_pointer()) as Ptr) + .to_any() + .memcmp( + &((addr_be.as_pointer() as Ptr::) as Ptr::).to_any(), + 4_usize + ) + == 0) as i32) + != 0) + ); + { + let mut __cur = (*res.borrow()).clone(); + while !__cur.is_null() { + let __next = __cur.with(|__ai| { + let __addr = __ai.ai_addr.borrow(); + if !__addr.is_null() { + __addr.delete(); + } + (*__ai.ai_next.borrow()).clone() + }); + __cur.delete(); + __cur = __next; + } + }; +} +pub fn test_ipv6_literal_1() { + let hints: Value = Rc::new(RefCell::new(Default::default())); + (*(*hints.borrow()).ai_flags.borrow_mut()) = 0; + (*(*hints.borrow()).ai_protocol.borrow_mut()) = 0; + (*(*hints.borrow()).ai_addrlen.borrow_mut()) = 0_u32; + (*(*hints.borrow()).ai_addr.borrow_mut()) = Ptr::::null(); + (*(*hints.borrow()).ai_canonname.borrow_mut()) = Ptr::::null(); + (*(*hints.borrow()).ai_next.borrow_mut()) = Ptr::::null(); + (*(*hints.borrow()).ai_family.borrow_mut()) = libc::AF_INET6; + (*(*hints.borrow()).ai_socktype.borrow_mut()) = libc::SOCK_STREAM; + let res: Value> = + Rc::new(RefCell::new(Ptr::::null())); + assert!( + ((({ + let __node = Ptr::from_string_literal(b"::1").clone(); + let __service = Ptr::from_string_literal(b"443").clone(); + let __hints = (hints.as_pointer()).clone(); + let __out = (res.as_pointer()).clone(); + let __family = if __hints.is_null() { + ::libc::AF_UNSPEC + } else { + __hints.with(|__h| *__h.ai_family.borrow()) + }; + let __socktype = if __hints.is_null() { + 0 + } else { + __hints.with(|__h| *__h.ai_socktype.borrow()) + }; + let __protocol = if __hints.is_null() { + 0 + } else { + __hints.with(|__h| *__h.ai_protocol.borrow()) + }; + let __port: u16 = if __service.is_null() { + 0 + } else { + __service.to_rust_string().parse().unwrap_or(0) + }; + let mut __addrs: Vec<::std::net::IpAddr> = Vec::new(); + if __node.is_null() { + if __family == ::libc::AF_INET6 { + __addrs.push(::std::net::IpAddr::V6(::std::net::Ipv6Addr::UNSPECIFIED)); + } else { + __addrs.push(::std::net::IpAddr::V4(::std::net::Ipv4Addr::UNSPECIFIED)); + } + } else { + let __host = __node.to_rust_string(); + match __host.parse::<::std::net::IpAddr>() { + Ok(__ip) => __addrs.push(__ip), + Err(_) => { + use ::std::net::ToSocketAddrs; + match (__host.as_str(), __port).to_socket_addrs() { + Ok(__it) => { + for __sa in __it { + __addrs.push(__sa.ip()); + } + } + Err(_) => {} + } + } + } + } + __addrs.retain(|__ip| match __family { + ::libc::AF_INET => __ip.is_ipv4(), + ::libc::AF_INET6 => __ip.is_ipv6(), + _ => true, + }); + if __addrs.is_empty() { + ::libc::EAI_NONAME + } else { + let mut __next = Ptr::::null(); + for __ip in __addrs.iter().rev() { + let __ai = Addrinfo::default(); + *__ai.ai_socktype.borrow_mut() = __socktype; + *__ai.ai_protocol.borrow_mut() = __protocol; + let __storage = Ptr::alloc(SockaddrStorage::default()); + match __ip { + ::std::net::IpAddr::V4(__v4) => { + *__ai.ai_family.borrow_mut() = ::libc::AF_INET; + *__ai.ai_addrlen.borrow_mut() = + ::std::mem::size_of::<::libc::sockaddr_in>() as u32; + __storage + .reinterpret_cast::() + .write(SockaddrIn::from_ipv4(__v4, __port)); + } + ::std::net::IpAddr::V6(__v6) => { + *__ai.ai_family.borrow_mut() = ::libc::AF_INET6; + *__ai.ai_addrlen.borrow_mut() = + ::std::mem::size_of::<::libc::sockaddr_in6>() as u32; + __storage + .reinterpret_cast::() + .write(SockaddrIn6::from_ipv6(__v6, __port)); + } + } + *__ai.ai_addr.borrow_mut() = __storage.reinterpret_cast::(); + *__ai.ai_next.borrow_mut() = __next.clone(); + __next = Ptr::alloc(__ai); + } + __out.write(__next); + 0 + } + } == 0) as i32) + != 0) + ); + assert!((((!((*res.borrow()).is_null())) as i32) != 0)); + assert!( + ((((*(*(*res.borrow()).upgrade().deref()).ai_family.borrow()) == libc::AF_INET6) as i32) + != 0) + ); + assert!( + (((((*(*(*res.borrow()).upgrade().deref()).ai_addrlen.borrow()) as usize) == 28usize) + as i32) + != 0) + ); + assert!( + (((!((*(*(*res.borrow()).upgrade().deref()).ai_addr.borrow()).is_null())) as i32) != 0) + ); + let sin6: Value> = Rc::new(RefCell::new( + (*(*(*res.borrow()).upgrade().deref()).ai_addr.borrow()) + .reinterpret_cast::(), + )); + assert!( + (((((*(*(*sin6.borrow()).upgrade().deref()).sin6_family.borrow()) as i32) == libc::AF_INET6) + as i32) + != 0) + ); + let port_be: Value> = Rc::new(RefCell::new(Box::new([ + ((443 / 256) as u8), + ((443 % 256) as u8), + ]))); + assert!( + ((((((*(*sin6.borrow()).upgrade().deref()).sin6_port.as_pointer()) as Ptr::) + .to_any() + .memcmp( + &((port_be.as_pointer() as Ptr::) as Ptr::).to_any(), + 2_usize + ) + == 0) as i32) + != 0) + ); + let addr_be: Value> = Rc::new(RefCell::new(Box::new([ + 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, + 1_u8, + ]))); + assert!( + ((((((*(*sin6.borrow()).upgrade().deref()).sin6_addr.as_pointer()) + as Ptr) + .to_any() + .memcmp( + &((addr_be.as_pointer() as Ptr::) as Ptr::).to_any(), + 16_usize + ) + == 0) as i32) + != 0) + ); + { + let mut __cur = (*res.borrow()).clone(); + while !__cur.is_null() { + let __next = __cur.with(|__ai| { + let __addr = __ai.ai_addr.borrow(); + if !__addr.is_null() { + __addr.delete(); + } + (*__ai.ai_next.borrow()).clone() + }); + __cur.delete(); + __cur = __next; + } + }; +} +pub fn test_null_hints_2() { + let res: Value> = + Rc::new(RefCell::new(Ptr::::null())); + assert!( + ((({ + let __node = Ptr::from_string_literal(b"127.0.0.1").clone(); + let __service = Ptr::from_string_literal(b"80").clone(); + let __hints = Ptr::::null().clone(); + let __out = (res.as_pointer()).clone(); + let __family = if __hints.is_null() { + ::libc::AF_UNSPEC + } else { + __hints.with(|__h| *__h.ai_family.borrow()) + }; + let __socktype = if __hints.is_null() { + 0 + } else { + __hints.with(|__h| *__h.ai_socktype.borrow()) + }; + let __protocol = if __hints.is_null() { + 0 + } else { + __hints.with(|__h| *__h.ai_protocol.borrow()) + }; + let __port: u16 = if __service.is_null() { + 0 + } else { + __service.to_rust_string().parse().unwrap_or(0) + }; + let mut __addrs: Vec<::std::net::IpAddr> = Vec::new(); + if __node.is_null() { + if __family == ::libc::AF_INET6 { + __addrs.push(::std::net::IpAddr::V6(::std::net::Ipv6Addr::UNSPECIFIED)); + } else { + __addrs.push(::std::net::IpAddr::V4(::std::net::Ipv4Addr::UNSPECIFIED)); + } + } else { + let __host = __node.to_rust_string(); + match __host.parse::<::std::net::IpAddr>() { + Ok(__ip) => __addrs.push(__ip), + Err(_) => { + use ::std::net::ToSocketAddrs; + match (__host.as_str(), __port).to_socket_addrs() { + Ok(__it) => { + for __sa in __it { + __addrs.push(__sa.ip()); + } + } + Err(_) => {} + } + } + } + } + __addrs.retain(|__ip| match __family { + ::libc::AF_INET => __ip.is_ipv4(), + ::libc::AF_INET6 => __ip.is_ipv6(), + _ => true, + }); + if __addrs.is_empty() { + ::libc::EAI_NONAME + } else { + let mut __next = Ptr::::null(); + for __ip in __addrs.iter().rev() { + let __ai = Addrinfo::default(); + *__ai.ai_socktype.borrow_mut() = __socktype; + *__ai.ai_protocol.borrow_mut() = __protocol; + let __storage = Ptr::alloc(SockaddrStorage::default()); + match __ip { + ::std::net::IpAddr::V4(__v4) => { + *__ai.ai_family.borrow_mut() = ::libc::AF_INET; + *__ai.ai_addrlen.borrow_mut() = + ::std::mem::size_of::<::libc::sockaddr_in>() as u32; + __storage + .reinterpret_cast::() + .write(SockaddrIn::from_ipv4(__v4, __port)); + } + ::std::net::IpAddr::V6(__v6) => { + *__ai.ai_family.borrow_mut() = ::libc::AF_INET6; + *__ai.ai_addrlen.borrow_mut() = + ::std::mem::size_of::<::libc::sockaddr_in6>() as u32; + __storage + .reinterpret_cast::() + .write(SockaddrIn6::from_ipv6(__v6, __port)); + } + } + *__ai.ai_addr.borrow_mut() = __storage.reinterpret_cast::(); + *__ai.ai_next.borrow_mut() = __next.clone(); + __next = Ptr::alloc(__ai); + } + __out.write(__next); + 0 + } + } == 0) as i32) + != 0) + ); + assert!((((!((*res.borrow()).is_null())) as i32) != 0)); + assert!( + ((((*(*(*res.borrow()).upgrade().deref()).ai_family.borrow()) == libc::AF_INET) as i32) + != 0) + ); + let sin: Value> = Rc::new(RefCell::new( + (*(*(*res.borrow()).upgrade().deref()).ai_addr.borrow()) + .reinterpret_cast::(), + )); + let addr_be: Value> = Rc::new(RefCell::new(Box::new([127_u8, 0_u8, 0_u8, 1_u8]))); + assert!( + ((((((*(*sin.borrow()).upgrade().deref()).sin_addr.as_pointer()) as Ptr) + .to_any() + .memcmp( + &((addr_be.as_pointer() as Ptr::) as Ptr::).to_any(), + 4_usize + ) + == 0) as i32) + != 0) + ); + { + let mut __cur = (*res.borrow()).clone(); + while !__cur.is_null() { + let __next = __cur.with(|__ai| { + let __addr = __ai.ai_addr.borrow(); + if !__addr.is_null() { + __addr.delete(); + } + (*__ai.ai_next.borrow()).clone() + }); + __cur.delete(); + __cur = __next; + } + }; +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_ipv4_literal_0() }); + ({ test_ipv6_literal_1() }); + ({ test_null_hints_2() }); + return 0; +} diff --git a/tests/unit/out/refcount/tag_vs_identifier_collision.rs b/tests/unit/out/refcount/tag_vs_identifier_collision.rs index 98e95a3d..07e5a40e 100644 --- a/tests/unit/out/refcount/tag_vs_identifier_collision.rs +++ b/tests/unit/out/refcount/tag_vs_identifier_collision.rs @@ -262,10 +262,9 @@ impl ByteRepr for Inner_struct { } pub fn is_active_0(w: Ptr) -> i32 { let w: Value> = Rc::new(RefCell::new(w)); - return (({ - let _lhs = ((*(*(*w.borrow()).upgrade().deref()).mode.borrow()) as u32).clone(); - _lhs == ((widget_enum::MODE_ACTIVE as i32) as u32) - }) as i32); + return ((((*(*(*w.borrow()).upgrade().deref()).mode.borrow()) as u32) + == ((widget_enum::MODE_ACTIVE as i32) as u32)) as i32) + .clone(); } pub fn main() { std::process::exit(main_0()); diff --git a/tests/unit/out/unsafe/ifaddrs.rs b/tests/unit/out/unsafe/ifaddrs.rs new file mode 100644 index 00000000..9244e84e --- /dev/null +++ b/tests/unit/out/unsafe/ifaddrs.rs @@ -0,0 +1,88 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut list: *mut libc::ifaddrs = std::ptr::null_mut(); + assert!(((((libc::getifaddrs((&mut list as *mut *mut libc::ifaddrs))) == (0)) as i32) != 0)); + assert!((((!((list).is_null())) as i32) != 0)); + let mut found_loopback: i32 = 0; + let mut ifa: *mut libc::ifaddrs = std::ptr::null_mut(); + ifa = list; + 'loop_: while (((!((ifa).is_null())) as i32) != 0) { + assert!((((!(((*ifa).ifa_name).is_null())) as i32) != 0)); + if (((((*ifa).ifa_addr).is_null()) as i32) != 0) { + ifa = (*ifa).ifa_next; + continue 'loop_; + } + if (((((*(*ifa).ifa_addr).sa_family as i32) != (libc::AF_INET)) as i32) != 0) { + ifa = (*ifa).ifa_next; + continue 'loop_; + } + let mut sin: *mut ::libc::sockaddr_in = ((*ifa).ifa_addr as *mut ::libc::sockaddr_in); + let mut lo_be: [u8; 4] = [127_u8, 0_u8, 0_u8, 1_u8]; + if (((({ + let sa = core::slice::from_raw_parts( + ((&mut (*sin).sin_addr as *mut ::libc::in_addr) as *const ::libc::in_addr + as *const ::libc::c_void) as *const u8, + 4_usize as usize, + ); + let sb = core::slice::from_raw_parts( + (lo_be.as_mut_ptr() as *const u8 as *const ::libc::c_void) as *const u8, + 4_usize as usize, + ); + let mut diff = 0_i32; + for (x, y) in sa.iter().zip(sb.iter()) { + if x != y { + diff = (*x as i32) - (*y as i32); + break; + } + } + diff + }) == (0)) as i32) + != 0) + { + found_loopback = 1; + assert!((((((*ifa).ifa_flags) != (0_u32)) as i32) != 0)); + assert!((((!(((*ifa).ifa_netmask).is_null())) as i32) != 0)); + let mut mask: *mut ::libc::sockaddr_in = + ((*ifa).ifa_netmask as *mut ::libc::sockaddr_in); + let mut mask_be: [u8; 4] = [255_u8, 0_u8, 0_u8, 0_u8]; + assert!( + (((({ + let sa = core::slice::from_raw_parts( + ((&mut (*mask).sin_addr as *mut ::libc::in_addr) as *const ::libc::in_addr + as *const ::libc::c_void) as *const u8, + 4_usize as usize, + ); + let sb = core::slice::from_raw_parts( + (mask_be.as_mut_ptr() as *const u8 as *const ::libc::c_void) as *const u8, + 4_usize as usize, + ); + let mut diff = 0_i32; + for (x, y) in sa.iter().zip(sb.iter()) { + if x != y { + diff = (*x as i32) - (*y as i32); + break; + } + } + diff + }) == (0)) as i32) + != 0) + ); + } + ifa = (*ifa).ifa_next; + } + assert!((found_loopback != 0)); + libc::freeifaddrs(list); + return 0; +} diff --git a/tests/unit/out/unsafe/netdb.rs b/tests/unit/out/unsafe/netdb.rs new file mode 100644 index 00000000..3afa9b06 --- /dev/null +++ b/tests/unit/out/unsafe/netdb.rs @@ -0,0 +1,217 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub unsafe fn test_ipv4_literal_0() { + let mut hints: ::libc::addrinfo = unsafe { std::mem::zeroed() }; + hints.ai_flags = 0; + hints.ai_protocol = 0; + hints.ai_addrlen = 0_u32; + hints.ai_addr = std::ptr::null_mut(); + hints.ai_canonname = std::ptr::null_mut(); + hints.ai_next = std::ptr::null_mut(); + hints.ai_family = libc::AF_INET; + hints.ai_socktype = libc::SOCK_STREAM; + let mut res: *mut ::libc::addrinfo = std::ptr::null_mut(); + assert!( + ((((libc::getaddrinfo( + (c"127.0.0.1".as_ptr().cast_mut()).cast_const(), + (c"8080".as_ptr().cast_mut()).cast_const(), + (&mut hints as *mut ::libc::addrinfo).cast_const(), + (&mut res as *mut *mut ::libc::addrinfo) + )) == (0)) as i32) + != 0) + ); + assert!((((!((res).is_null())) as i32) != 0)); + assert!((((((*res).ai_family) == (libc::AF_INET)) as i32) != 0)); + assert!((((((*res).ai_socktype) == (libc::SOCK_STREAM)) as i32) != 0)); + assert!( + (((((*res).ai_addrlen as usize) == (::std::mem::size_of::<::libc::sockaddr_in>())) as i32) + != 0) + ); + assert!((((!(((*res).ai_addr).is_null())) as i32) != 0)); + let mut sin: *mut ::libc::sockaddr_in = ((*res).ai_addr as *mut ::libc::sockaddr_in); + assert!((((((*sin).sin_family as i32) == (libc::AF_INET)) as i32) != 0)); + let mut port_be: [u8; 2] = [(((8080) / (256)) as u8), (((8080) % (256)) as u8)]; + assert!( + (((({ + let sa = core::slice::from_raw_parts( + ((&mut (*sin).sin_port as *mut u16) as *const u16 as *const ::libc::c_void) + as *const u8, + 2_usize as usize, + ); + let sb = core::slice::from_raw_parts( + (port_be.as_mut_ptr() as *const u8 as *const ::libc::c_void) as *const u8, + 2_usize as usize, + ); + let mut diff = 0_i32; + for (x, y) in sa.iter().zip(sb.iter()) { + if x != y { + diff = (*x as i32) - (*y as i32); + break; + } + } + diff + }) == (0)) as i32) + != 0) + ); + let mut addr_be: [u8; 4] = [127_u8, 0_u8, 0_u8, 1_u8]; + assert!( + (((({ + let sa = core::slice::from_raw_parts( + ((&mut (*sin).sin_addr as *mut ::libc::in_addr) as *const ::libc::in_addr + as *const ::libc::c_void) as *const u8, + 4_usize as usize, + ); + let sb = core::slice::from_raw_parts( + (addr_be.as_mut_ptr() as *const u8 as *const ::libc::c_void) as *const u8, + 4_usize as usize, + ); + let mut diff = 0_i32; + for (x, y) in sa.iter().zip(sb.iter()) { + if x != y { + diff = (*x as i32) - (*y as i32); + break; + } + } + diff + }) == (0)) as i32) + != 0) + ); + libc::freeaddrinfo(res); +} +pub unsafe fn test_ipv6_literal_1() { + let mut hints: ::libc::addrinfo = unsafe { std::mem::zeroed() }; + hints.ai_flags = 0; + hints.ai_protocol = 0; + hints.ai_addrlen = 0_u32; + hints.ai_addr = std::ptr::null_mut(); + hints.ai_canonname = std::ptr::null_mut(); + hints.ai_next = std::ptr::null_mut(); + hints.ai_family = libc::AF_INET6; + hints.ai_socktype = libc::SOCK_STREAM; + let mut res: *mut ::libc::addrinfo = std::ptr::null_mut(); + assert!( + ((((libc::getaddrinfo( + (c"::1".as_ptr().cast_mut()).cast_const(), + (c"443".as_ptr().cast_mut()).cast_const(), + (&mut hints as *mut ::libc::addrinfo).cast_const(), + (&mut res as *mut *mut ::libc::addrinfo) + )) == (0)) as i32) + != 0) + ); + assert!((((!((res).is_null())) as i32) != 0)); + assert!((((((*res).ai_family) == (libc::AF_INET6)) as i32) != 0)); + assert!( + (((((*res).ai_addrlen as usize) == (::std::mem::size_of::<::libc::sockaddr_in6>())) + as i32) + != 0) + ); + assert!((((!(((*res).ai_addr).is_null())) as i32) != 0)); + let mut sin6: *mut ::libc::sockaddr_in6 = ((*res).ai_addr as *mut ::libc::sockaddr_in6); + assert!((((((*sin6).sin6_family as i32) == (libc::AF_INET6)) as i32) != 0)); + let mut port_be: [u8; 2] = [(((443) / (256)) as u8), (((443) % (256)) as u8)]; + assert!( + (((({ + let sa = core::slice::from_raw_parts( + ((&mut (*sin6).sin6_port as *mut u16) as *const u16 as *const ::libc::c_void) + as *const u8, + 2_usize as usize, + ); + let sb = core::slice::from_raw_parts( + (port_be.as_mut_ptr() as *const u8 as *const ::libc::c_void) as *const u8, + 2_usize as usize, + ); + let mut diff = 0_i32; + for (x, y) in sa.iter().zip(sb.iter()) { + if x != y { + diff = (*x as i32) - (*y as i32); + break; + } + } + diff + }) == (0)) as i32) + != 0) + ); + let mut addr_be: [u8; 16] = [ + 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, + 1_u8, + ]; + assert!( + (((({ + let sa = core::slice::from_raw_parts( + ((&mut (*sin6).sin6_addr as *mut ::libc::in6_addr) as *const ::libc::in6_addr + as *const ::libc::c_void) as *const u8, + 16_usize as usize, + ); + let sb = core::slice::from_raw_parts( + (addr_be.as_mut_ptr() as *const u8 as *const ::libc::c_void) as *const u8, + 16_usize as usize, + ); + let mut diff = 0_i32; + for (x, y) in sa.iter().zip(sb.iter()) { + if x != y { + diff = (*x as i32) - (*y as i32); + break; + } + } + diff + }) == (0)) as i32) + != 0) + ); + libc::freeaddrinfo(res); +} +pub unsafe fn test_null_hints_2() { + let mut res: *mut ::libc::addrinfo = std::ptr::null_mut(); + assert!( + ((((libc::getaddrinfo( + (c"127.0.0.1".as_ptr().cast_mut()).cast_const(), + (c"80".as_ptr().cast_mut()).cast_const(), + std::ptr::null(), + (&mut res as *mut *mut ::libc::addrinfo) + )) == (0)) as i32) + != 0) + ); + assert!((((!((res).is_null())) as i32) != 0)); + assert!((((((*res).ai_family) == (libc::AF_INET)) as i32) != 0)); + let mut sin: *mut ::libc::sockaddr_in = ((*res).ai_addr as *mut ::libc::sockaddr_in); + let mut addr_be: [u8; 4] = [127_u8, 0_u8, 0_u8, 1_u8]; + assert!( + (((({ + let sa = core::slice::from_raw_parts( + ((&mut (*sin).sin_addr as *mut ::libc::in_addr) as *const ::libc::in_addr + as *const ::libc::c_void) as *const u8, + 4_usize as usize, + ); + let sb = core::slice::from_raw_parts( + (addr_be.as_mut_ptr() as *const u8 as *const ::libc::c_void) as *const u8, + 4_usize as usize, + ); + let mut diff = 0_i32; + for (x, y) in sa.iter().zip(sb.iter()) { + if x != y { + diff = (*x as i32) - (*y as i32); + break; + } + } + diff + }) == (0)) as i32) + != 0) + ); + libc::freeaddrinfo(res); +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_ipv4_literal_0() }); + (unsafe { test_ipv6_literal_1() }); + (unsafe { test_null_hints_2() }); + return 0; +}