[Lldb-commits] [lldb] r198902 - Fixed an issue with the byte order of ports in KDP packets.

Greg Clayton gclayton at apple.com
Thu Jan 9 16:31:10 PST 2014


Author: gclayton
Date: Thu Jan  9 18:31:10 2014
New Revision: 198902

URL: http://llvm.org/viewvc/llvm-project?rev=198902&view=rev
Log:
Fixed an issue with the byte order of ports in KDP packets. 

I previously fixed a bug in the SocketAddress class where SocketAddress::GetPort() wasn't using ntohs() on the port number in the structures.

After fixing this, it broke places where we weren't using ntohs() and htons() correctly.

<rdar://problem/15767514>


Modified:
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp?rev=198902&r1=198901&r2=198902&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp Thu Jan  9 18:31:10 2014
@@ -409,8 +409,8 @@ CommunicationKDP::SendRequestConnect (ui
     MakeRequestPacketHeader (command, request_packet, command_length);
     // Always send connect ports as little endian
     request_packet.SetByteOrder (eByteOrderLittle);
-    request_packet.PutHex16 (reply_port);
-    request_packet.PutHex16 (exc_port);
+    request_packet.PutHex16 (htons(reply_port));
+    request_packet.PutHex16 (htons(exc_port));
     request_packet.SetByteOrder (m_byte_order);
     request_packet.PutCString (greeting);
     DataExtractor reply_packet;
@@ -438,7 +438,7 @@ CommunicationKDP::SendRequestReattach (u
     MakeRequestPacketHeader (command, request_packet, command_length);
     // Always send connect ports as little endian
     request_packet.SetByteOrder (eByteOrderLittle);
-    request_packet.PutHex16(reply_port);
+    request_packet.PutHex16(htons(reply_port));
     request_packet.SetByteOrder (m_byte_order);
     DataExtractor reply_packet;
     if (SendRequestAndGetReply (command, request_packet, reply_packet))
@@ -1035,8 +1035,8 @@ CommunicationKDP::DumpPacket (Stream &s,
                 {
                     case KDP_CONNECT:               
                         {
-                            const uint16_t reply_port = packet.GetU16 (&offset);
-                            const uint16_t exc_port = packet.GetU16 (&offset);
+                            const uint16_t reply_port = ntohs(packet.GetU16 (&offset));
+                            const uint16_t exc_port = ntohs(packet.GetU16 (&offset));
                             s.Printf(" (reply_port = %u, exc_port = %u, greeting = \"%s\")", reply_port, exc_port, packet.GetCStr(&offset));
                         }
                         break;
@@ -1214,7 +1214,7 @@ CommunicationKDP::DumpPacket (Stream &s,
 
                     case KDP_REATTACH:
                         {
-                            const uint16_t reply_port = packet.GetU16 (&offset);
+                            const uint16_t reply_port = ntohs(packet.GetU16 (&offset));
                             s.Printf(" (reply_port = %u)", reply_port);
                         }
                         break;





More information about the lldb-commits mailing list