API

New to jNetpcap and Java :)

import java.util.Arrays;

import org.jnetpcap.packet.JHeader;
import org.jnetpcap.packet.annotate.Field;
import org.jnetpcap.packet.annotate.Header;
import org.jnetpcap.protocol.JProtocol;

@Header(length=14)
public class Abcd extends JHeader{

public static final int ID = JProtocol.ETHERNET_ID;

@Field(offset = 0 * BYTE, length = 6 * BYTE, format = "#mac#")
public byte[] destination() {
return getByteArray(0, 6);
}

@Field(offset = 6 * BYTE, length = 6 * BYTE, format = "#mac#")
public byte[] source() {
return getByteArray(6, 6);
}

@Field(offset = 12 * BYTE, length = 2 * BYTE, format = "%x")
public int type() {
return getUShort(12);
}

@Override
public String toString() {
return "Abcd [destination()=" + Arrays.toString(destination())
+ ", source()=" + Arrays.toString(source()) + "]";
}
}

I am using nextPacket method to get the destination and source address. It looks like

pcap.loop(Pcap.LOOP_INFINATE, new JPacketHandler() {
final Abcd abcd = new Abcd();
public void nextPacket(JPacket packet, StringBuilder errbuf)
{

System.out.println(" Frame" + packet.getFrameNumber());

if(packet.hasHeader(Abcd.ID)){
System.out.println("ABCD packet found");
packet.getHeader(abcd);
System.out.println("Buffer" + packet.getTotalSize());
System.out.println("Header count"+ packet.getHeaderCount());
}

System.out.println("ethernet header::"+abcd.destination());

}
},errbuf);

is there an API call to check the jnetpcap version?

Syndicate content