From dcb9afd439bf589abddc64e7f7a5155a82e2df8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B8is=C3=A6ther=20Rasch?= Date: Thu, 6 Feb 2020 18:23:22 +0100 Subject: [PATCH 1/2] IN_ADDR structure, inaddr.h line 37 --- TH-NETII Windows API.sln | 15 ++++ .../THNETII.WinApi.Sample.Native/main.c | 9 ++- .../GlobalSuppressions.cs | 10 +++ src/THNETII.WinApi.Headers.InAddr/IN_ADDR.cs | 80 +++++++++++++++++++ .../THNETII.WinApi.Headers.InAddr.csproj | 11 +++ 5 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 src/THNETII.WinApi.Headers.InAddr/GlobalSuppressions.cs create mode 100644 src/THNETII.WinApi.Headers.InAddr/IN_ADDR.cs create mode 100644 src/THNETII.WinApi.Headers.InAddr/THNETII.WinApi.Headers.InAddr.csproj diff --git a/TH-NETII Windows API.sln b/TH-NETII Windows API.sln index 571cd59c..c315b5d5 100644 --- a/TH-NETII Windows API.sln +++ b/TH-NETII Windows API.sln @@ -91,6 +91,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "THNETII.WinApi.Constants.SC EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "THNETII.WinApi.Headers.WinSCard", "src\THNETII.WinApi.Headers.WinSCard\THNETII.WinApi.Headers.WinSCard.csproj", "{56348771-2C99-4C0A-B63A-C7F0736621DA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "THNETII.WinApi.Headers.InAddr", "src\THNETII.WinApi.Headers.InAddr\THNETII.WinApi.Headers.InAddr.csproj", "{5C37B204-B1DB-41B2-8081-B84870477F43}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -473,6 +475,18 @@ Global {56348771-2C99-4C0A-B63A-C7F0736621DA}.Release|x64.Build.0 = Release|Any CPU {56348771-2C99-4C0A-B63A-C7F0736621DA}.Release|x86.ActiveCfg = Release|Any CPU {56348771-2C99-4C0A-B63A-C7F0736621DA}.Release|x86.Build.0 = Release|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Debug|x64.ActiveCfg = Debug|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Debug|x64.Build.0 = Debug|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Debug|x86.ActiveCfg = Debug|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Debug|x86.Build.0 = Debug|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Release|Any CPU.Build.0 = Release|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Release|x64.ActiveCfg = Release|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Release|x64.Build.0 = Release|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Release|x86.ActiveCfg = Release|Any CPU + {5C37B204-B1DB-41B2-8081-B84870477F43}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -510,6 +524,7 @@ Global {35C252B4-AD97-4E09-8097-72FDCA04EBF7} = {9689DB3E-1ED7-478C-AC14-C734B0397619} {25A891EB-9BF0-45D1-89EE-B24E80DE259E} = {9689DB3E-1ED7-478C-AC14-C734B0397619} {56348771-2C99-4C0A-B63A-C7F0736621DA} = {9689DB3E-1ED7-478C-AC14-C734B0397619} + {5C37B204-B1DB-41B2-8081-B84870477F43} = {9689DB3E-1ED7-478C-AC14-C734B0397619} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6EF7C9CF-E403-4B60-AB44-5F9FFEB668B7} diff --git a/src-native-c/THNETII.WinApi.Sample.Native/main.c b/src-native-c/THNETII.WinApi.Sample.Native/main.c index f36a265a..fad3550a 100644 --- a/src-native-c/THNETII.WinApi.Sample.Native/main.c +++ b/src-native-c/THNETII.WinApi.Sample.Native/main.c @@ -1,12 +1,13 @@ -#include +#include +#include int main(int argc, char* argv[]) { - SCARD_READERSTATE instance; + IN_ADDR instance; const int size = sizeof(instance); - const int value = SCARD_ABSENT; + const int value = UNIX_PATH_MAX; - const void* ptr = SCardGetReaderDeviceInstanceId; + const void* ptr = NULL; return EXIT_SUCCESS; } diff --git a/src/THNETII.WinApi.Headers.InAddr/GlobalSuppressions.cs b/src/THNETII.WinApi.Headers.InAddr/GlobalSuppressions.cs new file mode 100644 index 00000000..c31c9e9b --- /dev/null +++ b/src/THNETII.WinApi.Headers.InAddr/GlobalSuppressions.cs @@ -0,0 +1,10 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Naming", "CA1707: Identifiers should not contain underscores")] +[assembly: SuppressMessage("Style", "IDE1006: Naming Styles")] +[assembly: SuppressMessage("Performance", "CA1815: Override equals and operator equals on value types")] diff --git a/src/THNETII.WinApi.Headers.InAddr/IN_ADDR.cs b/src/THNETII.WinApi.Headers.InAddr/IN_ADDR.cs new file mode 100644 index 00000000..02dd46d5 --- /dev/null +++ b/src/THNETII.WinApi.Headers.InAddr/IN_ADDR.cs @@ -0,0 +1,80 @@ +using System.Runtime.InteropServices; + +namespace THNETII.WinApi.Native.InAddr +{ + // C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\inaddr.h, line 21 + // + // IPv4 Internet address + // This is an 'on-wire' format structure. + // + + /// + /// The structure represents an IPv4 address. + /// The IPaddr type definition in IP Helper also represents an IPv4 address and can be cast to an interchangeable in_addr structure when needed. The in_addr structure in IP Helper has the same syntax and usage as the Windows Sockets in_addr structure, and is interchangeable with in_addr structure used in Windows sockets. Windows sockets also defines an IN_ADDR typedef for the in_addr structure. + /// + /// + /// Microsoft Docs page: IN_ADDR structure + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + [StructLayout(LayoutKind.Explicit, Pack = 4)] + public unsafe struct IN_ADDR + { + [FieldOffset(0)] + internal fixed byte S_un_b[4]; + [FieldOffset(0)] + internal fixed ushort S_un_w[2]; + [FieldOffset(0)] + internal uint S_addr; + + /// Address of the host formatted as a 32-bit integer + public uint s_addr + { + get => S_addr; + set => S_addr = value; + } + + /// host on imp + public byte s_host + { + get => S_un_b[1]; + set => S_un_b[1] = value; + } + + /// network + public byte s_net + { + get => S_un_b[0]; + set => S_un_b[0] = value; + } + + /// imp + public ushort s_imp + { + get => S_un_w[1]; + set => S_un_w[1] = value; + } + + /// imp # + public byte s_impno + { + get => S_un_b[3]; + set => S_un_b[3] = value; + } + + /// logical host + public byte s_lh + { + get => S_un_b[2]; + set => S_un_b[2] = value; + } + } +} diff --git a/src/THNETII.WinApi.Headers.InAddr/THNETII.WinApi.Headers.InAddr.csproj b/src/THNETII.WinApi.Headers.InAddr/THNETII.WinApi.Headers.InAddr.csproj new file mode 100644 index 00000000..8f99a8fa --- /dev/null +++ b/src/THNETII.WinApi.Headers.InAddr/THNETII.WinApi.Headers.InAddr.csproj @@ -0,0 +1,11 @@ + + + + + true + netstandard1.3;netstandard2.0 + true + THNETII.WinApi.Native.InAddr + + + From 0dfd96a2ab85d8d9c0a3fd2e8847689d796a336f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B8is=C3=A6ther=20Rasch?= Date: Thu, 6 Feb 2020 19:13:49 +0100 Subject: [PATCH 2/2] Create Ws2Def project, ws2def.h --- TH-NETII Windows API.sln | 15 +++++++++++++++ src-native-c/THNETII.WinApi.Sample.Native/main.c | 8 ++++---- .../THNETII.WinApi.Headers.Ws2Def.csproj | 11 +++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/THNETII.WinApi.Headers.Ws2Def/THNETII.WinApi.Headers.Ws2Def.csproj diff --git a/TH-NETII Windows API.sln b/TH-NETII Windows API.sln index 571cd59c..d63c23bc 100644 --- a/TH-NETII Windows API.sln +++ b/TH-NETII Windows API.sln @@ -91,6 +91,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "THNETII.WinApi.Constants.SC EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "THNETII.WinApi.Headers.WinSCard", "src\THNETII.WinApi.Headers.WinSCard\THNETII.WinApi.Headers.WinSCard.csproj", "{56348771-2C99-4C0A-B63A-C7F0736621DA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "THNETII.WinApi.Headers.Ws2Def", "src\THNETII.WinApi.Headers.Ws2Def\THNETII.WinApi.Headers.Ws2Def.csproj", "{2ADE678A-17A4-45EF-8E2B-F95A0B612749}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -473,6 +475,18 @@ Global {56348771-2C99-4C0A-B63A-C7F0736621DA}.Release|x64.Build.0 = Release|Any CPU {56348771-2C99-4C0A-B63A-C7F0736621DA}.Release|x86.ActiveCfg = Release|Any CPU {56348771-2C99-4C0A-B63A-C7F0736621DA}.Release|x86.Build.0 = Release|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Debug|x64.ActiveCfg = Debug|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Debug|x64.Build.0 = Debug|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Debug|x86.ActiveCfg = Debug|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Debug|x86.Build.0 = Debug|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Release|Any CPU.Build.0 = Release|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Release|x64.ActiveCfg = Release|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Release|x64.Build.0 = Release|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Release|x86.ActiveCfg = Release|Any CPU + {2ADE678A-17A4-45EF-8E2B-F95A0B612749}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -510,6 +524,7 @@ Global {35C252B4-AD97-4E09-8097-72FDCA04EBF7} = {9689DB3E-1ED7-478C-AC14-C734B0397619} {25A891EB-9BF0-45D1-89EE-B24E80DE259E} = {9689DB3E-1ED7-478C-AC14-C734B0397619} {56348771-2C99-4C0A-B63A-C7F0736621DA} = {9689DB3E-1ED7-478C-AC14-C734B0397619} + {2ADE678A-17A4-45EF-8E2B-F95A0B612749} = {9689DB3E-1ED7-478C-AC14-C734B0397619} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6EF7C9CF-E403-4B60-AB44-5F9FFEB668B7} diff --git a/src-native-c/THNETII.WinApi.Sample.Native/main.c b/src-native-c/THNETII.WinApi.Sample.Native/main.c index f36a265a..282de067 100644 --- a/src-native-c/THNETII.WinApi.Sample.Native/main.c +++ b/src-native-c/THNETII.WinApi.Sample.Native/main.c @@ -1,12 +1,12 @@ -#include +#include int main(int argc, char* argv[]) { - SCARD_READERSTATE instance; + ADDRESS_FAMILY instance; const int size = sizeof(instance); - const int value = SCARD_ABSENT; + const int value = NULL; - const void* ptr = SCardGetReaderDeviceInstanceId; + const void* ptr = NULL; return EXIT_SUCCESS; } diff --git a/src/THNETII.WinApi.Headers.Ws2Def/THNETII.WinApi.Headers.Ws2Def.csproj b/src/THNETII.WinApi.Headers.Ws2Def/THNETII.WinApi.Headers.Ws2Def.csproj new file mode 100644 index 00000000..522e7bab --- /dev/null +++ b/src/THNETII.WinApi.Headers.Ws2Def/THNETII.WinApi.Headers.Ws2Def.csproj @@ -0,0 +1,11 @@ + + + + + true + netstandard1.3;netstandard2.0 + true + THNETII.WinApi.Native.Ws2Def + + +