I am trying to send udp packets with multicast and receive them with jpcap. The multicast code works and when I sniff with wireshark I receive all the packets which i want to have. But my jpcap code does not work, I get this exception:
Exception in thread "main" java.lang.InstantiationException: jpcap.packet.DatalinkPacket
at jpcap.JpcapCaptor.getPacket(Native Method)
at Receiver.Receiver.main(Receiver.java:54)
This is my Code:
NetworkInterface[] devices = JpcapCaptor.getDeviceList();
int index = 0;
JpcapCaptor captor=JpcapCaptor.openDevice(devices[index], 60000, true, 20);
//captor.setFilter("udp", true);
for(int i=0;i<1000;i++){
//capture a single packet and print it out
Packet pac = captor.getPacket();
System.out.println(pac);
}
The Network Interface works perfectly in wireshark. When I run the Code without captor.setFilter() I get the exception . Sometimes I get 1-2 times "null" before the exception, so it seems like there are several packets which let my program crash (e.g beacons). When I set a filter, like "udp", I get no exception but every time "null" because no packet is captured.
My Network Interface is a Wifi Adapter which runs in Monitor Mode, so it captures all packets which it receives.
If you dont know an answer, could you tell me if there are other librarys like jpcap which can do the same? I found nothing else. Or would you say that I better should use another language for this (C#)? I really just want to capture the packets and write them to a file, so I will just use the language in which this is working best. I would really appreciate your help.