More removals that were tracked for some reason.
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
package li.cil.oc2.common.vxlan;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ARPParser {
|
||||
|
||||
public static ARPInfo parseARP(byte[] frame) {
|
||||
if (frame.length < 28) {
|
||||
throw new IllegalArgumentException("Frame is too short to be a valid ARP packet");
|
||||
}
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(frame);
|
||||
|
||||
buffer.getInt();
|
||||
buffer.getInt();
|
||||
buffer.getInt();
|
||||
buffer.getShort();
|
||||
|
||||
int hardwareType = buffer.getShort();
|
||||
int protocolType = buffer.getShort();
|
||||
int hardwareAddressLength = buffer.get();
|
||||
int protocolAddressLength = buffer.get();
|
||||
int operation = buffer.getShort();
|
||||
|
||||
byte[] senderHardwareAddress = new byte[hardwareAddressLength];
|
||||
byte[] senderProtocolAddress = new byte[protocolAddressLength];
|
||||
byte[] targetHardwareAddress = new byte[hardwareAddressLength];
|
||||
byte[] targetProtocolAddress = new byte[protocolAddressLength];
|
||||
|
||||
buffer.get(senderHardwareAddress);
|
||||
buffer.get(senderProtocolAddress);
|
||||
buffer.get(targetHardwareAddress);
|
||||
buffer.get(targetProtocolAddress);
|
||||
|
||||
return new ARPInfo(hardwareType, protocolType, operation,
|
||||
senderHardwareAddress, senderProtocolAddress,
|
||||
targetHardwareAddress, targetProtocolAddress);
|
||||
}
|
||||
|
||||
public static boolean isArpPacket(byte[] data) {
|
||||
// Check if the frame is an ARP packet
|
||||
// Ethernet frame type for ARP is 0x0806
|
||||
int frameType = ((data[12] & 0xFF) << 8) | (data[13] & 0xFF);
|
||||
return frameType == 0x0806;
|
||||
}
|
||||
|
||||
public static class ARPInfo {
|
||||
public final int hardwareType;
|
||||
public final int protocolType;
|
||||
public final int operation;
|
||||
public final byte[] senderHardwareAddress;
|
||||
public final byte[] senderProtocolAddress;
|
||||
public final byte[] targetHardwareAddress;
|
||||
public final byte[] targetProtocolAddress;
|
||||
|
||||
public ARPInfo(int hardwareType, int protocolType, int operation,
|
||||
byte[] senderHardwareAddress, byte[] senderProtocolAddress,
|
||||
byte[] targetHardwareAddress, byte[] targetProtocolAddress) {
|
||||
this.hardwareType = hardwareType;
|
||||
this.protocolType = protocolType;
|
||||
this.operation = operation;
|
||||
this.senderHardwareAddress = senderHardwareAddress;
|
||||
this.senderProtocolAddress = senderProtocolAddress;
|
||||
this.targetHardwareAddress = targetHardwareAddress;
|
||||
this.targetProtocolAddress = targetProtocolAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ARPInfo{" +
|
||||
"hardwareType=" + hardwareType +
|
||||
", protocolType=" + protocolType +
|
||||
", operation=" + operation +
|
||||
", senderHardwareAddress=" + Arrays.toString(senderHardwareAddress) +
|
||||
", senderProtocolAddress=" + Arrays.toString(senderProtocolAddress) +
|
||||
", targetHardwareAddress=" + Arrays.toString(targetHardwareAddress) +
|
||||
", targetProtocolAddress=" + Arrays.toString(targetProtocolAddress) +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package li.cil.oc2.common.vxlan;
|
||||
|
||||
public class BoolConverter {
|
||||
public static byte BooleanToByte(boolean b) {
|
||||
return (byte) (b ? 1 : 0);
|
||||
}
|
||||
|
||||
public static boolean ByteToBoolean(byte b) {
|
||||
return (b == 1);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package li.cil.oc2.common.vxlan;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class GREHeader implements Serializable
|
||||
{
|
||||
public static final int LENGTH = 21;
|
||||
|
||||
public InetAddress FinalDestinationAddress;
|
||||
public InetAddress SourceAddress;
|
||||
public int FinalDestinationPort;
|
||||
public int SourcePort;
|
||||
public int Vti;
|
||||
public boolean IsArp;
|
||||
|
||||
public GREHeader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public GREHeader(InetAddress fda, InetAddress sa, int finalDestinationPort, int sourcePort, int vti, boolean isArp)
|
||||
{
|
||||
FinalDestinationAddress = fda;
|
||||
SourceAddress = sa;
|
||||
FinalDestinationPort = finalDestinationPort;
|
||||
SourcePort = sourcePort;
|
||||
Vti = vti;
|
||||
IsArp = isArp;
|
||||
}
|
||||
|
||||
public byte[] getBytes() throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
baos.write(FinalDestinationAddress.getAddress());
|
||||
baos.write(SourceAddress.getAddress());
|
||||
baos.write(ByteBuffer.allocate(4).putInt(FinalDestinationPort).array());
|
||||
baos.write(ByteBuffer.allocate(4).putInt(SourcePort).array());
|
||||
baos.write(ByteBuffer.allocate(4).putInt(Vti).array());
|
||||
baos.write(ByteBuffer.allocate(1).put(BoolConverter.BooleanToByte(IsArp)).array());
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
public static GREHeader deserialize(byte[] bytes) throws IOException {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||
return new GREHeader(InetAddress.getByAddress(bais.readNBytes(4)), InetAddress.getByAddress(bais.readNBytes(4)), ByteBuffer.wrap(bais.readNBytes(4)).getInt(), ByteBuffer.wrap(bais.readNBytes(4)).getInt(), ByteBuffer.wrap(bais.readNBytes(4)).getInt(), BoolConverter.ByteToBoolean(ByteBuffer.wrap(bais.readNBytes(1)).get(0)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("Destination IP: %s\nSource IP: %s\nDestination Port: %d\nSource Port: %d", FinalDestinationPort, SourceAddress, FinalDestinationPort, SourcePort);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
package li.cil.oc2.common.vxlan;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ICMPParser {
|
||||
|
||||
public static ICMPInfo parseICMP(byte[] frame) {
|
||||
if (frame.length < 34) { // Minimum length: Ethernet (14) + IP (20)
|
||||
throw new IllegalArgumentException("Frame is too short to be a valid ICMP packet");
|
||||
}
|
||||
|
||||
// Ethernet frame: [Destination MAC (6)] [Source MAC (6)] [Type (2)]
|
||||
int etherType = ((frame[12] & 0xFF) << 8) | (frame[13] & 0xFF);
|
||||
if (etherType != 0x0800) { // Check if EtherType is IPv4
|
||||
throw new IllegalArgumentException("Not an IPv4 packet");
|
||||
}
|
||||
|
||||
// Skip Ethernet header
|
||||
ByteBuffer buffer = ByteBuffer.wrap(frame, 14, frame.length - 14);
|
||||
|
||||
// IP header: [Version/IHL (1)] [Type of Service (1)] [Total Length (2)] [ID (2)] [Flags/Offset (2)] [TTL (1)] [Protocol (1)] [Checksum (2)] [Source IP (4)] [Destination IP (4)]
|
||||
buffer.get(); // Version/IHL
|
||||
buffer.get(); // Type of Service
|
||||
buffer.getShort(); // Total Length
|
||||
buffer.getShort(); // ID
|
||||
buffer.getShort(); // Flags/Offset
|
||||
buffer.get(); // TTL
|
||||
byte protocol = buffer.get(); // Protocol
|
||||
if (protocol != 1) { // Check if protocol is ICMP
|
||||
throw new IllegalArgumentException("Not an ICMP packet");
|
||||
}
|
||||
|
||||
buffer.getShort(); // Checksum
|
||||
byte[] sourceIP = new byte[4];
|
||||
buffer.get(sourceIP);
|
||||
byte[] destinationIP = new byte[4];
|
||||
buffer.get(destinationIP);
|
||||
|
||||
// ICMP header: [Type (1)] [Code (1)] [Checksum (2)] [Rest of Header (4)]
|
||||
byte type = buffer.get();
|
||||
byte code = buffer.get();
|
||||
short checksum = buffer.getShort();
|
||||
int restOfHeader = buffer.getInt(); // This could include identifier and sequence number for echo requests/replies
|
||||
|
||||
// The rest of the packet is the ICMP payload
|
||||
byte[] payload = new byte[buffer.remaining()];
|
||||
buffer.get(payload);
|
||||
|
||||
return new ICMPInfo(type, code, checksum, restOfHeader, sourceIP, destinationIP, payload);
|
||||
}
|
||||
|
||||
public static boolean isIcmpPacket(byte[] data) {
|
||||
if (data.length < 34) { // Minimum length: Ethernet (14) + IP (20)
|
||||
return false;
|
||||
}
|
||||
|
||||
int etherType = ((data[12] & 0xFF) << 8) | (data[13] & 0xFF);
|
||||
if (etherType != 0x0800) { // Check if EtherType is IPv4
|
||||
return false;
|
||||
}
|
||||
|
||||
int ipHeaderStart = 14;
|
||||
byte protocol = data[ipHeaderStart + 9];
|
||||
return protocol == 1; // Check if protocol is ICMP
|
||||
}
|
||||
|
||||
public static class ICMPInfo {
|
||||
public final byte type;
|
||||
public final byte code;
|
||||
public final short checksum;
|
||||
public final int restOfHeader;
|
||||
public final byte[] sourceIP;
|
||||
public final byte[] destinationIP;
|
||||
public final byte[] payload;
|
||||
|
||||
public ICMPInfo(byte type, byte code, short checksum, int restOfHeader, byte[] sourceIP, byte[] destinationIP, byte[] payload) {
|
||||
this.type = type;
|
||||
this.code = code;
|
||||
this.checksum = checksum;
|
||||
this.restOfHeader = restOfHeader;
|
||||
this.sourceIP = sourceIP;
|
||||
this.destinationIP = destinationIP;
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ICMPInfo{" +
|
||||
"type=" + (type & 0xFF) +
|
||||
", code=" + (code & 0xFF) +
|
||||
", checksum=" + (checksum & 0xFFFF) +
|
||||
", restOfHeader=" + restOfHeader +
|
||||
", sourceIP=" + Arrays.toString(sourceIP) +
|
||||
", destinationIP=" + Arrays.toString(destinationIP) +
|
||||
", payload=" + Arrays.toString(payload) +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user