Struct UpnpConfig

Source
pub struct UpnpConfig {
    pub address: Option<Ipv4Cidr>,
    pub port: u16,
    pub protocol: PortMappingProtocol,
    pub duration: u32,
    pub comment: String,
}
Expand description

This struct defines a configuration for a port mapping.

The configuration consists of all necessary pieces of information for a proper port opening.

§Examples

use easy_upnp::{Ipv4Cidr, PortMappingProtocol, UpnpConfig};

let config_no_address = UpnpConfig {
    address: None,
    port: 80,
    protocol: PortMappingProtocol::TCP,
    duration: 3600,
    comment: "Webserver".to_string(),
};

let config_specific_address = UpnpConfig {
    address: Some(Ipv4Cidr::from_str("192.168.0.10/24")?),
    port: 80,
    protocol: PortMappingProtocol::TCP,
    duration: 3600,
    comment: "Webserver".to_string(),
};

let config_address_range = UpnpConfig {
    address: Some(Ipv4Cidr::from_str("192.168.0")?),
    port: 80,
    protocol: PortMappingProtocol::TCP,
    duration: 3600,
    comment: "Webserver".to_string(),
};

Fields§

§address: Option<Ipv4Cidr>

The IP address for which the port mapping should be added.

This field can be None, in which case every connected interface will be tried, until one gateway reports success. Useful if the IP address is dynamic and not consistent over reboots.

Fill in an IP address if you want to add a port mapping for a foreign device, or if you know your machine’s address and want to slightly speed up the process.

For examples how to specify IP addresses, check the documentation of Ipv4Cidr.

§port: u16

The port number to open for the given IP address.

Note that we are greedy at the moment, if a port mapping is already in place, it will be deleted and re-added with the given IP address. This might be configurable in a future release.

§protocol: PortMappingProtocol

The protocol for which the given port will be opened. Possible values are UDP and TCP.

§duration: u32

The lease duration for the port mapping in seconds.

Please note that some UPnP capable routers might choose to ignore this value, so do not exclusively rely on this.

§comment: String

A comment about the reason for the port mapping.

Will be stored together with the mapping in the router.

Trait Implementations§

Source§

impl Debug for UpnpConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for UpnpConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,