Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Interop.cs
Go to the documentation of this file.
1using System;
9
10internal static class Interop
11{
12 internal static class IpHlpApi
13 {
14 internal struct IPOptions
15 {
16 internal byte ttl;
17
18 internal byte tos;
19
20 internal byte flags;
21
22 internal byte optionsSize;
23
25
27 {
28 ttl = 128;
29 tos = 0;
30 flags = 0;
31 optionsSize = 0;
33 if (options != null)
34 {
35 ttl = (byte)options.Ttl;
36 if (options.DontFragment)
37 {
38 flags = 2;
39 }
40 }
41 }
42 }
43
44 internal struct IcmpEchoReply
45 {
46 internal uint address;
47
48 internal uint status;
49
50 internal uint roundTripTime;
51
52 internal ushort dataSize;
53
54 internal ushort reserved;
55
56 internal IntPtr data;
57
59 }
60
61 [StructLayout(LayoutKind.Sequential, Pack = 1)]
62 internal struct Ipv6Address
63 {
64 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
65 internal byte[] Goo;
66
67 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
68 internal byte[] Address;
69
70 internal uint ScopeID;
71 }
72
73 internal struct Icmp6EchoReply
74 {
76
77 internal uint Status;
78
79 internal uint RoundTripTime;
80
81 internal IntPtr data;
82 }
83
85 {
87 : base(ownsHandle: true)
88 {
89 }
90
91 protected override bool ReleaseHandle()
92 {
93 return IcmpCloseHandle(handle);
94 }
95 }
96
97 [DllImport("iphlpapi.dll", SetLastError = true)]
98 internal static extern SafeCloseIcmpHandle IcmpCreateFile();
99
100 [DllImport("iphlpapi.dll", SetLastError = true)]
101 internal static extern SafeCloseIcmpHandle Icmp6CreateFile();
102
103 [DllImport("iphlpapi.dll", SetLastError = true)]
104 internal static extern bool IcmpCloseHandle(IntPtr handle);
105
106 [DllImport("iphlpapi.dll", SetLastError = true)]
107 internal static extern uint IcmpSendEcho2(SafeCloseIcmpHandle icmpHandle, SafeWaitHandle Event, IntPtr apcRoutine, IntPtr apcContext, uint ipAddress, [In] SafeLocalAllocHandle data, ushort dataSize, ref IPOptions options, SafeLocalAllocHandle replyBuffer, uint replySize, uint timeout);
108
109 [DllImport("iphlpapi.dll", SetLastError = true)]
110 internal static extern uint Icmp6SendEcho2(SafeCloseIcmpHandle icmpHandle, SafeWaitHandle Event, IntPtr apcRoutine, IntPtr apcContext, byte[] sourceSocketAddress, byte[] destSocketAddress, [In] SafeLocalAllocHandle data, ushort dataSize, ref IPOptions options, SafeLocalAllocHandle replyBuffer, uint replySize, uint timeout);
111 }
112
113 internal static class Winsock
114 {
115 [StructLayout(LayoutKind.Sequential, Size = 408)]
116 private struct WSAData
117 {
118 }
119
120 private static int s_initialized;
121
122 [DllImport("ws2_32.dll", ExactSpelling = true, SetLastError = true)]
123 internal static extern SocketError closesocket([In] IntPtr socketHandle);
124
125 [DllImport("ws2_32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
126 internal static extern IntPtr WSASocketW([In] AddressFamily addressFamily, [In] System.Net.Internals.SocketType socketType, [In] int protocolType, [In] IntPtr protocolInfo, [In] int group, [In] int flags);
127
128 internal static void EnsureInitialized()
129 {
130 if (s_initialized == 0)
131 {
132 Initialize();
133 }
134 unsafe static void Initialize()
135 {
136 Unsafe.SkipInit(out WSAData wSAData);
137 SocketError socketError = WSAStartup(514, &wSAData);
138 if (socketError != 0)
139 {
140 throw new SocketException((int)socketError);
141 }
142 if (Interlocked.CompareExchange(ref s_initialized, 1, 0) != 0)
143 {
144 socketError = WSACleanup();
145 }
146 }
147 }
148
149 [DllImport("ws2_32.dll")]
150 private unsafe static extern SocketError WSAStartup(short wVersionRequested, WSAData* lpWSAData);
151
152 [DllImport("ws2_32.dll")]
153 private static extern SocketError WSACleanup();
154 }
155}
static SafeCloseIcmpHandle Icmp6CreateFile()
static SafeCloseIcmpHandle IcmpCreateFile()
static uint IcmpSendEcho2(SafeCloseIcmpHandle icmpHandle, SafeWaitHandle Event, IntPtr apcRoutine, IntPtr apcContext, uint ipAddress, [In] SafeLocalAllocHandle data, ushort dataSize, ref IPOptions options, SafeLocalAllocHandle replyBuffer, uint replySize, uint timeout)
static uint Icmp6SendEcho2(SafeCloseIcmpHandle icmpHandle, SafeWaitHandle Event, IntPtr apcRoutine, IntPtr apcContext, byte[] sourceSocketAddress, byte[] destSocketAddress, [In] SafeLocalAllocHandle data, ushort dataSize, ref IPOptions options, SafeLocalAllocHandle replyBuffer, uint replySize, uint timeout)
static bool IcmpCloseHandle(IntPtr handle)
static SocketError WSACleanup()
static int s_initialized
Definition Interop.cs:67
static SocketError closesocket([In] IntPtr socketHandle)
static void EnsureInitialized()
Definition Interop.cs:128
static IntPtr WSASocketW([In] AddressFamily addressFamily, [In] System.Net.Internals.SocketType socketType, [In] int protocolType, [In] IntPtr protocolInfo, [In] int group, [In] int flags)
static unsafe SocketError WSAStartup(short wVersionRequested, WSAData *lpWSAData)
static int CompareExchange(ref int location1, int value, int comparand)
IPOptions(PingOptions options)
Definition Interop.cs:26
static readonly IntPtr Zero
Definition IntPtr.cs:18