

Use the following code that basically works on TCP/IP protocol suit. Hope it will help you :-)
import java.net.*;
07 import java.io.*;
08 import jpcap.JpcapCaptor;
09 import jpcap.JpcapSender;
10 import jpcap.NetworkInterface;
11 import jpcap.NetworkInterfaceAddress;
12 import jpcap.packet.*;
13
14 class Main {
15
16 /* variables */
17 JpcapCaptor captor;
18 NetworkInterface[] list;
19 String str,info;
20 int x, choice; 21
22 public static void main(String args[]) {
23 new Main(); 24 } 25
26 public Main() {
27
28 /* first fetch available interfaces to listen on */
29 list = JpcapCaptor.getDeviceList();
30 System.out.println("Available interfaces: "); 31
32 for(x=0; x 33 System.out.println(x+" -> "+list[x].description); 34 }
35 36 choice = Integer.parseInt(getInput("Choose interface (0,1..): ")); 37 System.out.println("Listening on interface -> "+list[choice].description); 38 System.out.println("-------------------------\n");
39 40 43 try {
44 captor=JpcapCaptor.openDevice(list[choice], 65535, false, 20); 45 /* listen for TCP/IP only */ 46 captor.setFilter("ip and tcp", true); 47 } 48 catch(IOException ioe) { ioe.printStackTrace(); } 49 52 while (true) {
53 55 if(info != null)
56 System.out.print(getPacketText(info)); 57 }
58 }
59 62 public static String getInput(String q) { 63 String input = ""; 64 System.out.print(q); 65 BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in)); 66 try { 67 input =bufferedreader.readLine(); 68 } 69 catch(IOException ioexception) { } 70 return input; 71 }
72 74 /* return packet data in true text */ 75 String getPacketText(Packet pack){ 76 int i=0,j=0; 77 byte[] bytes=new byte[pack.header.length + pack.data.length]; 78 79 System.arraycopy(pack.header, 0, bytes, 0, pack.header.length); 80 System.arraycopy(pack.data, 0, bytes, pack.header.length, pack.data.length); 81 StringBuffer buffer = new StringBuffer(); 82 84 for(j=0;j<8 && i 85 String d = Integer.toHexString((int)(bytes [i] &0xff)); 86 buffer.append((d.length() == 1 ? "0" + d:d ) + " ");
87 88 if(bytes[i]<32 || bytes[i]>126) 89 bytes[i] = 46;
90 } 91 } 92 return new String(bytes,i - j, j); 93 }
94 }
System.out.println("-------------------------\n");
41
42 /*Setup device listener */
50
51 /* start listening for packets */
54 Packet info =captor.getPacket();
60
61 /* get user input */
73
83 for(i=0; i

Can you please post the complete code....it's incomplete at line number 32...
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.