Steps to reproduce (using jnetpcap 1.3, win32, winpcap 4.1.2, oracle java 1.6.24).
1/ run the attached code (based on classic example).
2/ open in firefox http://www.damnsmalllinux.org/
then an exception is thrown:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:686)
at org.jnetpcap.packet.AbstractMessageHeader.decodeHeader(Unknown Source)
at org.jnetpcap.packet.JHeader.decode(Unknown Source)
at org.jnetpcap.packet.JPacket.getHeaderByIndex(Unknown Source)
at org.jnetpcap.packet.JPacket.hasHeader(Unknown Source)
at org.jnetpcap.packet.JPacket.hasHeader(Unknown Source)
at Demo$1.nextPacket(Demo.java:66)
at Demo$1.nextPacket(Demo.java:61)
at org.jnetpcap.Pcap.loop(Native Method)
at org.jnetpcap.Pcap.loop(Unknown Source)
at Demo.main(Demo.java:85)
Java Result: 1
Java demo:
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.jnetpcap.Pcap;
import org.jnetpcap.PcapIf;
import org.jnetpcap.packet.PcapPacket;
import org.jnetpcap.packet.PcapPacketHandler;
import org.jnetpcap.protocol.tcpip.Http;
public class Demo {
public static void main(String[] args) {
List
StringBuilder errbuf = new StringBuilder(); // For any error msgs
/***************************************************************************
* First get a list of devices on this system
**************************************************************************/
int r = Pcap.findAllDevs(alldevs, errbuf);
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
System.err.printf("Can't read list of devices, error is %s", errbuf.toString());
return;
}
System.out.println("Network devices found:");
int i = 0;
I try to read the packets from a recorded DECT pcap file. Each packet has a length of 73 bytes. Is it possible to save all packet bytes to a java byte array for further modification? I do not need to subdivide them into header and data parts. I only found guides for usual packets like TCP, UDP, IP so far.
I need to get IP address and maybe flag of comming in packets in real time. No need to storage whole packet, juz this one/two informations. What i need to do?