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
§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.