/src/PcapPlusPlus/Packet++/src/IPLayer.cpp
Line | Count | Source |
1 | | #include "IPLayer.h" |
2 | | |
3 | | namespace pcpp |
4 | | { |
5 | | ProtocolType IPLayer::getIPVersion(uint8_t const* data, size_t dataLen) |
6 | 2.07k | { |
7 | | // The data requires at least 1 byte of valid buffer |
8 | 2.07k | if (data == nullptr || dataLen < 1) |
9 | 0 | { |
10 | 0 | return UnknownProtocol; |
11 | 0 | } |
12 | | |
13 | | // The first 4 bits of the first byte of the IP header represent the IP version |
14 | 2.07k | uint8_t version = data[0] >> 4; |
15 | | |
16 | 2.07k | switch (version) |
17 | 2.07k | { |
18 | 1.78k | case 4: |
19 | 1.78k | return IPv4; |
20 | 77 | case 6: |
21 | 77 | return IPv6; |
22 | 215 | default: |
23 | 215 | return UnknownProtocol; |
24 | 2.07k | } |
25 | 2.07k | } |
26 | | } // namespace pcpp |