Charlotte A Bit Based Packet manipulation utilityCharlotte is a tool for manipulating Bit Based Packet (BBP). A BBP is a single series of bits representing multiple values. For example, a TCP header has the following form. The total number of bits in the above definition is 160 bytes. A charlotte encoding description for a TCP Header would look like this:
name: TCP Header
version=4
headerLength=4
typeOfService=8
totalLength=16
id=16
flags=3
fragmentOffset=13
timeToLive=8
protocol=8
headerChecksum=16
sourceIp=32
destinationIp=32
It would then be used like this:
import code316.charlotte.Encoding;
import code316.charlotte.EncodingUtil;
import code316.charlotte.Parser;
public class Test {
private static final Encoding TCP_ENCODING;
private static final String TCP_ENCODING_FILE = "encoding-definitions/tcp-encoding.enc";
static {
try {
Parser ep = new Parser();
InputStream in =
Test.class.getClassLoader().getResourceAsStream(TCP_ENCODING_FILE);
if ( in == null ) {
throw new IllegalStateException("could not load tcp encoding file: " + TCP_ENCODING_FILE);
}
TCP_ENCODING = ep.parse(in);
}
catch (IOException ioe) {
throw new RuntimeException("Could not create encoding", ioe);
}
}
public static TcpValue decodeTcpValue(BigInteger bits) {
// contains a Map of String to Double
Map valueMap = EncodingUtil.expandFields(TCP_ENCODING, bits);
TcpValue tcp = new TcpValue();
tcp.setVersion( valueMap.get("version") );
....
|