Packet Class Reference

Inheritance diagram for Packet:

WritablePacket List of all members.

Detailed Description

A network packet.

Click's Packet class represents network packets within a router. Packet objects are passed from Element to Element via the Element::push() and Element::pull() functions. The vast majority of elements handle packets.

A packet consists of a data buffer, which stores the actual packet wire data, and a set of annotations, which store extra information calculated about the packet, such as the destination address to be used for routing. Every Packet object has different annotations, but a data buffer may be shared among multiple Packet objects, saving memory and speeding up packet copies. (See Packet::clone.) As a result a Packet's data buffer is not writable. To write into a packet, turn it into a nonshared WritablePacket first, using uniqueify(), push(), or put().

Data Buffer

A packet's data buffer is a single flat array of bytes. The buffer may be larger than the actual packet data, leaving unused spaces called headroom and tailroom before and after the data proper. Prepending headers or appending data to a packet can be quite efficient if there is enough headroom or tailroom.

The relationships among a Packet object's data buffer variables is shown here:

                     data()               end_data()
                        |                      |
       |<- headroom() ->|<----- length() ----->|<- tailroom() ->|
       |                v                      v                |
       +================+======================+================+
       |XXXXXXXXXXXXXXXX|   PACKET CONTENTS    |XXXXXXXXXXXXXXXX|
       +================+======================+================+
       ^                                                        ^
       |<------------------ buffer_length() ------------------->|
       |                                                        |
    buffer()                                               end_buffer()
 

Most code that manipulates packets is interested only in data() and length().

To create a Packet, call one of the make() functions. To destroy a Packet, call kill(). To clone a Packet, which creates a new Packet object that shares this packet's data, call clone(). To uniqueify a Packet, which unshares the packet data if necessary, call uniqueify(). To allocate extra space for headers or trailers, call push() and put(). To remove headers or trailers, call pull() and take().

                data()                          end_data()
                   |                                |
           push()  |  pull()                take()  |  put()
          <======= | =======>              <======= | =======>
                   v                                v                 
       +===========+================================+===========+
       |XXXXXXXXXXX|        PACKET CONTENTS         |XXXXXXXXXXX|
       +===========+================================+===========+
 

Packet objects are implemented in different ways in different drivers. The userlevel driver has its own C++ implementation. In the linuxmodule driver, however, Packet is an overlay on Linux's native sk_buff object: the Packet methods access underlying sk_buff data directly, with no overhead. (For example, Packet::data() returns the sk_buff's data field.)

Annotations

Annotations are extra information about a packet above and beyond the packet data. Packet supports several specific annotations, plus a user annotation area available for arbitrary use by elements.

New packets start wth all annotations set to zero or null. Cloning a packet copies its annotations.


Data

enum  { default_headroom = 28, min_buffer_length = 64 }
static WritablePacketmake (uint32_t headroom, const void *data, uint32_t length, uint32_t tailroom)
 Create and return a new packet.
static WritablePacketmake (const void *data, uint32_t length)
 Create and return a new packet.
static WritablePacketmake (uint32_t length)
 Create and return a new packet.
static Packetmake (struct sk_buff *skb)
 Change an sk_buff into a Packet (linuxmodule).
static WritablePacketmake (unsigned char *data, uint32_t length, void(*destructor)(unsigned char *, size_t))
 Create and return a new packet (userlevel).
void kill ()
 Delete this packet.
bool shared () const
 Test whether this packet's data is shared.
Packetclone ()
 Create a clone of this packet.
WritablePacketuniqueify ()
 Return an unshared packet containing this packet's data.
const unsigned char * data () const
 Return the packet's data pointer.
const unsigned char * end_data () const
 Return the packet's end data pointer.
uint32_t length () const
 Return the packet's length.
uint32_t headroom () const
 Return the packet's headroom.
uint32_t tailroom () const
 Return the packet's tailroom.
const unsigned char * buffer () const
 Return a pointer to the packet's data buffer.
const unsigned char * end_buffer () const
 Return the packet's end data buffer pointer.
