Bump version to 0.7.0

main
shellrow 2 years ago
parent aec1e2017c
commit 38fc10e014
  1. 6
      Cargo.toml
  2. 20
      README.md
  3. 13
      src/interface/mod.rs
  4. 1
      src/interface/shared.rs

@ -1,9 +1,9 @@
[package]
name = "default-net"
version = "0.6.0"
authors = ["shellrow <81893184+shellrow@users.noreply.github.com>"]
version = "0.7.0"
authors = ["shellrow <shellrow@protonmail.com>"]
edition = "2018"
description = "Get default network information"
description = "Cross-platform library for network interface and gateway"
repository = "https://github.com/shellrow/default-net"
readme = "README.md"
keywords = ["network"]

@ -15,7 +15,7 @@ Get default network information
Add `default-net` to your dependencies
```toml:Cargo.toml
[dependencies]
default-net = "0.6.0"
default-net = "0.7.0"
```
## Example
@ -53,25 +53,9 @@ fn main(){
## Tested on
- Linux
- Ubuntu 20.04, 18.04
- Ubuntu 21.10, 20.04, 18.04
- Kali 2021.1 (VM)
- macOS 11.6
- Windows 10 20H2
For more details, see [examples][examples-url] or doc.
## v0.6.0
Remove libpnet from Windows build dependencies and changed to windows-rs only.
## For Windows users using v0.5.0 or lower
To build [libpnet](https://github.com/libpnet/libpnet) on Windows, follow the instructions below.
> ### Windows
> * You must use a version of Rust which uses the MSVC toolchain
> * You must have [WinPcap](https://www.winpcap.org/) or [npcap](https://nmap.org/npcap/) installed
> (tested with version WinPcap 4.1.3) (If using npcap, make sure to install with the "Install Npcap in WinPcap API-compatible Mode")
> * You must place `Packet.lib` from the [WinPcap Developers pack](https://www.winpcap.org/devel.htm)
> in a directory named `lib`, in the root of this repository. Alternatively, you can use any of the
> locations listed in the `%LIB%`/`$Env:LIB` environment variables. For the 64 bit toolchain it is
> in `WpdPack/Lib/x64/Packet.lib`, for the 32 bit toolchain, it is in `WpdPack/Lib/Packet.lib`.
[Source](https://github.com/libpnet/libpnet/blob/master/README.md#windows "libpnet#windows")

@ -19,7 +19,7 @@ use crate::gateway::{Gateway};
pub struct MacAddr(u8, u8, u8, u8, u8, u8);
impl MacAddr {
/// Construct a new MacAddr struct from the given octets
/// Construct a new MacAddr instance from the given octets
pub fn new(octets: [u8; 6]) -> MacAddr {
MacAddr(octets[0], octets[1], octets[2], octets[3], octets[4], octets[5])
}
@ -31,9 +31,11 @@ impl MacAddr {
pub fn address(&self) -> String {
format!("{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", self.0,self.1,self.2,self.3,self.4,self.5)
}
/// Construct an all-zero MacAddr instance
pub fn zero() -> MacAddr {
MacAddr(0,0,0,0,0,0)
}
/// Construct a new MacAddr instance from a colon-separated string of hex format
pub fn from_hex_format(hex_mac_addr: &str) -> MacAddr {
if hex_mac_addr.len() != 17 {
return MacAddr(0,0,0,0,0,0)
@ -59,12 +61,21 @@ impl std::fmt::Display for MacAddr {
/// Structure of Network Interface information
#[derive(Clone, Debug)]
pub struct Interface {
/// Index of network interface
pub index: u32,
/// Name of network interface
pub name: String,
/// Description of the network interface
///
/// On Windows, this field is the adapter name
pub description: Option<String>,
/// MAC address of network interface
pub mac_addr: Option<MacAddr>,
/// List of IPv4 addresses for the network interface
pub ipv4: Vec<Ipv4Addr>,
/// List of IPv6 addresses for the network interface
pub ipv6: Vec<Ipv6Addr>,
/// Default gateway for the network interface
pub gateway: Option<Gateway>,
}

@ -1,5 +1,6 @@
use std::net::{IpAddr, UdpSocket};
/// Get IP address of the default Network Interface
pub fn get_local_ipaddr() -> Option<IpAddr> {
let socket = match UdpSocket::bind("0.0.0.0:0") {
Ok(s) => s,

Loading…
Cancel
Save