os-interface 0.2.1

Interface to retrieve OS information.
Documentation
  • Coverage
  • 87.5%
    28 out of 32 items documented0 out of 11 items with examples
  • Size
  • Source code size: 29.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.12 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • cmasus/os-interface
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • cmasus

OS-Interface

Crate holding easy to use functions for retrieving information from the operating system.

PR contributions are welcome. Contributions could be in the form of improvements to existing functionality, adding new functionality or adding support for other operating systems.

Goals

  • This crate aims to give an easy-to-use interface for retrieving data from the OS, e.g. network information.
  • Expand with more functionality as long as it adheres to above point.
  • Have as few dependencies as possible. For example, in the Unix environments, this crate only depends on libc which in turn does not depend on anything else.
  • Encapsulate unsafe code.
  • Return data in a Rust-like manner.

Usage

Example usage

use os_interface::network::network_interfaces;

fn main() {
    let network_interfaces = network_interfaces().unwrap();

    println!("Network interfaces: {:#?}", network_interfaces);
}

gives an output similar to the following

Network interfaces: [
    NetworkInterface {
        index: 1,
        name: "lo",
        addr: [
            IPv4(
                IfAddrV4 {
                    ip: 127.0.0.1,
                    netmask: Some(
                        255.0.0.0,
                    ),
                    broadcast: None,
                },
            ),
            IPv6(
                IfAddrV6 {
                    ip: ::1,
                    netmask: Some(
                        ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff,
                    ),
                },
            ),
        ],
        mac_addr: Some(
            "00:00:00:00:00:00",
        ),
        flags: Flags {
            up: true,
            loopback: true,
            running: true,
            multicast: false,
            broadcast: false,
        },
    },
    ...
]

Supported functions per operating system

function linux macos windows freebsd android ios
network_interfaces() yes yes no yes yes yes
local_ipv4_addresses() yes yes no yes yes yes
local_ipv6_addresses() yes yes no yes yes yes
hostname() yes yes no yes yes yes

License

Distributed under the terms of both the MIT license and the Apache License (Version 2.0)