mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +00:00
Add a few comments to IP.h
This commit is contained in:
parent
65307764f4
commit
76ef36e048
1 changed files with 42 additions and 1 deletions
43
src/IP.h
43
src/IP.h
|
@ -260,6 +260,10 @@ public:
|
||||||
IPAddr DstAddr() const
|
IPAddr DstAddr() const
|
||||||
{ return ip4 ? IPAddr(ip4->ip_dst) : IPAddr(ip6->ip6_dst); }
|
{ return ip4 ? IPAddr(ip4->ip_dst) : IPAddr(ip6->ip6_dst); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pointer to the payload of the IP packet, usually an
|
||||||
|
* upper-layer protocol.
|
||||||
|
*/
|
||||||
const u_char* Payload() const
|
const u_char* Payload() const
|
||||||
{
|
{
|
||||||
if ( ip4 )
|
if ( ip4 )
|
||||||
|
@ -268,6 +272,10 @@ public:
|
||||||
return ((const u_char*) ip6) + ip6_hdrs->TotalLength();
|
return ((const u_char*) ip6) + ip6_hdrs->TotalLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the length of the IP packet's payload (length of packet minus
|
||||||
|
* header length or, for IPv6, also minus length of all extension headers).
|
||||||
|
*/
|
||||||
uint16 PayloadLen() const
|
uint16 PayloadLen() const
|
||||||
{
|
{
|
||||||
if ( ip4 )
|
if ( ip4 )
|
||||||
|
@ -276,16 +284,30 @@ public:
|
||||||
return ntohs(ip6->ip6_plen) + 40 - ip6_hdrs->TotalLength();
|
return ntohs(ip6->ip6_plen) + 40 - ip6_hdrs->TotalLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the length of the IP packet (length of headers and payload).
|
||||||
|
*/
|
||||||
uint32 TotalLen() const
|
uint32 TotalLen() const
|
||||||
{ return ip4 ? ntohs(ip4->ip_len) : ntohs(ip6->ip6_plen) + 40; }
|
{ return ip4 ? ntohs(ip4->ip_len) : ntohs(ip6->ip6_plen) + 40; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns length of IP packet header (includes extension headers for IPv6).
|
||||||
|
*/
|
||||||
uint16 HdrLen() const
|
uint16 HdrLen() const
|
||||||
{ return ip4 ? ip4->ip_hl * 4 : ip6_hdrs->TotalLength(); }
|
{ return ip4 ? ip4->ip_hl * 4 : ip6_hdrs->TotalLength(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For IPv6 header chains, returns the type of the last header in the chain.
|
||||||
|
*/
|
||||||
uint8 LastHeader() const
|
uint8 LastHeader() const
|
||||||
{ return ip4 ? IPPROTO_RAW :
|
{ return ip4 ? IPPROTO_RAW :
|
||||||
((*ip6_hdrs)[ip6_hdrs->Size()-1])->Type(); }
|
((*ip6_hdrs)[ip6_hdrs->Size()-1])->Type(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the protocol type of the IP packet's payload, usually an
|
||||||
|
* upper-layer protocol. For IPv6, this returns the last (extension)
|
||||||
|
* header's Next Header value.
|
||||||
|
*/
|
||||||
unsigned char NextProto() const
|
unsigned char NextProto() const
|
||||||
{ return ip4 ? ip4->ip_p :
|
{ return ip4 ? ip4->ip_p :
|
||||||
((*ip6_hdrs)[ip6_hdrs->Size()-1])->NextHdr(); }
|
((*ip6_hdrs)[ip6_hdrs->Size()-1])->NextHdr(); }
|
||||||
|
@ -297,23 +319,42 @@ public:
|
||||||
{ return ip4 ? (ntohs(ip4->ip_off) & 0x3fff) != 0 :
|
{ return ip4 ? (ntohs(ip4->ip_off) & 0x3fff) != 0 :
|
||||||
ip6_hdrs->IsFragment(); }
|
ip6_hdrs->IsFragment(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the fragment packet's offset in relation to the original
|
||||||
|
* packet in bytes.
|
||||||
|
*/
|
||||||
uint16 FragOffset() const
|
uint16 FragOffset() const
|
||||||
{ return ip4 ? (ntohs(ip4->ip_off) & 0x1fff) * 8 :
|
{ return ip4 ? (ntohs(ip4->ip_off) & 0x1fff) * 8 :
|
||||||
ip6_hdrs->FragOffset(); }
|
ip6_hdrs->FragOffset(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the fragment packet's identification field.
|
||||||
|
*/
|
||||||
uint32 ID() const
|
uint32 ID() const
|
||||||
{ return ip4 ? ntohs(ip4->ip_id) : ip6_hdrs->ID(); }
|
{ return ip4 ? ntohs(ip4->ip_id) : ip6_hdrs->ID(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether a fragment packet's "More Fragments" field is set.
|
||||||
|
*/
|
||||||
int MF() const
|
int MF() const
|
||||||
{ return ip4 ? (ntohs(ip4->ip_off) & 0x2000) != 0 : ip6_hdrs->MF(); }
|
{ return ip4 ? (ntohs(ip4->ip_off) & 0x2000) != 0 : ip6_hdrs->MF(); }
|
||||||
|
|
||||||
// IPv6 has no "Don't Fragment" flag.
|
/**
|
||||||
|
* Returns whether a fragment packet's "Don't Fragment" field is set.
|
||||||
|
* Note that IPv6 has no such field.
|
||||||
|
*/
|
||||||
int DF() const
|
int DF() const
|
||||||
{ return ip4 ? ((ntohs(ip4->ip_off) & 0x4000) != 0) : 0; }
|
{ return ip4 ? ((ntohs(ip4->ip_off) & 0x4000) != 0) : 0; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns number of IP headers in packet (includes IPv6 extension headers).
|
||||||
|
*/
|
||||||
size_t NumHeaders() const
|
size_t NumHeaders() const
|
||||||
{ return ip4 ? 1 : ip6_hdrs->Size(); }
|
{ return ip4 ? 1 : ip6_hdrs->Size(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an ip_hdr or ip6_hdr_chain RecordVal.
|
||||||
|
*/
|
||||||
RecordVal* BuildRecordVal() const;
|
RecordVal* BuildRecordVal() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue