|
| 1 | +// Copyright (c) 2022-present INESC-ID. |
| 2 | +// Distributed under the MIT license that can be found in the LICENSE file. |
| 3 | + |
| 4 | +use libcc2rs::*; |
| 5 | + |
| 6 | +fn f5(a0: i32, a1: Ptr<u8>, a2: AnyPtr) -> i32 { |
| 7 | + if a0 == libc::AF_INET { |
| 8 | + match a1.to_rust_string().parse::<std::net::Ipv4Addr>() { |
| 9 | + Ok(__ip) => { |
| 10 | + let __octets = __ip.octets(); |
| 11 | + for __i in 0..4 { |
| 12 | + a2.reinterpret_cast::<u8>().offset(__i).write(__octets[__i]); |
| 13 | + } |
| 14 | + 1 |
| 15 | + } |
| 16 | + Err(_) => 0, |
| 17 | + } |
| 18 | + } else if a0 == libc::AF_INET6 { |
| 19 | + match a1.to_rust_string().parse::<std::net::Ipv6Addr>() { |
| 20 | + Ok(__ip) => { |
| 21 | + let __octets = __ip.octets(); |
| 22 | + for __i in 0..16 { |
| 23 | + a2.reinterpret_cast::<u8>().offset(__i).write(__octets[__i]); |
| 24 | + } |
| 25 | + 1 |
| 26 | + } |
| 27 | + Err(_) => 0, |
| 28 | + } |
| 29 | + } else { |
| 30 | + -1 |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +fn f6(a0: i32, a1: AnyPtr, a2: Ptr<u8>, a3: u32) -> Ptr<u8> { |
| 35 | + let __text = if a0 == libc::AF_INET { |
| 36 | + let mut __b = [0u8; 4]; |
| 37 | + for __i in 0..4 { |
| 38 | + __b[__i] = a1.reinterpret_cast::<u8>().offset(__i).read(); |
| 39 | + } |
| 40 | + Some(std::net::Ipv4Addr::from(__b).to_string()) |
| 41 | + } else if a0 == libc::AF_INET6 { |
| 42 | + let mut __b = [0u8; 16]; |
| 43 | + for __i in 0..16 { |
| 44 | + __b[__i] = a1.reinterpret_cast::<u8>().offset(__i).read(); |
| 45 | + } |
| 46 | + Some(std::net::Ipv6Addr::from(__b).to_string()) |
| 47 | + } else { |
| 48 | + None |
| 49 | + }; |
| 50 | + match __text { |
| 51 | + Some(__s) if (__s.len() as u32) < a3 => { |
| 52 | + for __i in 0..__s.len() { |
| 53 | + a2.offset(__i).write(__s.as_bytes()[__i]); |
| 54 | + } |
| 55 | + a2.offset(__s.len()).write(0); |
| 56 | + a2.clone() |
| 57 | + } |
| 58 | + _ => Ptr::null(), |
| 59 | + } |
| 60 | +} |
0 commit comments