uint32_t buffer_length () const
 Return the packet's buffer length.
sk_buff * skb ()
sk_buff * skb () const
WritablePacketpush (uint32_t len)
 Add space for a header before the packet.
WritablePacketpush_mac_header (uint32_t len)
 Add space for a MAC header before the packet.
Packetnonunique_push (uint32_t len)
 Add space for a header before the packet.
void pull (uint32_t len)
 Remove a header from the front of the packet.
WritablePacketput (uint32_t len)
 Add space for data after the packet.
Packetnonunique_put (uint32_t len)
 Add space for data after the packet.
void take (uint32_t len)
 Remove space from the end of the packet.
Packetshift_data (int offset, bool free_on_failure=true)
 Shift packet data within the data buffer.
void shrink_data (const unsigned char *data, uint32_t length)
 Shrink the packet's data.
void change_headroom_and_length (uint32_t headroom, uint32_t length)
 Shift the packet's data view to a different part of its buffer.

Annotations

enum  { anno_size = 48 }
enum  PacketType {
  HOST = 0, BROADCAST = 1, MULTICAST = 2, OTHERHOST = 3,
  OUTGOING = 4, LOOPBACK = 5, FASTROUTE = 6
}
 Values for packet_type_anno(). Must agree with Linux's PACKET_ constants in <linux/if_packet.h>. More...
enum  { dst_ip_anno_offset = 0, dst_ip_anno_size = 4, dst_ip6_anno_offset = 0, dst_ip6_anno_size = 16 }
const Timestamptimestamp_anno () const
 Return the timestamp annotation.
Timestamptimestamp_anno ()
void set_timestamp_anno (const Timestamp &t)
 Set the timestamp annotation.
net_device * device_anno () const
 Return the device annotation.
void set_device_anno (net_device *dev)
 Set the device annotation.
PacketType packet_type_anno () const
 Return the packet type annotation.
void set_packet_type_anno (PacketType t)
 Set the packet type annotation.
Packetnext () const
 Return the next packet annotation.
Packet *& next ()
void set_next (Packet *p)
 Set the next packet annotation.
Packetprev () const
 Return the previous packet annotation.
Packet *& prev ()
void set_prev (Packet *p)
 Set the previous packet annotation.
IPAddress dst_ip_anno () const
 Return the destination IPv4 address annotation.
void set_dst_ip_anno (IPAddress addr)
 Set the destination IPv4 address annotation.
void * anno ()
 Return a pointer to the annotation area.
const void * anno () const
uint8_t * anno_u8 ()
 Return a pointer to the annotation area as uint8_ts.
const uint8_t * anno_u8 () const
 overload
uint32_t * anno_u32 ()
 Return a pointer to the annotation area as uint32_ts.
const uint32_t * anno_u32 () const
 overload
uint8_t anno_u8 (int i) const
 Return annotation byte at offset i.
void set_anno_u8 (int i, uint8_t v)
 Set annotation byte at offset i.
uint16_t anno_u16 (int i) const
 Return 16-bit annotation at offset i.
void set_anno_u16 (int i, uint16_t v)
 Set 16-bit annotation at offset i.
int16_t anno_s16 (int i) const
 Return 16-bit annotation at offset i.
void set_anno_s16 (int i, int16_t v)
 Set 16-bit annotation at offset i.
uint32_t anno_u32 (int i) const
 Return 32-bit annotation at offset i.
void set_anno_u32 (int i, uint32_t v)
 Set 32-bit annotation at offset i.
int32_t anno_s32 (int i) const
 Return 32-bit annotation at offset i.
void set_anno_s32 (int i, int32_t v)
 Set 32-bit annotation at offset i.
uint64_t anno_u64 (int i) const
 Return 64-bit annotation at offset i.
void set_anno_u64 (int i, uint64_t v)
 Set 64-bit annotation at offset i.
void clear_annotations (bool all=true)
 Clear all packet annotations.
void copy_annotations (const Packet *)
 Copy most packet annotations from p.

Header Pointers

