rawsock 0.3.0

Library for receiving and sending raw packets. While most crate wrap just one library, rawsock allows you to use pcap, wpcap, npcap and pf_ring (pfring) using a consistent API for all of them.
Documentation
use std::ffi::CStr;
use libc::{c_char, strerror, c_int};
use errno::errno;

pub fn cstr_to_string(txt: * const c_char) -> String {
    if txt.is_null() {
        return String::new()
    }
    unsafe { CStr::from_ptr(txt) }.to_string_lossy().into_owned()
}

pub fn string_from_errno() -> String {
    cstr_to_string(
    unsafe{strerror(errno().into())}
    )
}

#[allow(dead_code)]
pub fn string_from_err_code(code: c_int) -> String {
    let corrected = if code <0 {
        -code
    } else {
        code
    };
    cstr_to_string(
        unsafe{strerror(corrected)}
    )
}