1 #ifndef PACKETPP_IPV4_LAYER 2 #define PACKETPP_IPV4_LAYER 24 #if (BYTE_ORDER == LITTLE_ENDIAN) 156 #define PCPP_IP_DONT_FRAGMENT 0x40 157 #define PCPP_IP_MORE_FRAGMENTS 0x20 231 if (
getTotalSize() - 2*
sizeof(uint8_t) - valueOffset <
sizeof(T))
235 memcpy(&result, value+valueOffset,
sizeof(T));
247 std::vector<IPv4Address> res;
253 uint8_t valueOffset = (uint8_t)(1);
255 while (valueOffset < dataSize)
258 memcpy(&curValue, value+valueOffset,
sizeof(uint32_t));
264 valueOffset += (uint8_t)(4);
291 uint8_t valueOffset = (uint8_t)(2);
294 while (valueOffset < dataSize)
297 memcpy(&curValue, value+valueOffset,
sizeof(uint32_t));
307 readIPAddr = !readIPAddr;
309 valueOffset += (uint8_t)(4);
322 return sizeof(uint8_t);
335 return (
size_t)len - (2*
sizeof(uint8_t));
376 IPv4Layer(uint8_t* data,
size_t dataLen,
Layer* prevLayer,
Packet* packet,
bool setTotalLenAsDataLen);
598 size_t m_OptionCount;
599 int m_NumOfTrailingBytes;
600 int m_TempHeaderExtension;
602 void copyLayerData(
const IPv4Layer& other);
605 void adjustOptionsTrailer(
size_t totalOptSize);
606 void buildIPListOptionData(
const std::vector<IPv4Address>& ipList, uint8_t** optionData,
int& optionDataLength);
607 void buildTimestampOptionData(
const IPv4TimestampOptionValue& timestampVal, uint8_t** optionData,
int& optionDataLength);
608 void incOptionCount(
int val);
609 void setOptionCount(
int val);
611 void initLayerInPacket(uint8_t* data,
size_t dataLen,
Layer* prevLayer,
Packet* packet,
bool setTotalLenAsDataLen);
uint8_t opCode
Definition: IPv4Layer.h:211
Definition: IPv4Layer.h:91
Definition: IPv4Layer.h:97
Definition: IPv4Layer.h:87
std::vector< IPv4Address > ipAddresses
Definition: IPv4Layer.h:189
Definition: IPv4Layer.h:75
Definition: IPv4Layer.h:67
std::vector< uint32_t > timestamps
Definition: IPv4Layer.h:186
uint8_t ipVersion
Definition: IPv4Layer.h:26
Definition: IPv4Layer.h:151
Definition: IPv4Layer.h:163
Definition: IPv4Layer.h:89
T getValueAs(int valueOffset=0)
Definition: IPv4Layer.h:227
IPv4OptionTypes getType()
Definition: IPv4Layer.h:341
Definition: IPv4Layer.h:63
IPv4OptionData * addTimestampOption(const IPv4TimestampOptionValue ×tampValue)
Definition: IPv4Layer.h:175
Definition: IPv4Layer.h:125
Definition: IPv4Layer.h:139
void computeCalculateFields()
uint32_t ipSrc
Definition: IPv4Layer.h:50
Definition: IPv4Layer.h:355
uint8_t typeOfService
Definition: IPv4Layer.h:36
Definition: IPv4Layer.h:23
The main namespace for the PcapPlusPlus lib.
void setDstIpAddress(const IPv4Address &ipAddr)
Definition: IPv4Layer.h:429
IPv4OptionData * addOptionAfter(IPv4OptionTypes optionType, uint8_t optionDataLength, const uint8_t *optionData, IPv4OptionTypes prevOption=IPV4OPT_Unknown)
bool removeOption(IPv4OptionTypes option)
iphdr * getIPv4Header()
Definition: IPv4Layer.h:405
Definition: IPv4Layer.h:69
Definition: IpAddress.h:113
Definition: IPv4Layer.h:177
uint16_t ipId
Definition: IPv4Layer.h:40
void clear()
Definition: IPv4Layer.h:194
Definition: IPv4Layer.h:85
size_t getHeaderLen()
Definition: IPv4Layer.h:582
Definition: IPv4Layer.h:103
Definition: IPv4Layer.h:179
IPv4OptionData * addOption(IPv4OptionTypes optionType, uint8_t optionDataLength, const uint8_t *optionData)
IPv4OptionData * getOptionData(IPv4OptionTypes option)
Definition: IPv4Layer.h:77
OsiModelLayer
Definition: ProtocolType.h:208
Definition: IPv4Layer.h:119
Definition: IPv4Layer.h:95
Definition: IPv4Layer.h:141
Definition: IPv4Layer.h:101
Definition: IPv4Layer.h:73
uint8_t internetHeaderLength
Definition: IPv4Layer.h:26
uint16_t fragmentOffset
Definition: IPv4Layer.h:42
Definition: IPv4Layer.h:143
size_t getTotalSize() const
Definition: IPv4Layer.h:319
IPv4Address getSrcIpAddress()
Definition: IPv4Layer.h:411
Definition: IPv4Layer.h:81
IPv4Address getDstIpAddress()
Definition: IPv4Layer.h:423
uint16_t headerChecksum
Definition: IPv4Layer.h:48
uint8_t value[]
Definition: IPv4Layer.h:215
Definition: IPv4Layer.h:173
Definition: IPv4Layer.h:113
Definition: IPv4Layer.h:135
uint8_t timeToLive
Definition: IPv4Layer.h:44
Definition: IPv4Layer.h:147
Definition: IPv4Layer.h:121
IPProtocolTypes
Definition: IPv4Layer.h:60
IPv4OptionData * getFirstOptionData()
Definition: IPv4Layer.h:137
Definition: IPv4Layer.h:131
uint8_t protocol
Definition: IPv4Layer.h:46
TimestampType type
Definition: IPv4Layer.h:183
Definition: IPv4Layer.h:79
Definition: IPv4Layer.h:127
Definition: IPv4Layer.h:133
Definition: ProtocolType.h:215
Definition: IPv4Layer.h:99
TimestampType
Definition: IPv4Layer.h:170
IPv4TimestampOptionValue getTimestampOptionValue()
Definition: IPv4Layer.h:277
Definition: IPv4Layer.h:83
OsiModelLayer getOsiModelLayer()
Definition: IPv4Layer.h:595
Definition: IPv4Layer.h:93
std::vector< IPv4Address > getValueAsIpList()
Definition: IPv4Layer.h:245
Definition: IPv4Layer.h:145
void setSrcIpAddress(const IPv4Address &ipAddr)
Definition: IPv4Layer.h:417
IPv4OptionData * addTimestampOptionAfter(const IPv4TimestampOptionValue ×tampValue, IPv4OptionTypes prevOption=IPV4OPT_Unknown)
IPv4OptionData * getNextOptionData(IPv4OptionData *option)
uint16_t getFragmentOffset()
Definition: IPv4Layer.h:117
Definition: IPv4Layer.h:207
Definition: IPv4Layer.h:153
uint32_t ipDst
Definition: IPv4Layer.h:52
IPv4Layer & operator=(const IPv4Layer &other)
uint8_t len
Definition: IPv4Layer.h:213
uint8_t getFragmentFlags()
Definition: IPv4Layer.h:115
Definition: IPv4Layer.h:71
Definition: IPv4Layer.h:65
Definition: IPv4Layer.h:149
size_t getDataSize()
Definition: IPv4Layer.h:330
IPv4OptionTypes
Definition: IPv4Layer.h:110
Definition: IPv4Layer.h:129
Definition: IPv4Layer.h:123
uint16_t totalLength
Definition: IPv4Layer.h:38