[][src]Struct libnatpmp::Natpmp

pub struct Natpmp { /* fields omitted */ }

NAT-PMP main struct.

Examples

use std::thread;
use std::time::Duration;
use natpmp::*;

let mut n = Natpmp::new()?;
n.send_port_mapping_request(Protocol::UDP, 4020, 4020, 30)?;
thread::sleep(Duration::from_millis(100));
let response = n.read_response_or_retry()?;
 match response {
     Response::UDP(ur) => {
         assert_eq!(ur.private_port(), 4020);
         assert_eq!(ur.public_port(), 4020);
     }
     _ => panic!("Not a udp mapping response"),
}

Methods

impl Natpmp
[src]

Create a NAT-PMP object with default gateway.

Errors

See get_default_gateway and Natpmp::new_with.

Examples

use natpmp::*;

let n = Natpmp::new();
assert_eq!(n.is_ok(), true);

Create a NAT-PMP object with a specified gateway.

Errors

Examples

use std::str::FromStr;
use std::net::Ipv4Addr;
use natpmp::*;

let n = Natpmp::new_with("192.168.0.1".parse().unwrap()).unwrap();

NAT-PMP gateway address.

Examples

use std::net::Ipv4Addr;
use natpmp::*;

let gateway = Ipv4Addr::from([192, 168, 0, 1]);
let n = Natpmp::new_with(gateway)?;
assert_eq!(n.gateway(), &gateway);

Get timeout duration of the currently pending NAT-PMP request.

Errors:

Examples

use std::time::Duration;
use natpmp::*;

let mut n = Natpmp::new()?;
n.send_public_address_request()?;
// do something
let duration = n.get_natpmp_request_timeout()?;
if duration <= Duration::from_millis(10) {
    // read response ...
}

Send public address request.

Errors

Examples

use natpmp::*;

let mut n = Natpmp::new()?;
n.send_public_address_request()?;
// do something then read response

Send new port mapping request.

Errors

Examples

use natpmp::*;

let mut n = Natpmp::new()?;
n.send_port_mapping_request(Protocol::UDP, 4020, 4020, 30)?;
// do something then read response

Trait Implementations

impl Debug for Natpmp
[src]

Auto Trait Implementations

impl Send for Natpmp

impl Sync for Natpmp

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]