예제 #1
0
        public static Interop.FIXED_INFO GetFixedInfo()
        {
            uint pOutBufLen = 0;

            Interop.FIXED_INFO fixedInfo = new Interop.FIXED_INFO();
            uint networkParams           = Interop.GetNetworkParams(SafeLocalAllocHandle.InvalidHandle, ref pOutBufLen);

            while ((int)networkParams == 111)
            {
                SafeLocalAllocHandle pFixedInfo;
                using (pFixedInfo = Kernel32.LocalAlloc(0, (UIntPtr)pOutBufLen))
                {
                    if (pFixedInfo.IsInvalid)
                    {
                        throw new OutOfMemoryException();
                    }
                    networkParams = Interop.GetNetworkParams(pFixedInfo, ref pOutBufLen);
                    if ((int)networkParams == 0)
                    {
                        fixedInfo = Marshal.PtrToStructure <Interop.FIXED_INFO>(pFixedInfo.DangerousGetHandle());
                    }
                }
            }
            if ((int)networkParams != 0)
            {
                throw new Win32Exception((int)networkParams);
            }
            return(fixedInfo);
        }
예제 #2
0
        internal SystemNetworkInterface(Interop.FIXED_INFO fixedInfo, Interop.IpAdapterAddresses ipAdapterAddresses)
        {
            this._id              = ipAdapterAddresses.AdapterName;
            this._name            = ipAdapterAddresses.friendlyName;
            this._description     = ipAdapterAddresses.description;
            this._index           = ipAdapterAddresses.index;
            this._physicalAddress = ipAdapterAddresses.address;
            this._addressLength   = ipAdapterAddresses.addressLength;
            this._type            = ipAdapterAddresses.type;
            this._operStatus      = ipAdapterAddresses.operStatus;
            this._speed           = (long)ipAdapterAddresses.receiveLinkSpeed;
            this._ipv6Index       = ipAdapterAddresses.ipv6Index;
            this._adapterFlags    = ipAdapterAddresses.flags;

            return;

            Type     typeInAssem     = typeof(System.Net.NetworkInformation.DuplicateAddressDetectionState);
            Assembly assem           = typeInAssem.Assembly;
            Type     fixedInfType    = assem.GetType("System.Net.NetworkInformation.FIXED_INFO");
            var      fixedInfInst    = Activator.CreateInstance(fixedInfType);
            var      fields          = fixedInfType.GetFields((BindingFlags)0xffff);
            Type     myFixedInfoType = fixedInfo.GetType();

            FieldInfo[] myFields = myFixedInfoType.GetFields((BindingFlags)0xffff);
            foreach (FieldInfo fieldInfo in fields)
            {
                var match = myFields.Single(info => info.Name == fieldInfo.Name);
                fieldInfo.SetValue(fixedInfInst, match.GetValue(fixedInfo));
            }

            Type res    = assem.GetType("System.Net.NetworkInformation.SystemIPInterfaceProperties");
            var  consts = res.GetConstructors((BindingFlags)0xffff);
            var  item   = consts[0].Invoke(new object[] { fixedInfo, ipAdapterAddresses });
            //this.interfaceProperties = new SystemIPInterfaceProperties(fixedInfo, ipAdapterAddresses);
        }