From 164c9a415521347a6c56f34b27f22b030c173789 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 7 Jan 2016 11:55:39 +0100 Subject: [PATCH] Make IP packet validation optional --- .../java/eu/faircode/netguard/Packet.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/netguard/Packet.java b/app/src/main/java/eu/faircode/netguard/Packet.java index a70b8c50..3aa4ecaf 100644 --- a/app/src/main/java/eu/faircode/netguard/Packet.java +++ b/app/src/main/java/eu/faircode/netguard/Packet.java @@ -45,21 +45,29 @@ public class Packet { try { IPv4 = new IPv4Header(buffer); - IPv4.validate(); - - if (IPv4.protocol == IPv4.UDP) { + if (IPv4.protocol == IPv4.UDP) UDP = new UDPHeader(buffer); - UDP.validate(); - } else if (IPv4.protocol == IPv4.TCP) { + else if (IPv4.protocol == IPv4.TCP) TCP = new TCP(IPv4.sourceAddress, IPv4.destinationAddress, buffer); - TCP.validate(); - } else + else throw new IOException("Unsupported protocol=" + IPv4.protocol); } catch (IOException ex) { throw new IOException(ex.toString() + " " + this); } } + public void validate() throws IOException { + try { + IPv4.validate(); + if (this.UDP != null) + this.UDP.validate(); + if (this.TCP != null) + this.TCP.validate(); + } catch (IOException ex) { + throw new IOException(ex.toString() + " " + this); + } + } + public void swapAddresses() { InetAddress sourceAddress = this.IPv4.sourceAddress; this.IPv4.sourceAddress = this.IPv4.destinationAddress;