The totally new Packet module provides sophisticated API for working with packet contents. In jNetPcap v1, everything was in the main module. In version 2 we split the functionality into a Packet module and much much more.
The Packet module is a standalone module from Pcap. Pcap applications can include the Packet module and utilize full packet API as can other unrelated projects.
More on this later with examples.
Packet module capabilities
Protocol Stack (OSI Layers 2-7)
Multiple protocol packs (extensions)
Dissectors, reassemblers, crypto ciphers
Meta representation and formatters
Flexible data sources such as ByteBuffer, byte and native memory
BinaryLayout for describing binary structure
BitFields for accessing binary structures
Example 1: IP version 4 header using BinaryLayout definition:
IP ver 4 definition taken from Ip4.java class, defined using BinaryLayout with bit-level granularity
Ip4.java: extended layout
The extended Ip4 layout adds addition bit level granularity to dsfield and other ways to access the header including via byte, full 32-bit words, etc..
Example 2: IP version 6 header using BinaryLayout definition:
IP ver 6 header definition taken from Ip6.java class defined using BinaryLayout with bit-level granularity
Ip6: extended layout
Note: For those not familiar with the C structure concept. A structure is composed of elements which are layed out one after the previous one. The size of the structure is combined size of each element within. A union overlays each element on top of the previous one. The size of a union is the size of the biggest element within the union. Each structure and union can have structures and unions as child elements.