bool has_mac_header () const
 Return true iff the packet's MAC header pointer is set.
const unsigned char * mac_header () const
 Return the packet's MAC header pointer.
int mac_header_offset () const
 Return the offset from the packet data to the MAC header.
uint32_t mac_header_length () const
 Return the MAC header length.
int mac_length () const
 Return the packet's length starting from its MAC header pointer.
void set_mac_header (const unsigned char *p)
 Set the MAC header pointer.
void set_mac_header (const unsigned char *p, uint32_t len)
 Set the MAC and network header pointers.
void clear_mac_header ()
 Unset the MAC header pointer.
bool has_network_header () const
 Return true iff the packet's network header pointer is set.
const unsigned char * network_header () const
 Return the packet's network header pointer.
int network_header_offset () const
 Return the offset from the packet data to the network header.
uint32_t network_header_length () const
 Return the network header length.
int network_length () const
 Return the packet's length starting from its network header pointer.
void set_network_header (const unsigned char *p, uint32_t len)
 Set the network and transport header pointers.
void set_network_header_length (uint32_t len)
 Set the network header length.
void clear_network_header ()
 Unset the network header pointer.
bool has_transport_header () const
 Return true iff the packet's network header pointer is set.
const unsigned char * transport_header () const
 Return the packet's transport header pointer.
int transport_header_offset () const
 Return the offset from the packet data to the transport header.
int transport_length () const
 Return the packet's length starting from its transport header pointer.
void clear_transport_header ()
 Unset the transport header pointer.
const click_ether * ether_header () const
 Return the packet's MAC header pointer as Ethernet.
void set_ether_header (const click_ether *ethh)
 Set the MAC header pointer to an Ethernet header.
const click_ip * ip_header () const
 Return the packet's network header pointer as IPv4.
int ip_header_offset () const
 Return the offset from the packet data to the IP header.
uint32_t ip_header_length () const
 Return the IP header length.
void set_ip_header (const click_ip *iph, uint32_t len)
 Set the network header pointer to an IPv4 header.
const click_ip6 * ip6_header () const
 Return the packet's network header pointer as IPv6.
int ip6_header_offset () const
 Return the offset from the packet data to the IPv6 header.
uint32_t ip6_header_length () const
 Return the IPv6 header length.
void set_ip6_header (const click_ip6 *ip6h)
 Set the network header pointer to an IPv6 header.
void set_ip6_header (const click_ip6 *ip6h, uint32_t len)
 Set the network header pointer to an IPv6 header.
const click_icmp * icmp_header () const
 Return the packet's transport header pointer as ICMP.
const click_tcp * tcp_header () const
 Return the packet's transport header pointer as TCP.
const click_udp * udp_header () const
 Return the packet's transport header pointer as UDP.


Member Enumeration Documentation

anonymous enum

Enumerator:
default_headroom  Default packet headroom() for Packet::make(). 4-byte aligned.
min_buffer_length  Minimum buffer_length() for Packet::make()

anonymous enum

Enumerator:
anno_size  Size of annotation area.

enum Packet::PacketType

Values for packet_type_anno(). Must agree with Linux's PACKET_ constants in <linux/if_packet.h>.

Enumerator:
HOST  Packet was sent to this host.
BROADCAST  Packet was sent to a link-level multicast address.
MULTICAST  Packet was sent to a link-level multicast address.
OTHERHOST  Packet was sent to a different host, but received anyway. The receiving device is probably in promiscuous mode.
OUTGOING  Packet was generated by this host and is being sent elsewhere.


Member Function Documentation

WritablePacket * Packet::make ( uint32_t  headroom,
const void *  data,
uint32_t  length,
uint32_t  tailroom 
) [static]

Create and return a new packet.

Parameters:
headroom headroom in new packet
data data to be copied into the new packet
length length of packet
tailroom tailroom in new packet
Returns:
new packet, or null if no packet could be created
The data is copied into the new packet. If data is null, the packet's data is left uninitialized. The resulting packet's buffer_length() will be at least min_buffer_length ; if headroom + length + tailroom would be less, then tailroom is increased to make the total min_buffer_length .

