{"action":"created","issue":{"url":"https://api.github.com/repos/basil00/Divert/issues/55","labels_url":"https://api.github.com/repos/basil00/Divert/issues/55/labels{/name}","comments_url":"https://api.github.com/repos/basil00/Divert/issues/55/comments","events_url":"https://api.github.com/repos/basil00/Divert/issues/55/events","html_url":"https://github.com/basil00/Divert/issues/55","id":117117151,"number":55,"title":"C# Wrapper","user":{"login":"fahminlb33","id":8360880,"avatar_url":"https://avatars.githubusercontent.com/u/8360880?v=3","gravatar_id":"","url":"https://api.github.com/users/fahminlb33","html_url":"https://github.com/fahminlb33","followers_url":"https://api.github.com/users/fahminlb33/followers","following_url":"https://api.github.com/users/fahminlb33/following{/other_user}","gists_url":"https://api.github.com/users/fahminlb33/gists{/gist_id}","starred_url":"https://api.github.com/users/fahminlb33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fahminlb33/subscriptions","organizations_url":"https://api.github.com/users/fahminlb33/orgs","repos_url":"https://api.github.com/users/fahminlb33/repos","events_url":"https://api.github.com/users/fahminlb33/events{/privacy}","received_events_url":"https://api.github.com/users/fahminlb33/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2015-11-16T12:52:55Z","updated_at":"2015-11-18T04:48:05Z","closed_at":null,"body":"I'm wrapping this library in C#. I have trouble with WinDivertRecv method.\r\n\r\nI always get 0 handle in ```packData``` .\r\n\r\n```\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\nusing System.Runtime.InteropServices;\r\n\r\nnamespace ConsoleApplication2\r\n{\r\n    class Program\r\n    {\r\n        const int MAXBUF = 0xFFFF;\r\n\r\n        static void Main(string[] args)\r\n        {\r\n            //Open handle\r\n            IntPtr capHandle = NativeMethods.WinDivertOpen(\"true\", WINDIVERT_LAYER.WINDIVERT_LAYER_NETWORK, 0, NativeConstants.WINDIVERT_FLAG_SNIFF);\r\n            if (capHandle.ToInt64() < 0)\r\n            {\r\n                Console.WriteLine(\"Handle error.\");\r\n                Console.Read();\r\n                Environment.Exit(0);\r\n            }\r\n\r\n            //Set queue length\r\n            if (!NativeMethods.WinDivertSetParam(capHandle, WINDIVERT_PARAM.WINDIVERT_PARAM_QUEUE_LEN, 8192))\r\n            {\r\n                Console.WriteLine(\"Can't set queue length.\");\r\n                Console.Read();\r\n                Environment.Exit(0);\r\n            }\r\n\r\n            //Set queue time\r\n            if (!NativeMethods.WinDivertSetParam(capHandle, WINDIVERT_PARAM.WINDIVERT_PARAM_QUEUE_TIME, 2048))\r\n            {\r\n                Console.WriteLine(\"Can't set queue time.\");\r\n                Console.Read();\r\n                Environment.Exit(0);\r\n            }\r\n\r\n            //Capture packets\r\n            while (true)\r\n            {\r\n                //Receive packet\r\n                IntPtr recvPacket = IntPtr.Zero;\r\n                IntPtr recvAddr = IntPtr.Zero;\r\n                IntPtr recvLength = IntPtr.Zero;\r\n                if (!NativeMethods.WinDivertRecv(capHandle, ref recvPacket, (uint)IntPtr.Size, ref recvAddr, ref recvLength))\r\n                {\r\n                    //Console.WriteLine(\"Failed to read packet.\");\r\n                    continue;\r\n                }\r\n\r\n                Console.WriteLine(\"==============================================\");\r\n\r\n                //Copy data into managed data\r\n                byte[] packData = new byte[MAXBUF];\r\n                int packLength = recvLength.ToInt32(); //Marshal.ReadInt32(recvLength);\r\n                Marshal.Copy(recvPacket, packData, 0, packLength);\r\n\r\n                //Write to console\r\n                for (int i = 0; i < packLength; i++)\r\n                {\r\n                    if (i % 20 == 0)\r\n                    {\r\n                        Console.Write(\"\\n\\t\");\r\n                    }\r\n                    Console.Write(\"{0:2X}\", packData[i]);\r\n                }\r\n\r\n                for (int i = 0; i < packLength; i++)\r\n                {\r\n                    if (i % 40 == 0)\r\n                    {\r\n                        Console.Write(\"\\n\\t\");\r\n                    }\r\n                    Console.Write(packData[i]);\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n```\r\nAnd this is my P/Invoke signature\r\n```\r\n/// Return Type: HANDLE->void*\r\n        ///filter: char*\r\n        ///layer: WINDIVERT_LAYER->Anonymous_ec549c13_388a_4ceb_9226_dbcceaafef56\r\n        ///priority: INT16->short\r\n        ///flags: UINT64->unsigned __int64\r\n        [DllImportAttribute(NativeConstants.WinDivertLib, EntryPoint = \"WinDivertOpen\", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]\r\n        public static extern System.IntPtr WinDivertOpen([InAttribute()] [MarshalAsAttribute(UnmanagedType.LPStr)] string filter, WINDIVERT_LAYER layer, short priority, ulong flags);\r\n                \r\n        /// Return Type: BOOL->int\r\n        ///handle: HANDLE->void*\r\n        ///pPacket: PVOID->void*\r\n        ///packetLen: UINT->unsigned int\r\n        ///pAddr: PWINDIVERT_ADDRESS->Anonymous_656602c6_58d0_42b1_aac9_fb4189b2366f*\r\n        ///readLen: UINT*\r\n        [DllImportAttribute(NativeConstants.WinDivertLib, EntryPoint = \"WinDivertRecv\", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]\r\n        [return: MarshalAsAttribute(UnmanagedType.Bool)]\r\n        public static extern bool WinDivertRecv([InAttribute()] System.IntPtr handle, ref System.IntPtr pPacket, [InAttribute()] uint packetLen, ref System.IntPtr pAddr, ref System.IntPtr readLen);\r\n\r\n\r\n        /// Return Type: BOOL->int\r\n        ///handle: HANDLE->void*\r\n        ///pPacket: PVOID->void*\r\n        ///packetLen: UINT->unsigned int\r\n        ///pAddr: PWINDIVERT_ADDRESS->Anonymous_656602c6_58d0_42b1_aac9_fb4189b2366f*\r\n        ///writeLen: UINT*\r\n        [DllImportAttribute(NativeConstants.WinDivertLib, EntryPoint = \"WinDivertSend\", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]\r\n        [return: MarshalAsAttribute(UnmanagedType.Bool)]\r\n        public static extern bool WinDivertSend([InAttribute()] System.IntPtr handle, [InAttribute()] System.IntPtr pPacket, uint packetLen, [InAttribute()] ref WINDIVERT_ADDRESS pAddr, System.IntPtr writeLen);\r\n\r\n\r\n        /// Return Type: BOOL->int\r\n        ///handle: HANDLE->void*\r\n        [DllImportAttribute(NativeConstants.WinDivertLib, EntryPoint = \"WinDivertClose\", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]\r\n        [return: MarshalAsAttribute(UnmanagedType.Bool)]\r\n        public static extern bool WinDivertClose([InAttribute()] System.IntPtr handle);\r\n\r\n\r\n        /// Return Type: BOOL->int\r\n        ///handle: HANDLE->void*\r\n        ///param: WINDIVERT_PARAM->Anonymous_a7169b5f_684b_48de_a3cd_3e9f153061a1\r\n        ///value: UINT64->unsigned __int64\r\n        [DllImportAttribute(NativeConstants.WinDivertLib, EntryPoint = \"WinDivertSetParam\", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]\r\n        [return: MarshalAsAttribute(UnmanagedType.Bool)]\r\n        public static extern bool WinDivertSetParam([InAttribute()] System.IntPtr handle, WINDIVERT_PARAM param, ulong value);\r\n\r\n\r\n        /// Return Type: BOOL->int\r\n        ///handle: HANDLE->void*\r\n        ///param: WINDIVERT_PARAM->Anonymous_a7169b5f_684b_48de_a3cd_3e9f153061a1\r\n        ///pValue: UINT64*\r\n        [DllImportAttribute(NativeConstants.WinDivertLib, EntryPoint = \"WinDivertGetParam\", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]\r\n        [return: MarshalAsAttribute(UnmanagedType.Bool)]\r\n        public static extern bool WinDivertGetParam([InAttribute()] System.IntPtr handle, WINDIVERT_PARAM param, [OutAttribute()] out ulong pValue);\r\n```"},"comment":{"url":"https://api.github.com/repos/basil00/Divert/issues/comments/157603489","html_url":"https://github.com/basil00/Divert/issues/55#issuecomment-157603489","issue_url":"https://api.github.com/repos/basil00/Divert/issues/55","id":157603489,"user":{"login":"TechnikEmpire","id":11234763,"avatar_url":"https://avatars.githubusercontent.com/u/11234763?v=3","gravatar_id":"","url":"https://api.github.com/users/TechnikEmpire","html_url":"https://github.com/TechnikEmpire","followers_url":"https://api.github.com/users/TechnikEmpire/followers","following_url":"https://api.github.com/users/TechnikEmpire/following{/other_user}","gists_url":"https://api.github.com/users/TechnikEmpire/gists{/gist_id}","starred_url":"https://api.github.com/users/TechnikEmpire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TechnikEmpire/subscriptions","organizations_url":"https://api.github.com/users/TechnikEmpire/orgs","repos_url":"https://api.github.com/users/TechnikEmpire/repos","events_url":"https://api.github.com/users/TechnikEmpire/events{/privacy}","received_events_url":"https://api.github.com/users/TechnikEmpire/received_events","type":"User","site_admin":false},"created_at":"2015-11-18T04:48:04Z","updated_at":"2015-11-18T04:48:04Z","body":"@basil00 Okay cool. Are you okay with me copying some snippets of documentation into comment sections of my code? I figured it'd be okay but I wanted to double check. I'm putting links back to the source in with such comments."}}