[Mono-dev] Patch for NetworkInformation on OSX

Bryan Crotaz bryan.crotaz at silvercurve.co.uk
Thu Jun 5 10:42:56 UTC 2014


Does it work on Linux and windows? Or does it fall back to the old
behaviour? Or does it throw nasty errors?

Bryan Crotaz
Silver Curve

On 5 Jun 2014, at 11:41, "Hüning, Christian" <
Christian.Huening at haw-hamburg.de> wrote:

 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

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20140605/67632d7b/attachment-0001.html>


More information about the Mono-devel-list mailing list