By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,614 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

tcp packets and the < operator

P: n/a
Hi,

I am trying to group packets by their TCP connection, this is more of
a logic question so I hope this is the relevant group. In a tcp
connection A-B, I would like to put a packet in a container for A->B
or B->A (depending on the source and destination).

To do this I overloaded the < operator below.

if (one.src_addr < two.src_addr)
if (one.dst_addr < two.dst_addr)
if (one.src_port < two.src_port)
if (one.dst_port < two.dst_port)
return true;
/*else*/
return false;

However a packet going from b->a will be put in the same container as
a packet going from a->b. Why is this?

Thanks for any help
Chris
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Chris" <cs******@exeter.ac.uk> wrote in message
news:18**************************@posting.google.c om...
Hi,

I am trying to group packets by their TCP connection, this is more of
a logic question so I hope this is the relevant group. In a tcp
connection A-B, I would like to put a packet in a container for A->B
or B->A (depending on the source and destination).
Packets and tcp are not topical, but questions about code like this are.
See below...

To do this I overloaded the < operator below.

if (one.src_addr < two.src_addr)
if (one.dst_addr < two.dst_addr)
if (one.src_port < two.src_port)
if (one.dst_port < two.dst_port)
return true;
/*else*/
return false;

However a packet going from b->a will be put in the same container as
a packet going from a->b. Why is this?


We can't tell from this little code snippet. We don't even know what one
and two are, nor the types of their members, nor in what context this code
is called or how it relates to the container you mention. Your question
appears to have little to do with the tcp connetion or packets, but rather
with the logic of those nested if statements, right? So I'm guessing that
you're getting false back when you should get true (or vise-versa)? Well,
to see what's going on, we simply need more of the code that's causing a
problem, and the class declaration for those variables.

But here's a simplification of what I think you're trying to write above:

return ((one.src_addr < two.src_addr) &&
(one.dest_addr < two.dest_addr) &&
(one.src_port < two.src_port) &&
(one.dst_port < two.dst_port));

But is that how you really want to tell which direction this "packet" is
going to go? Seems odd to me that if any one of those members of two are
equal or greater than the matching member in one, that that's enough to tell
you anything important. But like I said, I can't tell with what you've
given so far.

-Howard


Jul 22 '05 #2

P: n/a
Chris wrote:
I am trying to group packets by their TCP connection, this is more of
a logic question so I hope this is the relevant group. In a tcp
connection A-B, I would like to put a packet in a container for A->B
or B->A (depending on the source and destination).

To do this I overloaded the < operator below.

if (one.src_addr < two.src_addr)
if (one.dst_addr < two.dst_addr)
if (one.src_port < two.src_port)
if (one.dst_port < two.dst_port)
return true;
/*else*/
return false;

However a packet going from b->a will be put in the same container as
a packet going from a->b. Why is this?


According to your code, the logic is too strict, IMO. You need to check
the dst_addr (and other members) only if 'src_addr' are _the_same_. The
correct logic, I believe, should be

if (one.src_addr < two.src_addr)
return true;
else if (one.src_addr > two.src_addr)
return false;
else
{
// check other fields the same way
}

Victor
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.