The new packet's annotations are cleared and its header pointers are null.

WritablePacket * Packet::make ( const void *  data,
uint32_t  length 
) [inline, static]

Create and return a new packet.

Parameters:
data data to be copied into the new packet
length length of packet
Returns:
new packet, or null if no packet could be created
The data is copied into the new packet. If data is null, the packet's data is left uninitialized. The new packet's headroom equals default_headroom , its tailroom is 0.

The returned packet's annotations are cleared and its header pointers are null.

WritablePacket * Packet::make ( uint32_t  length  )  [inline, static]

Create and return a new packet.

Parameters:
length length of packet
Returns:
new packet, or null if no packet could be created
The packet's data is left uninitialized. The new packet's headroom equals default_headroom , its tailroom is 0.

The returned packet's annotations are cleared and its header pointers are null.

Packet * Packet::make ( struct sk_buff *  skb  )  [inline, static]

Change an sk_buff into a Packet (linuxmodule).

Parameters:
skb input sk_buff
Returns:
the packet
In the Linux kernel module, Packet objects are sk_buff objects. This function simply changes an sk_buff into a Packet by claiming its skb argument. If skb->users is 1, then skb is orphaned by skb_orphan(skb) and returned. If it is larger than 1, then skb is cloned and the clone is returned. (sk_buffs used for Click Packet objects must have skb->users == 1.) Null might be returned if there's no memory for the clone.

The returned packet's annotations and header pointers are not cleared: they have the same values they did in the sk_buff. If the packet came from Linux, then the header pointers and shared annotations (timestamp, packet type, next/prev packet) might have valid values, but the Click annotations (address, user) likely do not. Use clear_annotations() to clear them.

WritablePacket * Packet::make ( unsigned char *  data,
uint32_t  length,
void(*)(unsigned char *, size_t)  destructor 
) [static]

Create and return a new packet (userlevel).

Parameters:
data data used in the new packet
length length of packet
destructor destructor function
Returns:
new packet, or null if no packet could be created
The packet's data pointer becomes the data: the data is not copied into the new packet, rather the packet owns the data pointer. When the packet's data is eventually destroyed, either because the packet is deleted or because of something like a push() or full(), the destructor will be called with arguments destructor(data, length). (If destructor is null, the packet data will be freed by delete[] data.) The packet has zero headroom and tailroom.

The returned packet's annotations are cleared and its header pointers are null.

void Packet::kill (  )  [inline]

Delete this packet.

The packet header (including annotations) is destroyed and its memory returned to the system. The packet's data is also freed if this is the last clone.

bool Packet::shared (  )  const [inline]

Test whether this packet's data is shared.

Returns true iff the packet's data is shared. If shared() is false, then the result of uniqueify() will equal this.

Packet * Packet::clone (  ) 

Create a clone of this packet.

Returns:
the cloned packet
The returned clone has independent annotations, initially copied from this packet, but shares this packet's data. shared() returns true for both the packet and its clone. Returns null if there's no memory for the clone.

WritablePacket * Packet::uniqueify (  )  [inline]

Return an unshared packet containing this packet's data.

Returns:
the unshared packet, which is writable
The returned packet's data is unshared with any other packet, so it's safe to write the data. If shared() is false, this operation simply returns the input packet. If shared() is true, uniqueify() makes a copy of the data. The input packet is freed if the copy fails.

The returned WritablePacket pointer may not equal the input Packet pointer, so do not use the input pointer after the uniqueify() call.

The input packet's headroom and tailroom areas are copied in addition to its true contents. The header annotations are shifted to point into the new packet data if necessary.

uniqueify() is usually used like this:

 WritablePacket *q = p->uniqueify();
 if (!q)
     return 0;
 // p must not be used here.

const unsigned char * Packet::data (  )  const [inline]

Return the packet's data pointer.

This is the pointer to the first byte of packet data.

Reimplemented in WritablePacket.

const unsigned char * Packet::end_data (  )  const [inline]

