[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] TCP_SEQ_BETWEEN
From: |
K.J. Mansley |
Subject: |
Re: [lwip-users] TCP_SEQ_BETWEEN |
Date: |
14 Oct 2004 13:42:14 +0100 |
On Thu, 2004-10-14 at 13:29, Leon Woestenberg wrote:
> However, the current macro TCP_SEQ_BETWEEN
>
> (c-b>=a-b) merely checks that (c>=a)
>
> Was this an intentional simplification?
No.
However, it's the same macro as used in the linux kernel to compare
sequence numbers:
(from include/net/tcp.h)
/*
* The next routines deal with comparing 32 bit unsigned ints
* and worry about wraparound (automatic with unsigned arithmetic).
*/
extern __inline int before(__u32 seq1, __u32 seq2)
{
return (__s32)(seq1-seq2) < 0;
}
extern __inline int after(__u32 seq1, __u32 seq2)
{
return (__s32)(seq2-seq1) < 0;
}
/* is s2<=s1<=s3 ? */
extern __inline int between(__u32 seq1, __u32 seq2, __u32 seq3)
{
return seq3 - seq2 >= seq1 - seq2;
}
Maybe there's something we're missing? e.g. As we're comparing
*unsigned* integers, if b > a, then (a-b) will be very large (I think),
and so cause the test to fail (as it should). Unless of course b is
also greater than c, in which case it might not (as (c-b) will also be
very large). However, if we require b < c for this macro to be valid, I
think it might work, but don't have enough time to convince myself of
this 100%.
I think we're best to stick with the slightly less efficient version,
(the change you outline above) as it's more obviously correct, unless
anyone can explain why the ((c)-(b) >= (a)-(b)) should definitely work!
Kieran