map

suspend fun map(internalPort: Int, externalPort: Int, tcp: Boolean, lifetimeSeconds: Int = 3600): Int?

Request a port mapping (opcode 1 for UDP, 2 for TCP). Mirrors the version_natpmp branch of natpmp::send_map_request → the map branch of on_reply.

On success returns the public port the gateway actually granted (which can differ from the requested externalPort: NAT-PMP routers may assign a different port, and on_reply adopts public_port from the response). Returns null if the gateway never answered within maxAttempts retransmissions or replied with a non-zero result code.

Parameters

lifetimeSeconds

the requested lease duration; libtorrent defaults to 3600s (configured_ttl > 0 ? configured_ttl : 3600). Pass 0 to delete the mapping.