[Mono-bugs] [Bug 416526] New: IPv4Mask - Not implemented exception

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Aug 12 05:31:37 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=416526


           Summary: IPv4Mask - Not implemented exception
           Product: Mono: Class Libraries
           Version: SVN
          Platform: i686
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: fredrik.kling at swissqual.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


Solve IPv4Mask in UnicastIPAddressInformation
----------------------------------------------
The information is available in the IP-Helper structure "IP_ADDR_STRING", this
can be obtained through IP_ADAPTER_INFO available in:
Win32NetworkInterface2.GetAdapterInfoByIndex(int index);  
or:
unsafe static Win32_IP_ADAPTER_INFO [] GetAdaptersInfo ();

However, there is no link between the adapter index and the current structure 
used to get the properties "IP_ADAPTER_UNICAST_ADDRESS", either such a link
must be made or the structure must be replaced by another one. Replacing is
not a very good option since it would cause other problems, providing the 
Interface/Adapter-index for the UNICAST_ADDRESS structure is IMHO a better way.

The class "Win32UnicastIPAddressInformation" takes a IP_ADAPTER_UNICAST_ADDRESS 
in the constructor, what is missing to enable IPv4Mask parameter is the 
"IFIndex". Adding the interface index parameter would allow IPv4Mask to be set
correctly.

Proposed changes:
-----------------
In: IPInterfaceProperties.cs

Property: UnicastAddresses 
Add the IfIndex parameter to Win32FromUnicast, like:
        UnicastIPAddressInformationImplCollection.Win32FromUnicast
(ainfo.Index, addr.FirstUnicastAddress); }

========

In: UnicastIPAddressInformationCollection.cs

Pass interface index to "Win32FromUnicast" in function "Win32FromUnicast",
like:
Win32FromUnicast (int IfIndex, IntPtr ptr);

And in the implementation change from:
c.Add (new Win32UnicastIPAddressInformation (a));
to:
c.Add (new Win32UnicastIPAddressInformation (IfIndex, a));

=======
In: UnicastIPAddressInformation.cs

The constructor for the Win32UnicastIPAddressInformation would then be:
public Win32UnicastIPAddressInformation (int IfIndex,
Win32_IP_ADAPTER_UNICAST_ADDRESS info)
{
    this.IfIndex = IfIndex;
        this.info = info;
}


And the Mask can be fetched, instead of:

                // FIXME: where to get this info?
                public override IPAddress IPv4Mask {
                        get { throw new NotImplementedException (); }
                }

we get (Note: Not Tested nor Compiled!!):
public override IPAddress IPv4Mask 
        {
                        get
            {
                Win32_IP_ADAPTER_INFO ai =
Win32NetworkInterface2.GetAdapterInfoByIndex (IfIndex);
                unsafe
                {
                    p = ai.IPAddressList; 
                    while (p!=null)
                    {
                        Win32_IP_ADDR_STRING addr = (Win32_IP_ADDR_STRING)
Marshal.PtrToStructure (p, typeof (Win32_IP_ADDR_STRING));
                        if (addr.IpAddress == info.Address.GetIPAddress())
                        {
                            return new IPAddress(addr.IpMask);
                        }
                        p = addr.Next;
                    }
                    // Or whatever it should be...
                    return null;                                                
                }
            }
                }


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list