Permalink
Browse files

Added a Java workaround for lack of unsigned ints. tcp_seq/tcp_ack fi…

…elds are now accessable.
  • Loading branch information...
1 parent e65de31 commit 34bec6654b96f340c3e6b3595a76ae05a0d1281d @FaustDeGoethe FaustDeGoethe committed Jan 28, 2013
View
@@ -1,10 +1,6 @@
-Hadoop PCAP library :: Forked by Mrrrgn
+Hadoop PCAP library
===================
-Why did I fork it? The original library doesn't have support for sequence/acknowledgement numbers or adequate payload filtering.
-I've already added seq/ack support with payload filtering to come. This is in anticipation of having a hadoop based tcp stream
-assembler. :)
-
License
-------
This library is distributed under the LGPL.
@@ -279,8 +279,8 @@ private void buildInternetProtocolV4Packet(Packet packet, byte[] packetData, int
//Store the sequence and acknowledgement numbers --M
- packet.put(Packet.TCP_SEQ,PcapReaderUtil.convertInt(packetData,ipStart+ ipHeaderLen + PROTOCOL_HEADER_TCP_SEQ_OFFSET));
- packet.put(Packet.TCP_ACK,PcapReaderUtil.convertInt(packetData,ipStart + ipHeaderLen + PROTOCOL_HEADER_TCP_ACK_OFFSET));
+ packet.put(Packet.TCP_SEQ,PcapReaderUtil.convertUnsignedInt(packetData,ipStart+ ipHeaderLen + PROTOCOL_HEADER_TCP_SEQ_OFFSET));
+ packet.put(Packet.TCP_ACK,PcapReaderUtil.convertUnsignedInt(packetData,ipStart + ipHeaderLen + PROTOCOL_HEADER_TCP_ACK_OFFSET));
// Flags stretch two bytes starting at the TCP header offset
@@ -4,6 +4,7 @@
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
+import java.math.BigInteger;
public class PcapReaderUtil {
private static Map<Integer, String> protocols;
@@ -61,6 +62,15 @@ public static int convertShort(byte[] data, int offset) {
return convertShort(target);
}
+ //A java workaround for header fields like seq/ack which are ulongs --M
+ public static long convertUnsignedInt(byte[] data,int offset) {
+ byte[] target = new byte[4];
+ System.arraycopy(data, offset, target, 0, target.length);
+
+ BigInteger placeholder = new BigInteger(1,target);
+ return placeholder.longValue();
+ }
+
public static String convertProtocolIdentifier(int identifier) {
return protocols.get(identifier);
}
@@ -75,4 +85,4 @@ public static String convertAddress(byte[] data, int offset) {
return null;
}
}
-}
+}

0 comments on commit 34bec66

Please sign in to comment.