Make a v4 nattKeepalivePacket helper method
This is a preparation change for the subsequent changes to separate the logic for constructing a v4 NAT-T keepalive packets to a dedicated method. Bug: 196453719 Test: atest FrameworksNetTests Change-Id: If72b4875e65a547bbf90367eacce7b145358006a
This commit is contained in:
committed by
Chiachang Wang
parent
f2b38772ac
commit
df347448a1
@@ -55,15 +55,22 @@ public final class NattKeepalivePacketData extends KeepalivePacketData implement
|
||||
public static NattKeepalivePacketData nattKeepalivePacket(
|
||||
InetAddress srcAddress, int srcPort, InetAddress dstAddress, int dstPort)
|
||||
throws InvalidPacketException {
|
||||
if (dstPort != NattSocketKeepalive.NATT_PORT) {
|
||||
throw new InvalidPacketException(ERROR_INVALID_PORT);
|
||||
}
|
||||
|
||||
if (!(srcAddress instanceof Inet4Address) || !(dstAddress instanceof Inet4Address)) {
|
||||
throw new InvalidPacketException(ERROR_INVALID_IP_ADDRESS);
|
||||
}
|
||||
|
||||
if (dstPort != NattSocketKeepalive.NATT_PORT) {
|
||||
throw new InvalidPacketException(ERROR_INVALID_PORT);
|
||||
}
|
||||
return nattKeepalivePacketv4(
|
||||
(Inet4Address) srcAddress, srcPort,
|
||||
(Inet4Address) dstAddress, dstPort);
|
||||
}
|
||||
|
||||
private static NattKeepalivePacketData nattKeepalivePacketv4(
|
||||
Inet4Address srcAddress, int srcPort, Inet4Address dstAddress, int dstPort)
|
||||
throws InvalidPacketException {
|
||||
int length = IPV4_HEADER_LENGTH + UDP_HEADER_LENGTH + 1;
|
||||
ByteBuffer buf = ByteBuffer.allocate(length);
|
||||
buf.order(ByteOrder.BIG_ENDIAN);
|
||||
|
||||
Reference in New Issue
Block a user