PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/APIMonLib/Hooks/ws2_32.dll/WS2_32Support.cs

#
C# | 326 lines | 143 code | 28 blank | 155 comment | 0 complexity | aa2fca18c2245ef847e9d32e17dcd081 MD5 | raw file
Possible License(s): LGPL-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Runtime.InteropServices;
  5. namespace APIMonLib.Hooks.ws2_32.dll
  6. {
  7. public class WS2_32Support {
  8. public enum ADDRESS_FAMILIES : short {
  9. /// <summary>
  10. /// Unspecified [value = 0].
  11. /// </summary>
  12. AF_UNSPEC = 0,
  13. /// <summary>
  14. /// Local to host (pipes, portals) [value = 1].
  15. /// </summary>
  16. AF_UNIX = 1,
  17. /// <summary>
  18. /// Internetwork: UDP, TCP, etc [value = 2].
  19. /// </summary>
  20. AF_INET = 2,
  21. /// <summary>
  22. /// Arpanet imp addresses [value = 3].
  23. /// </summary>
  24. AF_IMPLINK = 3,
  25. /// <summary>
  26. /// Pup protocols: e.g. BSP [value = 4].
  27. /// </summary>
  28. AF_PUP = 4,
  29. /// <summary>
  30. /// Mit CHAOS protocols [value = 5].
  31. /// </summary>
  32. AF_CHAOS = 5,
  33. /// <summary>
  34. /// XEROX NS protocols [value = 6].
  35. /// </summary>
  36. AF_NS = 6,
  37. /// <summary>
  38. /// IPX protocols: IPX, SPX, etc [value = 6].
  39. /// </summary>
  40. AF_IPX = 6,
  41. /// <summary>
  42. /// ISO protocols [value = 7].
  43. /// </summary>
  44. AF_ISO = 7,
  45. /// <summary>
  46. /// OSI is ISO [value = 7].
  47. /// </summary>
  48. AF_OSI = 7,
  49. /// <summary>
  50. /// european computer manufacturers [value = 8].
  51. /// </summary>
  52. AF_ECMA = 8,
  53. /// <summary>
  54. /// datakit protocols [value = 9].
  55. /// </summary>
  56. AF_DATAKIT = 9,
  57. /// <summary>
  58. /// CCITT protocols, X.25 etc [value = 10].
  59. /// </summary>
  60. AF_CCITT = 10,
  61. /// <summary>
  62. /// IBM SNA [value = 11].
  63. /// </summary>
  64. AF_SNA = 11,
  65. /// <summary>
  66. /// DECnet [value = 12].
  67. /// </summary>
  68. AF_DECnet = 12,
  69. /// <summary>
  70. /// Direct data link interface [value = 13].
  71. /// </summary>
  72. AF_DLI = 13,
  73. /// <summary>
  74. /// LAT [value = 14].
  75. /// </summary>
  76. AF_LAT = 14,
  77. /// <summary>
  78. /// NSC Hyperchannel [value = 15].
  79. /// </summary>
  80. AF_HYLINK = 15,
  81. /// <summary>
  82. /// AppleTalk [value = 16].
  83. /// </summary>
  84. AF_APPLETALK = 16,
  85. /// <summary>
  86. /// NetBios-style addresses [value = 17].
  87. /// </summary>
  88. AF_NETBIOS = 17,
  89. /// <summary>
  90. /// VoiceView [value = 18].
  91. /// </summary>
  92. AF_VOICEVIEW = 18,
  93. /// <summary>
  94. /// Protocols from Firefox [value = 19].
  95. /// </summary>
  96. AF_FIREFOX = 19,
  97. /// <summary>
  98. /// Somebody is using this! [value = 20].
  99. /// </summary>
  100. AF_UNKNOWN1 = 20,
  101. /// <summary>
  102. /// Banyan [value = 21].
  103. /// </summary>
  104. AF_BAN = 21,
  105. /// <summary>
  106. /// Native ATM Services [value = 22].
  107. /// </summary>
  108. AF_ATM = 22,
  109. /// <summary>
  110. /// Internetwork Version 6 [value = 23].
  111. /// </summary>
  112. AF_INET6 = 23,
  113. /// <summary>
  114. /// Microsoft Wolfpack [value = 24].
  115. /// </summary>
  116. AF_CLUSTER = 24,
  117. /// <summary>
  118. /// IEEE 1284.4 WG AF [value = 25].
  119. /// </summary>
  120. AF_12844 = 25,
  121. /// <summary>
  122. /// IrDA [value = 26].
  123. /// </summary>
  124. AF_IRDA = 26,
  125. /// <summary>
  126. /// Network Designers OSI &amp; gateway enabled protocols [value = 28].
  127. /// </summary>
  128. AF_NETDES = 28,
  129. /// <summary>
  130. /// [value = 29].
  131. /// </summary>
  132. AF_TCNPROCESS = 29,
  133. /// <summary>
  134. /// [value = 30].
  135. /// </summary>
  136. AF_TCNMESSAGE = 30,
  137. /// <summary>
  138. /// [value = 31].
  139. /// </summary>
  140. AF_ICLFXBM = 31
  141. }
  142. public enum SOCKET_TYPE : short {
  143. /// <summary>
  144. /// stream socket
  145. /// </summary>
  146. SOCK_STREAM = 1,
  147. /// <summary>
  148. /// datagram socket
  149. /// </summary>
  150. SOCK_DGRAM = 2,
  151. /// <summary>
  152. /// raw-protocol interface
  153. /// </summary>
  154. SOCK_RAW = 3,
  155. /// <summary>
  156. /// reliably-delivered message
  157. /// </summary>
  158. SOCK_RDM = 4,
  159. /// <summary>
  160. /// sequenced packet stream
  161. /// </summary>
  162. SOCK_SEQPACKET = 5
  163. }
  164. public enum PROTOCOL : short {//dummy for IP
  165. IPPROTO_IP = 0,
  166. //control message protocol
  167. IPPROTO_ICMP = 1,
  168. //internet group management protocol
  169. IPPROTO_IGMP = 2,
  170. //gateway^2 (deprecated)
  171. IPPROTO_GGP = 3,
  172. //tcp
  173. IPPROTO_TCP = 6,
  174. //pup
  175. IPPROTO_PUP = 12,
  176. //user datagram protocol
  177. IPPROTO_UDP = 17,
  178. //xns idp
  179. IPPROTO_IDP = 22,
  180. //IPv6
  181. IPPROTO_IPV6 = 41,
  182. //UNOFFICIAL net disk proto
  183. IPPROTO_ND = 77,
  184. IPPROTO_ICLFXBM = 78,
  185. //raw IP packet
  186. IPPROTO_RAW = 255,
  187. IPPROTO_MAX = 256
  188. }
  189. public enum OPTION_FLAGS_PER_SOCKET : short {
  190. // turn on debugging info recording
  191. SO_DEBUG = 0x0001,
  192. // socket has had listen()
  193. SO_ACCEPTCONN = 0x0002,
  194. // allow local address reuse
  195. SO_REUSEADDR = 0x0004,
  196. // keep connections alive
  197. SO_KEEPALIVE = 0x0008,
  198. // just use interface addresses
  199. SO_DONTROUTE = 0x0010,
  200. // permit sending of broadcast msgs
  201. SO_BROADCAST = 0x0020,
  202. // bypass hardware when possible
  203. SO_USELOOPBACK = 0x0040,
  204. // linger on close if data present
  205. SO_LINGER = 0x0080,
  206. // leave received OOB data in line
  207. SO_OOBINLINE = 0x0100,
  208. SO_DONTLINGER = (int)(~SO_LINGER),
  209. // disallow local address reuse
  210. SO_EXCLUSIVEADDRUSE = ((int)(~SO_REUSEADDR)),
  211. ///*
  212. // * Additional options.
  213. // */
  214. // send buffer size
  215. SO_SNDBUF = 0x1001,
  216. // receive buffer size
  217. SO_RCVBUF = 0x1002,
  218. // send low-water mark
  219. SO_SNDLOWAT = 0x1003,
  220. // receive low-water mark
  221. SO_RCVLOWAT = 0x1004,
  222. // send timeout
  223. SO_SNDTIMEO = 0x1005,
  224. // receive timeout
  225. SO_RCVTIMEO = 0x1006,
  226. // get error status and clear
  227. SO_ERROR = 0x1007,
  228. // get socket type
  229. SO_TYPE = 0x1008,
  230. ///*
  231. // * WinSock 2 extension -- new options
  232. // */
  233. // ID of a socket group
  234. SO_GROUP_ID = 0x2001,
  235. // the relative priority within a group
  236. SO_GROUP_PRIORITY = 0x2002,
  237. // maximum message size
  238. SO_MAX_MSG_SIZE = 0x2003,
  239. // WSAPROTOCOL_INFOA structure
  240. SO_PROTOCOL_INFOA = 0x2004,
  241. // WSAPROTOCOL_INFOW structure
  242. SO_PROTOCOL_INFOW = 0x2005,
  243. // configuration info for service provider
  244. PVD_CONFIG = 0x3001,
  245. // enable true conditional accept: connection is not ack-ed to the other side until conditional function returns CF_ACCEPT
  246. SO_CONDITIONAL_ACCEPT = 0x3002
  247. }
  248. public const int SOCKET_ERROR = -1;
  249. public const int INVALID_SOCKET = -1;
  250. [DllImport("ws2_32.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  251. public static extern IntPtr WSASocketW(ADDRESS_FAMILIES af, SOCKET_TYPE socket_type, PROTOCOL protocol,
  252. IntPtr lpProtocolInfo, Int32 group, OPTION_FLAGS_PER_SOCKET dwFlags);
  253. [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
  254. public delegate IntPtr DWSASocketW(ADDRESS_FAMILIES af, SOCKET_TYPE socket_type, PROTOCOL protocol,
  255. IntPtr lpProtocolInfo, Int32 group, OPTION_FLAGS_PER_SOCKET dwFlags);
  256. [DllImport("ws2_32.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  257. public static extern int WSAConnect(IntPtr socket, IntPtr lpSockAddr, int namelen, IntPtr lpCallerData, IntPtr lpCalleeData, IntPtr lpSQOS, IntPtr lpGQOS);
  258. [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
  259. public delegate int DWSAConnect(IntPtr socket, IntPtr lpSockAddr, int namelen, IntPtr lpCallerData, IntPtr lpCalleeData, IntPtr lpSQOS, IntPtr lpGQOS);
  260. [DllImport("ws2_32.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  261. public static extern int connect(IntPtr socket, IntPtr lpSockAddr, int namelen);
  262. [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
  263. public delegate int Dconnect(IntPtr socket, IntPtr lpSockAddr, int namelen);
  264. [DllImport("ws2_32.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  265. public static extern int bind(IntPtr socket, IntPtr lpSockAddr, int namelen);
  266. [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
  267. public delegate int Dbind(IntPtr socket, IntPtr lpSockAddr, int namelen);
  268. [DllImport("ws2_32.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  269. public static extern int listen(IntPtr socket, int backlog);
  270. [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
  271. public delegate int Dlisten(IntPtr socket, int backlog);
  272. [DllImport("ws2_32.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  273. public static extern IntPtr WSAAccept(IntPtr socket, IntPtr lpSockAddr, IntPtr int_addrlen, IntPtr lpConditionProc, Int32 dwCallbackData);
  274. [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
  275. public delegate IntPtr DWSAAccept(IntPtr socket, IntPtr lpSockAddr, IntPtr int_addrlen, IntPtr lpConditionProc, Int32 dwCallbackData);
  276. [DllImport("ws2_32.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  277. public static extern IntPtr accept(IntPtr socket, IntPtr lpSockAddr, IntPtr int_addrlen);
  278. [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
  279. public delegate IntPtr Daccept(IntPtr socket, IntPtr lpSockAddr, IntPtr int_addrlen);
  280. [DllImport("ws2_32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  281. public static extern int send(IntPtr socket, IntPtr lpBuffer, int buflen, int flags);
  282. [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
  283. public delegate int Dsend(IntPtr socket, IntPtr lpBuffer, int buflen, int flags);
  284. [StructLayout(LayoutKind.Sequential)]
  285. public struct WSABUF {
  286. public uint len;
  287. public IntPtr buf;
  288. }
  289. [DllImport("ws2_32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  290. public static extern int WSASend(IntPtr socket, IntPtr lpBuffers, Int32 dwBufferCount, ref Int32 lpNumberOfBytesSent, int flags, IntPtr lpOverlapped, IntPtr lpCompletionRoutine);
  291. [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
  292. public delegate int DWSASend(IntPtr socket, IntPtr lpBuffers, Int32 dwBufferCount, ref Int32 lpNumberOfBytesSent, int flags, IntPtr lpOverlapped, IntPtr lpCompletionRoutine);
  293. [DllImport("ws2_32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  294. public static extern int WSAGetLastError();
  295. [DllImport("ws2_32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
  296. public static extern void WSASetLastError(int iError);
  297. }
  298. }