Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SystemIPv4InterfaceProperties.cs
Go to the documentation of this file.
2
4
6{
7 private readonly bool _haveWins;
8
9 private readonly bool _dhcpEnabled;
10
11 private readonly bool _routingEnabled;
12
13 private readonly uint _index;
14
15 private readonly uint _mtu;
16
17 private bool _autoConfigEnabled;
18
19 private bool _autoConfigActive;
20
21 public override bool UsesWins => _haveWins;
22
23 public override bool IsDhcpEnabled => _dhcpEnabled;
24
25 public override bool IsForwardingEnabled => _routingEnabled;
26
28
30
31 public override int Mtu => (int)_mtu;
32
33 public override int Index => (int)_index;
34
35 internal SystemIPv4InterfaceProperties(global::Interop.IpHlpApi.FIXED_INFO fixedInfo, global::Interop.IpHlpApi.IpAdapterAddresses ipAdapterAddresses)
36 {
37 _index = ipAdapterAddresses.index;
38 _routingEnabled = fixedInfo.enableRouting;
39 _dhcpEnabled = (ipAdapterAddresses.flags & global::Interop.IpHlpApi.AdapterFlags.DhcpEnabled) != 0;
40 _haveWins = ipAdapterAddresses.firstWinsServerAddress != IntPtr.Zero;
41 _mtu = ipAdapterAddresses.mtu;
42 GetPerAdapterInfo(ipAdapterAddresses.index);
43 }
44
45 private void GetPerAdapterInfo(uint index)
46 {
47 if (index == 0)
48 {
49 return;
50 }
51 uint pOutBufLen = 0u;
52 uint perAdapterInfo = global::Interop.IpHlpApi.GetPerAdapterInfo(index, IntPtr.Zero, ref pOutBufLen);
53 while (true)
54 {
55 switch (perAdapterInfo)
56 {
57 case 111u:
58 {
59 IntPtr intPtr = Marshal.AllocHGlobal((int)pOutBufLen);
60 try
61 {
62 perAdapterInfo = global::Interop.IpHlpApi.GetPerAdapterInfo(index, intPtr, ref pOutBufLen);
63 if (perAdapterInfo == 0)
64 {
65 global::Interop.IpHlpApi.IpPerAdapterInfo ipPerAdapterInfo = Marshal.PtrToStructure<global::Interop.IpHlpApi.IpPerAdapterInfo>(intPtr);
66 _autoConfigEnabled = ipPerAdapterInfo.autoconfigEnabled;
67 _autoConfigActive = ipPerAdapterInfo.autoconfigActive;
68 }
69 }
70 finally
71 {
72 Marshal.FreeHGlobal(intPtr);
73 }
74 break;
75 }
76 default:
77 throw new NetworkInformationException((int)perAdapterInfo);
78 case 0u:
79 return;
80 }
81 }
82 }
83}
SystemIPv4InterfaceProperties(global::Interop.IpHlpApi.FIXED_INFO fixedInfo, global::Interop.IpHlpApi.IpAdapterAddresses ipAdapterAddresses)
static void FreeHGlobal(IntPtr hglobal)
Definition Marshal.cs:1680
static ? object PtrToStructure(IntPtr ptr, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type structureType)
Definition Marshal.cs:1164
static IntPtr AllocHGlobal(int cb)
Definition Marshal.cs:625
static readonly IntPtr Zero
Definition IntPtr.cs:18