#ifndef __ip_h__ #define __ip_h__ #include "type.h" struct Ip { RelativeRef words; struct Address { U8 bytes[4]; inline void operator=(const Address& ad) { *(U32*)this=*(U32*)&ad; } inline bool operator==(const Address& ad) { return *(U32*)this==*(U32*)&ad; } inline bool operator!=(const Address& ad) { return !(*this==ad); } }; RelativeField headerLength; RelativeField version; Relative services; Relative totalLength; Relative identification; Relative ff; RelativeField fragmentOffset; RelativeField flags; Relative ttl; Relative protocol; Relative headerChecksum; Relative checksum; RelativeRef source; RelativeRef destination; RelativeRef options; U8 buf[0]; inline U32 headerSize() { return headerLength*4; } inline U8 *data() { return buf+headerSize(); } U16 checkSum(U8 *data,U32 len); inline void checkSumSet() { checksum=0; checksum=~checkSum(buf,headerSize()); } bool checkSumGood() { return checkSum(buf,headerSize())==(U16)~0; } }; #endif /* __ip_h__ */