2014-10-30 8 views
0

패킷을 바이트 형식으로 변환하고 디코딩해야합니다. jnetpcap 라이브러리를 사용하여 캡쳐 된 패킷을 Java [?] 또는 그 반대로 배열로 변환하는 방법은 무엇입니까?Pcap 패킷의 인코딩 및 디코딩

답변

0

PcapPacket 클래스는 패킷의 내용을 바이트 배열에 복사하는public int transferStateAndDataTo (byte [] buffer) 메서드를 가지고 있습니다.
는 packet.getTotalSize()

다른 방법이있는 다른 헤더 데이터 (이더넷/IP/TCP)에 대한 페이로드

//opens an offline pcap file 
Pcap pcap = Pcap.openOffline(pcapIpFile, errbuf); 

//packet object 
PcapPacket packet = new PcapPacket(JMemory.POINTER); 

Payload pl = new Payload(); 

pcap.nextEx(packet);  // retrieves the next packet from input loop thru until eof 

if(packet.hasHeader(pl)) //this will check for and retrieve the payload 
    pl.data() // this will give you the data in the payload as a byte stream 

찾는 경우로서 크기 바이트 []를 정의 구현시 사용 가능

+0

감사합니다. 그러나 바이트 배열 패킷을 다시 pcap 패킷으로 디코딩하는 동안 IP4() 프로토콜에서 예외가 발생했습니다. 다음과 같이 변환하면 충분합니다 : PcapPacket packet = new PcapPacket (bytes)? – user3823859