[Mono-dev] Patch for NetworkInformation on OSX

Marek Safar marek.safar at gmail.com
Thu Jun 5 11:05:57 UTC 2014


Hi,

Please sent suggested change/fix as a git pull request.

Thanks
Marek


> 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/a206e570/attachment-0001.html>


More information about the Mono-devel-list mailing list