tcp packets and the < operator

C

Chris

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
 
V

Victor Bazarov

Chris said:
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
 
H

Howard

Chris said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top