ipfw: Fix broken length checks on routing messages
Subtracting unsigned and signed types of the same rank yields an
unsigned value that is never less than 0. Rewrite the checks to use
the pattern of 'if (msglen < <desired size>)' instead of
'if (msglen - <desired_size> < 0)' to avoid the subtraction.
To avoid adding lots of casts to appease -Wsign-compare, use a
separate ssize_t variable for the return value of read(2) and convert
msglen to size_t.
While here, fix the first check against the size of the route message
header which was inverted and would have rejected all valid messages
if not for the unsigned vs signed bug causing all of the checks to be
broken.
sbin/ipfw/ipfw2.c: In function 'ipfw_rtsock_monitor':
sbin/ipfw/ipfw2.c:6088:43: error: comparison of unsigned expression in '< 0' is always false [-Werror=type-limits]
6088 | if (sizeof(*hdr) - msglen < 0)
| ^
Reported by: GCC -Wtype-limits
Fixes: 3c76623ad553 ("ipfw: add 'internal monitor' subcommand to capture rtsock messages.")