]> git.llucax.com Git - z.facultad/75.74/practicos.git/blobdiff - practicas/pipi/src/ipheader.h
Primera aproximación al cache y a la resolución de nombres.
[z.facultad/75.74/practicos.git] / practicas / pipi / src / ipheader.h
index 98893be6b4645555d6d1d59bdca3b1e418ac4121..f22c703fbbd0bd50b381a37bd0fcdb79331e8fd0 100644 (file)
@@ -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_