|
| 1 | +extern crate libcc2rs; |
| 2 | +use libcc2rs::*; |
| 3 | +use std::cell::RefCell; |
| 4 | +use std::collections::BTreeMap; |
| 5 | +use std::io::prelude::*; |
| 6 | +use std::io::{Read, Seek, Write}; |
| 7 | +use std::os::fd::AsFd; |
| 8 | +use std::rc::{Rc, Weak}; |
| 9 | +pub fn check_buf_0( |
| 10 | + mut fd: i32, |
| 11 | + mut buf: Ptr<u8>, |
| 12 | + mut size: u32, |
| 13 | + mut cap: libc::socklen_t, |
| 14 | + mut full: AnyPtr, |
| 15 | + mut actual: libc::socklen_t, |
| 16 | +) { |
| 17 | + match ({ (buf).to_any() },) { |
| 18 | + (mut __tmp_0,) => { |
| 19 | + __tmp_0.memset((165) as u8, (size as usize)); |
| 20 | + (__tmp_0).clone() |
| 21 | + } |
| 22 | + }; |
| 23 | + let len: Value<libc::socklen_t> = Rc::new(RefCell::new(cap)); |
| 24 | + assert!( |
| 25 | + (match ({ buf.reinterpret_cast::<libcc2rs::Sockaddr>() }, { |
| 26 | + (len.as_pointer()) |
| 27 | + },) |
| 28 | + { |
| 29 | + (mut __tmp_1, mut __tmp_2) => { |
| 30 | + match nix::sys::socket::getsockname::<nix::sys::socket::SockaddrStorage>(fd) { |
| 31 | + Ok(__ss) => { |
| 32 | + Sockaddr::encode(&__ss, &__tmp_1, &__tmp_2); |
| 33 | + 0 |
| 34 | + } |
| 35 | + Err(__e) => { |
| 36 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 37 | + -1 |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + } == 0) |
| 42 | + ); |
| 43 | + let mut copied: u32 = (if (cap < actual) { cap } else { actual } as u32); |
| 44 | + assert!(((buf).to_any().memcmp(&full, (copied as usize)) == 0)); |
| 45 | + { |
| 46 | + let mut j: u32 = copied; |
| 47 | + 'loop_: while (j < size) { |
| 48 | + assert!((((elem!(buf, j).read()) as i32) == 165)); |
| 49 | + j.prefix_inc(); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | +pub fn check_name_1(mut family: i32) { |
| 54 | + let mut fd: i32 = { |
| 55 | + let __family = match family { |
| 56 | + ::libc::AF_INET => nix::sys::socket::AddressFamily::Inet, |
| 57 | + ::libc::AF_INET6 => nix::sys::socket::AddressFamily::Inet6, |
| 58 | + ::libc::AF_UNIX => nix::sys::socket::AddressFamily::Unix, |
| 59 | + __d => panic!("socket: unsupported domain {__d}"), |
| 60 | + }; |
| 61 | + let __flags = nix::sys::socket::SockFlag::from_bits_truncate(libc::SOCK_DGRAM); |
| 62 | + let __ty = match libc::SOCK_DGRAM & !nix::sys::socket::SockFlag::all().bits() { |
| 63 | + ::libc::SOCK_STREAM => nix::sys::socket::SockType::Stream, |
| 64 | + ::libc::SOCK_DGRAM => nix::sys::socket::SockType::Datagram, |
| 65 | + __t => panic!("socket: unsupported type {__t}"), |
| 66 | + }; |
| 67 | + let __proto = match 0 { |
| 68 | + 0 => None, |
| 69 | + ::libc::IPPROTO_TCP => Some(nix::sys::socket::SockProtocol::Tcp), |
| 70 | + ::libc::IPPROTO_UDP => Some(nix::sys::socket::SockProtocol::Udp), |
| 71 | + __p => panic!("socket: unsupported protocol {__p}"), |
| 72 | + }; |
| 73 | + match nix::sys::socket::socket(__family, __ty, __flags, __proto) { |
| 74 | + Ok(__ofd) => FdRegistry::register(__ofd), |
| 75 | + Err(__e) => { |
| 76 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 77 | + -1 |
| 78 | + } |
| 79 | + } |
| 80 | + }; |
| 81 | + assert!((fd >= 0)); |
| 82 | + let full: Value<libcc2rs::SockaddrStorage> = Rc::new(RefCell::new(Default::default())); |
| 83 | + match ({ (full.as_pointer()).to_any() },) { |
| 84 | + (mut __tmp_3,) => { |
| 85 | + __tmp_3.memset((165) as u8, 128usize); |
| 86 | + (__tmp_3).clone() |
| 87 | + } |
| 88 | + }; |
| 89 | + let len: Value<libc::socklen_t> = Rc::new(RefCell::new((128usize as libc::socklen_t))); |
| 90 | + assert!( |
| 91 | + (match ( |
| 92 | + { (full.as_pointer()).reinterpret_cast::<libcc2rs::Sockaddr>() }, |
| 93 | + { (len.as_pointer()) }, |
| 94 | + ) { |
| 95 | + (mut __tmp_4, mut __tmp_5) => { |
| 96 | + match nix::sys::socket::getsockname::<nix::sys::socket::SockaddrStorage>(fd) { |
| 97 | + Ok(__ss) => { |
| 98 | + Sockaddr::encode(&__ss, &__tmp_4, &__tmp_5); |
| 99 | + 0 |
| 100 | + } |
| 101 | + Err(__e) => { |
| 102 | + libcc2rs::cpp2rust_errno().write(__e as i32); |
| 103 | + -1 |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + } == 0) |
| 108 | + ); |
| 109 | + assert!(({ (({ (*full.borrow()).ss_family } as i32) == family) })); |
| 110 | + let mut actual: libc::socklen_t = (if (family == libc::AF_INET) { |
| 111 | + 16usize |
| 112 | + } else { |
| 113 | + 28usize |
| 114 | + } as libc::socklen_t); |
| 115 | + let mut capacities: [libc::socklen_t; 6] = [ |
| 116 | + (0 as libc::socklen_t), |
| 117 | + (1 as libc::socklen_t), |
| 118 | + (2 as libc::socklen_t), |
| 119 | + (actual).wrapping_sub((1 as libc::socklen_t)), |
| 120 | + actual, |
| 121 | + (actual).wrapping_add((1 as libc::socklen_t)), |
| 122 | + ]; |
| 123 | + { |
| 124 | + let mut i: u32 = 0_u32; |
| 125 | + 'loop_: while ((i as usize) |
| 126 | + < (::std::mem::size_of::<[libc::socklen_t; 6]>() as usize) |
| 127 | + .wrapping_div((::std::mem::size_of::<libc::socklen_t>() as usize))) |
| 128 | + { |
| 129 | + let out: Value<Box<[u8]>> = |
| 130 | + Rc::new(RefCell::new((0..136).map(|_| 0_u8).collect::<Box<[u8]>>())); |
| 131 | + ({ |
| 132 | + let _buf: Ptr<u8> = out.decay(); |
| 133 | + let _size: u32 = (::std::mem::size_of::<[u8; 136]>() as u32); |
| 134 | + check_buf_0( |
| 135 | + fd, |
| 136 | + _buf, |
| 137 | + _size, |
| 138 | + capacities[(i) as usize], |
| 139 | + (full.as_pointer()).to_any(), |
| 140 | + actual, |
| 141 | + ) |
| 142 | + }); |
| 143 | + let mut size: u32 = (if (capacities[(i) as usize] != 0) { |
| 144 | + capacities[(i) as usize] |
| 145 | + } else { |
| 146 | + (1 as libc::socklen_t) |
| 147 | + } as u32); |
| 148 | + let mut small: Ptr<u8> = |
| 149 | + libcc2rs::malloc_refcount((size as usize)).reinterpret_cast::<u8>(); |
| 150 | + assert!(!(small).is_null()); |
| 151 | + ({ |
| 152 | + check_buf_0( |
| 153 | + fd, |
| 154 | + (small).clone(), |
| 155 | + size, |
| 156 | + capacities[(i) as usize], |
| 157 | + (full.as_pointer()).to_any(), |
| 158 | + actual, |
| 159 | + ) |
| 160 | + }); |
| 161 | + libcc2rs::free_refcount((small).to_any()); |
| 162 | + i.prefix_inc(); |
| 163 | + } |
| 164 | + } |
| 165 | + assert!((FdRegistry::close(fd) == 0)); |
| 166 | +} |
| 167 | +pub fn main() { |
| 168 | + __cpp2rust_init_globals(); |
| 169 | + libcc2rs::cpp2rust_exit(main_0()); |
| 170 | +} |
| 171 | +fn main_0() -> i32 { |
| 172 | + ({ check_name_1(libc::AF_INET) }); |
| 173 | + ({ check_name_1(libc::AF_INET6) }); |
| 174 | + return 0; |
| 175 | +} |
| 176 | +pub fn __cpp2rust_init_globals() {} |
0 commit comments