Problem when sending UDP packet using jpcap
843790Dec 6 2006 — edited Dec 23 2006Hi,
I am trying to send UDP packets using jpcap, but it always gives this Exception: Exception in thread "main" java.io.IOException:
at jpcap.JpcapSender.nativeSendPacket(Native Method)
at jpcap.JpcapSender.sendPacket(JpcapSender.java:92)
Here is the code.
public static void main(String[] args) throws Exception{
NetworkInterface device=JpcapCaptor.getDeviceList()[1];
JpcapCaptor captor=JpcapCaptor.openDevice(device,2000,false,5000);
InetAddress thisIP=null;
for(NetworkInterfaceAddress addr:device.addresses)
if(addr.address instanceof Inet4Address){
thisIP=addr.address;
break;
}
byte[] gwmac={0,-128,72,48,-89,-79};
UDPPacket udp = new UDPPacket(1000, 161);
udp.setIPv4Parameter (0,false,false,false,0,false,false,false,0,0,0,IPPacket.IPPROTO_UDP,
thisIP,InetAddress.getByName("www.seznam.cz"));
udp.data="data".getBytes();
EthernetPacket ether=new EthernetPacket();
ether.frametype=EthernetPacket.ETHERTYPE_IP;
ether.src_mac=device.mac_address;
ether.dst_mac=gwmac;
udp.datalink = ether;
JpcapSender sender=captor.getJpcapSenderInstance();
sender.sendPacket(udp);
}
I also tried some examples downloaded from the jpcap homepage, but they don't work either. I use Windows XP.
Does anybody know, where the problem is?
If anybody has a source code that works, could you please send it at tomas.klima@atlas.cz
Thanks. Tom