[Mono-dev] Patch for NetworkInformation on OSX

Hüning, Christian Christian.Huening at haw-hamburg.de
Thu Jun 5 10:31:09 UTC 2014


Hi everybody,

I just ran into a problem regarding the usage of
System.Net.NetworkInformation.NetworkInterface.cs on OSX. Especially the
Properties „SupportsMulticast“ and „OperationalStatus“ were not implemented
properly (always returning false / unknown). So I just fixed that.

On http://mono-project.com/Contributing#Ways_to_Contribute it’s written to
post patches to this mailing list, so I do :)

My solution basically works by extracting the ifa_flags via getifaddrs and
storing the flags in the MacOsNetworkInterface class inside of
NetworkInterface.cs. I can then implement the two properties like so:

public override OperationalStatus OperationalStatus {
            get {
                if(((MacOsInterfaceFlags)_ifa_flags &
MacOsInterfaceFlags.IFF_UP) == MacOsInterfaceFlags.IFF_UP){
                    return OperationalStatus.Up;
                }
                return OperationalStatus.Unknown;
            }
        }

        public override bool SupportsMulticast {
            get {
                return ((MacOsInterfaceFlags)_ifa_flags &
MacOsInterfaceFlags.IFF_MULTICAST) == MacOsInterfaceFlags.IFF_MULTICAST;
            }
        } 

MacOsInterfaceFlags is an Enum residing in MacOsNetworkInterfaceMarshal.cs:
    internal enum MacOsInterfaceFlags {
        IFF_UP = 0x1,                /* interface is up */
        IFF_BROADCAST = 0x2,        /* broadcast address valid */
        IFF_DEBUG = 0x4,            /* turn on debugging */
        IFF_LOOPBACK = 0x8,            /* is a loopback net */
        IFF_POINTOPOINT = 0x10,        /* interface is point-to-point link
*/
        IFF_NOTRAILERS = 0x20,        /* avoid use of trailers */
        IFF_RUNNING = 0x40,            /* resources allocated */
        IFF_NOARP = 0x80,            /* no address resolution protocol */
        IFF_PROMISC = 0x100,        /* receive all packets */
        IFF_ALLMULTI = 0x200,        /* receive all multicast packets */
        IFF_OACTIVE = 0x400,        /* transmission in progress */
        IFF_SIMPLEX = 0x800,        /* can't hear own transmissions */
        IFF_LINK0 = 0x1000,            /* per link layer defined bit */
        IFF_LINK1 = 0x2000,            /* per link layer defined bit */
        IFF_LINK2 = 0x4000,            /* per link layer defined bit */
        IFF_MULTICAST = 0x8000        /* supports multicast */
    } 

So is this a valid solution? It works well in my project and the
corresponding test cases.

Cheers,
Christian

-----------------------------------------------

Christian Hüning, BSc.

Fakultät Technik und Informatik, Department Informatik

Berliner Tor 7

20099 Hamburg

Tel.: +49 40 / 42875 - 8436

Mobil: +49 40 / 180 55 44 5

Web: http://www.mars-group.org




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20140605/4e315766/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5199 bytes
Desc: not available
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20140605/4e315766/attachment-0001.bin>


More information about the Mono-devel-list mailing list