Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions rules/net_if/tgt_refcount.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2022-present INESC-ID.
// Distributed under the MIT license that can be found in the LICENSE file.

use libcc2rs::*;

fn f1(a0: Ptr<u8>) -> u32 {
match nix::net::if_::if_nametoindex(a0.to_rust_string().as_str()) {
Ok(__i) => __i,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
0
}
}
}
2 changes: 2 additions & 0 deletions rules/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pub mod map_tgt_refcount;
pub mod map_tgt_unsafe;
#[path = r#"../math/tgt_unsafe.rs"#]
pub mod math_tgt_unsafe;
#[path = r#"../net_if/tgt_refcount.rs"#]
pub mod net_if_tgt_refcount;
#[path = r#"../net_if/tgt_unsafe.rs"#]
pub mod net_if_tgt_unsafe;
#[path = r#"../netdb/tgt_refcount.rs"#]
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/ifaddrs.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <assert.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <netinet/in.h>
#include <string.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -28,9 +29,12 @@ int main(void) {
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(if_nametoindex(ifa->ifa_name) > 0);
}
}
assert(found_loopback);
freeifaddrs(list);

assert(if_nametoindex("cpp2rust_no_such_if") == 0);
return 0;
}
28 changes: 28 additions & 0 deletions tests/unit/out/refcount/ifaddrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ fn main_0() -> i32 {
== 0) as i32)
!= 0)
);
assert!(
(((match nix::net::if_::if_nametoindex(
(*(*(*ifa.borrow()).upgrade().deref()).ifa_name.borrow())
.to_rust_string()
.as_str()
) {
Ok(__i) => __i,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
0
}
} > 0_u32) as i32)
!= 0)
);
}
let __rhs = (*(*(*ifa.borrow()).upgrade().deref()).ifa_next.borrow()).clone();
(*ifa.borrow_mut()) = __rhs;
Expand Down Expand Up @@ -131,5 +145,19 @@ fn main_0() -> i32 {
__cur = __next;
}
};
assert!(
(((match nix::net::if_::if_nametoindex(
Ptr::from_string_literal(b"cpp2rust_no_such_if")
.to_rust_string()
.as_str()
) {
Ok(__i) => __i,
Err(__e) => {
libcc2rs::cpp2rust_errno().write(__e as i32);
0
}
} == 0_u32) as i32)
!= 0)
);
return 0;
}
8 changes: 8 additions & 0 deletions tests/unit/out/unsafe/ifaddrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,18 @@ unsafe fn main_0() -> i32 {
}) == (0)) as i32)
!= 0)
);
assert!(
((((libc::if_nametoindex(((*ifa).ifa_name).cast_const())) > (0_u32)) as i32) != 0)
);
}
ifa = (*ifa).ifa_next;
}
assert!((found_loopback != 0));
libc::freeifaddrs(list);
assert!(
((((libc::if_nametoindex((c"cpp2rust_no_such_if".as_ptr().cast_mut()).cast_const()))
== (0_u32)) as i32)
!= 0)
);
return 0;
}
Loading