Package org.drasyl.util.protocol
Class NatPmpUtil
java.lang.Object
org.drasyl.util.protocol.NatPmpUtil
Utility class for NAT Port Mapping Protocol (NAT-PMP)-related stuff.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static interface
static enum
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
To determine the external address, the client behind the NAT sends the following UDP payload to port 5351 of the configured gateway address: 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Vers = 0 | OP = 0 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+static byte[]
buildMappingRequestMessage
(int internalPort, int externalPort, Duration lifetime) To create a mapping, the client sends a UDP packet to port 5351 of the gateway's internal IP address with the following format: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Vers = 0 | OP = x | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Internal Port | Suggested External Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Requested Port Mapping Lifetime in Seconds | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Opcodes supported: 1 - Map UDP 2 - Map TCP The Reserved field MUST be set to zero on transmission and MUST be ignored on reception.static NatPmpUtil.Message
readMessage
(InputStream inputStream)
-
Field Details
-
NAT_PMP_PORT
public static final int NAT_PMP_PORT- See Also:
-
NAT_PMP_VERSION
public static final int NAT_PMP_VERSION- See Also:
-
EXTERNAL_ADDRESS_REQUEST_OP
public static final int EXTERNAL_ADDRESS_REQUEST_OP- See Also:
-
EXTERNAL_ADDRESS_RESPONSE_OP
public static final int EXTERNAL_ADDRESS_RESPONSE_OP- See Also:
-
MAPPING_UDP_REQUEST_OP
public static final int MAPPING_UDP_REQUEST_OP- See Also:
-
MAPPING_UDP_RESPONSE_OP
public static final int MAPPING_UDP_RESPONSE_OP- See Also:
-
MAPPING_TCP_REQUEST_OP
public static final int MAPPING_TCP_REQUEST_OP- See Also:
-
MAPPING_TCP_RESPONSE_OP
public static final int MAPPING_TCP_RESPONSE_OP- See Also:
-
RESERVED_LENGTH
public static final int RESERVED_LENGTH- See Also:
-
LIFETIME_LENGTH
public static final int LIFETIME_LENGTH- See Also:
-
-
Method Details
-
buildExternalAddressRequestMessage
public static byte[] buildExternalAddressRequestMessage()To determine the external address, the client behind the NAT sends the following UDP payload to port 5351 of the configured gateway address: 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Vers = 0 | OP = 0 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
buildMappingRequestMessage
public static byte[] buildMappingRequestMessage(int internalPort, int externalPort, Duration lifetime) To create a mapping, the client sends a UDP packet to port 5351 of the gateway's internal IP address with the following format: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Vers = 0 | OP = x | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Internal Port | Suggested External Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Requested Port Mapping Lifetime in Seconds | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Opcodes supported: 1 - Map UDP 2 - Map TCP The Reserved field MUST be set to zero on transmission and MUST be ignored on reception. The Ports and Lifetime are transmitted in the traditional network byte order (i.e., most significant byte first). The Internal Port is set to the local port on which the client is listening.
- Throws:
IllegalArgumentException
- ifinternalPort
orexternalPort
is not in range of [0, 2^16)
-
readMessage
- Throws:
IOException
-