1 #ifndef PACKETPP_IPV4_LAYER 2 #define PACKETPP_IPV4_LAYER 11 #ifndef PCPP_DEPRECATED 12 #if defined(__GNUC__) || defined(__clang__) 13 #define PCPP_DEPRECATED __attribute__((deprecated)) 14 #elif defined(_MSC_VER) 15 #define PCPP_DEPRECATED __declspec(deprecated) 17 #pragma message("WARNING: DEPRECATED feature is not implemented for this compiler") 18 #define PCPP_DEPRECATED 38 #if (BYTE_ORDER == LITTLE_ENDIAN) 170 #define PCPP_IP_DONT_FRAGMENT 0x40 171 #define PCPP_IP_MORE_FRAGMENTS 0x20 189 TimestampsForPrespecifiedIPs = 2,
246 std::vector<IPv4Address> res;
251 size_t dataSize = getDataSize();
255 uint8_t valueOffset = (uint8_t)(1);
257 while ((
size_t)valueOffset < dataSize)
260 memcpy(&curValue, m_Data->recordValue + valueOffset,
sizeof(uint32_t));
266 valueOffset += (uint8_t)(4);
290 size_t dataSize = getDataSize();
296 uint8_t valueOffset = (uint8_t)(2);
299 while ((
size_t)valueOffset < dataSize)
302 memcpy(&curValue, m_Data->recordValue + valueOffset,
sizeof(uint32_t));
312 readIPAddr = !readIPAddr;
314 valueOffset += (uint8_t)(4);
340 return sizeof(uint8_t);
342 return (
size_t)m_Data->recordLen;
353 return (
size_t)m_Data->recordLen - (2*
sizeof(uint8_t));
366 bool m_BuilderParamsValid;
380 TLVRecordBuilder((uint8_t)optionType, optionValue, optionValueLen) { m_BuilderParamsValid =
true; }
389 TLVRecordBuilder((uint8_t)optionType, optionValue) { m_BuilderParamsValid =
true; }
441 IPv4Layer(uint8_t* data,
size_t dataLen,
Layer* prevLayer,
Packet* packet,
bool setTotalLenAsDataLen);
482 PCPP_DEPRECATED
IPv4Address getSrcIpAddress()
const {
return getSrcIPv4Address(); }
506 PCPP_DEPRECATED
IPv4Address getDstIpAddress()
const {
return getDstIPv4Address(); }
523 bool isFragment()
const;
529 bool isFirstFragment()
const;
535 bool isLastFragment()
const;
540 uint8_t getFragmentFlags()
const;
545 uint16_t getFragmentOffset()
const;
573 size_t getOptionCount()
const;
607 bool removeAllOptions();
626 void parseNextLayer();
631 size_t getHeaderLen()
const {
return (
size_t)((uint16_t)(getIPv4Header()->internetHeaderLength) * 4) + m_TempHeaderExtension; }
640 void computeCalculateFields();
642 std::string toString()
const;
652 static inline bool isDataValid(
const uint8_t* data,
size_t dataLen);
655 int m_NumOfTrailingBytes;
656 int m_TempHeaderExtension;
659 void copyLayerData(
const IPv4Layer& other);
660 uint8_t* getOptionsBasePtr()
const {
return m_Data +
sizeof(
iphdr); }
662 void adjustOptionsTrailer(
size_t totalOptSize);
664 void initLayerInPacket(uint8_t* data,
size_t dataLen,
Layer* prevLayer,
Packet* packet,
bool setTotalLenAsDataLen);
672 const iphdr* hdr =
reinterpret_cast<const iphdr*
>(data);
Definition: IPv4Layer.h:115
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:258
size_t getTotalSize() const
Definition: IPv4Layer.h:334
Definition: IPv4Layer.h:111
std::vector< uint32_t > timestamps
Definition: IPv4Layer.h:198
Definition: IPv4Layer.h:143
uint16_t ipId
Definition: IPv4Layer.h:54
Definition: IPv4Layer.h:139
Definition: IPv4Layer.h:145
IPv4Option(uint8_t *optionRawData)
Definition: IPv4Layer.h:231
uint8_t timeToLive
Definition: IPv4Layer.h:58
uint8_t internetHeaderLength
Definition: IPv4Layer.h:40
Definition: IPv4Layer.h:83
uint8_t typeOfService
Definition: IPv4Layer.h:50
Definition: IPv4Layer.h:129
Definition: IPv4Layer.h:109
Definition: IPv4Layer.h:151
Definition: TLVData.h:363
Definition: IPv4Layer.h:161
Definition: IPv4Layer.h:153
Definition: IPv4Layer.h:165
IPAddress getDstIPAddress() const
Definition: IPv4Layer.h:501
Definition: IPv4Layer.h:137
IPv4OptionTypes getIPv4OptionType() const
Definition: IPv4Layer.h:323
Definition: IPv4Layer.h:187
TimestampType
Definition: IPv4Layer.h:182
void setSrcIPv4Address(const IPv4Address &ipAddr)
Definition: IPv4Layer.h:494
Definition: IPv4Layer.h:127
Definition: IPv4Layer.h:81
std::vector< IPv4Address > getValueAsIpList() const
Definition: IPv4Layer.h:244
Definition: TLVData.h:207
Definition: IPv4Layer.h:103
IPProtocolTypes
Definition: IPv4Layer.h:74
Definition: IPv4Layer.h:93
Definition: ProtocolType.h:265
Definition: IPv4Layer.h:101
Definition: IPv4Layer.h:159
Definition: IPv4Layer.h:363
uint16_t totalLength
Definition: IPv4Layer.h:52
IPv4Address getSrcIPv4Address() const
Definition: IPv4Layer.h:488
Definition: IPv4Layer.h:95
Definition: IPv4Layer.h:36
Definition: IPv4Layer.h:99
Definition: IPv4Layer.h:191
IPv4OptionBuilder(IPv4OptionTypes optionType, const uint8_t *optionValue, uint8_t optionValueLen)
Definition: IPv4Layer.h:379
Definition: IPv4Layer.h:163
Definition: IPv4Layer.h:131
Definition: IPv4Layer.h:85
Definition: IpAddress.h:27
IPv4TimestampOptionValue getTimestampOptionValue() const
Definition: IPv4Layer.h:279
uint16_t fragmentOffset
Definition: IPv4Layer.h:56
IPAddress getSrcIPAddress() const
Definition: IPv4Layer.h:477
std::vector< IPv4Address > ipAddresses
Definition: IPv4Layer.h:201
Definition: IPv4Layer.h:223
Definition: IPv4Layer.h:149
Definition: IPv4Layer.h:107
Definition: IPv4Layer.h:133
void setDstIPv4Address(const IPv4Address &ipAddr)
Definition: IPv4Layer.h:518
uint8_t ipVersion
Definition: IPv4Layer.h:40
OsiModelLayer getOsiModelLayer() const
Definition: IPv4Layer.h:644
uint8_t protocol
Definition: IPv4Layer.h:60
Definition: IPv4Layer.h:141
Definition: IPv4Layer.h:177
TimestampType type
Definition: IPv4Layer.h:195
Definition: IPv4Layer.h:91
IPv4TimestampOptionValue()
Definition: IPv4Layer.h:204
uint16_t headerChecksum
Definition: IPv4Layer.h:62
~IPv4Option()
Definition: IPv4Layer.h:236
void clear()
Definition: IPv4Layer.h:209
size_t getDataSize() const
Definition: IPv4Layer.h:345
Definition: IPv4Layer.h:105
IPv4OptionBuilder(IPv4OptionTypes optionType, uint16_t optionValue)
Definition: IPv4Layer.h:388
Definition: IPv4Layer.h:113
uint32_t ipDst
Definition: IPv4Layer.h:66
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: IPv4Layer.h:670
Definition: IPv4Layer.h:97
Definition: IPv4Layer.h:418
IPv4Address getDstIPv4Address() const
Definition: IPv4Layer.h:512
Definition: IpAddress.h:278
Definition: IPv4Layer.h:157
Definition: IPv4Layer.h:117
Definition: IPv4Layer.h:147
Definition: IPv4Layer.h:135
Definition: IPv4Layer.h:77
uint32_t ipSrc
Definition: IPv4Layer.h:64
Definition: IPv4Layer.h:79
Definition: IPv4Layer.h:87
IPv4OptionTypes
Definition: IPv4Layer.h:124
uint32_t toInt() const
Definition: IpAddress.h:156
size_t getHeaderLen() const
Definition: IPv4Layer.h:631
Definition: IPv4Layer.h:89
Definition: IPv4Layer.h:167
Definition: IPv4Layer.h:155
iphdr * getIPv4Header() const
Definition: IPv4Layer.h:470