Do all shifts in SWAPSHORT() and SWAPLONG() on unsigned values.
To quote C99 section 6.5.7 "Bitwise shift operators":
The result of E1 << E2 is E1 left-shifted E2 bit positions;
vacated bits are filled with zeros. ... If E1 has a signed
type and nonnegative value, and E1 x 2^E2 is representable in
the result type, then that is the resulting value; otherwise,
the behavior is undefined.
In practice, signed vs. unsigned shouldn't make a difference, as long
as we don't get a trap of some sort in the "isn't representable" case,
but we might as well do an unsigned shift, because we're just doing
bit-banging, so we *want* unsigned - yeah, it means the result may not
have the same signedness as the value we pass in, but, as the saying
goes, bits are bits. We end up stuffing the result back into the place
from which we extracted it, so it ultimately will get back the correct
signedness.
This should keep UBSAN quiet.
While we're at it, in SWAPSHORT(), do all the bit-banging on u_int
values, and cast the result to u_short.