Class NatPMPDeviceImpl
java.lang.Object
com.biglybt.net.natpmp.impl.NatPMPDeviceImpl
- All Implemented Interfaces:
NatPMPDevice
Main class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate NATPMPDeviceAdapterprivate Stringprivate InetAddressprivate int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final String(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final byte(package private) static final byte(package private) static final byteprivate static NatPMPDeviceImplSingleton creation(package private) static final int(package private) static final intprivate InetAddressprivate InetAddress(package private) static final intNetwork Failure (e.g.(package private) static final int(package private) static final intNot Authorized/Refused (e.g.(package private) static final int(package private) static final int(package private) static final intprivate NetworkInterface -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintaddPortMapping(boolean tcp, int publicPort, int privatePort) Asks for a public port to be mapped to a private port from this host.byteArrayString(byte[] buf) protected voidbooleanconnect()Try to connect with a NAT-PMP device.private StringvoiddeletePortMapping(boolean tcp, int publicPort, int privatePort) Delete a mapped public portintgetEpoch()getLocalAddress(boolean ipv4) static NatPMPDeviceImplgetSingletonObject(NATPMPDeviceAdapter adapter) intArrayString(int[] buf) byte[]intToByteArray(int v) Convert a 32-bit int into a 4 byte arrayprotected voidintportMappingProtocol(boolean tcp, int publicPort, int privatePort, int lifetime) General port mapping protocolsendNATMsg(InetAddress dstInet, DatagramPacket dstPkt, byte[] recBuf) Send a request and wait for reply This class should be threaded!!! This sends to the default NATPMP_PORT.byte[]shortToByteArray(short v) Convert a 16-bit short into a 2 byte arraystatic intunsigned16ByteArrayToInt(byte[] b, int offset) Convert the byte array containing 16-bits to an int starting from the given offset.static intunsigned32ByteArrayToInt(byte[] b, int offset) Convert the byte array containing 32-bit to an int starting from the given offset.static intunsigned8ByteArrayToInt(byte[] b, int offset) Convert the byte array containing 8-bits to an int starting from the given offset.shortunsignedByteArrayToShort(byte[] buf)
-
Field Details
-
NATMAP_VER
static final int NATMAP_VER- See Also:
-
NATMAP_PORT
static final int NATMAP_PORT- See Also:
-
NATMAP_RESPONSE_MASK
static final int NATMAP_RESPONSE_MASK- See Also:
-
NATMAP_INIT_RETRY
static final int NATMAP_INIT_RETRY- See Also:
-
NATMAP_MAX_RETRY
static final int NATMAP_MAX_RETRY- See Also:
-
NATMAP_DEFAULT_LEASE
static final int NATMAP_DEFAULT_LEASE- See Also:
-
NATMAP_LLM
- See Also:
-
NATOp_AddrRequest
static final byte NATOp_AddrRequest- See Also:
-
NATOp_MapUDP
static final byte NATOp_MapUDP- See Also:
-
NATOp_MapTCP
static final byte NATOp_MapTCP- See Also:
-
NATAddrRequest
static final int NATAddrRequest- See Also:
-
NATPortMapRequestLen
static final int NATPortMapRequestLen- See Also:
-
NATAddrReplyLen
static final int NATAddrReplyLen- See Also:
-
NATPortMapReplyLen
static final int NATPortMapReplyLen- See Also:
-
NATResultSuccess
static final int NATResultSuccess- See Also:
-
NATResultUnsupportedVer
static final int NATResultUnsupportedVer- See Also:
-
NATResultNotAuth
static final int NATResultNotAuthNot Authorized/Refused (e.g. box supports mapping, but user has turned feature off)- See Also:
-
NATResultNetFailure
static final int NATResultNetFailureNetwork Failure (e.g. NAT box itself has not obtained a DHCP lease)- See Also:
-
NATResultNoResc
static final int NATResultNoResc- See Also:
-
NATResultUnsupportedOp
static final int NATResultUnsupportedOp- See Also:
-
current_router_address
-
hostInet
-
natPriInet
-
natPubInet
-
networkInterface
-
nat_epoch
private int nat_epoch -
adapter
-
NatPMPDeviceSingletonRef
Singleton creation
-
-
Constructor Details
-
NatPMPDeviceImpl
- Throws:
Exception
-
-
Method Details
-
getSingletonObject
- Throws:
Exception
-
checkRouterAddress
-
sendNATMsg
public DatagramPacket sendNATMsg(InetAddress dstInet, DatagramPacket dstPkt, byte[] recBuf) throws Exception Send a request and wait for reply This class should be threaded!!! This sends to the default NATPMP_PORT.- Parameters:
dstInet- destination address (should be the private NAT address)dstPkt- packet to sendrecBuf- byte buffer big enough to hold received- Throws:
Exception
-
connect
Try to connect with a NAT-PMP device. This could take sometime.- Specified by:
connectin interfaceNatPMPDevice- Returns:
- true if it found one
- Throws:
Exception
-
addPortMapping
Asks for a public port to be mapped to a private port from this host. NAP-PMP allows the device to assign another public port if the requested one is taken. So, you should check the returned port.- Specified by:
addPortMappingin interfaceNatPMPDevice- Parameters:
tcp- true TCP, false UDP- Returns:
- the returned publicPort. -1 if error occured
- Throws:
Exception
-
deletePortMapping
Delete a mapped public port- Specified by:
deletePortMappingin interfaceNatPMPDevice- Parameters:
tcp- true TCP, false UDP portpublicPort- the public port to closeprivatePort- the private port that it is mapped to- Throws:
Exception
-
portMappingProtocol
-
getLocalAddress
- Specified by:
getLocalAddressin interfaceNatPMPDevice
-
getNetworkInterface
- Specified by:
getNetworkInterfacein interfaceNatPMPDevice
-
getExternalIPAddress
- Specified by:
getExternalIPAddressin interfaceNatPMPDevice
-
getEpoch
public int getEpoch()- Specified by:
getEpochin interfaceNatPMPDevice
-
log
-
unsigned32ByteArrayToInt
public static int unsigned32ByteArrayToInt(byte[] b, int offset) Convert the byte array containing 32-bit to an int starting from the given offset.- Parameters:
b- The byte arrayoffset- The array offset- Returns:
- The integer
-
unsigned16ByteArrayToInt
public static int unsigned16ByteArrayToInt(byte[] b, int offset) Convert the byte array containing 16-bits to an int starting from the given offset.- Parameters:
b- The byte arrayoffset- The array offset- Returns:
- The integer
-
unsigned8ByteArrayToInt
public static int unsigned8ByteArrayToInt(byte[] b, int offset) Convert the byte array containing 8-bits to an int starting from the given offset.- Parameters:
b- The byte arrayoffset- The array offset- Returns:
- The integer
-
unsignedByteArrayToShort
public short unsignedByteArrayToShort(byte[] buf) -
shortToByteArray
public byte[] shortToByteArray(short v) Convert a 16-bit short into a 2 byte array- Returns:
- unsigned byte array
-
intToByteArray
public byte[] intToByteArray(int v) Convert a 32-bit int into a 4 byte array- Returns:
- unsigned byte array
-
intArrayString
-
byteArrayString
-
convertHost2RouterAddress
- Parameters:
init- takes the host address- Returns:
- String the address as (xxx.xxx.xxx.1)
-