I want to send and receive packets in WiFi network. using the following codes
To send packet.
int id = Integer.parseInt(text_device.getText().trim());
JpcapCaptor jpcap = JpcapCaptor.openDevice(devices[id], 65535, true, 20);
JpcapSender sender = jpcap.getJpcapSenderInstance();
TCPPacket packet = new TCPPacket(210, 210, 0l, 12l, true, true, true, true, true, true, true, true, 1, 2);
packet.setIPv4Parameter(0, true, true, true, 0, true, true, true, 0, 1010101, 100, IPPacket.IPPROTO_TCP, InetAddress.getLocalHost(), InetAddress.getByName(text_ip.getText().trim()));
packet.data = "Sample Data".getBytes();
Date date = new Date();
packet.usec = date.getTime();
packet.sec = date.getTime();
EthernetPacket ether = new EthernetPacket();
ether.src_mac = new byte[]{(byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1};
ether.dst_mac = new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255};
ether.frametype = EthernetPacket.ETHERTYPE_IP;
packet.datalink = ether;
sender.sendPacket(packet);
To receive packet, i write this code in public void receivePacket(Packet packet)
TCPPacket tcp = (TCPPacket) packet;
String src = tcp.src_ip.getHostAddress();
int src_port = tcp.src_port;
String dst = tcp.dst_ip.getHostAddress();
int dst_port = tcp.dst_port;
String data = new String(tcp.data);
System.out.println("" + data + "");
It works when i connect two machines with LAN, but unable to receive packet when i connect with WiFi.
Can anyone suggest me, whats going wrong??