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 37 #if (BYTE_ORDER == LITTLE_ENDIAN) 169 #define PCPP_IP_DONT_FRAGMENT 0x40 170 #define PCPP_IP_MORE_FRAGMENTS 0x20 188 TimestampsForPrespecifiedIPs = 2,
245 std::vector<IPv4Address> res;
250 size_t dataSize = getDataSize();
254 uint8_t valueOffset = (uint8_t)(1);
256 while ((
size_t)valueOffset < dataSize)
259 memcpy(&curValue, m_Data->recordValue + valueOffset,
sizeof(uint32_t));
265 valueOffset += (uint8_t)(4);
289 size_t dataSize = getDataSize();
295 uint8_t valueOffset = (uint8_t)(2);
298 while ((
size_t)valueOffset < dataSize)
301 memcpy(&curValue, m_Data->recordValue + valueOffset,
sizeof(uint32_t));
311 readIPAddr = !readIPAddr;
313 valueOffset += (uint8_t)(4);
339 return sizeof(uint8_t);
341 return (
size_t)m_Data->recordLen;
352 return (
size_t)m_Data->recordLen - (2*
sizeof(uint8_t));
365 bool m_BuilderParamsValid;
379 TLVRecordBuilder((uint8_t)optionType, optionValue, optionValueLen) { m_BuilderParamsValid =
true; }
388 TLVRecordBuilder((uint8_t)optionType, optionValue) { m_BuilderParamsValid =
true; }
440 IPv4Layer(uint8_t* data,
size_t dataLen,
Layer* prevLayer,
Packet* packet,
bool setTotalLenAsDataLen);
481 PCPP_DEPRECATED
IPv4Address getSrcIpAddress()
const {
return getSrcIPv4Address(); }
505 PCPP_DEPRECATED
IPv4Address getDstIpAddress()
const {
return getDstIPv4Address(); }
522 bool isFragment()
const;
528 bool isFirstFragment()
const;
534 bool isLastFragment()
const;
539 uint8_t getFragmentFlags()
const;
544 uint16_t getFragmentOffset()
const;
572 size_t getOptionCount()
const;
606 bool removeAllOptions();
625 void parseNextLayer();
630 size_t getHeaderLen()
const {
return (
size_t)((uint16_t)(getIPv4Header()->internetHeaderLength) * 4) + m_TempHeaderExtension; }
639 void computeCalculateFields();
641 std::string toString()
const;
651 static inline bool isDataValid(
const uint8_t* data,
size_t dataLen);
654 int m_NumOfTrailingBytes;
655 int m_TempHeaderExtension;
658 void copyLayerData(
const IPv4Layer& other);
659 uint8_t* getOptionsBasePtr()
const {
return m_Data +
sizeof(
iphdr); }
661 void adjustOptionsTrailer(
size_t totalOptSize);
663 void initLayerInPacket(uint8_t* data,
size_t dataLen,
Layer* prevLayer,
Packet* packet,
bool setTotalLenAsDataLen);
671 const iphdr* hdr =
reinterpret_cast<const iphdr*
>(data);
Definition: IPv4Layer.h:114
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:253
size_t getTotalSize() const
Definition: IPv4Layer.h:333
Definition: IPv4Layer.h:110
std::vector< uint32_t > timestamps
Definition: IPv4Layer.h:197
Definition: IPv4Layer.h:142
uint16_t ipId
Definition: IPv4Layer.h:53
Definition: IPv4Layer.h:138
Definition: IPv4Layer.h:144
IPv4Option(uint8_t *optionRawData)
Definition: IPv4Layer.h:230
uint8_t timeToLive
Definition: IPv4Layer.h:57
uint8_t internetHeaderLength
Definition: IPv4Layer.h:39
Definition: IPv4Layer.h:82
uint8_t typeOfService
Definition: IPv4Layer.h:49
Definition: IPv4Layer.h:128
Definition: IPv4Layer.h:108
Definition: IPv4Layer.h:150
Definition: TLVData.h:351
Definition: IPv4Layer.h:160
Definition: IPv4Layer.h:152
Definition: IPv4Layer.h:164
IPAddress getDstIPAddress() const
Definition: IPv4Layer.h:500
Definition: IPv4Layer.h:136
IPv4OptionTypes getIPv4OptionType() const
Definition: IPv4Layer.h:322
Definition: IPv4Layer.h:186
TimestampType
Definition: IPv4Layer.h:181
void setSrcIPv4Address(const IPv4Address &ipAddr)
Definition: IPv4Layer.h:493
Definition: IPv4Layer.h:126
Definition: IPv4Layer.h:80
std::vector< IPv4Address > getValueAsIpList() const
Definition: IPv4Layer.h:243
Definition: TLVData.h:197
Definition: IPv4Layer.h:102
IPProtocolTypes
Definition: IPv4Layer.h:73
Definition: IPv4Layer.h:92
Definition: ProtocolType.h:260
Definition: IPv4Layer.h:100
Definition: IPv4Layer.h:158
Definition: IPv4Layer.h:362
uint16_t totalLength
Definition: IPv4Layer.h:51
IPv4Address getSrcIPv4Address() const
Definition: IPv4Layer.h:487
Definition: IPv4Layer.h:94
Definition: IPv4Layer.h:36
Definition: IPv4Layer.h:98
Definition: IPv4Layer.h:190
IPv4OptionBuilder(IPv4OptionTypes optionType, const uint8_t *optionValue, uint8_t optionValueLen)
Definition: IPv4Layer.h:378
Definition: IPv4Layer.h:162
Definition: IPv4Layer.h:130
Definition: IPv4Layer.h:84
Definition: IpAddress.h:26
IPv4TimestampOptionValue getTimestampOptionValue() const
Definition: IPv4Layer.h:278
uint16_t fragmentOffset
Definition: IPv4Layer.h:55
IPAddress getSrcIPAddress() const
Definition: IPv4Layer.h:476
std::vector< IPv4Address > ipAddresses
Definition: IPv4Layer.h:200
Definition: IPv4Layer.h:222
Definition: IPv4Layer.h:148
Definition: IPv4Layer.h:106
Definition: IPv4Layer.h:132
void setDstIPv4Address(const IPv4Address &ipAddr)
Definition: IPv4Layer.h:517
uint8_t ipVersion
Definition: IPv4Layer.h:39
OsiModelLayer getOsiModelLayer() const
Definition: IPv4Layer.h:643
uint8_t protocol
Definition: IPv4Layer.h:59
Definition: IPv4Layer.h:140
Definition: IPv4Layer.h:176
TimestampType type
Definition: IPv4Layer.h:194
Definition: IPv4Layer.h:90
IPv4TimestampOptionValue()
Definition: IPv4Layer.h:203
uint16_t headerChecksum
Definition: IPv4Layer.h:61
~IPv4Option()
Definition: IPv4Layer.h:235
void clear()
Definition: IPv4Layer.h:208
size_t getDataSize() const
Definition: IPv4Layer.h:344
Definition: IPv4Layer.h:104
IPv4OptionBuilder(IPv4OptionTypes optionType, uint16_t optionValue)
Definition: IPv4Layer.h:387
Definition: IPv4Layer.h:112
uint32_t ipDst
Definition: IPv4Layer.h:65
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: IPv4Layer.h:669
Definition: IPv4Layer.h:96
Definition: IPv4Layer.h:417
IPv4Address getDstIPv4Address() const
Definition: IPv4Layer.h:511
Definition: IpAddress.h:265
Definition: IPv4Layer.h:156
Definition: IPv4Layer.h:116
Definition: IPv4Layer.h:146
Definition: IPv4Layer.h:134
Definition: IPv4Layer.h:76
uint32_t ipSrc
Definition: IPv4Layer.h:63
Definition: IPv4Layer.h:78
Definition: IPv4Layer.h:86
IPv4OptionTypes
Definition: IPv4Layer.h:123
uint32_t toInt() const
Definition: IpAddress.h:149
size_t getHeaderLen() const
Definition: IPv4Layer.h:630
Definition: IPv4Layer.h:88
Definition: IPv4Layer.h:166
Definition: IPv4Layer.h:154
iphdr * getIPv4Header() const
Definition: IPv4Layer.h:469