Package org.drasyl.util.protocol
Class NatPmpUtil
- java.lang.Object
-
- org.drasyl.util.protocol.NatPmpUtil
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NatPmpUtil.ExternalAddressResponseMessage
static class
NatPmpUtil.MappingUdpResponseMessage
static interface
NatPmpUtil.Message
static class
NatPmpUtil.ResultCode
-
Field Summary
Fields Modifier and Type Field Description static int
EXTERNAL_ADDRESS_REQUEST_OP
static int
EXTERNAL_ADDRESS_RESPONSE_OP
static int
LIFETIME_LENGTH
static int
MAPPING_TCP_REQUEST_OP
static int
MAPPING_TCP_RESPONSE_OP
static int
MAPPING_UDP_REQUEST_OP
static int
MAPPING_UDP_RESPONSE_OP
static int
NAT_PMP_PORT
static int
NAT_PMP_VERSION
static int
RESERVED_LENGTH
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+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 Detail
-
NAT_PMP_PORT
public static final int NAT_PMP_PORT
- See Also:
- Constant Field Values
-
NAT_PMP_VERSION
public static final int NAT_PMP_VERSION
- See Also:
- Constant Field Values
-
EXTERNAL_ADDRESS_REQUEST_OP
public static final int EXTERNAL_ADDRESS_REQUEST_OP
- See Also:
- Constant Field Values
-
EXTERNAL_ADDRESS_RESPONSE_OP
public static final int EXTERNAL_ADDRESS_RESPONSE_OP
- See Also:
- Constant Field Values
-
MAPPING_UDP_REQUEST_OP
public static final int MAPPING_UDP_REQUEST_OP
- See Also:
- Constant Field Values
-
MAPPING_UDP_RESPONSE_OP
public static final int MAPPING_UDP_RESPONSE_OP
- See Also:
- Constant Field Values
-
MAPPING_TCP_REQUEST_OP
public static final int MAPPING_TCP_REQUEST_OP
- See Also:
- Constant Field Values
-
MAPPING_TCP_RESPONSE_OP
public static final int MAPPING_TCP_RESPONSE_OP
- See Also:
- Constant Field Values
-
RESERVED_LENGTH
public static final int RESERVED_LENGTH
- See Also:
- Constant Field Values
-
LIFETIME_LENGTH
public static final int LIFETIME_LENGTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
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 - 1]
-
readMessage
public static NatPmpUtil.Message readMessage(InputStream inputStream) throws IOException
- Throws:
IOException
-
-