Make a v4 nattKeepalivePacket helper method am: df347448a1 am: 8802197935
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2616794 Change-Id: If797d5ac4dfc926ca666636adf6ee9cdecd77985 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -55,15 +55,22 @@ public final class NattKeepalivePacketData extends KeepalivePacketData implement
|
|||||||
public static NattKeepalivePacketData nattKeepalivePacket(
|
public static NattKeepalivePacketData nattKeepalivePacket(
|
||||||
InetAddress srcAddress, int srcPort, InetAddress dstAddress, int dstPort)
|
InetAddress srcAddress, int srcPort, InetAddress dstAddress, int dstPort)
|
||||||
throws InvalidPacketException {
|
throws InvalidPacketException {
|
||||||
|
if (dstPort != NattSocketKeepalive.NATT_PORT) {
|
||||||
|
throw new InvalidPacketException(ERROR_INVALID_PORT);
|
||||||
|
}
|
||||||
|
|
||||||
if (!(srcAddress instanceof Inet4Address) || !(dstAddress instanceof Inet4Address)) {
|
if (!(srcAddress instanceof Inet4Address) || !(dstAddress instanceof Inet4Address)) {
|
||||||
throw new InvalidPacketException(ERROR_INVALID_IP_ADDRESS);
|
throw new InvalidPacketException(ERROR_INVALID_IP_ADDRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dstPort != NattSocketKeepalive.NATT_PORT) {
|
return nattKeepalivePacketv4(
|
||||||
throw new InvalidPacketException(ERROR_INVALID_PORT);
|
(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;
|
int length = IPV4_HEADER_LENGTH + UDP_HEADER_LENGTH + 1;
|
||||||
ByteBuffer buf = ByteBuffer.allocate(length);
|
ByteBuffer buf = ByteBuffer.allocate(length);
|
||||||
buf.order(ByteOrder.BIG_ENDIAN);
|
buf.order(ByteOrder.BIG_ENDIAN);
|
||||||
|
|||||||
Reference in New Issue
Block a user