Ejemplo n.º 1
0
 int ISocketsDriver.UpdateAdapterConfiguration(uint interfaceIndex, uint updateFlags, ref NetworkAdapterConfiguration config)
 {
     //CLR_E_FAIL.  Update with better error?
     unchecked { return((int)(uint)CLR_ERRORCODE.CLR_E_FAIL); }
 }
Ejemplo n.º 2
0
        int ISocketsDriver.LoadAdapterConfiguration(uint interfaceIndex, ref NetworkAdapterConfiguration config)
        {
            NetworkInterface        networkInterface = NetworkInterface.GetAllNetworkInterfaces()[interfaceIndex];
            IPInterfaceProperties   props            = networkInterface.GetIPProperties();
            IPv4InterfaceProperties ipv4props        = null;

            try
            {
                ipv4props = props.GetIPv4Properties();
            }
            catch (NetworkInformationException)
            {
            }


            if (ipv4props != null)
            {
                if (props.IsDynamicDnsEnabled)
                {
                    config.flags |= NetworkAdapterConfiguration.FLAGS_DYNAMIC_DNS;
                }

                if (ipv4props.IsDhcpEnabled)
                {
                    config.flags |= NetworkAdapterConfiguration.FLAGS_DHCP;
                }

                for (int iAddress = 0; iAddress < props.UnicastAddresses.Count; iAddress++)
                {
                    UnicastIPAddressInformation unicastAddress = props.UnicastAddresses[iAddress];

                    if (IsIPAddressIPv4(unicastAddress.Address))
                    {
                        config.ipaddr     = this.IPAddressToUint(unicastAddress.Address);
                        config.subnetmask = this.IPAddressToUint(unicastAddress.IPv4Mask);

                        break;
                    }
                }

                for (int iAddress = 0; iAddress < props.GatewayAddresses.Count; iAddress++)
                {
                    GatewayIPAddressInformation gatewayAddress = props.GatewayAddresses[iAddress];

                    if (IsIPAddressIPv4(gatewayAddress.Address))
                    {
                        config.gateway = this.IPAddressToUint(gatewayAddress.Address);

                        break;
                    }
                }

                int dnsServerIndex = 0;
                for (int iAddress = 0; iAddress < props.DnsAddresses.Count && dnsServerIndex < 2; iAddress++)
                {
                    IPAddress address = props.DnsAddresses[iAddress];

                    if (IsIPAddressIPv4(address))
                    {
                        switch (dnsServerIndex)
                        {
                        case 0:
                            config.dnsServer1 = this.IPAddressToUint(address);
                            break;

                        case 1:
                            config.dnsServer2 = this.IPAddressToUint(address);
                            break;
                        }

                        dnsServerIndex++;
                    }
                }

                PhysicalAddress macAddress = networkInterface.GetPhysicalAddress();
                byte[]          macBytes   = macAddress.GetAddressBytes();

                config.networkInterfaceType = (uint)networkInterface.NetworkInterfaceType;
                config.networkAddressLen    = (uint)macBytes.Length;

                unsafe
                {
                    fixed(byte *p = config.networkAddressBuf)
                    {
                        Marshal.Copy(macBytes, 0, new IntPtr(p), macBytes.Length);
                    }
                }
            }

            return(0);
        }