Skip to main content

encode_map_request

Function encode_map_request 

Source
pub fn encode_map_request(
    nonce: &MapNonce,
    tcp: bool,
    internal_port: u16,
    suggested_external_port: u16,
    lifetime_secs: u32,
    client_ip: IpAddr,
) -> Vec<u8> 
Expand description

Encode a PCP MAP request (RFC 6887 §11.1 header + §11.2 body).

Header (24 bytes): [version][opcode][reserved:2][lifetime:4][client_ip:16]. MAP body (36 bytes): [nonce:12][protocol][reserved:3][internal_port:2][suggested_ext_port:2] [suggested_ext_ip:16].

client_ip is this node’s address as the gateway sees it, encoded as an IPv4-mapped IPv6 when IPv4 (RFC 6887 uses 128-bit address fields throughout).