Problem with sending IP(v4) packet (Jpcap)
Hi,
I'm writing GRE tunnel in java. I have problem with sending encapsulated packet through raw socket. I'm using Jpcap library to create IP packet and send it. Could anyone point errors in my code or write sample code that sends IP packets? This is my code:
import jpcap.*;
class IPSend
{
public static void main(String[] args) throws Exception{
System.out.println(Jpcap.getDeviceList()[1]);
JpcapSender sender=JpcapSender.openDevice(Jpcap.getDeviceList()[1]);
IPPacket a=new IPPacket();
a.setIPv4Parameter(0,false,false,false,0,false,false,false,0,5436,128,2,
new IPAddress("192.168.1.2"),new IPAddress("192.168.1.5"));
a.data="hjkg56yt".getBytes();
for(int i=0;i<10;i++){
sender.sendPacket(a);
}
sender.close();
}
}
hello everybody i had program with the JPCAP to send a packets and i had send a IP (tcp, udp,icmp too) packets with no problem with this portion of code:(this portion is for IP sending)
void ipsend(){
System.out.println(Jpcap.getDeviceList()[0]);
JpcapSender sender = null;
IPPacket p = new IPPacket();
try {
p.setIPv4Parameter(0, false, false, false, 0,false, false, false, 0,
0x1122, 32, 0, new IPAddress("10.35.16.111"),new IPAddress("10.35.16.120"));
p.data = "data".getBytes();
System.out.print(p+"\n");
}
catch (UnknownHostException ex1) {System.out.print("euh non non");
}
try {
sender = JpcapSender.openDevice(Jpcap.getDeviceList()[liste.getSelectedIndex()]);
sender.sendPacket(p);
System.out.print(p+"\n");
sender.close();
}
catch (IOException ex) {System.out.print("\n je suis ACOT?DE LA PLAK :("+ex);
}
System.out.print("\n c yes");
}
i hope that this portion of code can help you. GOOD LUCK ;)