#sockets #expose #unix #interface #windows #addr #winsock

no-std in_addr

Exposes a common interface to in_addr between Unix and Windows

5 releases (1 stable)

1.0.0 Feb 15, 2019
0.2.0 Feb 14, 2019
0.1.2 Feb 13, 2019
0.1.1 Feb 13, 2019
0.1.0 Feb 13, 2019

#8 in #addr


Used in ei-sys

BSD-3-Clause

6KB
78 lines

in_addr

This crate exposes a common interface to in_addr between Unix and Windows. Get rid of these #[cfg]s!

Features

  • no-std: Compile this crate with no_std. Conversions to and from std::net::Ipv4Addr will not be available.

Documentation


lib.rs:

This crate exposes a common interface to in_addr between Unix and Windows.

There are two types in this crate.

  • in_addr, a type alias to the platform specific version of this type. Use this in the signature of extern functions.
  • InAddr, a newtype wrapper around in_addr. It implements conversions to and from u32, std::net::Ipv4Addr, and in_addr.

Example

extern {
  fn inet_ntoa(addr: *const in_addr::in_addr) -> *const std::os::raw::c_char;
}

fn main() {
  let addr = in_addr::InAddr::new(std::net::Ipv4Addr::LOCALHOST);
  let addr_text = unsafe { std::ffi::CStr::from_ptr(inet_ntoa(&addr.into())) };
  println!("The address is {}.", addr_text.to_string_lossy());
}

Dependencies

~215KB