Make IP packet validation optional

This commit is contained in:
M66B 2016-01-07 11:55:39 +01:00
parent 49721cf2ab
commit 164c9a4155
1 changed files with 15 additions and 7 deletions

View File

@ -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;