Return the packet's end data pointer.

The result points at the byte following the packet data.

Invariant:
end_data() == data() + length()

Reimplemented in WritablePacket.

uint32_t Packet::length (  )  const [inline]

Return the packet's length.

uint32_t Packet::headroom (  )  const [inline]

Return the packet's headroom.

The headroom is the amount of space available in the current packet buffer before data(). A push() operation is cheap if the packet's unshared and the length pushed is less than headroom().

uint32_t Packet::tailroom (  )  const [inline]

Return the packet's tailroom.

The tailroom is the amount of space available in the current packet buffer following end_data(). A put() operation is cheap if the packet's unshared and the length put is less than tailroom().

const unsigned char * Packet::buffer (  )  const [inline]

Return a pointer to the packet's data buffer.

The result points at the packet's headroom, not its data.

Invariant:
buffer() == data() - headroom()

Reimplemented in WritablePacket.

const unsigned char * Packet::end_buffer (  )  const [inline]

Return the packet's end data buffer pointer.

The result points past the packet's tailroom.

Invariant:
end_buffer() == end_data() + tailroom()

Reimplemented in WritablePacket.

uint32_t Packet::buffer_length (  )  const [inline]

Return the packet's buffer length.

Invariant:
buffer_length() == headroom() + length() + tailroom()

buffer() + buffer_length() == end_buffer()

WritablePacket * Packet::push ( uint32_t  len  )  [inline]

Add space for a header before the packet.

Parameters:
len amount of space to add
Returns:
packet with added header space, or null on failure
Returns a packet with an additional len bytes of uninitialized space before the current packet's data(). A copy of the packet data is made if there isn't enough headroom() in the current packet, or if the current packet is shared(). If no copy is made, this operation is quite efficient.

If a data copy would be required, but the copy fails because of lack of memory, then the current packet is freed.

push() is usually used like this:

 WritablePacket *q = p->push(14);
 if (!q)
     return 0;
 // p must not be used here.

Postcondition:
new length() == old length() + len (if no failure)
See also:
nonunique_push, push_mac_header, pull

WritablePacket * Packet::push_mac_header ( uint32_t  len  )  [inline]

Add space for a MAC header before the packet.

Parameters:
len amount of space to add and length of MAC header
Returns:
packet with added header space, or null on failure
Combines the action of push() and set_mac_header(). len bytes are pushed for a MAC header, and on success, the packet's returned MAC and network header pointers are set as by set_mac_header(data(), len).

See also:
push

Packet * Packet::nonunique_push ( uint32_t  len  )  [inline]

Add space for a header before the packet.

Parameters:
len amount of space to add
Returns:
packet with added header space, or null on failure
This is a variant of push(). Returns a packet with an additional len bytes of uninitialized space before the current packet's data(). A copy of the packet data is made if there isn't enough headroom() in the current packet. However, no copy is made if the current packet is shared; and if no copy is made, this operation is quite efficient.

If a data copy would be required, but the copy fails because of lack of memory, then the current packet is freed.

Note:
Unlike push(), nonunique_push() returns a Packet object, which has non-writable data.
See also:
push

void Packet::pull ( uint32_t  len  )  [inline]

Remove a header from the front of the packet.

Parameters:
len amount of space to remove
Removes len bytes from the initial part of the packet, usually corresponding to some network header (for example, pull(14) removes an Ethernet header). This operation is efficient: it just bumps a pointer.

It is an error to attempt to pull more than length() bytes.

Postcondition:
new data() == old data() + len

new length() == old length() - len

See also:
push

WritablePacket * Packet::put ( uint32_t  len  )  [inline]

Add space for data after the packet.

Parameters:
len amount of space to add
Returns:
packet with added trailer space, or null on failure
Returns a packet with an additional len bytes of uninitialized space after the current packet's data (starting at end_data()). A copy of the packet data is made if there isn't enough tailroom() in the current packet, or if the current packet is shared(). If no copy is made, this operation is quite efficient.

If a data copy would be required, but the copy fails because of lack of memory, then the current packet is freed.

