简体   繁体   English

Java pcap解析器转换为ByteBuffer

[英]Java pcap parser into ByteBuffer

So I used tcpdump to capture my UDP packets into a file. 因此,我使用tcpdump将UDP数据包捕获到一个文件中。 I now have my pcap file with my packets. 现在,我的数据包中有我的pcap文件。 Now I need: 现在我需要:

A Java program to open this file, parse it and place the packet contents, one at a time, into a ByteBuffer so my protocol parser can process each packet as it was getting them from the network. 一个Java程序来打开此文件,对其进行解析,然后一次将一个包的内容放入ByteBuffer,这样我的协议解析器就可以处理从网络中获取的每个包。 My protocol parser must not care whether it is being called by the network reader or by the pcap processor. 我的协议解析器不必在乎是由网络读取器还是由pcap处理器调用它。

Is there a library or a standard way in Java to do that? Java是否有库或标准方法可以做到这一点? Can you give me or point me out to some source code example? 您能给我还是指出一些源代码示例? Thanks! 谢谢!

使用jpcap ,这正是您需要的。

To read from a file and place it into a ByteBuffer you can use 要从文件读取并将其放入ByteBuffer,可以使用

FileChannel in = new FileInputStream(filename).getChannel();

// read into a ByteBuffer from a file.
in.read(byteBuffer);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM