Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Maybe <a href="http://netresearch.ics.uci.edu/kfujii/jpcap/doc" rel="noreferrer">Jpcap</a> can help. Notice that there's a Sourceforge project with the same name, but it doesn't seem to be the same project.</p> <p>Here's some sample code (from the library's tutorial) that uses Jpcap to send a TCP packet and an Ethernet frame:</p> <p>Edit: The sample code does create a <code>TCPPacket</code>, but you may create a regular <code>Packet</code> instead.</p> <pre><code>//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,1010101,100,IPPacket.IPPROTO_TCP, InetAddress.getByName("www.microsoft.com"),InetAddress.getByName("www.google.com")); //set the data field of the packet p.data=("data").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 ether.src_mac=new byte[]{(byte)0,(byte)1,(byte)2,(byte)3,(byte)4,(byte)5}; ether.dst_mac=new byte[]{(byte)0,(byte)6,(byte)7,(byte)8,(byte)9,(byte)10}; //set the datalink frame of the packet p as ether p.datalink=ether; //send the packet p sender.sendPacket(p); sender.close(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload