{"id":318328,"date":"2021-02-20T09:00:37","date_gmt":"2021-02-20T09:00:37","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=318328"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=318328","title":{"rendered":"\u041f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435 \u0432 unmanaged code: \u0442\u0443\u0434\u0430 \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u044f\u0437\u044b\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b, \u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u042d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u041e\u0421, \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u0445 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u0441 \u0447\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u044f \u0432 unmanaged code \u0438 \u0447\u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0432\u0437\u044f\u0442\u044c \u0441 \u0441\u043e\u0431\u043e\u0439.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dca\/9c0\/b01\/dca9c0b017c45acac9360dee20c9ed58.jpg\" width=\"1440\" height=\"500\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b \u0441\u0442\u043e\u0438\u0442\u0435 \u043d\u0430 \u043f\u043e\u0440\u043e\u0433\u0435 \u0441\u0432\u043e\u0435\u0439 \u0443\u044e\u0442\u043d\u043e\u0439 IDE, \u0438 \u0432\u0430\u0441 \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0442\u044f\u043d\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0432 \u043c\u0438\u0440 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0433\u0434\u0435 \u0442\u0435\u043c\u043d\u043e \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u0414\u043b\u044f \u0443\u0441\u043f\u0435\u0445\u0430 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u044f\u0442\u0438\u044f \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0436\u0438\u0442\u044c\u0441\u044f \u043a\u0430\u0440\u0442\u043e\u0439 \u2013 \u0441\u043e\u0439\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0430 \u043b\u0443\u0447\u0448\u0435 \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. \u041e\u0431\u044b\u0447\u043d\u043e \u043e\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">... #include &lt;linux\/netfilter_ipv4\/ip_tables.h&gt; #include &lt;libiptc\/xtcshared.h&gt;  #ifdef __cplusplus extern \"C\" { #endif  #define iptc_handle xtc_handle #define ipt_chainlabel xt_chainlabel  #define IPTC_LABEL_ACCEPT  \"ACCEPT\" #define IPTC_LABEL_DROP    \"DROP\" #define IPTC_LABEL_QUEUE   \"QUEUE\" #define IPTC_LABEL_RETURN  \"RETURN\"  \/* Does this chain exist? *\/ int iptc_is_chain(const char *chain, struct xtc_handle *const handle);  \/* Take a snapshot of the rules.  Returns NULL on error. *\/ struct xtc_handle *iptc_init(const char *tablename);  \/* Cleanup after iptc_init(). *\/ void iptc_free(struct xtc_handle *h); ...<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0432\u0430\u043c \u043f\u043e\u0432\u0435\u0437\u043b\u043e, \u0438 <a href=\"https:\/\/www.opennet.ru\/docs\/HOWTO\/Querying-libiptc-HOWTO\/\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f <\/a>\u0435\u0441\u0442\u044c. \u0417\u0434\u0435\u0441\u044c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438. \u041f\u0435\u0440\u0432\u044b\u0439 \u043a\u0432\u0435\u0441\u0442 \u2013 \u043d\u0430\u0439\u0442\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432 \u041e\u0421. \u0415\u0451 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e: <\/p>\n<pre><code class=\"bash\">~$ find \/usr\/lib\/x86_64-linux-gnu\/ -maxdepth 1 -name 'libip*' \/usr\/lib\/x86_64-linux-gnu\/libip6tc.so.0.1.0 \/usr\/lib\/x86_64-linux-gnu\/libip4tc.so \/usr\/lib\/x86_64-linux-gnu\/libiptc.so.0 \/usr\/lib\/x86_64-linux-gnu\/libip4tc.so.0.1.0 \/usr\/lib\/x86_64-linux-gnu\/libip6tc.so.0 \/usr\/lib\/x86_64-linux-gnu\/libiptc.so.0.0.0 \/usr\/lib\/x86_64-linux-gnu\/libip4tc.so.0 \/usr\/lib\/x86_64-linux-gnu\/libiptc.so \/usr\/lib\/x86_64-linux-gnu\/libip6tc.so<\/code><\/pre>\n<p>\u0426\u0438\u0444\u0440\u043e\u0432\u043e\u0439 \u0441\u0443\u0444\u0444\u0438\u043a\u0441 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b  libip4tc.so. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u044c \u043e\u0434\u043d\u0438\u043c \u0433\u043b\u0430\u0437\u043a\u043e\u043c \u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0434\u0435\u043b\u043e \u0441\u0442\u043e\u044f\u0449\u0435\u0435: <\/p>\n<pre><code class=\"bash\">~$ nm -D \/usr\/lib\/x86_64-linux-gnu\/libip4tc.so ... 0000000000206230 D _edata 0000000000206240 B _end                  U __errno_location                  U fcntl 000000000000464c T _fini                  U __fprintf_chk                  U free                  U getsockopt                  w __gmon_start__ 0000000000001440 T _init 0000000000003c80 T iptc_append_entry 0000000000003700 T iptc_builtin 0000000000004640 T iptc_check_entry 0000000000003100 T iptc_commit 0000000000002ff0 T iptc_create_chain 00000000000043f0 T iptc_delete_chain ...<\/code><\/pre>\n<p>\u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442&nbsp; \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0442\u043a\u043d\u0443\u0442\u044c \u0432 \u043d\u0435\u0435 \u043f\u0430\u043b\u043a\u043e\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0430\u043d\u0443\u0441\u043a\u0440\u0438\u043f\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<pre><code class=\"cs\">public static class Libiptc4 {         \/* Prototype: iptc_handle_t iptc_init(const char *tablename) *\/         [DllImport(\"libip4tc.so\")]         public static extern IntPtr iptc_init(string tablename); } <\/code><\/pre>\n<p>\u041a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u043a\u0430\u0447\u0430\u0442\u044c \u043d\u0430\u0432\u044b\u043a <a href=\"https:\/\/docs.microsoft.com\/ru-ru\/dotnet\/framework\/interop\/interop-marshaling\" rel=\"noopener noreferrer nofollow\">\u043c\u0430\u0440\u0448\u0430\u043b\u0438\u043d\u0433\u0430<\/a>: \u043e\u043d \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0438 \u0432\u044b\u0445\u043e\u0434\u0435 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0412\u0441\u0435 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432 <a href=\"https:\/\/docs.microsoft.com\/ru-ru\/dotnet\/framework\/interop\/marshaling-data-with-platform-invoke\" rel=\"noopener noreferrer nofollow\">\u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b<\/a>. \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 <code>IntPtr<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438\u043d\u0430\u0447\u0435:<\/p>\n<pre><code class=\"cs\">\/* Prototype: iptc_handle_t iptc_init(const char *tablename) *\/ [DllImport(\"libip4tc.so\")] public static extern IntPtr iptc_init(IntPtr tblPtr); ... var tblPtr = Marshal.StringToHGlobalAnsi(\"filter\"); var _handle = Libiptc4.iptc_init_ptr(tblPtr); Marshal.FreeHGlobal(tblPtr);<\/code><\/pre>\n<p>\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0447\u0438\u0449\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c.<code> <\/code>\u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f, \u043f\u043e \u043c\u043e\u0438\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f\u043c, \u0441\u0442\u0440\u043e\u043a\u0438, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u043a\u043b\u0430\u0441\u0441\u044b \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e, \u0435\u0441\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0441\u044b\u043b\u043a\u0438.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u0435\u043f\u0435\u0440\u044c, \u0447\u0442\u043e \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043d\u0430\u0441 \u043a \u043f\u0435\u0449\u0435\u0440\u0435 \u0433\u043e\u0440\u043d\u043e\u0433\u043e \u0442\u0440\u043e\u043b\u043b\u044f: \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u043e\u0440\u0443\u0434\u0438\u0442\u044c \u043d\u0430 \u0432\u0445\u043e\u0434 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430. \u041f\u0440\u043e\u0442\u043e\u0442\u0438\u043f \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">struct ipt_entry { \tstruct ipt_ip ip;  \t\/* Mark with fields that we care about. *\/ \tunsigned int nfcache;  \t\/* Size of ipt_entry + matches *\/ \t__u16 target_offset; \t\/* Size of ipt_entry + matches + target *\/ \t__u16 next_offset;  \t\/* Back pointer *\/ \tunsigned int comefrom;  \t\/* Packet and byte counters. *\/ \tstruct xt_counters counters;  \t\/* The matches (if any), then the target. *\/ \tunsigned char elems[0]; };<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u043e\u043b\u0435 <code>unsigned char elems[0]<\/code> \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430. \u0415\u0441\u043b\u0438 \u044f \u043d\u0435 \u043e\u0448\u0438\u0431\u0430\u044e\u0441\u044c, \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0431\u0430\u0439\u0442\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b, \u0438 \u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u043d\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>******************************************* * ip_entry                                * * 112 bytes                               * ******************************************* * matches                                 * * target_offset - 112 bytes               * ******************************************* * target                                  * * next_offset - target_offset - 112 bytes * *******************************************<\/code><\/pre>\n<p>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 (<code>matches <\/code>\u0438 <code>target<\/code>) \u043f\u0440\u0438\u0441\u0442\u044b\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0443 <code>ip_entry<\/code>. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0430 \u044d\u0442\u0430\u043f\u0430:<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043d\u0443\u0436\u043d\u044b\u0435 \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438, \u0438\u043c\u0435\u044e\u0449\u0438\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 <code>ipt_entry <\/code>\u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cs\">[StructLayout(LayoutKind.Sequential)] public struct IptEntry {  \tpublic IptIp ip; \tpublic uint nfcache; \tpublic ushort target_offset; \tpublic ushort next_offset; \tpublic uint comefrom; \tpublic IptCounters counters; };<\/code><\/pre>\n<p>\u0420\u0430\u0437\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a <code>Marshal.SizeOf&lt;IptEntry&gt;()<\/code>\u0438 \u0440\u0430\u0432\u0435\u043d 112 \u0431\u0430\u0439\u0442. \u0417\u0430\u0442\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0432\u0441\u0435\u0445 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<code>matches <\/code>\u0438 <code>target <\/code>( \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438). \u041d\u044e\u0430\u043d\u0441: \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439<code>libiptc <\/code>\u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e 8 ( \u0440\u0430\u0437\u043c\u0435\u0440 <code>long<\/code>), \u0442\u0430\u043a \u0447\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u0431\u0430\u0439\u0442 \u0432 \u0445\u0432\u043e\u0441\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0432\u043e\u0441\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0430. \u0412\u0438\u0434\u0438\u043c\u043e, \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cs\">static readonly int  _WORDLEN = Marshal.SizeOf&lt;long&gt;(); public static int Align(int size) { \treturn ((size + (_WORDLEN - 1)) &amp; ~(_WORDLEN - 1)); }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 <code>entry.target_offset<\/code> \u0438 <code>entry.next_offset<\/code>, \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b:<\/p>\n<pre><code class=\"cs\">IntPtr entryPtr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr&lt;IptEntry&gt;(entryPtr, entry, false); Marshal.StructureToPtr&lt;Match&gt;(entryPtr + 112, match, false);<\/code><\/pre>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435:&nbsp; \u0447\u0438\u0442\u0430\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435, \u0447\u0438\u0442\u0430\u0435\u043c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c:<\/p>\n<pre><code class=\"cs\">var entry = Marshal.PtrToStructure&lt;IptEntry&gt;(point); var match = Marshal.PtrToStructure&lt;Match&gt;(point + 112)<\/code><\/pre>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440, \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u043f\u0443\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0437\u0432\u0435\u0440\u044c \u043a\u0430\u043a <code>union:<\/code><\/p>\n<pre><code class=\"cpp\">struct xt_entry_match { \tunion { \t\tstruct { \t\t\t__u16 match_size;  \t\t\t\/* Used by userspace *\/ \t\t\tchar name[XT_EXTENSION_MAXNAMELEN]; \t\t\t__u8 revision; \t\t} user; \t\tstruct { \t\t\t__u16 match_size;  \t\t\t\/* Used inside the kernel *\/ \t\t\tstruct xt_match *match; \t\t} kernel;  \t\t\/* Total length *\/ \t\t__u16 match_size; \t} u;  \tunsigned char data[0]; };<\/code><\/pre>\n<p><em>Union <\/em>&#8212; \u044d\u0442\u043e \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043f\u0430\u043c\u044f\u0442\u0438: \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u043a\u0430\u043a \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b.  \u0414\u043b\u044f \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0430 \u0432 \u044f\u0437\u044b\u043a\u0435 c#. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430 \u0432 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438. \u041f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0440\u0430\u0437\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0430\u043c\u044f\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 (\u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430).  \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432 <a href=\"https:\/\/docs.microsoft.com\/ru-ru\/dotnet\/framework\/interop\/marshaling-classes-structures-and-unions\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0438\u043c\u0435\u0440\u0435<\/a>.<\/p>\n<p>\u0412 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u044b \u0434\u043b\u044f \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"cpp\">#define XT_EXTENSION_MAXNAMELEN   29 ... char name [XT_EXTENSION_MAXNAMELEN]<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u0433\u0430\u0434\u043a\u043e\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0441\u043a\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445  header \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<p>\u041f\u043e\u0441\u0442\u0430\u0440\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0435 \u0437\u043b\u0438\u0442\u044c \u043c\u0430\u0433\u043e\u0432, \u0438\u043d\u0430\u0447\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043f\u0440\u043e\u043a\u043b\u044f\u0442\u044c\u0435 \u0432 \u0441\u043f\u0438\u043d\u0443. \u0412\u0430\u0448\u0438 ushort, uint \u0438 long \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0442\u043e, \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0435. \u0412\u0441\u0435 \u0434\u0435\u043b\u043e \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0431\u0430\u0439\u0442. \u041f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u043e\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a: \u0441\u043b\u0435\u0432\u0430 \u0441\u0442\u0430\u0440\u0448\u0438\u0439 \u0431\u0430\u0439\u0442, \u0441\u043f\u0440\u0430\u0432\u0430 \u043c\u0435\u043d\u044c\u0448\u0438\u0439. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0441\u0435\u0442\u0435\u0432\u044b\u043c\u0438 \u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 \u0438 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u043f\u043e\u0440\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0431\u0430\u0439\u0442. \u0414\u043b\u044f \u0437\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0435\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 <a href=\"https:\/\/docs.microsoft.com\/ru-Ru\/dotnet\/api\/system.net.ipaddress.hosttonetworkorder\" rel=\"noopener noreferrer nofollow\">\u043c\u0435\u0442\u043e\u0434<\/a>. \u0414\u043b\u044f \u0431\u0435\u0437\u0437\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0441\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u0440\u043e\u043a\u043b\u044f\u0442\u044c\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0438\u043c:<\/p>\n<pre><code class=\"cs\">byte [] convArray = BitConverter.GetBytes(value); Array.Reverse(convArray); ushort reverseEndian = BitConverter.ToUInt16(convArray,0);<\/code><\/pre>\n<pre><code class=\"cs\">ushort reverseEndian = (ushort)((value &lt;&lt; 8) | (value &gt;&gt; 8));<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0435 \u043e\u0448\u0438\u0431\u043e\u043a. \u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 unmanaged code \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438. \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0444\u043b\u0430\u0433 \u0443\u0441\u043f\u0435\u0445\/\u043d\u0435\u0443\u0434\u0430\u0447\u0430, \u0430 \u043d\u043e\u043c\u0435\u0440 \u043e\u0448\u0438\u0431\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f errno. \u0412 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u0435\u0435 \u043d\u0438\u0433\u0434\u0435 \u043d\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0435\u0440\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u0432\u0435\u0441\u0442, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443: <\/p>\n<pre><code class=\"cs\">[DllImport(\"libip4tc.so\", SetLastError = true)]<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0435\u0441\u043b\u0438 \u043d\u0430\u0441 \u043f\u043e\u0441\u0442\u0438\u0433\u043d\u0435\u0442 \u043d\u0435\u0443\u0434\u0430\u0447\u0430, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"cs\">int errno = Marshal.GetLastWin32Error(); var errPtr = Libiptc4.iptc_strerror(errno); string errStr = Marshal.PtrToStringAnsi(errPtr);<\/code><\/pre>\n<p>\u0418 \u044d\u0442\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u0430\u0436\u0435 \u0432 Linux c net.core (\u0432\u0438\u0434\u0438\u043c\u043e, \u043d\u0435 \u0443\u0441\u043f\u0435\u043b\u0438 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c\/\u0437\u0430\u0431\u0438\u043b\u0438). \u0422\u0430\u043a\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0431\u043e\u0440\u043a\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a:  \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043a\u0440\u043e\u0441\u0441-\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0435, \u0442\u0430\u043a \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e 32\/64 \u0431\u0438\u0442\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438, \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0435\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043f\u043e\u0440\u0442\u044b \u0432 <a href=\"https:\/\/packages.msys2.org\/package\/\" rel=\"noopener noreferrer nofollow\">Windows <\/a>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043d\u0430\u0448\u0435 \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043d\u0446\u0443. \u0414\u043e\u0431\u0430\u0432\u043b\u044e, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u0438 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c \u0432 \u043f\u043b\u0430\u043d\u0435 \u0443\u0441\u043f\u0435\u0445\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c. \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043f\u0443\u0433\u043d\u0443\u0442\u044c. \u041e\u0434\u043d\u0430\u043a\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u2013 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/543306\/\"> https:\/\/habr.com\/ru\/post\/543306\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u044f\u0437\u044b\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b, \u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u042d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u041e\u0421, \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u0445 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u0441 \u0447\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u044f \u0432 unmanaged code \u0438 \u0447\u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u0432\u0437\u044f\u0442\u044c \u0441 \u0441\u043e\u0431\u043e\u0439.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b \u0441\u0442\u043e\u0438\u0442\u0435 \u043d\u0430 \u043f\u043e\u0440\u043e\u0433\u0435 \u0441\u0432\u043e\u0435\u0439 \u0443\u044e\u0442\u043d\u043e\u0439 IDE, \u0438 \u0432\u0430\u0441 \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0442\u044f\u043d\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0432 \u043c\u0438\u0440 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0433\u0434\u0435 \u0442\u0435\u043c\u043d\u043e \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u0414\u043b\u044f \u0443\u0441\u043f\u0435\u0445\u0430 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u044f\u0442\u0438\u044f \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0436\u0438\u0442\u044c\u0441\u044f \u043a\u0430\u0440\u0442\u043e\u0439 \u2013 \u0441\u043e\u0439\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0430 \u043b\u0443\u0447\u0448\u0435 \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. \u041e\u0431\u044b\u0447\u043d\u043e \u043e\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">... #include &lt;linux\/netfilter_ipv4\/ip_tables.h&gt; #include &lt;libiptc\/xtcshared.h&gt;  #ifdef __cplusplus extern \"C\" { #endif  #define iptc_handle xtc_handle #define ipt_chainlabel xt_chainlabel  #define IPTC_LABEL_ACCEPT  \"ACCEPT\" #define IPTC_LABEL_DROP    \"DROP\" #define IPTC_LABEL_QUEUE   \"QUEUE\" #define IPTC_LABEL_RETURN  \"RETURN\"  \/* Does this chain exist? *\/ int iptc_is_chain(const char *chain, struct xtc_handle *const handle);  \/* Take a snapshot of the rules.  Returns NULL on error. *\/ struct xtc_handle *iptc_init(const char *tablename);  \/* Cleanup after iptc_init(). *\/ void iptc_free(struct xtc_handle *h); ...<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0432\u0430\u043c \u043f\u043e\u0432\u0435\u0437\u043b\u043e, \u0438 <a href=\"https:\/\/www.opennet.ru\/docs\/HOWTO\/Querying-libiptc-HOWTO\/\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f <\/a>\u0435\u0441\u0442\u044c. \u0417\u0434\u0435\u0441\u044c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438. \u041f\u0435\u0440\u0432\u044b\u0439 \u043a\u0432\u0435\u0441\u0442 \u2013 \u043d\u0430\u0439\u0442\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432 \u041e\u0421. \u0415\u0451 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e: <\/p>\n<pre><code class=\"bash\">~$ find \/usr\/lib\/x86_64-linux-gnu\/ -maxdepth 1 -name 'libip*' \/usr\/lib\/x86_64-linux-gnu\/libip6tc.so.0.1.0 \/usr\/lib\/x86_64-linux-gnu\/libip4tc.so \/usr\/lib\/x86_64-linux-gnu\/libiptc.so.0 \/usr\/lib\/x86_64-linux-gnu\/libip4tc.so.0.1.0 \/usr\/lib\/x86_64-linux-gnu\/libip6tc.so.0 \/usr\/lib\/x86_64-linux-gnu\/libiptc.so.0.0.0 \/usr\/lib\/x86_64-linux-gnu\/libip4tc.so.0 \/usr\/lib\/x86_64-linux-gnu\/libiptc.so \/usr\/lib\/x86_64-linux-gnu\/libip6tc.so<\/code><\/pre>\n<p>\u0426\u0438\u0444\u0440\u043e\u0432\u043e\u0439 \u0441\u0443\u0444\u0444\u0438\u043a\u0441 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b  libip4tc.so. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u044c \u043e\u0434\u043d\u0438\u043c \u0433\u043b\u0430\u0437\u043a\u043e\u043c \u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0434\u0435\u043b\u043e \u0441\u0442\u043e\u044f\u0449\u0435\u0435: <\/p>\n<pre><code class=\"bash\">~$ nm -D \/usr\/lib\/x86_64-linux-gnu\/libip4tc.so ... 0000000000206230 D _edata 0000000000206240 B _end                  U __errno_location                  U fcntl 000000000000464c T _fini                  U __fprintf_chk                  U free                  U getsockopt                  w __gmon_start__ 0000000000001440 T _init 0000000000003c80 T iptc_append_entry 0000000000003700 T iptc_builtin 0000000000004640 T iptc_check_entry 0000000000003100 T iptc_commit 0000000000002ff0 T iptc_create_chain 00000000000043f0 T iptc_delete_chain ...<\/code><\/pre>\n<p>\u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442&nbsp; \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0442\u043a\u043d\u0443\u0442\u044c \u0432 \u043d\u0435\u0435 \u043f\u0430\u043b\u043a\u043e\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0430\u043d\u0443\u0441\u043a\u0440\u0438\u043f\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<pre><code class=\"cs\">public static class Libiptc4 {         \/* Prototype: iptc_handle_t iptc_init(const char *tablename) *\/         [DllImport(\"libip4tc.so\")]         public static extern IntPtr iptc_init(string tablename); } <\/code><\/pre>\n<p>\u041a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u043a\u0430\u0447\u0430\u0442\u044c \u043d\u0430\u0432\u044b\u043a <a href=\"https:\/\/docs.microsoft.com\/ru-ru\/dotnet\/framework\/interop\/interop-marshaling\" rel=\"noopener noreferrer nofollow\">\u043c\u0430\u0440\u0448\u0430\u043b\u0438\u043d\u0433\u0430<\/a>: \u043e\u043d \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0438 \u0432\u044b\u0445\u043e\u0434\u0435 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0412\u0441\u0435 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432 <a href=\"https:\/\/docs.microsoft.com\/ru-ru\/dotnet\/framework\/interop\/marshaling-data-with-platform-invoke\" rel=\"noopener noreferrer nofollow\">\u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b<\/a>. \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 <code>IntPtr<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438\u043d\u0430\u0447\u0435:<\/p>\n<pre><code class=\"cs\">\/* Prototype: iptc_handle_t iptc_init(const char *tablename) *\/ [DllImport(\"libip4tc.so\")] public static extern IntPtr iptc_init(IntPtr tblPtr); ... var tblPtr = Marshal.StringToHGlobalAnsi(\"filter\"); var _handle = Libiptc4.iptc_init_ptr(tblPtr); Marshal.FreeHGlobal(tblPtr);<\/code><\/pre>\n<p>\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0447\u0438\u0449\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c.<code> <\/code>\u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f, \u043f\u043e \u043c\u043e\u0438\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f\u043c, \u0441\u0442\u0440\u043e\u043a\u0438, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u043a\u043b\u0430\u0441\u0441\u044b \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e, \u0435\u0441\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0441\u044b\u043b\u043a\u0438.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u0435\u043f\u0435\u0440\u044c, \u0447\u0442\u043e \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043d\u0430\u0441 \u043a \u043f\u0435\u0449\u0435\u0440\u0435 \u0433\u043e\u0440\u043d\u043e\u0433\u043e \u0442\u0440\u043e\u043b\u043b\u044f: \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u043e\u0440\u0443\u0434\u0438\u0442\u044c \u043d\u0430 \u0432\u0445\u043e\u0434 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430. \u041f\u0440\u043e\u0442\u043e\u0442\u0438\u043f \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">struct ipt_entry { \tstruct ipt_ip ip;  \t\/* Mark with fields that we care about. *\/ \tunsigned int nfcache;  \t\/* Size of ipt_entry + matches *\/ \t__u16 target_offset; \t\/* Size of ipt_entry + matches + target *\/ \t__u16 next_offset;  \t\/* Back pointer *\/ \tunsigned int comefrom;  \t\/* Packet and byte counters. *\/ \tstruct xt_counters counters;  \t\/* The matches (if any), then the target. *\/ \tunsigned char elems[0]; };<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u043e\u043b\u0435 <code>unsigned char elems[0]<\/code> \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430. \u0415\u0441\u043b\u0438 \u044f \u043d\u0435 \u043e\u0448\u0438\u0431\u0430\u044e\u0441\u044c, \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0431\u0430\u0439\u0442\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b, \u0438 \u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u043d\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>******************************************* * ip_entry                                * * 112 bytes                               * ******************************************* * matches                                 * * target_offset - 112 bytes               * ******************************************* * target                                  * * next_offset - target_offset - 112 bytes * *******************************************<\/code><\/pre>\n<p>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 (<code>matches <\/code>\u0438 <code>target<\/code>) \u043f\u0440\u0438\u0441\u0442\u044b\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0443 <code>ip_entry<\/code>. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0430 \u044d\u0442\u0430\u043f\u0430:<\/p>\n<ol>\n<li>\n<p>\u0412\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043d\u0443\u0436\u043d\u044b\u0435 \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438, \u0438\u043c\u0435\u044e\u0449\u0438\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 <code>ipt_entry <\/code>\u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cs\">[StructLayout(LayoutKind.Sequential)] public struct IptEntry {  \tpublic IptIp ip; \tpublic uint nfcache; \tpublic ushort target_offset; \tpublic ushort next_offset; \tpublic uint comefrom; \tpublic IptCounters counters; };<\/code><\/pre>\n<p>\u0420\u0430\u0437\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a <code>Marshal.SizeOf&lt;IptEntry&gt;()<\/code>\u0438 \u0440\u0430\u0432\u0435\u043d 112 \u0431\u0430\u0439\u0442. \u0417\u0430\u0442\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0432\u0441\u0435\u0445 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<code>matches <\/code>\u0438 <code>target <\/code>( \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438). \u041d\u044e\u0430\u043d\u0441: \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439<code>libiptc <\/code>\u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e 8 ( \u0440\u0430\u0437\u043c\u0435\u0440 <code>long<\/code>), \u0442\u0430\u043a \u0447\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u0431\u0430\u0439\u0442 \u0432 \u0445\u0432\u043e\u0441\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0432\u043e\u0441\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0430. \u0412\u0438\u0434\u0438\u043c\u043e, \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0447\u0442\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cs\">static readonly int  _WORDLEN = Marshal.SizeOf&lt;long&gt;(); public static int Align(int size) { \treturn ((size + (_WORDLEN - 1)) &amp; ~(_WORDLEN - 1)); }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 <code>entry.target_offset<\/code> \u0438 <code>entry.next_offset<\/code>, \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b:<\/p>\n<pre><code class=\"cs\">IntPtr entryPtr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr&lt;IptEntry&gt;(entryPtr, entry, false); Marshal.StructureToPtr&lt;Match&gt;(entryPtr + 112, match, false);<\/code><\/pre>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435:&nbsp; \u0447\u0438\u0442\u0430\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435, \u0447\u0438\u0442\u0430\u0435\u043c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c:<\/p>\n<pre><code class=\"cs\">var entry = Marshal.PtrToStructure&lt;IptEntry&gt;(point); var match = Marshal.PtrToStructure&lt;Match&gt;(point + 112)<\/code><\/pre>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440, \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u043f\u0443\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0437\u0432\u0435\u0440\u044c \u043a\u0430\u043a <code>union:<\/code><\/p>\n<pre><code class=\"cpp\">struct xt_entry_match { \tunion { \t\tstruct { \t\t\t__u16 match_size;  \t\t\t\/* Used by userspace *\/ \t\t\tchar name[XT_EXTENSION_MAXNAMELEN]; \t\t\t__u8 revision; \t\t} user; \t\tstruct { \t\t\t__u16 match_size;  \t\t\t\/* Used inside the kernel *\/ \t\t\tstruct xt_match *match; \t\t} kernel;  \t\t\/* Total length *\/ \t\t__u16 match_size; \t} u;  \tunsigned char data[0]; };<\/code><\/pre>\n<p><em>Union <\/em>&#8212; \u044d\u0442\u043e \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043f\u0430\u043c\u044f\u0442\u0438: \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u043a\u0430\u043a \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b.  \u0414\u043b\u044f \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0430 \u0432 \u044f\u0437\u044b\u043a\u0435 c#. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430 \u0432 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438. \u041f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0440\u0430\u0437\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0430\u043c\u044f\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 (\u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430).  \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432 <a href=\"https:\/\/docs.microsoft.com\/ru-ru\/dotnet\/framework\/interop\/marshaling-classes-structures-and-unions\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0438\u043c\u0435\u0440\u0435<\/a>.<\/p>\n<p>\u0412 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u044b \u0434\u043b\u044f \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"cpp\">#define XT_EXTENSION_MAXNAMELEN   29 ... char name [XT_EXTENSION_MAXNAMELEN]<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u0433\u0430\u0434\u043a\u043e\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0441\u043a\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445  header \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<p>\u041f\u043e\u0441\u0442\u0430\u0440\u0430\u0439\u0442\u0435\u0441\u044c \u043d\u0435 \u0437\u043b\u0438\u0442\u044c \u043c\u0430\u0433\u043e\u0432, \u0438\u043d\u0430\u0447\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043f\u0440\u043e\u043a\u043b\u044f\u0442\u044c\u0435 \u0432 \u0441\u043f\u0438\u043d\u0443. \u0412\u0430\u0448\u0438 ushort, uint \u0438 long \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0442\u043e, \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0435. \u0412\u0441\u0435 \u0434\u0435\u043b\u043e \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0431\u0430\u0439\u0442. \u041f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u043e\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a: \u0441\u043b\u0435\u0432\u0430 \u0441\u0442\u0430\u0440\u0448\u0438\u0439 \u0431\u0430\u0439\u0442, \u0441\u043f\u0440\u0430\u0432\u0430 \u043c\u0435\u043d\u044c\u0448\u0438\u0439. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0441\u0435\u0442\u0435\u0432\u044b\u043c\u0438 \u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 \u0438 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u043f\u043e\u0440\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0431\u0430\u0439\u0442. \u0414\u043b\u044f \u0437\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0435\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 <a href=\"https:\/\/docs.microsoft.com\/ru-Ru\/dotnet\/api\/system.net.ipaddress.hosttonetworkorder\" rel=\"noopener noreferrer nofollow\">\u043c\u0435\u0442\u043e\u0434<\/a>. \u0414\u043b\u044f \u0431\u0435\u0437\u0437\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0441\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u0440\u043e\u043a\u043b\u044f\u0442\u044c\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0438\u043c:<\/p>\n<pre><code class=\"cs\">byte [] convArray = BitConverter.GetBytes(value); Array.Reverse(convArray); ushort reverseEndian = BitConverter.ToUInt16(convArray,0);<\/code><\/pre>\n<pre><code class=\"cs\">ushort reverseEndian = (ushort)((value &lt;&lt; 8) | (value &gt;&gt; 8));<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0435 \u043e\u0448\u0438\u0431\u043e\u043a. \u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 unmanaged code \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438. \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0444\u043b\u0430\u0433 \u0443\u0441\u043f\u0435\u0445\/\u043d\u0435\u0443\u0434\u0430\u0447\u0430, \u0430 \u043d\u043e\u043c\u0435\u0440 \u043e\u0448\u0438\u0431\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f errno. \u0412 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u0435\u0435 \u043d\u0438\u0433\u0434\u0435 \u043d\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0435\u0440\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u0432\u0435\u0441\u0442, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443: <\/p>\n<pre><code class=\"cs\">[DllImport(\"libip4tc.so\", SetLastError = true)]<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0435\u0441\u043b\u0438 \u043d\u0430\u0441 \u043f\u043e\u0441\u0442\u0438\u0433\u043d\u0435\u0442 \u043d\u0435\u0443\u0434\u0430\u0447\u0430, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"cs\">int errno = Marshal.GetLastWin32Error(); var errPtr = Libiptc4.iptc_strerror(errno); string errStr = Marshal.PtrToStringAnsi(errPtr);<\/code><\/pre>\n<p>\u0418 \u044d\u0442\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u0430\u0436\u0435 \u0432 Linux c net.core (\u0432\u0438\u0434\u0438\u043c\u043e, \u043d\u0435 \u0443\u0441\u043f\u0435\u043b\u0438 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c\/\u0437\u0430\u0431\u0438\u043b\u0438). \u0422\u0430\u043a\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0431\u043e\u0440\u043a\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a:  \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043a\u0440\u043e\u0441\u0441-\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0435, \u0442\u0430\u043a \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e 32\/64 \u0431\u0438\u0442\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438, \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0435\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043f\u043e\u0440\u0442\u044b \u0432 <a href=\"https:\/\/packages.msys2.org\/package\/\" rel=\"noopener noreferrer nofollow\">Windows <\/a>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043d\u0430\u0448\u0435 \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043d\u0446\u0443. \u0414\u043e\u0431\u0430\u0432\u043b\u044e, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u0438 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c \u0432 \u043f\u043b\u0430\u043d\u0435 \u0443\u0441\u043f\u0435\u0445\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c. \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043f\u0443\u0433\u043d\u0443\u0442\u044c. \u041e\u0434\u043d\u0430\u043a\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u2013 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/543306\/\"> https:\/\/habr.com\/ru\/post\/543306\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-318328","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=318328"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/318328\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}