Skip to content

Commit 45ac385

Browse files
committed
Delete unportable test part
Mismatching address family behaves different on macos. It returns a valid ipv4 address in ipv6 format.
1 parent 2e7aca4 commit 45ac385

3 files changed

Lines changed: 4 additions & 147 deletions

File tree

‎tests/unit/netdb.c‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,6 @@ static void test_ipv6_literal(void) {
5656
freeaddrinfo(res);
5757
}
5858

59-
static void test_family_mismatch(void) {
60-
struct addrinfo hints;
61-
hints.ai_flags = 0;
62-
hints.ai_protocol = 0;
63-
hints.ai_addrlen = 0;
64-
hints.ai_addr = NULL;
65-
hints.ai_canonname = NULL;
66-
hints.ai_next = NULL;
67-
hints.ai_family = AF_INET6;
68-
hints.ai_socktype = SOCK_STREAM;
69-
struct addrinfo *res = NULL;
70-
assert(getaddrinfo("127.0.0.1", "80", &hints, &res) != 0);
71-
}
72-
7359
static void test_null_hints(void) {
7460
struct addrinfo *res = NULL;
7561
assert(getaddrinfo("127.0.0.1", "80", NULL, &res) == 0);
@@ -84,7 +70,6 @@ static void test_null_hints(void) {
8470
int main(void) {
8571
test_ipv4_literal();
8672
test_ipv6_literal();
87-
test_family_mismatch();
8873
test_null_hints();
8974
return 0;
9075
}

‎tests/unit/out/refcount/netdb.rs‎

Lines changed: 2 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -347,112 +347,7 @@ pub fn test_ipv6_literal_1() {
347347
}
348348
};
349349
}
350-
pub fn test_family_mismatch_2() {
351-
let hints: Value<libcc2rs::Addrinfo> = Rc::new(RefCell::new(Default::default()));
352-
(*(*hints.borrow()).ai_flags.borrow_mut()) = 0;
353-
(*(*hints.borrow()).ai_protocol.borrow_mut()) = 0;
354-
(*(*hints.borrow()).ai_addrlen.borrow_mut()) = 0_u32;
355-
(*(*hints.borrow()).ai_addr.borrow_mut()) = Ptr::<libcc2rs::Sockaddr>::null();
356-
(*(*hints.borrow()).ai_canonname.borrow_mut()) = Ptr::<u8>::null();
357-
(*(*hints.borrow()).ai_next.borrow_mut()) = Ptr::<libcc2rs::Addrinfo>::null();
358-
(*(*hints.borrow()).ai_family.borrow_mut()) = libc::AF_INET6;
359-
(*(*hints.borrow()).ai_socktype.borrow_mut()) = libc::SOCK_STREAM;
360-
let res: Value<Ptr<libcc2rs::Addrinfo>> =
361-
Rc::new(RefCell::new(Ptr::<libcc2rs::Addrinfo>::null()));
362-
assert!(
363-
((({
364-
let __node = Ptr::from_string_literal(b"127.0.0.1").clone();
365-
let __service = Ptr::from_string_literal(b"80").clone();
366-
let __hints = (hints.as_pointer()).clone();
367-
let __out = (res.as_pointer()).clone();
368-
let __family = if __hints.is_null() {
369-
::libc::AF_UNSPEC
370-
} else {
371-
__hints.with(|__h| *__h.ai_family.borrow())
372-
};
373-
let __socktype = if __hints.is_null() {
374-
0
375-
} else {
376-
__hints.with(|__h| *__h.ai_socktype.borrow())
377-
};
378-
let __protocol = if __hints.is_null() {
379-
0
380-
} else {
381-
__hints.with(|__h| *__h.ai_protocol.borrow())
382-
};
383-
let __port: u16 = if __service.is_null() {
384-
0
385-
} else {
386-
__service.to_rust_string().parse().unwrap_or(0)
387-
};
388-
let mut __addrs: Vec<::std::net::IpAddr> = Vec::new();
389-
if __node.is_null() {
390-
if __family == ::libc::AF_INET6 {
391-
__addrs.push(::std::net::IpAddr::V6(::std::net::Ipv6Addr::UNSPECIFIED));
392-
} else {
393-
__addrs.push(::std::net::IpAddr::V4(::std::net::Ipv4Addr::UNSPECIFIED));
394-
}
395-
} else {
396-
let __host = __node.to_rust_string();
397-
match __host.parse::<::std::net::IpAddr>() {
398-
Ok(__ip) => __addrs.push(__ip),
399-
Err(_) => {
400-
use ::std::net::ToSocketAddrs;
401-
match (__host.as_str(), __port).to_socket_addrs() {
402-
Ok(__it) => {
403-
for __sa in __it {
404-
__addrs.push(__sa.ip());
405-
}
406-
}
407-
Err(_) => {}
408-
}
409-
}
410-
}
411-
}
412-
__addrs.retain(|__ip| match __family {
413-
::libc::AF_INET => __ip.is_ipv4(),
414-
::libc::AF_INET6 => __ip.is_ipv6(),
415-
_ => true,
416-
});
417-
if __addrs.is_empty() {
418-
::libc::EAI_NONAME
419-
} else {
420-
let mut __next = Ptr::<Addrinfo>::null();
421-
for __ip in __addrs.iter().rev() {
422-
let __ai = Addrinfo::default();
423-
*__ai.ai_socktype.borrow_mut() = __socktype;
424-
*__ai.ai_protocol.borrow_mut() = __protocol;
425-
let __storage = Ptr::alloc(SockaddrStorage::default());
426-
match __ip {
427-
::std::net::IpAddr::V4(__v4) => {
428-
*__ai.ai_family.borrow_mut() = ::libc::AF_INET;
429-
*__ai.ai_addrlen.borrow_mut() =
430-
::std::mem::size_of::<::libc::sockaddr_in>() as u32;
431-
__storage
432-
.reinterpret_cast::<SockaddrIn>()
433-
.write(SockaddrIn::from_ipv4(__v4, __port));
434-
}
435-
::std::net::IpAddr::V6(__v6) => {
436-
*__ai.ai_family.borrow_mut() = ::libc::AF_INET6;
437-
*__ai.ai_addrlen.borrow_mut() =
438-
::std::mem::size_of::<::libc::sockaddr_in6>() as u32;
439-
__storage
440-
.reinterpret_cast::<SockaddrIn6>()
441-
.write(SockaddrIn6::from_ipv6(__v6, __port));
442-
}
443-
}
444-
*__ai.ai_addr.borrow_mut() = __storage.reinterpret_cast::<Sockaddr>();
445-
*__ai.ai_next.borrow_mut() = __next.clone();
446-
__next = Ptr::alloc(__ai);
447-
}
448-
__out.write(__next);
449-
0
450-
}
451-
} != 0) as i32)
452-
!= 0)
453-
);
454-
}
455-
pub fn test_null_hints_3() {
350+
pub fn test_null_hints_2() {
456351
let res: Value<Ptr<libcc2rs::Addrinfo>> =
457352
Rc::new(RefCell::new(Ptr::<libcc2rs::Addrinfo>::null()));
458353
assert!(
@@ -588,7 +483,6 @@ pub fn main() {
588483
fn main_0() -> i32 {
589484
({ test_ipv4_literal_0() });
590485
({ test_ipv6_literal_1() });
591-
({ test_family_mismatch_2() });
592-
({ test_null_hints_3() });
486+
({ test_null_hints_2() });
593487
return 0;
594488
}

‎tests/unit/out/unsafe/netdb.rs‎

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,7 @@ pub unsafe fn test_ipv6_literal_1() {
165165
);
166166
libc::freeaddrinfo(res);
167167
}
168-
pub unsafe fn test_family_mismatch_2() {
169-
let mut hints: ::libc::addrinfo = unsafe { std::mem::zeroed() };
170-
hints.ai_flags = 0;
171-
hints.ai_protocol = 0;
172-
hints.ai_addrlen = 0_u32;
173-
hints.ai_addr = std::ptr::null_mut();
174-
hints.ai_canonname = std::ptr::null_mut();
175-
hints.ai_next = std::ptr::null_mut();
176-
hints.ai_family = libc::AF_INET6;
177-
hints.ai_socktype = libc::SOCK_STREAM;
178-
let mut res: *mut ::libc::addrinfo = std::ptr::null_mut();
179-
assert!(
180-
((((libc::getaddrinfo(
181-
(c"127.0.0.1".as_ptr().cast_mut()).cast_const(),
182-
(c"80".as_ptr().cast_mut()).cast_const(),
183-
(&mut hints as *mut ::libc::addrinfo).cast_const(),
184-
(&mut res as *mut *mut ::libc::addrinfo)
185-
)) != (0)) as i32)
186-
!= 0)
187-
);
188-
}
189-
pub unsafe fn test_null_hints_3() {
168+
pub unsafe fn test_null_hints_2() {
190169
let mut res: *mut ::libc::addrinfo = std::ptr::null_mut();
191170
assert!(
192171
((((libc::getaddrinfo(
@@ -233,7 +212,6 @@ pub fn main() {
233212
unsafe fn main_0() -> i32 {
234213
(unsafe { test_ipv4_literal_0() });
235214
(unsafe { test_ipv6_literal_1() });
236-
(unsafe { test_family_mismatch_2() });
237-
(unsafe { test_null_hints_3() });
215+
(unsafe { test_null_hints_2() });
238216
return 0;
239217
}

0 commit comments

Comments
 (0)