]> git.stg.codes - stg.git/blobdiff - tests/test_raw_ip.cpp
Added result and reason attributes for <user>.
[stg.git] / tests / test_raw_ip.cpp
index 6e14768670c556c1bc11e708ae3b1d22f594cafa..2f75c7855d216ba053af0be61d5e634b05f09259 100644 (file)
@@ -6,10 +6,11 @@
 #include <ctime>
 #include <iostream>
 
 #include <ctime>
 #include <iostream>
 
-#include <tut/tut.hpp>
+#include "tut/tut.hpp"
 
 
+#include "stg/os_int.h"
 #include "raw_ip_packet_old.h"
 #include "raw_ip_packet_old.h"
-#include "raw_ip_packet.h"
+#include "stg/raw_ip_packet.h"
 
 #ifndef ITERATIONS
 #define ITERATIONS 1000
 
 #ifndef ITERATIONS
 #define ITERATIONS 1000
@@ -36,21 +37,21 @@ namespace tut
         set_test_name("Check structure consistency");
 
         RAW_PACKET rp;
         set_test_name("Check structure consistency");
 
         RAW_PACKET rp;
-        rp.ipHeader.ip_v = 4;
-        rp.ipHeader.ip_hl = 5;
-        rp.ipHeader.ip_tos = 0;
-        rp.ipHeader.ip_len = htons(40); // 20 of header + 20 of data
-        rp.ipHeader.ip_p = 6;
-        rp.ipHeader.ip_src.s_addr = inet_addr("192.168.0.1");
-        rp.ipHeader.ip_dst.s_addr = inet_addr("192.168.0.101");
-        rp.sPort = htons(80);
-        rp.dPort = htons(38546);
-
-        ensure_equals("IP header size (explicitly)", sizeof(rp.ipHeader), 20);
+        rp.rawPacket.header.ipHeader.ip_v = 4;
+        rp.rawPacket.header.ipHeader.ip_hl = 5;
+        rp.rawPacket.header.ipHeader.ip_tos = 0;
+        rp.rawPacket.header.ipHeader.ip_len = htons(40); // 20 of header + 20 of data
+        rp.rawPacket.header.ipHeader.ip_p = 6;
+        rp.rawPacket.header.ipHeader.ip_src.s_addr = inet_addr("192.168.0.1");
+        rp.rawPacket.header.ipHeader.ip_dst.s_addr = inet_addr("192.168.0.101");
+        rp.rawPacket.header.sPort = htons(80);
+        rp.rawPacket.header.dPort = htons(38546);
+
+        ensure_equals("IP header size (explicitly)", sizeof(rp.rawPacket.header.ipHeader), static_cast<size_t>(20));
         ensure_equals("IP version", rp.GetIPVersion(), 4);
         ensure_equals("IP header size (with options)", rp.GetHeaderLen(), 20);
         ensure_equals("Underlying protocol version", rp.GetProto(), 6);
         ensure_equals("IP version", rp.GetIPVersion(), 4);
         ensure_equals("IP header size (with options)", rp.GetHeaderLen(), 20);
         ensure_equals("Underlying protocol version", rp.GetProto(), 6);
-        ensure_equals("Packet length", rp.GetLen(), 40);
+        ensure_equals("Packet length", rp.GetLen(), static_cast<uint32_t>(40));
         ensure_equals("Source IP address", rp.GetSrcIP(), inet_addr("192.168.0.1"));
         ensure_equals("Destination IP address", rp.GetDstIP(), inet_addr("192.168.0.101"));
         ensure_equals("Source port number", rp.GetSrcPort(), 80);
         ensure_equals("Source IP address", rp.GetSrcIP(), inet_addr("192.168.0.1"));
         ensure_equals("Destination IP address", rp.GetDstIP(), inet_addr("192.168.0.101"));
         ensure_equals("Source port number", rp.GetSrcPort(), 80);
@@ -71,8 +72,8 @@ namespace tut
             genVector(buf);
 
             memcpy(p1.pckt, buf, 68);
             genVector(buf);
 
             memcpy(p1.pckt, buf, 68);
-            memcpy(p2.pckt, buf, 68);
-            memcpy(p3.pckt, buf, 68);
+            memcpy(p2.rawPacket.pckt, buf, 68);
+            memcpy(p3.rawPacket.pckt, buf, 68);
 
             ensure_equals("IP versions", p1.GetIPVersion(), p2.GetIPVersion());
             ensure_equals("IP headers length", p1.GetHeaderLen(), p2.GetHeaderLen());
 
             ensure_equals("IP versions", p1.GetIPVersion(), p2.GetIPVersion());
             ensure_equals("IP headers length", p1.GetHeaderLen(), p2.GetHeaderLen());
@@ -101,8 +102,8 @@ std::ostream & operator<<(std::ostream & stream, const RAW_PACKET & p)
 {
     stream.unsetf(std::ios::dec);
     stream.setf(std::ios::hex);
 {
     stream.unsetf(std::ios::dec);
     stream.setf(std::ios::hex);
-    for (size_t i = 0; i < sizeof(p.pckt); ++i) {
-        stream << static_cast<unsigned>(p.pckt[i]);
+    for (size_t i = 0; i < sizeof(p.rawPacket.pckt); ++i) {
+        stream << static_cast<unsigned>(p.rawPacket.pckt[i]);
     }
     stream.unsetf(std::ios::hex);
     stream.setf(std::ios::dec);
     }
     stream.unsetf(std::ios::hex);
     stream.setf(std::ios::dec);