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 402658ae52c5845f
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
     1.1 --- a/src/applications/v4ping/v4ping.cc	Mon Dec 15 09:38:26 2008 -0800
     1.2 +++ b/src/applications/v4ping/v4ping.cc	Tue Dec 16 12:36:50 2008 -0800
     1.3 @@ -108,6 +108,15 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +void
     1.8 +V4Ping::Write32 (uint8_t *buffer, uint32_t data)
     1.9 +{
    1.10 +  buffer[0] = (data >> 0) & 0xff;
    1.11 +  buffer[1] = (data >> 8) & 0xff;
    1.12 +  buffer[2] = (data >> 16) & 0xff;
    1.13 +  buffer[3] = (data >> 24) & 0xff;
    1.14 +}
    1.15 +
    1.16  void 
    1.17  V4Ping::StartApplication (void)
    1.18  {
    1.19 @@ -128,13 +137,28 @@
    1.20    echo.SetSequenceNumber (m_seq);
    1.21    m_seq++;
    1.22    echo.SetIdentifier (0);
    1.23 -  uint32_t data[4];
    1.24 -  data[0] = GetNode ()->GetId ();
    1.25 -  data[1] = GetApplicationId ();
    1.26 +
    1.27 +  //
    1.28 +  // We must write quantities out in some form of network order.  Since there
    1.29 +  // isn't an htonl to work with we just follow the convention in pcap traces
    1.30 +  // (where any difference would show up anyway) and borrow that code.  Don't
    1.31 +  // be too surprised when you see that this is a little endian convention.
    1.32 +  //
    1.33 +  uint8_t data[4 * sizeof(uint32_t)];
    1.34 +  uint32_t tmp = GetNode ()->GetId ();
    1.35 +  Write32 (&data[0 * sizeof(uint32_t)], tmp);
    1.36 +
    1.37 +  tmp = GetApplicationId ();
    1.38 +  Write32 (&data[1 * sizeof(uint32_t)], tmp);
    1.39 +
    1.40    int64_t now = Simulator::Now ().GetTimeStep ();
    1.41 -  data[2] = now & 0xffffffff;
    1.42 +  tmp = now & 0xffffffff;
    1.43 +  Write32 (&data[2 * sizeof(uint32_t)], tmp);
    1.44 +
    1.45    now >>= 32;
    1.46 -  data[3] = now & 0xffffffff;
    1.47 +  tmp = now & 0xffffffff;
    1.48 +  Write32 (&data[3 * sizeof(uint32_t)], tmp);
    1.49 +
    1.50    Ptr<Packet> dataPacket = Create<Packet> ((uint8_t *) &data, 16);
    1.51    echo.SetData (dataPacket);
    1.52    p->AddHeader (echo);
     2.1 --- a/src/applications/v4ping/v4ping.h	Mon Dec 15 09:38:26 2008 -0800
     2.2 +++ b/src/applications/v4ping/v4ping.h	Tue Dec 16 12:36:50 2008 -0800
     2.3 @@ -18,6 +18,8 @@
     2.4    virtual ~V4Ping ();
     2.5  
     2.6  private:
     2.7 +  void Write32 (uint8_t *buffer, uint32_t data);
     2.8 +
     2.9    // inherited from Application base class.
    2.10    virtual void StartApplication (void);
    2.11    virtual void StopApplication (void);