Struct natpmp::Natpmp

source ·
pub struct Natpmp { /* private fields */ }
Expand description

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"),
}

Implementations

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.