bug 448: V4Ping Application Sends uint32_t Data in Host Order ns-3.3-RC5
authorCraig Dowell <craigdo@ee.washington.edu>
Tue, 16 Dec 2008 12:36:50 -0800
changeset 4026 58ae52c5845f
parent 4025 e4b42930e37a
child 4027 cb86fb0fd36e
bug 448: V4Ping Application Sends uint32_t Data in Host Order
src/applications/v4ping/v4ping.cc
src/applications/v4ping/v4ping.h
--- a/src/applications/v4ping/v4ping.cc	Mon Dec 15 09:38:26 2008 -0800
+++ b/src/applications/v4ping/v4ping.cc	Tue Dec 16 12:36:50 2008 -0800
@@ -108,6 +108,15 @@
     }
 }
 
+void
+V4Ping::Write32 (uint8_t *buffer, uint32_t data)
+{
+  buffer[0] = (data >> 0) & 0xff;
+  buffer[1] = (data >> 8) & 0xff;
+  buffer[2] = (data >> 16) & 0xff;
+  buffer[3] = (data >> 24) & 0xff;
+}
+
 void 
 V4Ping::StartApplication (void)
 {
@@ -128,13 +137,28 @@
   echo.SetSequenceNumber (m_seq);
   m_seq++;
   echo.SetIdentifier (0);
-  uint32_t data[4];
-  data[0] = GetNode ()->GetId ();
-  data[1] = GetApplicationId ();
+
+  //
+  // We must write quantities out in some form of network order.  Since there
+  // isn't an htonl to work with we just follow the convention in pcap traces
+  // (where any difference would show up anyway) and borrow that code.  Don't
+  // be too surprised when you see that this is a little endian convention.
+  //
+  uint8_t data[4 * sizeof(uint32_t)];
+  uint32_t tmp = GetNode ()->GetId ();
+  Write32 (&data[0 * sizeof(uint32_t)], tmp);
+
+  tmp = GetApplicationId ();
+  Write32 (&data[1 * sizeof(uint32_t)], tmp);
+
   int64_t now = Simulator::Now ().GetTimeStep ();
-  data[2] = now & 0xffffffff;
+  tmp = now & 0xffffffff;
+  Write32 (&data[2 * sizeof(uint32_t)], tmp);
+
   now >>= 32;
-  data[3] = now & 0xffffffff;
+  tmp = now & 0xffffffff;
+  Write32 (&data[3 * sizeof(uint32_t)], tmp);
+
   Ptr<Packet> dataPacket = Create<Packet> ((uint8_t *) &data, 16);
   echo.SetData (dataPacket);
   p->AddHeader (echo);
--- a/src/applications/v4ping/v4ping.h	Mon Dec 15 09:38:26 2008 -0800
+++ b/src/applications/v4ping/v4ping.h	Tue Dec 16 12:36:50 2008 -0800
@@ -18,6 +18,8 @@
   virtual ~V4Ping ();
 
 private:
+  void Write32 (uint8_t *buffer, uint32_t data);
+
   // inherited from Application base class.
   virtual void StartApplication (void);
   virtual void StopApplication (void);