« Return to Thread: [PATCH] Simple implementation of network interface properties for Mac OS X

Re: [PATCH] Simple implementation of network interface properties for Mac OS X

by Alexander Shulgin :: Rate this Message:

Reply to Author | View in Thread

Alex Shulgin wrote:

> Alex Shulgin wrote:
>> Hi,
>>
>> In the current version System.Net.NetworkInformation.NetworkInterface
>> provides limited information about network interfaces on the system
>> (their names only).
>>
>> The attached patch adds support for NetworkInterfaceType and
>> GetPhysicalAddress() on Mac OS.
>
> Oops, I've almost forgot about IPv6... and missed the added file
> MacOsNetworkInterfaceMarshal.
>
> Please see the fixed patch instead.
This worked fine, until one user reported a crash on Array.Copy in
NetworkInformation.MacOsNetworkInterface.ImplGetAllNetworkInterfaces().
  I traced this down to that I believe is a problem with non-standard
length interface name: thus the 12-byte buffer sockaddr_dl.sdl_data is
not enough.

I've noticed that sockaddr_dl contains sdl_len member which holds the
length of the whole sockaddr structure.  With that we can use
Marshal.Copy instead of Array.Copy to access data past default 12-byte
data array.  A patch against trunk is attached.

I didn't have a chance to try it with the problematic user, but still
would like someone to review the patch and comment on it.

--
Alex
PS: is there more appropriate way to increment IntPtr value w/o using
ToInt64()?

Index: System.Net.NetworkInformation/NetworkInterface.cs
===================================================================
--- System.Net.NetworkInformation/NetworkInterface.cs (revision 137150)
+++ System.Net.NetworkInformation/NetworkInterface.cs (working copy)
@@ -480,7 +480,8 @@
  MacOsStructs.sockaddr_dl sockaddrdl = (MacOsStructs.sockaddr_dl) Marshal.PtrToStructure (addr.ifa_addr, typeof (MacOsStructs.sockaddr_dl));
 
  macAddress = new byte [(int) sockaddrdl.sdl_alen];
- Array.Copy (sockaddrdl.sdl_data, sockaddrdl.sdl_nlen, macAddress, 0, macAddress.Length);
+ // copy `sdl_alen' bytes from `sdl_data + sdl_nlen'
+ Marshal.Copy ((IntPtr)(addr.ifa_addr.ToInt64 () + 8 + sockaddrdl.sdl_nlen), macAddress, 0, macAddress.Length);
  index = sockaddrdl.sdl_index;
 
  int hwtype = (int) sockaddrdl.sdl_type;

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

 « Return to Thread: [PATCH] Simple implementation of network interface properties for Mac OS X