什么没有被正确解码?你期待什么,你看到了什么?参数不会以任何方式“标记”。他们只是有一些专用的字节。你只需要知道去哪里找。
让我向您展示我的旧 jnetpcap 代码示例。现在,由于您熟悉 jnetpcap,而我无法真正理解问题所在,我只是向您展示代码片段,猜测您会掌握它的窍门。
下面的代码是我对Beacon Frames的解析。data
是从文件中提取的数据。
int packet_size = packet.size();
JBuffer packet_buf = packet;
byte[] data = packet_buf.getByteArray(0, packet_size);
int[] data_int = new int[max_byte_read];
for (int k = 0; k<max_byte_read; k++) {
data_int[k] = data[k]&0xFF;
}
byte[] frame_control = new byte[2];
byte[] duration = new byte[2];
byte[] dest_ip = new byte[6];
byte[] src_ip = new byte[6];
byte[] bss_id = new byte[6];
byte[] seq_ctrl = new byte[2];
byte[] time_stamp = new byte[8];
byte[] beacon_interval = new byte[2];
byte[] capability_info = new byte[2];
byte[] tag_nr = new byte[1];
byte[] tag_len = new byte[1];
if (data_int[0]==0x80) {
// It's a beacon
System.out.printf("It's a beacon!\n");
frame_control = Arrays.copyOfRange(data, 0, 2);
duration = Arrays.copyOfRange(data, 2, 4);
dest_ip = Arrays.copyOfRange(data, 4, 10);
src_ip = Arrays.copyOfRange(data, 10, 16);
bss_id = Arrays.copyOfRange(data, 16, 22);
seq_ctrl = Arrays.copyOfRange(data, 22, 24);
time_stamp = Arrays.copyOfRange(data, 24, 32);
beacon_interval = Arrays.copyOfRange(data, 32, 34);
capability_info = Arrays.copyOfRange(data, 34, 36);
tag_nr = Arrays.copyOfRange(data, 36, 37);
tag_len = Arrays.copyOfRange(data, 37, 38);
int ss_id_len = tag_len[0];
byte[] ss_id = new byte[ss_id_len];
ss_id = Arrays.copyOfRange(data, 38, 38+ss_id_len);
System.out.printf("SSID: ");
for (byte b : ss_id) {
int c = b&0xFF;
System.out.printf("%s", (char) c);
}
System.out.println("");
}
else {
System.out.println("Not a beacon unfortunately");
}
如果无论如何这对您没有帮助,我可以尝试发布一个完整的示例。但因为这可能有点过头了,所以我现在就坚持这个。