Search code examples
javapacket-capturejpcap

How does HTTP response relate to request?


I'm packet sniffing using jpcap, and I'm wondering how I can find out which request the response is for. The HTTP header fields don't even state the address of the server, and there are no ID's.

Do I need to check ports or something?


Solution

  • It sounds like you're looking at captured IP packets without understanding how TCP connections work. The answer is that the HTTP headers don't include the address of the server, because they don't need to. The HTTP data is set across a TCP connection, which manages the source and destination addresses for each packet.

    A TCP connection is like a virtual "pipe" between the client and the server. Any data sent on a TCP connection either:

    • arrives at the other end in the same order it was sent, or
    • does not arrive at all

    Even if the individual IP packets might be fragmented and arrive at the destination in a different order from what was sent, TCP will sort all that out and present the receiver with a consistent, guaranteed view of the same data the sender put into the pipe.