[Mono-bugs] [Bug 24666] New - Byte order reversed in IPAddress.Parse

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
14 May 2002 01:13:29 -0000


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by ipmccmono@hotmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=24666

--- shadow/24666	Mon May 13 21:13:29 2002
+++ shadow/24666.tmp.31289	Mon May 13 21:13:29 2002
@@ -0,0 +1,96 @@
+Bug#: 24666
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Red Hat 7.2
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: ipmccmono@hotmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Byte order reversed in IPAddress.Parse
+
+Description of Problem:
+
+After much wondering, I discovered that the byte ordering of the IPAddress 
+objects returned by IPAddress.Parse is backwards. See details below.
+
+Steps to reproduce the problem:
+The following source code helps illustrate the problem:
+using System;
+using System.Net;
+using System.Net.Sockets;
+
+class Test
+{
+	static void Main()
+	{
+		long theRightAddress = ((long)(128 << 24 | 2 << 16 | 11 << 
+8 | 44 << 0)) & 0x00000000FFFFFFFF;
+		long theParsedAddress = IPAddress.Parse
+("128.2.11.44").Address;
+		
+		Console.WriteLine("Done with Shift: {0}", theRightAddress);
+		Console.WriteLine("Done with Parse: {0}", 
+theParsedAddress);
+
+		Socket theGoodSocket = new Socket
+(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);	
+		Socket theBadSocket = new Socket
+(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);	
+		IPEndPoint theRightEndPoint = new IPEndPoint
+(theRightAddress, 79);
+		IPEndPoint theParsedEndPoint = new IPEndPoint
+(IPAddress.Parse("128.2.11.44"), 79);
+		
+		theGoodSocket.Connect(theRightEndPoint);
+		theGoodSocket.Close();
+		
+		theBadSocket.Connect(theParsedEndPoint);
+		theBadSocket.Close();
+	}
+	
+}
+	
+This program makes it through the first connect and close and hangs on the 
+second connect. The output of strace shows the following when running this 
+(among much else):
+
+connect(10, {sin_family=AF_INET, sin_port=htons(79), sin_addr=inet_addr
+("128.2.11.44")}}, 16) = 0
+close(10)                               = 0
+connect(11, {sin_family=AF_INET, sin_port=htons(79), sin_addr=inet_addr
+("44.11.2.128")}}, 16 <unfinished ...>
+
+A quick look at man 3 inet_addr reveals that it expects the address in 
+normal dotted-quad notation and not reversed, so the parsed address is 
+backwards.  Also, 128.2.11.44 is andrew.cmu.edu, which I can connect to 
+directly, so that corroborates the hang on connect with the quads reversed.
+
+Actual Results:
+
+When the address is parsed through IPAddress.Parse, it never connects 
+(although may connect to the wrong IP if there exists a host with the 
+dotted quad address byteqise opposite of the one you're trying to conenct 
+to)
+
+Expected Results:
+
+Not to reverse the quads in the IP address.
+
+How often does this happen? 
+
+Relaibaly.
+
+Additional Information:
+
+GhettoDiff(tm) of IPAddress.cs(151)
+- a |= (long) val << (i << 3);
++ a |= (long) val << (24 - (i << 3 )); // or some expression you like 
+better that does the same thing