pandora-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pandora] what's the diference between <Packet> and <Packet>+


From: Simon Patarin
Subject: Re: [Pandora] what's the diference between <Packet> and <Packet>+
Date: Fri, 6 Dec 2002 16:01:22 +0100 (MET)

Hi,

> for instance, the tcpprint component uses TCPPacket+ instead of the 
> "usual" TCPPacket
> 
>   component_export(TCPPrintComponent, TCPPacket+,);

As you may have notice, the TCPPacket (with or without a +) here denotes
the acceptable packet input types for the component. Without a '+' it
means that TCPPacket must be given to the component (since the parameter
is usualy directly casted into that type). On the other hand, when there
is a '+', it means that the component may accept "higher-level" packet
types. This last point deserves an explanation: packets are often built
upon another packet. For example, usually, TCPPacket are built upon an
IPPacket. Instead of recopying the data from one packet to another,
pandora keeps the link from one packet to its originator. The source IP
address for example is located only in the IPPacket class, but you may
need to access it from the TCPPacket one. In this case you only need to
find the reference to the IP packet embedded in the TCP packet. You do
that with the locatePacket macro (in packet.h):

locatePacket(IPPacket, ipp, tcpp);

here IPPacket is the type of the target packet, ipp is a variable where to
put it and tcpp is the original packet variable (actually a pointer to
it). The macro declares itself the target variable (ipp), so you do not
need to do it before. After that, you have an "IPPacket *ipp" variable
that points to the eventual underlying IPPacket. If no such packet were
found ipp is NULL. There is a variation of locatePacket, named
locatePacket0 that catches the case where the original variable (tcpp in
the example) might be of the right type already. Thus if your component
declares its add method like this:

bool MyComponent::add(Packet *pkt)
{
  locatePacket0(TCPPacket, tcpp, pkt);
  if (tcpp == NULL) {
    cleanPacket(pkt);
    return false;
  }

  // now you can use tcpp as a TCPPacket * variable

  [...]
}

it accepts any packet type that "inherits" or that "build upon" a
TCPPacket. In this case you use the "TCPPacket+" to signify it. If you
know for sure that your component will always get plain TCPPacket's, then
you do not need such things.

Is it understandable (I'm not sure to be very clear about this)?

Simon






reply via email to

[Prev in Thread] Current Thread [Next in Thread]