Help packet sending with Jpcap(netresearch) - TechRepublic
General discussion
February 16, 2011 at 07:57 AM
aniketsharma190

Help packet sending with Jpcap(netresearch)

by aniketsharma190 . Updated 14 years, 1 month ago

I am a beginner in Jpcap.
My problem is as follows:-
i am trying to send a TCP packet but unable to receive it.
The code for sending Tcp packet is as follows.
I am working on Windows XP.
hoping for reply.

import jpcap.*;
import jpcap.packet.*;
import java.net.InetAddress;
import java.lang.Object;

class SendPacket
{

public static void main(String args[]) throws Exception
{
int index=0;

//Obtain the list of network interfaces
NetworkInterface[] devices = JpcapCaptor.getDeviceList();

//open a network interface to send a packet to
JpcapSender sender=JpcapSender.openDevice(devices[index]);

//create a TCP packet with specified port numbers, flags, and other parameters
TCPPacket p=new TCPPacket(12,34,56,78,false,false,false,false,true,true,true,true,10,10);

//specify IPv4 header parameters

p.setIPv4Parameter(0,false,false,false,0,false,false,false,0,65,128,IPPacket.IPPROTO_TCP,InetAddress.getByName(“192.168.15.16”),InetAddress.getByName(“192.168.15.15”));

//set the data field of the packet
p.data=(“ABCD”).getBytes();

//create an Ethernet packet (frame)
EthernetPacket ether=new EthernetPacket();
//set frame type as IP
ether.frametype=EthernetPacket.ETHERTYPE_IP;
//set source and destination MAC addresses

String strdst = new String(“00:21:9B:D7:98:54”);
ether.dst_mac = strdst.getBytes();
String strsrc = new String(“00:0C:F1:DE:00:D0”);
ether.src_mac = strsrc.getBytes();

//set the datalink frame of the packet p as ether
p.datalink=ether;

//send the packet p
for(int k=0;k>=0;k++)
{
sender.sendPacket(p);
}
sender.close();
}

}

This discussion is locked

All Comments