put() is usually used like this:

 WritablePacket *q = p->put(100);
 if (!q)
     return 0;
 // p must not be used here.

Postcondition:
new length() == old length() + len (if no failure)
See also:
nonunique_put, take

Packet * Packet::nonunique_put ( uint32_t  len  )  [inline]

Add space for data after the packet.

Parameters:
len amount of space to add
Returns:
packet with added trailer space, or null on failure
This is a variant of put(). Returns a packet with an additional len bytes of uninitialized space after the current packet's data (starting at end_data()). A copy of the packet data is made if there isn't enough tailroom() in the current packet. However, no copy is made if the current packet is shared; and if no copy is made, this operation is quite efficient.

If a data copy would be required, but the copy fails because of lack of memory, then the current packet is freed.

See also:
put

void Packet::take ( uint32_t  len  )  [inline]

Remove space from the end of the packet.

Parameters:
len amount of space to remove
Removes len bytes from the end of the packet. This operation is efficient: it just bumps a pointer.

It is an error to attempt to pull more than length() bytes.

Postcondition:
new data() == old data()

new end_data() == old end_data() - len

new length() == old length() - len

See also:
push

Packet * Packet::shift_data ( int  offset,
bool  free_on_failure = true 
)

Shift packet data within the data buffer.

Parameters:
offset amount to shift packet data
free_on_failure if true, then delete the input packet on failure
Returns:
a packet with shifted data, or null on failure
Useful to align packet data. For example, if the packet's embedded IP header is located at pointer value 0x8CCA03, then shift_data(1) or shift_data(-3) will both align the header on a 4-byte boundary.

If the packet is shared() or there isn't enough headroom or tailroom for the operation, the packet is passed to uniqueify() first. This can fail if there isn't enough memory. If it fails, shift_data returns null, and if free_on_failure is true (the default), the input packet is freed.

The packet's mac_header, network_header, and transport_header areas are preserved, even if they lie within the headroom. Any headroom outside these regions may be overwritten, as may any tailroom.

Postcondition:
new data() == old data() + offset (if no copy is made)

new buffer() == old buffer() (if no copy is made)

void Packet::shrink_data ( const unsigned char *  data,
uint32_t  length 
) [inline]

Shrink the packet's data.

Parameters:
data new data pointer
length new length
Warning:
This function is useful only in special contexts.
Note:
Only available at user level
User-level programs that read packet logs commonly read a large chunk of data (32 kB or more) into a base Packet object. The log reader then works over the data buffer and, for each packet contained therein, outputs a clone that shares memory with the base packet. This is space- and time-efficient, but the generated packets have gigantic headroom and tailroom. Uniqueifying a generated packet will wastefully copy this headroom and tailroom as well. The shrink_data function addresses this problem.

shrink_data() removes all of a packet's headroom and tailroom. The resulting packet has data() equal to data, length() equal to length, and headroom() and tailroom() equal to zero.

Precondition:
The packet must be a clone() of another existing packet.

data >= data(), data <= end_data(), data + length >= data(), and data + length <= end_data()

See also:
change_headroom_and_length

void Packet::change_headroom_and_length ( uint32_t  headroom,
uint32_t  length 
) [inline]

Shift the packet's data view to a different part of its buffer.

Parameters:
headroom new headroom
length new length
Warning:
This function is useful only in special contexts.
Note:
Only available at user level
Shifts the packet's data() pointer to a different part of the packet's data buffer. The buffer pointer itself is not changed, and the packet's contents are not affected (except by the new view).

Precondition:
headroom + length <= buffer_length()
Postcondition:
new buffer() == old buffer()

new end_buffer() == old end_buffer()

new headroom() == headroom

new length() == length

See also:
shrink_data

bool Packet::has_mac_header (  )  const [inline]

Return true iff the packet's MAC header pointer is set.

See also:
set_mac_header, clear_mac_header

const unsigned char * Packet::mac_header (  )  const [inline]

Return the packet's MAC header pointer.

