9 /// Dispositivo de red (capa de enlace)
19 uint16_t reserved_flag: 1;
29 IPHeader(uint8_t version, uint16_t total_len, uint16_t id, bool df,
30 bool mf, uint16_t offset, uint8_t ttl, uint8_t proto,
31 const IPAddr& src, const IPAddr& dst):
32 version(version), total_len(total_len), id(id), reserved_flag(0),
33 df(df), mf(mf), offset(offset), ttl(ttl), proto(proto), checksum(0),
39 IPHeader(const std::string& s)
41 *this = *((IPHeader*)s.c_str());
44 bool check_checksum() const
48 char* raw = (char*) &iph;
50 for (unsigned i = 0; i < sizeof(IPHeader); ++i)
52 return sum == checksum;
58 char* raw = (char*) this;
60 for (unsigned i = 0; i < sizeof(IPHeader); ++i)
67 std::ostream& operator<<(std::ostream& os, const IPHeader& iph)
70 << "version=" << iph.version
71 << " total_len=" << iph.total_len
73 << " DF=" << bool(iph.df)
74 << " MF=" << bool(iph.mf)
75 << " offset=" << unsigned(iph.offset)
76 << " TTL=" << unsigned(iph.ttl)
77 << " proto=" << unsigned(iph.proto)
78 << " checksum=" << iph.checksum
79 << " src=" << IPAddr(iph.src)
80 << " dst=" << IPAddr(iph.dst);
83 #endif // _IPHEADER_H_
85 // vim: set et sw=4 sts=4 :