Hi,

after having realized that Mono-list is not the appropriate
list for patches (:)), I'll try it here once again.

Please find the mail and the patch below and please note that
I don't want you to apply exactly this patch, but I'd like to
clarify the actual misbehavior (as I think) of UnixEndPoint.


Thanks, ciao, phb

-- 
Philipp Baer <[EMAIL PROTECTED]> [http://www.npw.net/]
--------------- contact information ---------------
mobile |+49-179-488 26 63|  fax |+49-561-804 62 77|
most current contact details  |'whois pb4412-ripe'|
---------------- gnupg-fingerprint ----------------
|16C7 84E8 5C5F C3D6 A8F1 A4DC E4CB A9A9 F5FA FF5D|

--- Begin Message ---
Hi,

it's me again. I came across another issue with UnixEndPoint:
- the unix socket pathname in the sockaddr structure has to
  be zero-terminated. I've modified the serialization method
  so that a trailing zero is appended.
- the pathname returned by a recvfrom call contains a trailing
  zero which is preserved by the .NET string. This leads to
  a different string and thus a different hash.

I've attached the patch including the missing Equals method :)


phb

-- 
Philipp Baer <[EMAIL PROTECTED]> [http://www.npw.net/]
--------------- contact information ---------------
mobile |+49-179-488 26 63|  fax |+49-561-804 62 77|
most current contact details  |'whois pb4412-ripe'|
---------------- gnupg-fingerprint ----------------
|16C7 84E8 5C5F C3D6 A8F1 A4DC E4CB A9A9 F5FA FF5D|
Index: UnixEndPoint.cs
===================================================================
--- UnixEndPoint.cs     (revision 57605)
+++ UnixEndPoint.cs     (working copy)
@@ -76,16 +76,22 @@
                        }
 
                        string name = Encoding.Default.GetString (bytes);
-                       return new UnixEndPoint (name);
+                       return new UnixEndPoint (name.TrimEnd (new char[] { 
'\0' }));
                }
 
                public override SocketAddress Serialize ()
                {
-                       byte [] bytes = Encoding.Default.GetBytes (filename);
-                       SocketAddress sa = new SocketAddress (AddressFamily, 
bytes.Length + 2);
+                       // Remove trailing zeros
+                       string cleanFilename = filename.TrimEnd (new char[] { 
'\0' });
+                       byte [] bytes = Encoding.Default.GetBytes 
(cleanFilename);
+                       // Reserve one extra byte for the terminating null
+                       SocketAddress sa = new SocketAddress (AddressFamily, 
bytes.Length + 3);
                        // sa [0] -> family low byte, sa [1] -> family high byte
-                       for (int i = 0; i < bytes.Length; i++)
+                       for (int i = 0; i < bytes.Length; i++) {
                                sa [i + 2] = bytes [i];
+                       }
+                       // Add one trailing zero
+                       sa [bytes.Length + 2] = 0;
 
                        return sa;
                }
@@ -93,6 +99,19 @@
                public override string ToString() {
                        return(filename);
                }
+
+               public override int GetHashCode() {
+                       return filename.GetHashCode();
+               }
+
+               public override bool Equals(object o) {
+                       if (o is UnixEndPoint) {
+                               // check whether the two filenames are equal
+                               return 
filename.Equals(((UnixEndPoint)o).Filename);
+                       }
+
+                       return false;
+               }
        }
 }
 

--- End Message ---
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to