Warning:
Not useful if !has_mac_header().
See also:
ether_header, set_mac_header, clear_mac_header, mac_header_length, mac_length

Reimplemented in WritablePacket.

int Packet::mac_header_offset (  )  const [inline]

Return the offset from the packet data to the MAC header.

Returns:
mac_header() - data()
Warning:
Not useful if !has_mac_header().

uint32_t Packet::mac_header_length (  )  const [inline]

Return the MAC header length.

Returns:
network_header() - mac_header()
This equals the offset from the MAC header pointer to the network header pointer.
Warning:
Not useful if !has_mac_header() or !has_network_header().

int Packet::mac_length (  )  const [inline]

Return the packet's length starting from its MAC header pointer.

Invariant:
mac_length() == end_data() - mac_header()
Warning:
Not useful if !has_mac_header().

void Packet::set_mac_header ( const unsigned char *  p  )  [inline]

Set the MAC header pointer.

Parameters:
p new header pointer

void Packet::set_mac_header ( const unsigned char *  p,
uint32_t  len 
) [inline]

Set the MAC and network header pointers.

Parameters:
p new MAC header pointer
len new MAC header length
Postcondition:
mac_header() == p and network_header() == p + len

void Packet::clear_mac_header (  )  [inline]

Unset the MAC header pointer.

Postcondition:
has_mac_header() == false Does not affect the network or transport header pointers.

bool Packet::has_network_header (  )  const [inline]

Return true iff the packet's network header pointer is set.

See also:
set_network_header, clear_network_header

const unsigned char * Packet::network_header (  )  const [inline]

Return the packet's network header pointer.

Warning:
Not useful if !has_network_header().
See also:
ip_header, ip6_header, set_network_header, clear_network_header, network_header_length, network_length

Reimplemented in WritablePacket.

int Packet::network_header_offset (  )  const [inline]

Return the offset from the packet data to the network header.

Returns:
network_header() - data()
Warning:
Not useful if !has_network_header().

uint32_t Packet::network_header_length (  )  const [inline]

Return the network header length.

Returns:
transport_header() - network_header()
This equals the offset from the network header pointer to the transport header pointer.
Warning:
Not useful if !has_network_header() or !has_transport_header().

int Packet::network_length (  )  const [inline]

Return the packet's length starting from its network header pointer.

Invariant:
network_length() == end_data() - network_header()
Warning:
Not useful if !has_network_header().

void Packet::set_network_header ( const unsigned char *  p,
uint32_t  len 
) [inline]

Set the network and transport header pointers.

Parameters:
p new network header pointer
len new network header length
Postcondition:
network_header() == p and transport_header() == p + len

void Packet::set_network_header_length ( uint32_t  len  )  [inline]

Set the network header length.

Parameters:
len new network header length
Setting the network header length really just sets the transport header pointer.
Postcondition:
transport_header() == network_header() + len

void Packet::clear_network_header (  )  [inline]

Unset the network header pointer.

Postcondition:
has_network_header() == false Does not affect the MAC or transport header pointers.

bool Packet::has_transport_header (  )  const [inline]

Return true iff the packet's network header pointer is set.

See also:
set_network_header, clear_transport_header

const unsigned char * Packet::transport_header (  )  const [inline]

Return the packet's transport header pointer.

Warning:
Not useful if !has_transport_header().
See also:
tcp_header, udp_header, icmp_header, set_transport_header, clear_transport_header, transport_length

Reimplemented in WritablePacket.

int Packet::transport_header_offset (  )  const [inline]

Return the offset from the packet data to the transport header.

Returns:
transport_header() - data()
Warning:
Not useful if !has_transport_header().

int Packet::transport_length (  )  const [inline]

Return the packet's length starting from its transport header pointer.

Invariant:
transport_length() == end_data() - transport_header()
Warning:
Not useful if !has_transport_header().

void Packet::clear_transport_header (  )  [inline]

Unset the transport header pointer.

Postcondition:
has_transport_header() == false Does not affect the MAC or network header pointers.

const click_ether * Packet::ether_header (  )