Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SystemNetworkInterface.cs
Go to the documentation of this file.
5
7
9{
10 private readonly string _name;
11
12 private readonly string _id;
13
14 private readonly string _description;
15
16 private readonly byte[] _physicalAddress;
17
18 private readonly uint _addressLength;
19
20 private readonly NetworkInterfaceType _type;
21
23
24 private readonly long _speed;
25
26 private readonly uint _index;
27
28 private readonly uint _ipv6Index;
29
30 private readonly global::Interop.IpHlpApi.AdapterFlags _adapterFlags;
31
33
35
37
38 public override string Id => _id;
39
40 public override string Name => _name;
41
42 public override string Description => _description;
43
45
47
48 public override long Speed => _speed;
49
50 public override bool IsReceiveOnly => (_adapterFlags & global::Interop.IpHlpApi.AdapterFlags.ReceiveOnly) > (global::Interop.IpHlpApi.AdapterFlags)0;
51
52 public override bool SupportsMulticast => (_adapterFlags & global::Interop.IpHlpApi.AdapterFlags.NoMulticast) == 0;
53
55 {
57 int index;
58 int bestInterfaceEx = (int)global::Interop.IpHlpApi.GetBestInterfaceEx(socketAddress.Buffer, out index);
59 if (bestInterfaceEx != 0)
60 {
62 }
63 return index;
64 }
65
66 internal static bool InternalGetIsNetworkAvailable()
67 {
68 try
69 {
73 {
74 if (networkInterface.OperationalStatus == OperationalStatus.Up && networkInterface.NetworkInterfaceType != NetworkInterfaceType.Tunnel && networkInterface.NetworkInterfaceType != NetworkInterfaceType.Loopback)
75 {
76 return true;
77 }
78 }
79 }
80 catch (NetworkInformationException message)
81 {
82 if (System.Net.NetEventSource.Log.IsEnabled())
83 {
84 System.Net.NetEventSource.Error(null, message, "InternalGetIsNetworkAvailable");
85 }
86 }
87 return false;
88 }
89
91 {
93 uint outBufLen = 0u;
94 ref readonly global::Interop.IpHlpApi.FIXED_INFO fixedInfo = ref System.Net.NetworkInformation.HostInformationPal.FixedInfo;
96 global::Interop.IpHlpApi.GetAdaptersAddressesFlags flags = global::Interop.IpHlpApi.GetAdaptersAddressesFlags.IncludeWins | global::Interop.IpHlpApi.GetAdaptersAddressesFlags.IncludeGateways;
97 uint adaptersAddresses = global::Interop.IpHlpApi.GetAdaptersAddresses(family, (uint)flags, IntPtr.Zero, IntPtr.Zero, ref outBufLen);
98 while (true)
99 {
100 switch (adaptersAddresses)
101 {
102 case 111u:
103 {
105 try
106 {
107 adaptersAddresses = global::Interop.IpHlpApi.GetAdaptersAddresses(family, (uint)flags, IntPtr.Zero, intPtr, ref outBufLen);
108 if (adaptersAddresses == 0)
109 {
111 while (intPtr2 != IntPtr.Zero)
112 {
113 global::Interop.IpHlpApi.IpAdapterAddresses ipAdapterAddresses = Marshal.PtrToStructure<global::Interop.IpHlpApi.IpAdapterAddresses>(intPtr2);
116 }
117 }
118 }
119 finally
120 {
122 }
123 break;
124 }
125 case 87u:
126 case 232u:
127 return Array.Empty<SystemNetworkInterface>();
128 default:
130 case 0u:
131 return list.ToArray();
132 }
133 }
134 }
135
136 internal SystemNetworkInterface(in global::Interop.IpHlpApi.FIXED_INFO fixedInfo, in global::Interop.IpHlpApi.IpAdapterAddresses ipAdapterAddresses)
137 {
138 _id = ipAdapterAddresses.AdapterName;
139 _name = ipAdapterAddresses.friendlyName;
140 _description = ipAdapterAddresses.description;
143 _addressLength = ipAdapterAddresses.addressLength;
145 _operStatus = ipAdapterAddresses.operStatus;
146 _speed = (long)ipAdapterAddresses.receiveLinkSpeed;
147 _ipv6Index = ipAdapterAddresses.ipv6Index;
150 }
151
153 {
154 byte[] array = new byte[_addressLength];
156 return new PhysicalAddress(array);
157 }
158
160 {
162 }
163
168
170 {
172 }
173
175 {
176 if (networkInterfaceComponent == NetworkInterfaceComponent.IPv6 && (_adapterFlags & global::Interop.IpHlpApi.AdapterFlags.IPv6Enabled) != 0)
177 {
178 return true;
179 }
180 if (networkInterfaceComponent == NetworkInterfaceComponent.IPv4 && (_adapterFlags & global::Interop.IpHlpApi.AdapterFlags.IPv4Enabled) != 0)
181 {
182 return true;
183 }
184 return false;
185 }
186}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
static readonly IPAddress IPv6Loopback
Definition IPAddress.cs:33
static readonly IPAddress Loopback
Definition IPAddress.cs:21
static readonly System.Net.NetEventSource Log
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)
static ref readonly global::Interop.IpHlpApi.FIXED_INFO FixedInfo
override bool Supports(NetworkInterfaceComponent networkInterfaceComponent)
SystemNetworkInterface(in global::Interop.IpHlpApi.FIXED_INFO fixedInfo, in global::Interop.IpHlpApi.IpAdapterAddresses ipAdapterAddresses)
readonly SystemIPInterfaceProperties _interfaceProperties
readonly global::Interop.IpHlpApi.AdapterFlags _adapterFlags
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