Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-users: Re: [Wireshark-users] How source and destination is identified in Wireshark?

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Fri, 28 Jan 2011 12:14:30 -0800
On Jan 28, 2011, at 10:55 AM, Guy Harris wrote:

> AAA.BBB.CCC.DDD happens to be the source address, and XXX.YYY.ZZZ.WWW happens to be the destination address of the first packet in that TCP connection in the capture,

Actually, it is based on the first packet it sees, but the rules are:

	if the source port of that first packet is greater than the destination port of that first packet, the endpoints are {source IP}:{source port} and {destination IP}:{destination port};

	otherwise, if the source port of that first packet is less than the destination port of that first packet, the endpoints are {destination IP}:{destination port} and {source IP}:{source port};

	otherwise (i.e., if the source and destination ports are equal), if the source IP address is "greater than" the destination IP address, the endpoints are {source IP}:{source port} and {destination IP}:{destination port};

	otherwise, the endpoints are {destination IP}:{destination port} and {source IP}:{source port}.

So that doesn't magically always correctly determine the endpoint from which the connection was initiated - and it doesn't even bother looking at the SYN or ACK bits.

("Greater than", for IP addresses, is based on a byte-by-byte comparison of the addresses.)