java - Unable to receive packet using jpcap in WiFi network -
i want send , receive packets in wifi network. using 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, write 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 connect 2 machines lan, unable receive packet when connect wifi.
can suggest me, whats going wrong??
i suspect answer related quote jpcap faq:
q: can capture packets wifi (802.11) network interface?
the answer depends on operating system running , wifi devices system has. on windows, may not able capture packets wifi devices. linux or bsd may have higher probability of supporting packet capturing using wifi devices.
you may have better success on google discussion group jpcap if share precise adapter type , windows version details.
Comments
Post a Comment