kaitoy / pcap4j

A Java library for capturing, crafting, and sending packets.

Home Page:https://www.pcap4j.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get source and destination Ip from TCP packet

prashantkalkar opened this issue · comments

Hi,
I am trying to capture tcp traffic (similar to what tcpdump captures). From the tcp packet I am trying to get the source and destination port and source and destination IP addresses.
Here is how I am getting the tcpPacket

TcpPacket tcpPacket = pcapHandle.getNextPacketEx().get(TcpPacket.class);

But I can't see any method to obtain source and destination IPs. I tried looking into the tcp headers. I also tried looking into the payload like this.

tcpPacket.getPayload().get(IpV4Packet.class)
But this just provide null as payload is of type UnknownPacket.

Is there any way to get the IP information for TCP traffic?