# HG changeset patch # User Craig Dowell # Date 1229459810 28800 # Node ID 58ae52c5845ff03ba08dc921e13e6cf3604c810a # Parent e4b42930e37a016d29300b8fbfdd5af03ab6e202 bug 448: V4Ping Application Sends uint32_t Data in Host Order diff -r e4b42930e37a -r 58ae52c5845f src/applications/v4ping/v4ping.cc --- 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 dataPacket = Create ((uint8_t *) &data, 16); echo.SetData (dataPacket); p->AddHeader (echo); diff -r e4b42930e37a -r 58ae52c5845f src/applications/v4ping/v4ping.h --- 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);