This is what we are testing:
/* serial max = 4294967295 * rollover = (1 + max / 2) = 2147483648 * * returns: * 0 s1 = s2 * -1 s1 < s2 * 1 s1 > s2 * >1 undefined */
int cmp_serial(u_int32_t s1, u_int32_t s2) { u_int32_t rollover = 2147483647;
rollover += 1; /* silence unsigned integer compiler warning */
if (s1 == s2)
return(0);
else if ((s1 < s2 && s2 - s1 < rollover) ||
(s1 > s2 && s1 - s2 > rollover))
return(-1);
else if ((s1 < s2 && s2 - s1 > rollover) ||
(s1 > s2 && s1 - s2 < rollover))
return(1);
return(2);
}