Subject: Re: ip_nat MSS clamping
To: Martin Husemann <firstname.lastname@example.org>
From: Robert Elz <kre@munnari.OZ.AU>
Date: 06/05/2002 17:35:02
Date: Mon, 3 Jun 2002 20:40:28 +0200
From: Martin Husemann <email@example.com>
| > This is quite dangerous construction for any platform with strict
| > alignment.
I know it has been committed this (general) way now (with just some var
named changed), and what is there is safe, but it really is way overkill...
| + memcpy(&netmss, &cp, 2);
| + mss = (uint32_t)ntohs(netmss);
which really can just be
mss = (cp << 8) | cp;
We know what is there is network byte order, we know what that is,
and we know it isn't going to change, simply fetching the bytes and
constructing the integral value using the definition of what's in the
data stream is perfectly safe, portable, and all that...
| + netmss = htons((short)(maxmss));
| + memcpy(&cp, &netmss, 2);
cp = maxmss >> 8;
cp = maxmss /* & 0xFF */ ;
Save the function call, and allow the compiler to to a better job
(on a big endian system without alignment issues, a smart compiler could
simply do the 2 byte fetch/store after noticing what the code is doing).