|
| 1 | +// Copyright (c) 2022-present INESC-ID. |
| 2 | +// Distributed under the MIT license that can be found in the LICENSE file. |
| 3 | + |
| 4 | +use super::sockaddr; |
| 5 | +use crate::{ByteRepr, Ptr, Value}; |
| 6 | +use std::cell::RefCell; |
| 7 | +use std::rc::Rc; |
| 8 | + |
| 9 | +pub struct addrinfo { |
| 10 | + pub ai_flags: Value<i32>, |
| 11 | + pub ai_family: Value<i32>, |
| 12 | + pub ai_socktype: Value<i32>, |
| 13 | + pub ai_protocol: Value<i32>, |
| 14 | + pub ai_addrlen: Value<u32>, |
| 15 | + pub ai_addr: Value<Ptr<sockaddr>>, |
| 16 | + pub ai_canonname: Value<Ptr<u8>>, |
| 17 | + pub ai_next: Value<Ptr<addrinfo>>, |
| 18 | +} |
| 19 | + |
| 20 | +impl Default for addrinfo { |
| 21 | + fn default() -> Self { |
| 22 | + Self { |
| 23 | + ai_flags: Rc::new(RefCell::new(0)), |
| 24 | + ai_family: Rc::new(RefCell::new(0)), |
| 25 | + ai_socktype: Rc::new(RefCell::new(0)), |
| 26 | + ai_protocol: Rc::new(RefCell::new(0)), |
| 27 | + ai_addrlen: Rc::new(RefCell::new(0)), |
| 28 | + ai_addr: Rc::new(RefCell::new(Ptr::null())), |
| 29 | + ai_canonname: Rc::new(RefCell::new(Ptr::null())), |
| 30 | + ai_next: Rc::new(RefCell::new(Ptr::null())), |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +impl Clone for addrinfo { |
| 36 | + fn clone(&self) -> Self { |
| 37 | + Self { |
| 38 | + ai_flags: Rc::new(RefCell::new(*self.ai_flags.borrow())), |
| 39 | + ai_family: Rc::new(RefCell::new(*self.ai_family.borrow())), |
| 40 | + ai_socktype: Rc::new(RefCell::new(*self.ai_socktype.borrow())), |
| 41 | + ai_protocol: Rc::new(RefCell::new(*self.ai_protocol.borrow())), |
| 42 | + ai_addrlen: Rc::new(RefCell::new(*self.ai_addrlen.borrow())), |
| 43 | + ai_addr: Rc::new(RefCell::new(self.ai_addr.borrow().clone())), |
| 44 | + ai_canonname: Rc::new(RefCell::new(self.ai_canonname.borrow().clone())), |
| 45 | + ai_next: Rc::new(RefCell::new(self.ai_next.borrow().clone())), |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +impl ByteRepr for addrinfo {} |
| 51 | + |
| 52 | +impl ByteRepr for ::libc::addrinfo {} |
0 commit comments