X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/5d786cebd0c4fa43033a3e323190ab365ec4326e..659563a75d668130df84664e7e6b1220667cbc28:/practicas/pipi/src/ipheader.h?ds=sidebyside diff --git a/practicas/pipi/src/ipheader.h b/practicas/pipi/src/ipheader.h index 98893be..f22c703 100644 --- a/practicas/pipi/src/ipheader.h +++ b/practicas/pipi/src/ipheader.h @@ -28,57 +28,19 @@ struct IPHeader IPHeader(uint8_t version, uint16_t total_len, uint16_t id, bool df, bool mf, uint16_t offset, uint8_t ttl, uint8_t proto, - const IPAddr& src, const IPAddr& dst): - version(version), total_len(total_len), id(id), reserved_flag(0), - df(df), mf(mf), offset(offset), ttl(ttl), proto(proto), checksum(0), - src(src), dst(dst) - { - do_checksum(); - } + const IPAddr& src, const IPAddr& dst); - IPHeader(const std::string& s) - { - *this = *((IPHeader*)s.c_str()); - } + IPHeader(const std::string& s); - bool check_checksum() const - { - IPHeader iph = *this; - iph.checksum = 0; - char* raw = (char*) &iph; - uint16_t sum = 0; - for (unsigned i = 0; i < sizeof(IPHeader); ++i) - sum += raw[i]; - return sum == checksum; - } + static size_t header_len(); - void do_checksum() - { - checksum = 0; - char* raw = (char*) this; - uint16_t sum = 0; - for (unsigned i = 0; i < sizeof(IPHeader); ++i) - sum += raw[i]; - checksum = sum; - } + bool check_checksum() const; + + void do_checksum(); }; -std::ostream& operator<<(std::ostream& os, const IPHeader& iph) -{ - return os - << "version=" << iph.version - << " total_len=" << iph.total_len - << " id=" << iph.id - << " DF=" << bool(iph.df) - << " MF=" << bool(iph.mf) - << " offset=" << unsigned(iph.offset) - << " TTL=" << unsigned(iph.ttl) - << " proto=" << unsigned(iph.proto) - << " checksum=" << iph.checksum - << " src=" << IPAddr(iph.src) - << " dst=" << IPAddr(iph.dst); -} +std::ostream& operator<<(std::ostream& os, const IPHeader& iph); #endif // _IPHEADER_H_