mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +00:00
Make result of IP::ParsePacket easier to understand
This commit is contained in:
parent
40b1452905
commit
aa79356963
6 changed files with 56 additions and 39 deletions
|
@ -283,38 +283,38 @@ bool IPAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* packet)
|
|||
return return_val;
|
||||
}
|
||||
|
||||
int zeek::packet_analysis::IP::ParsePacket(int caplen, const u_char* const pkt, int proto,
|
||||
std::shared_ptr<zeek::IP_Hdr>& inner)
|
||||
ParseResult zeek::packet_analysis::IP::ParsePacket(int caplen, const u_char* const pkt, int proto,
|
||||
std::shared_ptr<zeek::IP_Hdr>& inner)
|
||||
{
|
||||
if ( proto == IPPROTO_IPV6 )
|
||||
{
|
||||
if ( caplen < (int)sizeof(struct ip6_hdr) )
|
||||
return -1;
|
||||
return ParseResult::CaplenTooSmall;
|
||||
|
||||
const struct ip6_hdr* ip6 = (const struct ip6_hdr*)pkt;
|
||||
inner = std::make_shared<zeek::IP_Hdr>(ip6, false, caplen);
|
||||
if ( (ip6->ip6_ctlun.ip6_un2_vfc & 0xF0) != 0x60 )
|
||||
return -2;
|
||||
return ParseResult::BadProtocol;
|
||||
}
|
||||
|
||||
else if ( proto == IPPROTO_IPV4 )
|
||||
{
|
||||
if ( caplen < (int)sizeof(struct ip) )
|
||||
return -1;
|
||||
return ParseResult::BadProtocol;
|
||||
|
||||
const struct ip* ip4 = (const struct ip*)pkt;
|
||||
inner = std::make_shared<zeek::IP_Hdr>(ip4, false);
|
||||
if ( ip4->ip_v != 4 )
|
||||
return -2;
|
||||
return ParseResult::BadProtocol;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return -2;
|
||||
return ParseResult::BadProtocol;
|
||||
}
|
||||
|
||||
if ( (uint32_t)caplen != inner->TotalLen() )
|
||||
return (uint32_t)caplen < inner->TotalLen() ? -1 : 1;
|
||||
return (uint32_t)caplen < inner->TotalLen() ? ParseResult::CaplenTooSmall
|
||||
: ParseResult::CaplenTooLarge;
|
||||
|
||||
return 0;
|
||||
return ParseResult::Ok;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue