It should be safe to multiply timeval seconds by million after substracting
sequence timestamp from now. The reason to postpone multiply operation is
to ensure there is smallest possible change for interger overflow to happen.
{
int at, fd, r;
struct timeval now;
- uint64_t unow, utime;
/* Can't do MPLS decoding */
struct mplslen mpls;
mpls.labels = 0;
gettimeofday(&now, NULL);
- unow = now.tv_sec * 1000000L + now.tv_usec;
for (at = 0; at < MaxSequence; at++) {
fd = sequence[at].socket;
}
}
if (fd > 0) {
- utime = sequence[at].time.tv_sec * 1000000L + sequence[at].time.tv_usec;
- if (unow - utime > tcp_timeout) {
+ struct timeval subtract;
+ timersub(&now, &sequence[at].time, &subtract);
+ if ((subtract.tv_sec * 1000000L + subtract.tv_usec) > tcp_timeout) {
close(fd);
sequence[at].socket = 0;
}