using System; using System.Linq; using System.Runtime.InteropServices; using Vanara.Extensions; using Vanara.InteropServices; using static Vanara.PInvoke.Ws2_32; using DNS_STATUS = Vanara.PInvoke.Win32Error; using IP4_ADDRESS = Vanara.PInvoke.Ws2_32.IN_ADDR; using IP6_ADDRESS = Vanara.PInvoke.Ws2_32.IN6_ADDR; #pragma warning disable IDE1006 // Naming Styles namespace Vanara.PInvoke { /// Functions, structures and constants from windns.h. public static partial class DnsApi { /// Defines the maximum sockaddr length for DNS addresses public const int DNS_ADDR_MAX_SOCKADDR_LENGTH = 32; /// Version settings. public const uint DNS_APP_SETTINGS_VERSION1 = 1; /// public const int DNS_ATMA_MAX_ADDR_LENGTH = 20; /// public const int DNS_MAX_NAME_BUFFER_LENGTH = 256; /// public const uint DNS_QUERY_REQUEST_VERSION1 = 0x1; /// public const uint DNS_QUERY_REQUEST_VERSION2 = 0x2; /// public const uint DNS_QUERY_REQUEST_VERSION3 = 0x3; /// public const uint DNS_QUERY_RESULTS_VERSION1 = 0x1; /// The format of the ATM address in Address. [PInvokeData("windns.h", MSDNShortId = "09df3990-36bd-4656-b5cd-792e521adf9d")] public enum ATMA : byte { /// /// An address of the form: +358.400.1234567\0. The null-terminated hex characters map one-to-one into the ATM address with /// arbitrarily placed "." separators. The '+' indicates it is an E.164 format address. Its length is less than /// DNS_ATMA_MAX_ADDR_LENGTH bytes. /// DNS_ATMA_FORMAT_E164 = 1, /// /// An address of the form: 39.246f.123456789abcdefa0123.00123456789a.00. It is a 40 hex character address mapped to 20 octets /// with arbitrarily placed "." separators. Its length is exactly DNS_ATMA_AESA_ADDR_LENGTH bytes. /// DNS_ATMA_FORMAT_AESA = 2, } /// Flags for . [PInvokeData("windns.h", MSDNShortId = "NS:windns._DNS_APPLICATION_SETTINGS")] [Flags] public enum DNS_APP_SETTINGSF { /// Use the custom DNS servers exclusively, and don't try the system-configured ones. DNS_APP_SETTINGS_EXCLUSIVE_SERVERS = 1, } /// The DNS_CHARSET enumeration specifies the character set used. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ne-windns-dns_charset typedef enum _DNS_CHARSET { DnsCharSetUnknown, // DnsCharSetUnicode, DnsCharSetUtf8, DnsCharSetAnsi } DNS_CHARSET; [PInvokeData("windns.h", MSDNShortId = "2674a4e5-c3e2-4a25-bd6f-1fc6b4db3012")] public enum DNS_CHARSET { /// The character set is unknown. DnsCharSetUnknown, /// The character set is Unicode. DnsCharSetUnicode, /// The character set is UTF8. DnsCharSetUtf8, /// The character set is ANSI. DnsCharSetAnsi, } /// A value that represents the RR DNS Record Class. [PInvokeData("windns.h")] public enum DNS_CLASS : ushort { /// DNS_CLASS_INTERNET = 0x0001, /// DNS_CLASS_CSNET = 0x0002, /// DNS_CLASS_CHAOS = 0x0003, /// DNS_CLASS_HESIOD = 0x0004, /// DNS_CLASS_NONE = 0x00fe, /// DNS_CLASS_ALL = 0x00ff, /// DNS_CLASS_ANY = 0x00ff, /// DNS_CLASS_UNICAST_RESPONSE = 0x8000 } /// A value that specifies whether to allocate memory for the configuration information. [PInvokeData("windns.h", MSDNShortId = "83de7df8-7e89-42fe-b609-1dc173afc9df")] [Flags] public enum DNS_CONFIG_FLAG : uint { /// Set Flag to DNS_CONFIG_FLAG_ALLOC to allocate memory; otherwise, set it to 0. DNS_CONFIG_FLAG_ALLOC = 1 } /// The DNS_CONFIG_TYPE enumeration provides DNS configuration type information. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ne-windns-dns_config_type typedef enum { DnsConfigPrimaryDomainName_W, // DnsConfigPrimaryDomainName_A, DnsConfigPrimaryDomainName_UTF8, DnsConfigAdapterDomainName_W, DnsConfigAdapterDomainName_A, // DnsConfigAdapterDomainName_UTF8, DnsConfigDnsServerList, DnsConfigSearchList, DnsConfigAdapterInfo, // DnsConfigPrimaryHostNameRegistrationEnabled, DnsConfigAdapterHostNameRegistrationEnabled, DnsConfigAddressRegistrationMaxCount, // DnsConfigHostName_W, DnsConfigHostName_A, DnsConfigHostName_UTF8, DnsConfigFullHostName_W, DnsConfigFullHostName_A, // DnsConfigFullHostName_UTF8, DnsConfigNameServer } DNS_CONFIG_TYPE; [PInvokeData("windns.h", MSDNShortId = "e0f0cc05-dcfe-48df-8dbd-e756cfa69154")] public enum DNS_CONFIG_TYPE { /// For use with Unicode on Windows 2000. [CorrespondingType(typeof(string))] [CorrespondingType(typeof(StrPtrUni))] DnsConfigPrimaryDomainName_W, /// For use with ANSI on Windows 2000. [CorrespondingType(typeof(StrPtrAnsi))] DnsConfigPrimaryDomainName_A, /// For use with UTF8 on Windows 2000. DnsConfigPrimaryDomainName_UTF8, /// Not currently available. // Unimplemented DnsConfigAdapterDomainName_W, /// Not currently available. // Unimplemented DnsConfigAdapterDomainName_A, /// Not currently available. // Unimplemented DnsConfigAdapterDomainName_UTF8, /// For configuring a DNS Server list on Windows 2000. [CorrespondingType(typeof(IP4_ARRAY))] DnsConfigDnsServerList, /// Not currently available. // Unimplemented DnsConfigSearchList, /// Not currently available. // Unimplemented DnsConfigAdapterInfo, /// Specifies that primary host name registration is enabled on Windows 2000. // Unimplemented [CorrespondingType(typeof(uint))] DnsConfigPrimaryHostNameRegistrationEnabled, /// Specifies that adapter host name registration is enabled on Windows 2000. // Unimplemented [CorrespondingType(typeof(uint))] DnsConfigAdapterHostNameRegistrationEnabled, /// Specifies configuration of the maximum number of address registrations on Windows 2000. // Unimplemented [CorrespondingType(typeof(uint))] DnsConfigAddressRegistrationMaxCount, /// /// Specifies configuration of the host name in Unicode on Windows XP, Windows Server 2003, and later versions of Windows. /// [CorrespondingType(typeof(string))] [CorrespondingType(typeof(StrPtrUni))] DnsConfigHostName_W, /// Specifies configuration of the host name in ANSI on Windows XP, Windows Server 2003, and later versions of Windows. [CorrespondingType(typeof(StrPtrAnsi))] DnsConfigHostName_A, /// Specifies configuration of the host name in UTF8 on Windows XP, Windows Server 2003, and later versions of Windows. DnsConfigHostName_UTF8, /// /// Specifies configuration of the full host name (fully qualified domain name) in Unicode on Windows XP, Windows Server 2003, /// and later versions of Windows. /// [CorrespondingType(typeof(string))] [CorrespondingType(typeof(StrPtrUni))] DnsConfigFullHostName_W, /// /// Specifies configuration of the full host name (fully qualified domain name) in ANSI on Windows XP, Windows Server 2003, and /// later versions of Windows. /// [CorrespondingType(typeof(StrPtrAnsi))] DnsConfigFullHostName_A, /// /// Specifies configuration of the full host name (fully qualified domain name) in UTF8 on Windows XP, Windows Server 2003, and /// later versions of Windows. /// DnsConfigFullHostName_UTF8, /// DnsConfigNameServer, } /// A value that contains a bitmap of the following options. [PInvokeData("windns.h", MSDNShortId = "NS:windns._DNS_CUSTOM_SERVER")] [Flags] public enum DNS_CUSTOM_SERVER_FLAGS : ulong { /// Server might fall back to unsecure resolution DNS_CUSTOM_SERVER_TYPE_UDP = 1, } /// The server type. Must be one of the following. [PInvokeData("windns.h", MSDNShortId = "NS:windns._DNS_CUSTOM_SERVER")] public enum DNS_CUSTOM_SERVER_TYPE : uint { /// Perform unsecure name resolution DNS_CUSTOM_SERVER_TYPE_UDP = 1, /// Perform DNS-over-HTTPS name resolution DNS_CUSTOM_SERVER_TYPE_DOH = 2 } /// The DNS_FREE_TYPE enumeration specifies the type of data to free. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ne-windns-dns_free_type typedef enum { DnsFreeFlat, DnsFreeRecordList, // DnsFreeParsedMessageFields } DNS_FREE_TYPE; [PInvokeData("windns.h", MSDNShortId = "976982a1-08f1-4c67-b823-1eea34f0c643")] public enum DNS_FREE_TYPE { /// The data freed is a flat structure. DnsFreeFlat, /// /// The data freed is a Resource Record list, and includes subfields of the DNS_RECORD structure. Resources freed include /// structures returned by the DnsQuery and DnsRecordSetCopyEx functions. /// DnsFreeRecordList, /// The data freed is a parsed message field. DnsFreeParsedMessageFields, } /// The DNS_NAME_FORMAT enumeration specifies name format information for DNS. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ne-windns-dns_name_format typedef enum _DNS_NAME_FORMAT { // DnsNameDomain, DnsNameDomainLabel, DnsNameHostnameFull, DnsNameHostnameLabel, DnsNameWildcard, DnsNameSrvRecord, // DnsNameValidateTld } DNS_NAME_FORMAT; [PInvokeData("windns.h", MSDNShortId = "f6f1cff3-4bff-4a07-bbc6-5255030b4164")] public enum DNS_NAME_FORMAT { /// The name format is a DNS domain. DnsNameDomain, /// The name format is a DNS domain label. DnsNameDomainLabel, /// The name format is a full DNS host name. DnsNameHostnameFull, /// The name format is a DNS host label. DnsNameHostnameLabel, /// The name format is a DNS wildcard. DnsNameWildcard, /// The name format is a DNS SRV record. DnsNameSrvRecord, /// Windows 7 or later: The name format is a DNS domain or a full DNS host name. DnsNameValidateTld, } /// A value representing the type of the query. [PInvokeData("windns.h")] public enum DNS_OPCODE : ushort { /// DNS_OPCODE_QUERY = 0, /// DNS_OPCODE_IQUERY = 1, /// DNS_OPCODE_SERVER_STATUS = 2, /// DNS_OPCODE_UNKNOWN = 3, /// DNS_OPCODE_NOTIFY = 4, /// DNS_OPCODE_UPDATE = 5, } /// /// The DNS_PROXY_INFORMATION_TYPE enumeration defines the proxy information type in the DNS_PROXY_INFORMATION structure. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ne-windns-dns_proxy_information_type typedef enum // DNS_PROXY_INFORMATION_TYPE { DNS_PROXY_INFORMATION_DIRECT, DNS_PROXY_INFORMATION_DEFAULT_SETTINGS, // DNS_PROXY_INFORMATION_PROXY_NAME, DNS_PROXY_INFORMATION_DOES_NOT_EXIST } ; [PInvokeData("windns.h", MSDNShortId = "983d38f3-3ee7-4df6-a9ff-f908f250020f")] public enum DNS_PROXY_INFORMATION_TYPE { /// The type is bypass proxy information. DNS_PROXY_INFORMATION_DIRECT, /// The type is the user's default browser proxy settings. DNS_PROXY_INFORMATION_DEFAULT_SETTINGS, /// The type is defined by the proxyName member of the DNS_PROXY_INFORMATION structure. DNS_PROXY_INFORMATION_PROXY_NAME, /// /// The type does not exist. DNS policy does not have proxy information for this name space. This type is used if no wildcard /// policy exists and there is no default proxy information. /// DNS_PROXY_INFORMATION_DOES_NOT_EXIST, } /// A value representing the query options. [PInvokeData("windns.h")] [Flags] public enum DNS_QUERY_OPTIONS : uint { /// Standard query. DNS_QUERY_STANDARD = 0x00000000, /// Returns truncated results. Does not retry under TCP. DNS_QUERY_ACCEPT_TRUNCATED_RESPONSE = 0x00000001, /// Uses TCP only for the query. DNS_QUERY_USE_TCP_ONLY = 0x00000002, /// /// Directs the DNS server to perform an iterative query (specifically directs the DNS server not to perform recursive /// resolution to resolve the query). /// DNS_QUERY_NO_RECURSION = 0x00000004, /// Bypasses the resolver cache on the lookup. DNS_QUERY_BYPASS_CACHE = 0x00000008, /// /// Directs DNS to perform a query on the local cache only.Windows 2000 Server and Windows 2000 Professional: This value is not /// supported. For similar functionality, use DNS_QUERY_CACHE_ONLY. /// DNS_QUERY_NO_WIRE_QUERY = 0x00000010, /// Directs DNS to ignore the local name.Windows 2000 Server and Windows 2000 Professional: This value is not supported. DNS_QUERY_NO_LOCAL_NAME = 0x00000020, /// /// Prevents the DNS query from consulting the HOSTS file.Windows 2000 Server and Windows 2000 Professional: This value is not supported. /// DNS_QUERY_NO_HOSTS_FILE = 0x00000040, /// /// Prevents the DNS query from using NetBT for resolution.Windows 2000 Server and Windows 2000 Professional: This value is not supported. /// DNS_QUERY_NO_NETBT = 0x00000080, /// /// Directs DNS to perform a query using the network only, bypassing local information.Windows 2000 Server and Windows 2000 /// Professional: This value is not supported. /// DNS_QUERY_WIRE_ONLY = 0x00000100, /// /// Directs DNS to return the entire DNS response message.Windows 2000 Server and Windows 2000 Professional: This value is not supported. /// DNS_QUERY_RETURN_MESSAGE = 0x00000200, /// /// Prevents the query from using DNS and uses only Local Link Multicast Name Resolution (LLMNR).Windows Vista and Windows /// Server 2008 or later.: This value is supported. /// DNS_QUERY_MULTICAST_ONLY = 0x00000400, /// DNS_QUERY_NO_MULTICAST = 0x00000800, /// Prevents the DNS response from attaching suffixes to the submitted name in a name resolution process. DNS_QUERY_TREAT_AS_FQDN = 0x00001000, /// /// Windows 7 only: Do not send A type queries if IPv4 addresses are not available on an interface and do not send AAAA type /// queries if IPv6 addresses are not available. /// DNS_QUERY_ADDRCONFIG = 0x00002000, /// /// Windows 7 only: Query both AAAA and A type records and return results for each. Results for A type records are mapped into /// AAAA type. /// DNS_QUERY_DUAL_ADDR = 0x00004000, /// Undocumented flag used by ipconfig to display DNS cache. DNS_QUERY_LOCAL = 0x00008000, /// /// Waits for a full timeout to collect all the responses from the Local Link. If not set, the default behavior is to return /// with the first response.Windows Vista and Windows Server 2008 or later.: This value is supported. /// DNS_QUERY_MULTICAST_WAIT = 0x00020000, /// /// Directs a test using the local machine hostname to verify name uniqueness on the same Local Link.Collects all responses even /// if normal LLMNR Sender behavior is not enabled.Windows Vista and Windows Server 2008 or later.: This value is supported. /// DNS_QUERY_MULTICAST_VERIFY = 0x00040000, /// /// If set, and if the response contains multiple records, records are stored with the TTL corresponding to the minimum value /// TTL from among all records. When this option is set, "Do not change the TTL of individual records" in the returned record /// set is not modified. /// DNS_QUERY_DONT_RESET_TTL_VALUES = 0x00100000, /// /// Disables International Domain Name (IDN) encoding support in the DnsQuery, DnsQueryEx, DnsModifyRecordsInSet, and /// DnsReplaceRecordSet APIs. All punycode names are treated as ASCII and will be ASCII encoded on the wire. All non-ASCII names /// are encoded in UTF8 on the wire. Windows 8 or later.: This value is supported. /// DNS_QUERY_DISABLE_IDN_ENCODING = 0x00200000, /// DNS_QUERY_APPEND_MULTILABEL = 0x00800000, /// DNS_QUERY_DNSSEC_OK = 0x01000000, /// DNS_QUERY_DNSSEC_CHECKING_DISABLED = 0x02000000, /// Reserved. DNS_QUERY_RESERVED = 0xf0000000, } /// An error or response code, expressed in expanded RCODE format. [PInvokeData("windns.h", MSDNShortId = "4dad3449-3e41-47d9-89c2-10fa6e51573b")] public enum DNS_RCODE : ushort { /// No error. DNS_RCODE_NOERROR = 0, /// Format error. DNS_RCODE_FORMERR = 1, /// Server failure. DNS_RCODE_SERVFAIL = 2, /// Name error DNS_RCODE_NXDOMAIN = 3, /// Not implemented. DNS_RCODE_NOTIMPL = 4, /// Connection refused. DNS_RCODE_REFUSED = 5, /// Domain name should not exist. DNS_RCODE_YXDOMAIN = 6, /// Resource Record (RR) set should not exist. DNS_RCODE_YXRRSET = 7, /// RR set does not exist DNS_RCODE_NXRRSET = 8, /// Not authoritative for zone DNS_RCODE_NOTAUTH = 9, /// Name not in zone DNS_RCODE_NOTZONE = 10, /// Bad version. DNS_RCODE_BADVERS = 16, /// The pSignature of the DNS_TSIG_DATA RR is bad. DNS_RCODE_BADSIG = 16, /// The pKey field is bad. DNS_RCODE_BADKEY = 17, /// A timestamp is bad. DNS_RCODE_BADTIME = 18, } /// /// The DNS_SECTION enumeration is used in record flags, and as an index into DNS wire message header section counts. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ne-windns-dns_section typedef enum _DnsSection { DnsSectionQuestion, // DnsSectionAnswer, DnsSectionAuthority, DnsSectionAddtional } DNS_SECTION; [PInvokeData("windns.h", MSDNShortId = "d51ef2c7-c2bb-4eed-a026-a559460352b6")] public enum DNS_SECTION { /// The DNS section specified is a DNS question. DnsSectionQuestion, /// The DNS section specified is a DNS answer. DnsSectionAnswer, /// The DNS section specified indicates a DNS authority. DnsSectionAuthority, /// The DNS section specified is additional DNS information. DnsSectionAddtional, } /// A scheme used for key agreement or the purpose of the TKEY DNS Message. [PInvokeData("windns.h", MSDNShortId = "4dad3449-3e41-47d9-89c2-10fa6e51573b")] public enum DNS_TKEY_MODE : ushort { /// The key is assigned by the DNS server and is not negotiated. DNS_TKEY_MODE_SERVER_ASSIGN = 1, /// The Diffie-Hellman key exchange algorithm is used to negotiate the key. DNS_TKEY_MODE_DIFFIE_HELLMAN = 2, /// The key is exchanged through Generic Security Services-Application Program Interface (GSS-API) negotiation. DNS_TKEY_MODE_GSS = 3, /// The key is assigned by the DNS resolver and is not negotiated. DNS_TKEY_MODE_RESOLVER_ASSIGN = 4, } /// DNS record types. [PInvokeData("windns.h")] public enum DNS_TYPE : ushort { /// [CorrespondingType(typeof(DNS_A_DATA))] DNS_TYPE_A = 0x0001, /// [CorrespondingType(typeof(DNS_PTR_DATA))] DNS_TYPE_NS = 0x0002, /// [CorrespondingType(typeof(DNS_PTR_DATA))] DNS_TYPE_MD = 0x0003, /// [CorrespondingType(typeof(DNS_PTR_DATA))] DNS_TYPE_MF = 0x0004, /// [CorrespondingType(typeof(DNS_PTR_DATA))] DNS_TYPE_CNAME = 0x0005, /// [CorrespondingType(typeof(DNS_SOA_DATA))] DNS_TYPE_SOA = 0x0006, /// [CorrespondingType(typeof(DNS_PTR_DATA))] DNS_TYPE_MB = 0x0007, /// [CorrespondingType(typeof(DNS_PTR_DATA))] DNS_TYPE_MG = 0x0008, /// [CorrespondingType(typeof(DNS_PTR_DATA))] DNS_TYPE_MR = 0x0009, /// [CorrespondingType(typeof(DNS_NULL_DATA))] DNS_TYPE_NULL = 0x000a, /// [CorrespondingType(typeof(DNS_WKS_DATA))] DNS_TYPE_WKS = 0x000b, /// [CorrespondingType(typeof(DNS_PTR_DATA))] DNS_TYPE_PTR = 0x000c, /// [CorrespondingType(typeof(DNS_TXT_DATA))] DNS_TYPE_HINFO = 0x000d, /// [CorrespondingType(typeof(DNS_MINFO_DATA))] DNS_TYPE_MINFO = 0x000e, /// [CorrespondingType(typeof(DNS_MX_DATA))] DNS_TYPE_MX = 0x000f, /// [CorrespondingType(typeof(DNS_TXT_DATA))] DNS_TYPE_TEXT = 0x0010, /// [CorrespondingType(typeof(DNS_MINFO_DATA))] DNS_TYPE_RP = 0x0011, /// [CorrespondingType(typeof(DNS_MX_DATA))] DNS_TYPE_AFSDB = 0x0012, /// [CorrespondingType(typeof(DNS_TXT_DATA))] DNS_TYPE_X25 = 0x0013, /// [CorrespondingType(typeof(DNS_TXT_DATA))] DNS_TYPE_ISDN = 0x0014, /// [CorrespondingType(typeof(DNS_MX_DATA))] DNS_TYPE_RT = 0x0015, /// DNS_TYPE_NSAP = 0x0016, /// DNS_TYPE_NSAPPTR = 0x0017, /// [CorrespondingType(typeof(DNS_SIG_DATA))] DNS_TYPE_SIG = 0x0018, /// [CorrespondingType(typeof(DNS_KEY_DATA))] DNS_TYPE_KEY = 0x0019, /// DNS_TYPE_PX = 0x001a, /// DNS_TYPE_GPOS = 0x001b, /// [CorrespondingType(typeof(DNS_AAAA_DATA))] DNS_TYPE_AAAA = 0x001c, /// [CorrespondingType(typeof(DNS_LOC_DATA))] DNS_TYPE_LOC = 0x001d, /// [CorrespondingType(typeof(DNS_NXT_DATA))] DNS_TYPE_NXT = 0x001e, /// DNS_TYPE_EID = 0x001f, /// DNS_TYPE_NIMLOC = 0x0020, /// [CorrespondingType(typeof(DNS_SRV_DATA))] DNS_TYPE_SRV = 0x0021, /// [CorrespondingType(typeof(DNS_ATMA_DATA))] DNS_TYPE_ATMA = 0x0022, /// [CorrespondingType(typeof(DNS_NAPTR_DATA))] DNS_TYPE_NAPTR = 0x0023, /// DNS_TYPE_KX = 0x0024, /// DNS_TYPE_CERT = 0x0025, /// DNS_TYPE_A6 = 0x0026, /// [CorrespondingType(typeof(DNS_PTR_DATA))] DNS_TYPE_DNAME = 0x0027, /// DNS_TYPE_SINK = 0x0028, /// [CorrespondingType(typeof(DNS_OPT_DATA))] DNS_TYPE_OPT = 0x0029, /// [CorrespondingType(typeof(DNS_DS_DATA))] DNS_TYPE_DS = 0x002b, /// DNS_TYPE_RRSIG = 0x002e, /// [CorrespondingType(typeof(DNS_NSEC_DATA))] DNS_TYPE_NSEC = 0x002f, /// DNS_TYPE_DNSKEY = 0x0030, /// [CorrespondingType(typeof(DNS_DHCID_DATA))] DNS_TYPE_DHCID = 0x0031, /// [CorrespondingType(typeof(DNS_NSEC3_DATA))] DNS_TYPE_NSEC3 = 0x0032, /// [CorrespondingType(typeof(DNS_NSEC3PARAM_DATA))] DNS_TYPE_NSEC3PARAM = 0x0033, /// [CorrespondingType(typeof(DNS_TLSA_DATA))] DNS_TYPE_TLSA = 0x0034, /// DNS_TYPE_UINFO = 0x0064, /// DNS_TYPE_UID = 0x0065, /// DNS_TYPE_GID = 0x0066, /// DNS_TYPE_UNSPEC = 0x0067, /// DNS_TYPE_ADDRS = 0x00f8, /// [CorrespondingType(typeof(DNS_TKEY_DATA))] DNS_TYPE_TKEY = 0x00f9, /// [CorrespondingType(typeof(DNS_TSIG_DATA))] DNS_TYPE_TSIG = 0x00fa, /// DNS_TYPE_IXFR = 0x00fb, /// DNS_TYPE_AXFR = 0x00fc, /// DNS_TYPE_MAILB = 0x00fd, /// DNS_TYPE_MAILA = 0x00fe, /// DNS_TYPE_ALL = 0x00ff, /// DNS_TYPE_ANY = 0x00ff, /// [CorrespondingType(typeof(DNS_WINS_DATA))] DNS_TYPE_WINS = 0xff01, /// [CorrespondingType(typeof(DNS_WINSR_DATA))] DNS_TYPE_WINSR = 0xff02, /// [CorrespondingType(typeof(DNS_WINSR_DATA))] DNS_TYPE_NBSTAT = (DNS_TYPE_WINSR), } /// A value that contains a bitmap of DNS Update Options. [PInvokeData("windns.h", MSDNShortId = "7b99f440-72fa-4cf4-9267-98f436e99a50")] [Flags] public enum DNS_UPDATE : uint { /// Uses the default behavior, which is specified in the registry, for secure dynamic DNS updates. DNS_UPDATE_SECURITY_USE_DEFAULT = 0x00000000, /// Does not attempt secure dynamic updates. DNS_UPDATE_SECURITY_OFF = 0x00000010, /// Attempts non-secure dynamic update; if refused, attempts secure dynamic update. DNS_UPDATE_SECURITY_ON = 0x00000020, /// Attempts secure dynamic updates only. DNS_UPDATE_SECURITY_ONLY = 0x00000100, /// Caches the security context for use in future transactions. DNS_UPDATE_CACHE_SECURITY_CONTEXT = 0x00000200, /// Uses credentials of the local computer account. DNS_UPDATE_TEST_USE_LOCAL_SYS_ACCT = 0x00000400, /// Does not use cached security context. DNS_UPDATE_FORCE_SECURITY_NEGO = 0x00000800, /// Sends DNS updates to all multi-master DNS servers. DNS_UPDATE_TRY_ALL_MASTER_SERVERS = 0x00001000, /// /// Do not update adapters where dynamic DNS updates are disabled. Windows 2000 Server with SP2 or later.: This value is supported. /// DNS_UPDATE_SKIP_NO_UPDATE_ADAPTERS = 0x00002000, /// /// Register CNAME records on a remote server in addition to the local DNS server.Windows 2000 Server with SP2 or later.: This /// value is supported. /// DNS_UPDATE_REMOTE_SERVER = 0x00004000, /// Reserved for future use. DNS_UPDATE_RESERVED = 0xffff0000, } /// The WINS mapping flag that specifies whether the record must be included in zone replication. [PInvokeData("windns.h", MSDNShortId = "df41c397-e662-42b4-9193-6776f9071898")] public enum DNS_WINS_FLAG : uint { /// Record is not local, replicate across zones. DNS_WINS_FLAG_SCOPE = 0x80000000, /// Record is local, do not replicate. DNS_WINS_FLAG_LOCAL = 0x00010000, } /// Represents the query validation status. [PInvokeData("windns.h", MSDNShortId = "5b362d05-87b2-44dd-8198-bcb5ab5a64f6")] public enum DnsServerStatus : uint { /// No errors. The call was successful. ERROR_SUCCESS = 0, /// server IP address was invalid. DNS_VALSVR_ERROR_INVALID_ADDR = 0x01, /// queryName FQDN was invalid. DNS_VALSVR_ERROR_INVALID_NAME = 0x02, /// DNS server was unreachable. DNS_VALSVR_ERROR_UNREACHABLE = 0x03, /// Timeout waiting for the DNS server response. DNS_VALSVR_ERROR_NO_RESPONSE = 0x04, /// DNS server was not authoritative or queryName was not found. DNS_VALSVR_ERROR_NO_AUTH = 0x05, /// DNS server refused the query. DNS_VALSVR_ERROR_REFUSED = 0x06, /// /// The TCP query did not return ERROR_SUCCESS after the validation system had already completed a successful query to the DNS /// server using UDP. /// DNS_VALSVR_ERROR_NO_TCP = 0x10, /// An unknown error occurred. DNS_VALSVR_ERROR_UNKNOWN = 0xFF, } /// The DNS_A_DATA structure represents a DNS address (A) record as specified in section 3.4.1 of RFC 1035. /// /// The DNS_A_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_a_data typedef struct { IP4_ADDRESS IpAddress; } // DNS_A_DATA, *PDNS_A_DATA; [PInvokeData("windns.h", MSDNShortId = "0fd21930-1319-4ae7-b46f-2b744f4faae9")] [StructLayout(LayoutKind.Sequential)] public struct DNS_A_DATA { /// An IP4_ADDRESS data type that contains an IPv4 address. public IP4_ADDRESS IpAddress; } /// The DNS_AAAA_DATA structure represents a DNS IPv6 (AAAA) record as specified in RFC 3596. /// /// The DNS_AAAA_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_aaaa_data typedef struct { IP6_ADDRESS Ip6Address; } // DNS_AAAA_DATA, *PDNS_AAAA_DATA; [PInvokeData("windns.h", MSDNShortId = "0bc48e86-368c-431c-b67a-b7689dca8d3c")] [StructLayout(LayoutKind.Sequential)] public struct DNS_AAAA_DATA { /// An IP6_ADDRESS data type that contains an IPv6 address. public IP6_ADDRESS Ip6Address; } /// A DNS_ADDR structure stores an IPv4 or IPv6 address. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_addr typedef struct _DnsAddr { CHAR // MaxSa[DNS_ADDR_MAX_SOCKADDR_LENGTH]; DWORD DnsAddrUserDword[8]; } DNS_ADDR, *PDNS_ADDR; [PInvokeData("windns.h", MSDNShortId = "c14e6fc0-34b3-40e8-b9b8-61e4aea01677")] [StructLayout(LayoutKind.Sequential)] public struct DNS_ADDR { /// /// A value that contains the socket IP address. It is a sockaddr_in structure if the address is IPv4 and a sockaddr_in6 /// structure if the address is IPv6. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = DNS_ADDR_MAX_SOCKADDR_LENGTH)] public byte[] MaxSa; /// Reserved. Must be 0. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public uint[] DnsAddrUserDword; /// Performs an explicit conversion from to . /// The DNS address. /// The resulting instance from the conversion. public static explicit operator System.Net.IPAddress(DNS_ADDR dnsAddr) => new(dnsAddr.MaxSa); } /// The DNS_ADDR_ARRAY structure stores an array of IPv4 or IPv6 addresses. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_addr_array typedef struct _DnsAddrArray { DWORD MaxCount; // DWORD AddrCount; DWORD Tag; WORD Family; WORD WordReserved; DWORD Flags; DWORD MatchFlag; DWORD Reserved1; DWORD Reserved2; // DNS_ADDR AddrArray[]; } DNS_ADDR_ARRAY, *PDNS_ADDR_ARRAY; [PInvokeData("windns.h", MSDNShortId = "5FD7F28B-D1A6-4731-ACB9-A7BB23CC1FB4")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(AddrCount))] [StructLayout(LayoutKind.Sequential)] public struct DNS_ADDR_ARRAY { /// Indicates, the size, in bytes, of this structure. public uint MaxCount; /// Indicates the number of DNS_ADDR structures contained in the AddrArray member. public uint AddrCount; /// Reserved. Do not use. public uint Tag; /// /// A value that specifies the IP family. Possible values are: /// /// /// Value /// Meaning /// /// /// AF_INET6 /// IPv6 /// /// /// AF_INET /// IPv4 /// /// /// public ADDRESS_FAMILY Family; /// Reserved. Do not use. public ushort WordReserved; /// Reserved. Do not use. public uint Flags; /// Reserved. Do not use. public uint MatchFlag; /// Reserved. Do not use. public uint Reserved1; /// Reserved. Do not use. public uint Reserved2; /// An array of DNS_ADDR structures that each contain an IP address. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public DNS_ADDR[] AddrArray; /// Initializes a new instance of the struct with IPv4 addresses. /// The list of IPv4 addresses. public DNS_ADDR_ARRAY(params SOCKADDR_IN[] addrs) : this(Array.ConvertAll(addrs, a => new SOCKADDR(a))) { } /// Initializes a new instance of the struct with IPv6 addresses. /// The list of IPv4 addresses. public DNS_ADDR_ARRAY(params SOCKADDR_IN6[] addrs) : this(Array.ConvertAll(addrs, a => new SOCKADDR(a))) { } /// Initializes a new instance of the struct with instances. /// The list of socket addresses. public DNS_ADDR_ARRAY(params SOCKADDR[] addrs) : this() { MaxCount = AddrCount = (uint)(addrs?.Length ?? 0); Family = AddrCount == 0 ? ADDRESS_FAMILY.AF_INET6 : addrs[0].sa_family; AddrArray = Array.ConvertAll(addrs, a => new DNS_ADDR() { MaxSa = a.GetBytes() }); } } /// Represents per-application DNS settings. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_application_settings typedef struct // _DNS_APPLICATION_SETTINGS { ULONG Version; ULONG64 Flags; } DNS_APPLICATION_SETTINGS; [PInvokeData("windns.h", MSDNShortId = "NS:windns._DNS_APPLICATION_SETTINGS")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_APPLICATION_SETTINGS { /// /// Type: ULONG /// Must be set to DNS_APP_SETTINGS_VERSION1. /// public uint Version; /// /// Type: ULONG /// A bitset containing the following options. /// /// /// /// DNS_APP_SETTINGS_EXCLUSIVE_SERVERS (0x1). Use the custom DNS servers exclusively, and don't try the system-configured ones. /// /// /// /// public DNS_APP_SETTINGSF Flags; } /// The DNS_ATMA_DATA structure represents a DNS ATM address (ATMA) resource record (RR). /// /// The DNS_ATMA_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_atma_data typedef struct { BYTE AddressType; BYTE // Address[DNS_ATMA_MAX_ADDR_LENGTH]; } DNS_ATMA_DATA, *PDNS_ATMA_DATA; [PInvokeData("windns.h", MSDNShortId = "09df3990-36bd-4656-b5cd-792e521adf9d")] [StructLayout(LayoutKind.Sequential)] public struct DNS_ATMA_DATA { /// /// The format of the ATM address in Address. The possible values for AddressType are: /// /// /// Value /// Meaning /// /// /// DNS_ATMA_FORMAT_AESA /// /// An address of the form: 39.246f.123456789abcdefa0123.00123456789a.00. It is a 40 hex character address mapped to 20 octets /// with arbitrarily placed "." separators. Its length is exactly DNS_ATMA_AESA_ADDR_LENGTH bytes. /// /// /// /// DNS_ATMA_FORMAT_E164 /// /// An address of the form: +358.400.1234567\0. The null-terminated hex characters map one-to-one into the ATM address with /// arbitrarily placed "." separators. The '+' indicates it is an E.164 format address. Its length is less than /// DNS_ATMA_MAX_ADDR_LENGTH bytes. /// /// /// /// public ATMA AddressType; /// A BYTE array that contains the ATM address whose format is specified by AddressType. [MarshalAs(UnmanagedType.ByValArray, SizeConst = DNS_ATMA_MAX_ADDR_LENGTH)] public byte[] Address; } /// Undocumented. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_CACHE_ENTRY { /// Pointer to next entry. public IntPtr pNext; /// DNS Record Name. public StrPtrUni pszName; /// DNS Record Type. public DNS_TYPE wType; /// Undocumented. public ushort wDataLength; /// Undocumented. public DNS_RECORD_FLAGS dwFlags; } /// /// Represents a DNS custom server. A DNS_CUSTOM_SERVER object is passed to DnsQueryEx via the DNS_QUERY_REQUEST3 structure. /// To use DNS_CUSTOM_SERVER together with ServerAddr, include ws2ipdef.h before windns.h. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_custom_server typedef struct _DNS_CUSTOM_SERVER { DWORD // dwServerType; ULONG64 ullFlags; union { PWSTR pwszTemplate; }; CHAR MaxSa[DNS_ADDR_MAX_SOCKADDR_LENGTH]; } DNS_CUSTOM_SERVER; [PInvokeData("windns.h", MSDNShortId = "NS:windns._DNS_CUSTOM_SERVER")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_CUSTOM_SERVER { /// /// Type: DWORD /// The server type. Must be one of the following. /// /// /// /// Value /// Description /// /// /// DNS_CUSTOM_SERVER_TYPE_UDP /// 0x1 /// Perform unsecure name resolution /// /// /// DNS_CUSTOM_SERVER_TYPE_DOH /// 0x2 /// Perform DNS-over-HTTPS name resolution /// /// /// public DNS_CUSTOM_SERVER_TYPE dwServerType; /// /// Type: ULONG64 /// A value that contains a bitmap of the following options. /// /// /// /// Value /// Description /// /// /// DNS_CUSTOM_SERVER_UDP_FALLBACK /// 0x1 /// Server might fall back to unsecure resolution /// /// /// public DNS_CUSTOM_SERVER_FLAGS ullFlags; /// /// Type: PWSTR /// A NULL-terminated wide string representing the DNS-over-HTTPS template. /// If dwServerType is set to DNS_CUSTOM_SERVER_TYPE_UDP, then this field must be NULL. /// /// If dwServerType is set to DNS_CUSTOM_SERVER_TYPE_DOH, then this field must point to a valid NULL-terminated string. /// /// public string pwszTemplate; /// /// Type: CHAR[DNS_ADDR_MAX_SOCKADDR_LENGTH] /// A byte array, which designates storage for a SOCKADDR_INET. MaxSa is a union with ServerAddr. /// /// To use DNS_CUSTOM_SERVER together with ServerAddr, you must include ws2ipdef.h before windns.h . /// /// /// Besides storage for the SOCKADDR_INET, MaxSa avoids compile errors caused by not including ws2ipdef.h . This /// allows you to use any functionality from windns.h except for the DNS_CUSTOM_SERVER. /// /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = DNS_ADDR_MAX_SOCKADDR_LENGTH)] public byte[] MaxSa; } /// /// The DNS_DHCID_DATA structure represents a DNS Dynamic Host Configuration Protocol Information (DHCID) resource record /// (RR) as specified in section 3 of RFC 4701. /// /// /// The DNS_DHCID_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_dhcid_data typedef struct { DWORD dwByteCount; #if ... // BYTE DHCID[]; #else BYTE DHCID[1]; #endif } DNS_DHCID_DATA, *PDNS_DHCID_DATA; [PInvokeData("windns.h", MSDNShortId = "868846bc-9f63-4bb3-ac8d-cea34232bb41")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(dwByteCount))] [StructLayout(LayoutKind.Sequential)] public struct DNS_DHCID_DATA { /// The length, in bytes, of DHCID. public uint dwByteCount; /// /// A BYTE array that contains the DHCID client, domain, and SHA-256 digest information as specified in section 4 of RFC 2671. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] DHCID; } /// /// The DNS_DS_DATA structure represents a DS resource record (RR) as specified in section 2 of RFC 4034 and is used to /// verify the contents of DNS_DNSKEY_DATA. /// /// /// The DNS_DS_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_ds_data typedef struct { WORD wKeyTag; BYTE chAlgorithm; // BYTE chDigestType; WORD wDigestLength; WORD wPad; #if ... BYTE Digest[]; #else BYTE Digest[1]; #endif } DNS_DS_DATA, *PDNS_DS_DATA; [PInvokeData("windns.h", MSDNShortId = "8624cc27-feb5-4e4a-8970-40aa1d43960e")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(wDigestLength))] [StructLayout(LayoutKind.Sequential)] public struct DNS_DS_DATA { /// /// A value that represents the method to choose which public key is used to verify Signature in DNS_RRSIG_DATA as /// specified in Appendix B of RFC 4034. This value is identical to the wKeyTag field in DNS_RRSIG_DATA. /// public ushort wKeyTag; /// /// A value that specifies the algorithm defined by DNS_DNSKEY_DATA. The possible values are shown in the following table. /// /// /// Value /// Meaning /// /// /// 1 /// RSA/MD5 (RFC 2537) /// /// /// 2 /// Diffie-Hellman (RFC 2539) /// /// /// 3 /// DSA (RFC 2536) /// /// /// 4 /// Elliptic curve cryptography /// /// /// 5 /// RSA/SHA-1 (RFC 3110) /// /// /// public byte chAlgorithm; /// /// /// A value that specifies the cryptographic algorithm used to generate Digest. The possible values are shown in the /// following table. /// /// /// /// Value /// Meaning /// /// /// 1 /// SHA-1 (RFC 3174) /// /// /// public byte chDigestType; /// /// The length, in bytes. of the message digest in Digest. This value is determined by the algorithm type in chDigestType. /// public ushort wDigestLength; /// Reserved for padding. Do not use. public ushort wPad; /// /// A BYTE array that contains a cryptographic digest of the DNSKEY RR and RDATA as specified in section 5.1.4 of RFC /// 4034. Its length is determined by wDigestLength. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] Digest; } /// /// The DNS_HEADER structure contains DNS header information used when sending DNS messages as specified in section 4.1.1 of /// RFC 1035. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_header typedef struct _DNS_HEADER { WORD Xid; BYTE // RecursionDesired : 1; BYTE Truncation : 1; BYTE Authoritative : 1; BYTE Opcode : 4; BYTE IsResponse : 1; BYTE ResponseCode : 4; // BYTE CheckingDisabled : 1; BYTE AuthenticatedData : 1; BYTE Reserved : 1; BYTE RecursionAvailable : 1; WORD QuestionCount; WORD // AnswerCount; WORD NameServerCount; WORD AdditionalCount; } DNS_HEADER, *PDNS_HEADER; [PInvokeData("windns.h", MSDNShortId = "e5bf19a1-4c71-482d-a075-1e149f94505b")] [StructLayout(LayoutKind.Sequential)] public struct DNS_HEADER { /// A value that specifies the unique DNS message identifier. public ushort Xid; private ushort flags; /// /// A value that specifies whether recursive name query should be used by the DNS name server. /// /// /// Value /// Meaning /// /// /// 0x00 /// Do not use recursive name query. /// /// /// 0x01 /// Use recursive name query. /// /// /// public bool RecursionDesired { get => BitHelper.GetBit(flags, 0); set => BitHelper.SetBit(ref flags, 0, value); } /// /// A value that specifies whether the DNS message has been truncated. /// /// /// Value /// Meaning /// /// /// 0x00 /// The message is not truncated. /// /// /// 0x01 /// The message is truncated. /// /// /// public bool Truncation { get => BitHelper.GetBit(flags, 1); set => BitHelper.SetBit(ref flags, 1, value); } /// /// /// A value that specifies whether the DNS server from which the DNS message is being sent is authoritative for the domain /// name's zone. /// /// /// /// Value /// Meaning /// /// /// 0x00 /// The DNS server is not authoritative in the zone. /// /// /// 0x01 /// The DNS server is authoritative in the zone. /// /// /// public bool Authoritative { get => BitHelper.GetBit(flags, 2); set => BitHelper.SetBit(ref flags, 2, value); } /// /// A value that specifies the operation code to be taken on the DNS message as defined in section 4.1.1 of RFC 1035 as the /// OPCODE field. /// public ushort Opcode { get => BitHelper.GetBits(flags, 3, 4); set => BitHelper.SetBits(ref flags, 3, 4, value); } /// /// A value that specifies whether the DNS message is a query or a response message. /// /// /// Value /// Meaning /// /// /// 0x00 /// The DNS message is a query. /// /// /// 0x01 /// The DNS message is a response. /// /// /// public bool IsResponse { get => BitHelper.GetBit(flags, 7); set => BitHelper.SetBit(ref flags, 7, value); } /// The DNS Response Code of the message. public ushort ResponseCode { get => BitHelper.GetBits(flags, 8, 4); set => BitHelper.SetBits(ref flags, 8, 4, value); } /// /// Windows 7 or later: A value that specifies whether checking is supported by the DNS resolver. /// /// /// Value /// Meaning /// /// /// 0x00 /// Checking is enabled on the DNS resolver. /// /// /// 0x01 /// Checking is disabled on the DNS resolver. /// /// /// public bool CheckingDisabled { get => BitHelper.GetBit(flags, 12); set => BitHelper.SetBit(ref flags, 12, value); } /// /// /// Windows 7 or later: A value that specifies whether the DNS data following the DNS_HEADER is authenticated by the DNS server. /// /// /// /// Value /// Meaning /// /// /// 0x00 /// The DNS data is not authenticated. /// /// /// 0x01 /// The DNS data is authenticated. /// /// /// public bool AuthenticatedData { get => BitHelper.GetBit(flags, 13); set => BitHelper.SetBit(ref flags, 13, value); } /// Reserved. Do not use. public bool Reserved { get => BitHelper.GetBit(flags, 14); set => BitHelper.SetBit(ref flags, 14, value); } /// /// A value that specifies whether recursive name query is supported by the DNS name server. /// /// /// Value /// Meaning /// /// /// 0x00 /// Recursive name query is not supported. /// /// /// 0x01 /// Recursive name query is supported. /// /// /// public bool RecursionAvailable { get => BitHelper.GetBit(flags, 15); set => BitHelper.SetBit(ref flags, 15, value); } /// The number of queries contained in the question section of the DNS message. public ushort QuestionCount; /// The number of resource records (RRs) contained in the answer section of the DNS message. public ushort AnswerCount; /// /// The number of DNS name server RRs contained in the authority section of the DNS message. This value is the number of DNS /// name servers the message has traversed in its search for resolution. /// public ushort NameServerCount; /// Reserved. Do not use. public ushort AdditionalCount; } /// The DNS_KEY_DATA structure represents a DNS key (KEY) resource record (RR) as specified in RFC 3445. /// /// /// The DNS_KEY_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// /// The DNS_DNSKEY_DATA structure represents a DNSKEY resource record as specified in section 2 of RFC 4034. /// The DNS_DNSKEY_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// /// The value of the wFlags member for DNS_DNSKEY_DATA is a set of flags that specify key properties as described in section /// 2.1.1 of RFC 4034. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_key_data typedef struct { WORD wFlags; BYTE chProtocol; // BYTE chAlgorithm; WORD wKeyLength; WORD wPad; #if ... BYTE Key[]; #else BYTE Key[1]; #endif } DNS_KEY_DATA, *PDNS_KEY_DATA, // DNS_DNSKEY_DATA, *PDNS_DNSKEY_DATA; [PInvokeData("windns.h", MSDNShortId = "d7d60322-4d06-4c57-b181-c6a38e09e1ef")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(wKeyLength))] [StructLayout(LayoutKind.Sequential)] public struct DNS_KEY_DATA { /// A set of flags that specify whether this is a zone key as described in section 4 of RFC 3445. public ushort wFlags; /// /// /// A value that specifies the protocol with which Key can be used. The possible values are shown in the following table. /// /// /// /// Value /// Meaning /// /// /// 3 /// Domain Name System Security Extensions (DNSSEC) /// /// /// public byte chProtocol; /// /// A value that specifies the algorithm to use with Key. The possible values are shown in the following table. /// /// /// Value /// Meaning /// /// /// 1 /// RSA/MD5 (RFC 2537) /// /// /// 2 /// Diffie-Hellman (RFC 2539) /// /// /// 3 /// DSA (RFC 2536) /// /// /// 4 /// Elliptic curve cryptography /// /// /// 5 /// RSA/SHA-1 (RFC 3110). DNS_DNSKEY_DATA only. /// /// /// public byte chAlgorithm; /// The length, in bytes, of Key. This value is determined by the algorithm type in chAlgorithm. public ushort wKeyLength; /// Reserved. Do not use. public ushort wPad; /// /// A BYTE array that contains the public key for the algorithm in chAlgorithm, represented in base 64, as /// described in Appendix A of RFC 2535. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] Key; } /// The DNS_LOC_DATA structure represents a DNS location (LOC) resource record (RR) as specified in RFC 1876. /// /// The DNS_LOC_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_loc_data typedef struct { WORD wVersion; WORD wSize; WORD // wHorPrec; WORD wVerPrec; DWORD dwLatitude; DWORD dwLongitude; DWORD dwAltitude; } DNS_LOC_DATA, *PDNS_LOC_DATA; [PInvokeData("windns.h", MSDNShortId = "c1e05479-17f0-4993-8dcf-02036989d6dc")] [StructLayout(LayoutKind.Sequential)] public struct DNS_LOC_DATA { /// The version number of the representation. Must be zero. public ushort wVersion; /// The diameter of a sphere enclosing the described entity, defined as "SIZE" in section 2 of RFC 1876. public ushort wSize; /// The horizontal data precision, defined as "HORIZ PRE" in section 2 of RFC 1876. public ushort wHorPrec; /// The vertical data precision, defined as "VERT PRE" in section 2 of RFC 1876. public ushort wVerPrec; /// The latitude of the center of the sphere, defined as "LATITUDE" in section 2 of RFC 1876. public uint dwLatitude; /// The longitude of the center of the sphere, defined as "LONGITUDE" in section 2 of RFC 1876. public uint dwLongitude; /// The altitude of the center of the sphere, defined as "ALTITUDE" in section 2 of RFC 1876. public uint dwAltitude; } /// The DNS_MESSAGE_BUFFER structure stores message information for DNS queries. /// /// /// The DNS_MESSAGE_BUFFER is used by the system to store DNS query information, and make that information available through /// various DNS function calls. /// /// /// The DnsWriteQuestionToBuffer method should be used to write a DNS query into a DNS_MESSAGE_BUFFER structure and the /// DnsExtractRecordsFromMessage method should be used to read the DNS RRs from a DNS_MESSAGE_BUFFER. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_message_buffer typedef struct _DNS_MESSAGE_BUFFER { // DNS_HEADER MessageHead; CHAR MessageBody[1]; } DNS_MESSAGE_BUFFER, *PDNS_MESSAGE_BUFFER; [PInvokeData("windns.h", MSDNShortId = "2a6fdf8f-ac30-4e32-9cde-67d41ddef8af")] [VanaraMarshaler(typeof(DNS_MESSAGE_BUFFER_Marshaler))] [StructLayout(LayoutKind.Sequential)] public struct DNS_MESSAGE_BUFFER { /// A DNS_HEADER structure that contains the header for the DNS message. public DNS_HEADER MessageHead; /// An array of characters that comprises the DNS query or resource records (RR). [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] MessageBody; } /// /// The DNS_MINFO_DATA structure represents a DNS mail information (MINFO) record as specified in section 3.3.7 of RFC 1035. /// /// /// The DNS_MINFO_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_minfo_dataa typedef struct { PSTR pNameMailbox; PSTR // pNameErrorsMailbox; } DNS_MINFO_DATAA, *PDNS_MINFO_DATAA; [PInvokeData("windns.h", MSDNShortId = "cd392b48-734f-462b-b893-855f07c30575")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_MINFO_DATA { /// /// A pointer to a string that represents the fully qualified domain name (FQDN) of the mailbox responsible for the mailing list /// or mailbox specified in the record's owner name. /// [MarshalAs(UnmanagedType.LPTStr)] public string pNameMailbox; /// /// A pointer to a string that represents the FQDN of the mailbox to receive error messages related to the mailing list. /// [MarshalAs(UnmanagedType.LPTStr)] public string pNameErrorsMailbox; } /// /// The DNS_MX_DATA structure represents a DNS mail exchanger (MX) record as specified in section 3.3.9 of RFC 1035. /// /// /// The DNS_MX_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_mx_dataa typedef struct { PSTR pNameExchange; WORD // wPreference; WORD Pad; } DNS_MX_DATAA, *PDNS_MX_DATAA; [PInvokeData("windns.h", MSDNShortId = "72a0b42e-a7af-42d2-b672-cf06d0b5d1ba")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_MX_DATA { /// /// A pointer to a string that represents the fully qualified domain name (FQDN) of the host willing to act as a mail exchange. /// [MarshalAs(UnmanagedType.LPTStr)] public string pNameExchange; /// A preference given to this resource record among others of the same owner. Lower values are preferred. public ushort wPreference; /// Reserved for padding. Do not use. public ushort Pad; } /// /// The DNS_NAPTR_DATA structure represents a Naming Authority Pointer (NAPTR) DNS Resource Record (RR) as specified in RFC 2915. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_naptr_dataw typedef struct { WORD wOrder; WORD // wPreference; PWSTR pFlags; PWSTR pService; PWSTR pRegularExpression; PWSTR pReplacement; } DNS_NAPTR_DATAW, *PDNS_NAPTR_DATAW; [PInvokeData("windns.h", MSDNShortId = "8f576efb-4ef3-4fc0-8cf5-d373460a3b3c")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_NAPTR_DATA { /// A value that determines the NAPTR RR processing order as defined in section 2 of RFC 2915. public ushort wOrder; /// /// A value that determines the NAPTR RR processing order for records with the same wOrder value as defined in section 2 /// of RFC 2915. /// public ushort wPreference; /// /// A pointer to a string that represents a set of NAPTR RR flags which determine the interpretation and processing of NAPTR /// record fields as defined in section 2 of RFC 2915. /// [MarshalAs(UnmanagedType.LPTStr)] public string pFlags; /// /// A pointer to a string that represents the available services in this rewrite path as defined in section 2 of RFC 2915. /// [MarshalAs(UnmanagedType.LPTStr)] public string pService; /// A pointer to a string that represents a substitution expression as defined in sections 2 and 3 of RFC 2915. [MarshalAs(UnmanagedType.LPTStr)] public string pRegularExpression; /// A pointer to a string that represents the next NAPTR query name as defined in section 2 of RFC 2915. [MarshalAs(UnmanagedType.LPTStr)] public string pReplacement; } /// The DNS_NSEC_DATA structure represents an NSEC resource record (RR) as specified in section 4 of RFC 4034. /// /// The DNS_NSEC_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_nsec_dataa typedef struct { PSTR pNextDomainName; WORD // wTypeBitMapsLength; WORD wPad; #if ... BYTE TypeBitMaps[]; #else BYTE TypeBitMaps[1]; #endif } DNS_NSEC_DATAA, *PDNS_NSEC_DATAA; [PInvokeData("windns.h", MSDNShortId = "ea446732-bc6a-4597-b164-11bfd77c07f2")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(wTypeBitMapsLength))] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_NSEC_DATA { /// /// A pointer to a string that represents the authoritative owner name of the next domain in the canonical ordering of the zone /// as specified in section 4.1.1 of RFC 4034. /// [MarshalAs(UnmanagedType.LPTStr)] public string pNextDomainName; /// The length, in bytes, of TypeBitMaps. public ushort wTypeBitMapsLength; /// Reserved. Do not use. public ushort wPad; /// /// A BYTE array that contains a bitmap that specifies which RR types are supported by the NSEC RR owner. Each bit in the /// array corresponds to a DNS Record Type as defined in section in section 4.1.2 of RFC 4034. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] TypeBitMaps; } /// Undocumented. [PInvokeData("windns.h")] [VanaraMarshaler(typeof(SafeDNS_NSEC3_DATAMarshaler))] [StructLayout(LayoutKind.Sequential)] public struct DNS_NSEC3_DATA { /// public byte chAlgorithm; /// public byte bFlags; /// public ushort wIterations; /// public byte bSaltLength; /// public byte bHashLength; /// public ushort wTypeBitMapsLength; /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] chData; } /// Undocumented. [PInvokeData("windns.h")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(bSaltLength))] [StructLayout(LayoutKind.Sequential)] public struct DNS_NSEC3PARAM_DATA { /// public byte chAlgorithm; /// public byte bFlags; /// public ushort wIterations; /// public byte bSaltLength; /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] bPad; // keep salt field aligned /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] pbSalt; } /// /// The DNS_NULL_DATA structure represents NULL data for a DNS resource record as specified in section 3.3.10 of RFC 1035. /// /// /// The DNS_NULL_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_null_data typedef struct { DWORD dwByteCount; #if ... // BYTE Data[]; #else BYTE Data[1]; #endif } DNS_NULL_DATA, *PDNS_NULL_DATA; [PInvokeData("windns.h", MSDNShortId = "c31e468f-8efd-4173-bc2c-442ee4df737f")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(dwByteCount))] [StructLayout(LayoutKind.Sequential)] public struct DNS_NULL_DATA { /// The number of bytes represented in Data. public uint dwByteCount; /// Null data. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] Data; } /// /// The DNS_NXT_DATA structure represents a DNS next (NXT) resource record (RR) as specified in section 5 of RFC 2535. /// /// /// The DNS_NXT_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_nxt_dataa typedef struct { PSTR pNameNext; WORD // wNumTypes; #if ... WORD wTypes[]; #else WORD wTypes[1]; #endif } DNS_NXT_DATAA, *PDNS_NXT_DATAA; [PInvokeData("windns.h", MSDNShortId = "0e5370c2-30d3-4bb7-85a0-f4412f5572fd")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(wNumTypes))] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_NXT_DATA { /// A pointer to a string that represents the name of the next domain. [MarshalAs(UnmanagedType.LPTStr)] public string pNameNext; /// The number of elements in the wTypes array. wNumTypes must be 2 or greater but cannot exceed 8. public ushort wNumTypes; /// /// A BYTE array that contains a bitmap which specifies the RR types that are present in the next domain. Each bit in the /// array corresponds to a DNS Record Type as defined in section 5.2 of RFC 2535. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public ushort[] wTypes; } /// /// The DNS_OPT_DATA structure represents a DNS Option (OPT) resource record (RR) as specified in section 4 of RFC 2671. /// /// /// The DNS_OPT_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_opt_data typedef struct { WORD wDataLength; WORD wPad; // #if ... BYTE Data[]; #else BYTE Data[1]; #endif } DNS_OPT_DATA, *PDNS_OPT_DATA; [PInvokeData("windns.h", MSDNShortId = "a8e23127-a625-4206-abe8-0787b4ac0f30")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(wDataLength))] [StructLayout(LayoutKind.Sequential)] public struct DNS_OPT_DATA { /// The length, in bytes, of Data. public ushort wDataLength; /// Reserved. Do not use. public ushort wPad; /// A BYTE array that contains variable transport level information as specified in section 4 of RFC 2671. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] Data; } /// /// The DNS_PROXY_INFORMATION structure contains the proxy information for a DNS server's name resolution policy table. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_proxy_information typedef struct DNS_PROXY_INFORMATION { // ULONG version; DNS_PROXY_INFORMATION_TYPE proxyInformationType; PWSTR proxyName; } DNS_PROXY_INFORMATION; [PInvokeData("windns.h", MSDNShortId = "cfe7653f-7e68-4e50-ba67-bd441f837ef8")] [StructLayout(LayoutKind.Sequential)] public struct DNS_PROXY_INFORMATION { /// A value that specifies the structure version. This value must be 1. public uint version; /// A DNS_PROXY_INFORMATION_TYPE enumeration that contains the proxy information type. public DNS_PROXY_INFORMATION_TYPE proxyInformationType; /// /// /// A pointer to a string that contains the proxy server name if proxyInformationType is /// DNS_PROXY_INFORMATION_PROXY_NAME. Otherwise, this member is ignored. /// /// Note To free this string, use the DnsFreeProxyName function. /// public IntPtr proxyName; /// public override string ToString() => $"{proxyInformationType}{(proxyInformationType == DNS_PROXY_INFORMATION_TYPE.DNS_PROXY_INFORMATION_PROXY_NAME ? $" {StringHelper.GetString(proxyName, CharSet.Unicode)}" : "")}"; } /// The DNS_PTR_DATA structure represents a DNS pointer (PTR) record as specified in section 3.3.12 of RFC 1035. /// /// The DNS_PTR_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_ptr_dataa typedef struct { PSTR pNameHost; } // DNS_PTR_DATAA, *PDNS_PTR_DATAA; [PInvokeData("windns.h", MSDNShortId = "8b7f8898-ac91-46da-876c-889c427068a3")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_PTR_DATA { /// A pointer to a string that represents the pointer (PTR) record data. [MarshalAs(UnmanagedType.LPTStr)] public string pNameHost; } /// A DNS_QUERY_CANCEL structure can be used to cancel an asynchronous DNS query. /// This structure is returned in the pCancelHandle parameter from a previous call to DnsQueryEx. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_query_cancel typedef struct _DNS_QUERY_CANCEL { CHAR // Reserved[32]; } DNS_QUERY_CANCEL, *PDNS_QUERY_CANCEL; [PInvokeData("windns.h", MSDNShortId = "543C6F9B-3200-44F6-A2B7-A5C7F5A927DB")] [StructLayout(LayoutKind.Sequential)] public struct DNS_QUERY_CANCEL { /// Contains a handle to the asynchronous query to cancel. Applications must not modify this value. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public byte[] Reserved; } /// The DNS_QUERY_REQUEST structure contains the DNS query parameters used in a call to DnsQueryEx. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_query_request typedef struct _DNS_QUERY_REQUEST { ULONG // Version; PCWSTR QueryName; WORD QueryType; ULONG64 QueryOptions; PDNS_ADDR_ARRAY pDnsServerList; ULONG InterfaceIndex; // PDNS_QUERY_COMPLETION_ROUTINE pQueryCompletionCallback; PVOID pQueryContext; } DNS_QUERY_REQUEST, *PDNS_QUERY_REQUEST; [PInvokeData("windns.h", MSDNShortId = "9C382800-DE71-4481-AC8D-9F89D6F59EE6")] [StructLayout(LayoutKind.Sequential)] public struct DNS_QUERY_REQUEST { /// /// The structure version must be one of the following: /// DNS_QUERY_REQUEST_VERSION1 (1) /// public uint Version; /// /// A pointer to a string that represents the DNS name to query. /// Note If QueryName is NULL, the query is for the local machine name. /// [MarshalAs(UnmanagedType.LPWStr)] public string QueryName; /// /// A value that represents the Resource Record (RR) DNS Record Type that is queried. QueryType determines the format of /// data pointed to by pQueryRecords returned in the DNS_QUERY_RESULT structure. For example, if the value of /// wType is DNS_TYPE_A, the format of data pointed to by pQueryRecords is DNS_A_DATA. /// public DNS_TYPE QueryType; // Hack to make this the right size even though the enum is a UInt32. private ulong _QueryOptions; /// /// A value that contains a bitmap of DNS Query Options to use in the DNS query. Options can be combined and all options /// override DNS_QUERY_STANDARD /// public DNS_QUERY_OPTIONS QueryOptions { get => (DNS_QUERY_OPTIONS)_QueryOptions; set => _QueryOptions = (ulong)value; } /// Query options padding. public uint QueryOptionsHigh; /// A pointer to a DNS_ADDR_ARRAY structure that contains a list of DNS servers to use in the query. public IntPtr pDnsServerList; /// /// A value that contains the interface index over which the query is sent. If InterfaceIndex is 0, all interfaces will /// be considered. /// public uint InterfaceIndex; /// /// /// A pointer to a DNS_QUERY_COMPLETION_ROUTINE callback that is used to return the results of an asynchronous query from a call /// to DnsQueryEx. /// /// Note If NULL, DnsQueryEx is called synchronously. /// [MarshalAs(UnmanagedType.FunctionPtr)] public DNS_QUERY_COMPLETION_ROUTINE pQueryCompletionCallback; /// A pointer to a user context. public IntPtr pQueryContext; /// Initializes a new instance of the struct. /// The Resource Record (RR) DNS Record Type that is queried. /// The DNS name to query. /// The DNS Query Options to use in the DNS query. public DNS_QUERY_REQUEST(DNS_TYPE type, string queryName = null, DNS_QUERY_OPTIONS options = 0) : this() { Version = DNS_QUERY_REQUEST_VERSION1; QueryName = queryName; QueryType = type; QueryOptions = options; } } /// Contains the DNS query parameters used in a call to DnsQueryEx. /// /// The custom servers specified in pCustomServers bypass the system-configured DNS servers. /// /// If the query name matches a rule in the Name Resolution Policy Table (NRPT), then the custom servers are ignored, and only /// the servers from the NRPT rule are used. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_query_request3 typedef struct _DNS_QUERY_REQUEST3 { ULONG // Version; PCWSTR QueryName; WORD QueryType; ULONG64 QueryOptions; PDNS_ADDR_ARRAY pDnsServerList; ULONG InterfaceIndex; // PDNS_QUERY_COMPLETION_ROUTINE pQueryCompletionCallback; PVOID pQueryContext; BOOL IsNetworkQueryRequired; DWORD // RequiredNetworkIndex; DWORD cCustomServers; DNS_CUSTOM_SERVER *pCustomServers; } DNS_QUERY_REQUEST3, *PDNS_QUERY_REQUEST3; [PInvokeData("windns.h", MSDNShortId = "NS:windns._DNS_QUERY_REQUEST3")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_QUERY_REQUEST3 { /// /// Type: ULONG /// The structure version must be the DNS_QUERY_REQUEST_VERSION3; which has a value of 3. /// public uint Version; /// /// Type: PCWSTR /// A pointer to a string that represents the DNS name to query. /// /// Note /// If QueryName is NULL, then the query is for the local machine name. /// /// [MarshalAs(UnmanagedType.LPWStr)] public string QueryName; /// /// Type: WORD /// /// A value that represents the Resource Record (RR) DNS Record Type that is queried. QueryType determines the format of data /// pointed to by pQueryRecords returned in the DNS_QUERY_RESULT structure. For example, if the value of wType is DNS_TYPE_A, /// then the format of data pointed to by pQueryRecords is DNS_A_DATA. /// /// public DNS_TYPE QueryType; // Hack to make this the right size even though the enum is a UInt32. private ulong _QueryOptions; /// /// A value that contains a bitmap of DNS Query Options to use in the DNS query. Options can be combined and all options /// override DNS_QUERY_STANDARD /// public DNS_QUERY_OPTIONS QueryOptions { get => (DNS_QUERY_OPTIONS)_QueryOptions; set => _QueryOptions = (ulong)value; } /// /// Type: PDNS_ADDR_ARRAY /// A pointer to a DNS_ADDR_ARRAY structure that contains a list of DNS servers to use in the query. /// public IntPtr pDnsServerList; /// /// Type: ULONG /// /// A value that contains the interface index over which the query is sent. If InterfaceIndex is 0, then all interfaces will be considered. /// /// public uint InterfaceIndex; /// /// Type: PDNS_QUERY_COMPLETION_ROUTINE /// /// A pointer to a DNS_QUERY_COMPLETION_ROUTINE callback that is used to return the results of an asynchronous query from a call /// to DnsQueryEx. /// /// /// Note /// If NULL, then DnsQueryEx is called synchronously. /// /// [MarshalAs(UnmanagedType.FunctionPtr)] public DNS_QUERY_COMPLETION_ROUTINE pQueryCompletionCallback; /// /// Type: PVOID /// A pointer to a user context. /// public IntPtr pQueryContext; /// /// Type: BOOL /// Reserved. /// [MarshalAs(UnmanagedType.Bool)] public bool IsNetworkQueryRequired; /// /// Type: DWORD /// Reserved. /// public uint RequiredNetworkIndex; /// /// Type: DWORD /// The number of custom servers pointed to by the pCustomServers member. /// public uint cCustomServers; /// /// Type: _Field_size_(cCustomServers) DNS_CUSTOM_SERVER* /// A pointer to an array of N (where N is given in the cCustomServers field) DNS_CUSTOM_SERVER objects. /// If cCustomServers is 0, then pCustomServers must be NULL. /// /// Note /// /// At least one of pCustomServers and pDnsServerList must be NULL. Both set to non- NULL values at the same time /// is not supported. /// /// /// public IntPtr pCustomServers; /// Initializes a new instance of the struct. /// The Resource Record (RR) DNS Record Type that is queried. /// The DNS name to query. /// The DNS Query Options to use in the DNS query. public DNS_QUERY_REQUEST3(DNS_TYPE type, string queryName = null, DNS_QUERY_OPTIONS options = 0) : this() { Version = DNS_QUERY_REQUEST_VERSION1; QueryName = queryName; QueryType = type; QueryOptions = options; } } /// A DNS_QUERY_RESULT structure contains the DNS query results returned from a call to DnsQueryEx. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_query_result typedef struct _DNS_QUERY_RESULT { ULONG // Version; DNS_STATUS QueryStatus; ULONG64 QueryOptions; PDNS_RECORD pQueryRecords; PVOID Reserved; } DNS_QUERY_RESULT, *PDNS_QUERY_RESULT; [PInvokeData("windns.h", MSDNShortId = "03EB1DC2-FAB0-45C5-B438-E8FFDD218F09")] [StructLayout(LayoutKind.Sequential)] public struct DNS_QUERY_RESULT { /// /// The structure version must be one of the following: /// DNS_QUERY_REQUEST_VERSION1 (1) /// public uint Version; /// /// The return status of the call to DnsQueryEx. /// /// If the query was completed asynchronously and this structure was returned directly from DnsQueryEx, QueryStatus /// contains DNS_REQUEST_PENDING. /// /// /// If the query was completed synchronously or if this structure was returned by the DNS_QUERY_COMPLETION_ROUTINE DNS callback, /// QueryStatus contains ERROR_SUCCESS if successful or the appropriate DNS-specific error code as defined in Winerror.h. /// /// public DNS_STATUS QueryStatus; /// /// A value that contains a bitmap of DNS Query Options that were used in the DNS query. Options can be combined and all options /// override DNS_QUERY_STANDARD /// public ulong QueryOptions; /// /// A pointer to a DNS_RECORD structure. /// /// If the query was completed asynchronously and this structure was returned directly from DnsQueryEx, pQueryRecords is NULL. /// /// /// If the query was completed synchronously or if this structure was returned by the DNS_QUERY_COMPLETION_ROUTINE DNS callback, /// pQueryRecords contains a list of Resource Records (RR) that comprise the response. /// /// Note Applications must free returned RR sets with the DnsRecordListFree function. /// public IntPtr pQueryRecords; /// public IntPtr Reserved; /// An instance of with the field set to . public static readonly DNS_QUERY_RESULT Default = new() { Version = DNS_QUERY_RESULTS_VERSION1 }; } /// The DNS_RECORD structure stores a DNS resource record (RR). /// /// When building a DNS_RECORD list as an input argument for the various DNS update routines found in the DNS API, all flags /// in the DNS_RECORD structure should be set to zero. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_recorda typedef struct _DnsRecordA { struct _DnsRecordA // *pNext; PSTR pName; WORD wType; WORD wDataLength; union { DWORD DW; DNS_RECORD_FLAGS S; } Flags; DWORD dwTtl; DWORD dwReserved; // union { DNS_A_DATA A; DNS_SOA_DATAA SOA; DNS_SOA_DATAA Soa; DNS_PTR_DATAA PTR; DNS_PTR_DATAA Ptr; DNS_PTR_DATAA NS; DNS_PTR_DATAA // Ns; DNS_PTR_DATAA CNAME; DNS_PTR_DATAA Cname; DNS_PTR_DATAA DNAME; DNS_PTR_DATAA Dname; DNS_PTR_DATAA MB; DNS_PTR_DATAA Mb; // DNS_PTR_DATAA MD; DNS_PTR_DATAA Md; DNS_PTR_DATAA MF; DNS_PTR_DATAA Mf; DNS_PTR_DATAA MG; DNS_PTR_DATAA Mg; DNS_PTR_DATAA MR; // DNS_PTR_DATAA Mr; DNS_MINFO_DATAA MINFO; DNS_MINFO_DATAA Minfo; DNS_MINFO_DATAA RP; DNS_MINFO_DATAA Rp; DNS_MX_DATAA MX; // DNS_MX_DATAA Mx; DNS_MX_DATAA AFSDB; DNS_MX_DATAA Afsdb; DNS_MX_DATAA RT; DNS_MX_DATAA Rt; DNS_TXT_DATAA HINFO; DNS_TXT_DATAA // Hinfo; DNS_TXT_DATAA ISDN; DNS_TXT_DATAA Isdn; DNS_TXT_DATAA TXT; DNS_TXT_DATAA Txt; DNS_TXT_DATAA X25; DNS_NULL_DATA Null; // DNS_WKS_DATA WKS; DNS_WKS_DATA Wks; DNS_AAAA_DATA AAAA; DNS_KEY_DATA KEY; DNS_KEY_DATA Key; DNS_SIG_DATAA SIG; DNS_SIG_DATAA Sig; // DNS_ATMA_DATA ATMA; DNS_ATMA_DATA Atma; DNS_NXT_DATAA NXT; DNS_NXT_DATAA Nxt; DNS_SRV_DATAA SRV; DNS_SRV_DATAA Srv; // DNS_NAPTR_DATAA NAPTR; DNS_NAPTR_DATAA Naptr; DNS_OPT_DATA OPT; DNS_OPT_DATA Opt; DNS_DS_DATA DS; DNS_DS_DATA Ds; DNS_RRSIG_DATAA // RRSIG; DNS_RRSIG_DATAA Rrsig; DNS_NSEC_DATAA NSEC; DNS_NSEC_DATAA Nsec; DNS_DNSKEY_DATA DNSKEY; DNS_DNSKEY_DATA Dnskey; // DNS_TKEY_DATAA TKEY; DNS_TKEY_DATAA Tkey; DNS_TSIG_DATAA TSIG; DNS_TSIG_DATAA Tsig; DNS_WINS_DATA WINS; DNS_WINS_DATA Wins; // DNS_WINSR_DATAA WINSR; DNS_WINSR_DATAA WinsR; DNS_WINSR_DATAA NBSTAT; DNS_WINSR_DATAA Nbstat; DNS_DHCID_DATA DHCID; // DNS_NSEC3_DATA NSEC3; DNS_NSEC3_DATA Nsec3; DNS_NSEC3PARAM_DATA NSEC3PARAM; DNS_NSEC3PARAM_DATA Nsec3Param; DNS_TLSA_DATA TLSA; // DNS_TLSA_DATA Tlsa; DNS_UNKNOWN_DATA UNKNOWN; DNS_UNKNOWN_DATA Unknown; PBYTE pDataPtr; } Data; } DNS_RECORDA, *PDNS_RECORDA; [PInvokeData("windns.h", MSDNShortId = "ab7b96a5-346f-4e01-bb2a-885f44764590")] [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Unicode)] public struct DNS_RECORD { /// A pointer to the next DNS_RECORD structure. public IntPtr pNext; /// /// A pointer to a string that represents the domain name of the record set. This must be in the string format that corresponds /// to the function called, such as ANSI, Unicode, or UTF8. /// [MarshalAs(UnmanagedType.LPTStr)] public string pName; /// /// A value that represents the RR DNS Record Type. wType determines the format of Data. For example, if the value /// of wType is DNS_TYPE_A, the data type of Data is DNS_A_DATA. /// public DNS_TYPE wType; /// /// The length, in bytes, of Data. For fixed-length data types, this value is the size of the corresponding data type, /// such as sizeof(DNS_A_DATA). For the non-fixed data types, use one of the following macros to determine the length of /// the data: /// public ushort wDataLength; /// A set of flags in the form of a DNS_RECORD_FLAGS structure. public DNS_RECORD_FLAGS Flags; /// The DNS RR's Time To Live value (TTL), in seconds. public uint dwTtl; /// Reserved. Do not use. public uint dwReserved; // The next entries are contrived so that the structure works on either 32 or 64 systems. The total size of the variable is 40 // bytes on X86 and 56 on X64. private readonly IntPtr _Data; private readonly IntPtr _fillPtr1; private readonly IntPtr _fillPtr2; private readonly IntPtr _fillPtr3; private readonly ulong _fill8byte0; private readonly ulong _fill8byte1; private readonly ulong _fill8byte2; /// Gets the data value based on the value of . /// The value of . public object Data { get { if (wType == 0 || wDataLength == 0) return null; var type = CorrespondingTypeAttribute.GetCorrespondingTypes(wType, CorrespondingAction.GetSet).FirstOrDefault(); var ptr = DataPtr; return type is null ? ptr : ptr.Convert(wDataLength, type, CharSet.Unicode); } set => wDataLength = (ushort)DataPtr.Write(value, 0, DataSize); } private static readonly int DataSize = Marshal.SizeOf(typeof(DNS_RECORD)) - 16 - (IntPtr.Size * 2); /// Gets the pointer to the 'Data' union. /// The 'Data' union pointer. public IntPtr DataPtr { get { unsafe { fixed (void* p = &_Data) { return (IntPtr)p; } } } } /// Gets the data as a strongly-typed structure. /// The type of the structure to extract. /// The resulting type. /// The current record does not support retrieving the supplied type param. public T GetDataAsType() where T : struct { if (wType == 0 || wDataLength == 0) return default; if (!CorrespondingTypeAttribute.CanGet(typeof(T), out var tType) || tType != wType) throw new ArgumentException("The current record does not support retrieving the supplied type param."); var ptr = DataPtr; return ptr.Convert(wDataLength, CharSet.Unicode); } /* /// The DNS RR data type is determined by wType and is one of the following members: [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)] public struct DNS_RECORD_DATA { /// The RR data type is DNS_A_DATA. The value of wType is DNS_TYPE_A. [FieldOffset(0)] public DNS_A_DATA A; /// The RR data type is DNS_SOA_DATA. The value of wType is DNS_TYPE_SOA. [FieldOffset(0)] public DNS_SOA_DATA SOA; /// The RR data type is DNS_SOA_DATA. The value of wType is DNS_TYPE_SOA. [FieldOffset(0)] public DNS_SOA_DATA Soa; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA PTR; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA Ptr; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA NS; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA Ns; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA CNAME; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA Cname; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA DNAME; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA Dname; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA MB; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA Mb; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA MD; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA Md; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA MF; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA Mf; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA MG; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA Mg; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA MR; /// The RR data type is DNS_PTR_DATA. The value of wType is DNS_TYPE_PTR. [FieldOffset(0)] public DNS_PTR_DATA Mr; /// The RR data type is DNS_MINFO_DATA. The value of wType is DNS_TYPE_MINFO. [FieldOffset(0)] public DNS_MINFO_DATA MINFO; /// The RR data type is DNS_MINFO_DATA. The value of wType is DNS_TYPE_MINFO. [FieldOffset(0)] public DNS_MINFO_DATA Minfo; /// The RR data type is DNS_MINFO_DATA. The value of wType is DNS_TYPE_MINFO. [FieldOffset(0)] public DNS_MINFO_DATA RP; /// The RR data type is DNS_MINFO_DATA. The value of wType is DNS_TYPE_MINFO. [FieldOffset(0)] public DNS_MINFO_DATA Rp; /// The RR data type is DNS_MX_DATA. The value of wType is DNS_TYPE_MX. [FieldOffset(0)] public DNS_MX_DATA MX; /// The RR data type is DNS_MX_DATA. The value of wType is DNS_TYPE_MX. [FieldOffset(0)] public DNS_MX_DATA Mx; /// The RR data type is DNS_MX_DATA. The value of wType is DNS_TYPE_MX. [FieldOffset(0)] public DNS_MX_DATA AFSDB; /// The RR data type is DNS_MX_DATA. The value of wType is DNS_TYPE_MX. [FieldOffset(0)] public DNS_MX_DATA Afsdb; /// The RR data type is DNS_MX_DATA. The value of wType is DNS_TYPE_MX. [FieldOffset(0)] public DNS_MX_DATA RT; /// The RR data type is DNS_MX_DATA. The value of wType is DNS_TYPE_MX. [FieldOffset(0)] public DNS_MX_DATA Rt; /// The RR data type is DNS_TXT_DATA. The value of wType is DNS_TYPE_TXT. [FieldOffset(0)] public DNS_TXT_DATA HINFO; /// The RR data type is DNS_TXT_DATA. The value of wType is DNS_TYPE_TXT. [FieldOffset(0)] public DNS_TXT_DATA Hinfo; /// The RR data type is DNS_TXT_DATA. The value of wType is DNS_TYPE_TXT. [FieldOffset(0)] public DNS_TXT_DATA ISDN; /// The RR data type is DNS_TXT_DATA. The value of wType is DNS_TYPE_TXT. [FieldOffset(0)] public DNS_TXT_DATA Isdn; /// The RR data type is DNS_TXT_DATA. The value of wType is DNS_TYPE_TXT. [FieldOffset(0)] public DNS_TXT_DATA TXT; /// The RR data type is DNS_TXT_DATA. The value of wType is DNS_TYPE_TXT. [FieldOffset(0)] public DNS_TXT_DATA Txt; /// The RR data type is DNS_TXT_DATA. The value of wType is DNS_TYPE_TXT. [FieldOffset(0)] public DNS_TXT_DATA X25; /// The RR data type is DNS_NULL_DATA. The value of wType is DNS_TYPE_NULL. [FieldOffset(0)] public DNS_NULL_DATA Null; /// The RR data type is DNS_WKS_DATA. The value of wType is DNS_TYPE_WKS. [FieldOffset(0)] public DNS_WKS_DATA WKS; /// The RR data type is DNS_WKS_DATA. The value of wType is DNS_TYPE_WKS. [FieldOffset(0)] public DNS_WKS_DATA Wks; /// The RR data type is DNS_AAAA_DATA. The value of wType is DNS_TYPE_AAAA. [FieldOffset(0)] public DNS_AAAA_DATA AAAA; /// The RR data type is DNS_KEY_DATA. The value of wType is DNS_TYPE_KEY. [FieldOffset(0)] public DNS_KEY_DATA KEY; /// The RR data type is DNS_KEY_DATA. The value of wType is DNS_TYPE_KEY. [FieldOffset(0)] public DNS_KEY_DATA Key; /// The RR data type is DNS_SIG_DATA. The value of wType is DNS_TYPE_SIG. [FieldOffset(0)] public DNS_SIG_DATA SIG; /// The RR data type is DNS_SIG_DATA. The value of wType is DNS_TYPE_SIG. [FieldOffset(0)] public DNS_SIG_DATA Sig; /// The RR data type is DNS_ATMA_DATA. The value of wType is DNS_TYPE_ATMA. [FieldOffset(0)] public DNS_ATMA_DATA ATMA; /// The RR data type is DNS_ATMA_DATA. The value of wType is DNS_TYPE_ATMA. [FieldOffset(0)] public DNS_ATMA_DATA Atma; /// The RR data type is DNS_NXT_DATA. The value of wType is DNS_TYPE_NXT. [FieldOffset(0)] public DNS_NXT_DATA NXT; /// The RR data type is DNS_NXT_DATA. The value of wType is DNS_TYPE_NXT. [FieldOffset(0)] public DNS_NXT_DATA Nxt; /// The RR data type is DNS_SRV_DATA. The value of wType is DNS_TYPE_SRV. [FieldOffset(0)] public DNS_SRV_DATA SRV; /// The RR data type is DNS_SRV_DATA. The value of wType is DNS_TYPE_SRV. [FieldOffset(0)] public DNS_SRV_DATA Srv; /// The RR data type is DNS_NAPTR_DATA. The value of wType is DNS_TYPE_NAPTR. [FieldOffset(0)] public DNS_NAPTR_DATA NAPTR; /// The RR data type is DNS_NAPTR_DATA. The value of wType is DNS_TYPE_NAPTR. [FieldOffset(0)] public DNS_NAPTR_DATA Naptr; /// The RR data type is DNS_OPT_DATA. The value of wType is DNS_TYPE_OPT. [FieldOffset(0)] public DNS_OPT_DATA OPT; /// The RR data type is DNS_OPT_DATA. The value of wType is DNS_TYPE_OPT. [FieldOffset(0)] public DNS_OPT_DATA Opt; /// The RR data type is DNS_DS_DATA. The value of wType is DNS_TYPE_DS. [FieldOffset(0)] public DNS_DS_DATA DS; /// The RR data type is DNS_DS_DATA. The value of wType is DNS_TYPE_DS. [FieldOffset(0)] public DNS_DS_DATA Ds; /// The RR data type is DNS_SIG_DATA. The value of wType is DNS_TYPE_RRSIG. [FieldOffset(0)] public DNS_SIG_DATA RRSIG; /// The RR data type is DNS_SIG_DATA. The value of wType is DNS_TYPE_RRSIG. [FieldOffset(0)] public DNS_SIG_DATA Rrsig; /// The RR data type is DNSEC_DATA. The value of wType is DNS_TYPEEC. [FieldOffset(0)] public DNS_NSEC_DATA NSEC; /// The RR data type is DNSEC_DATA. The value of wType is DNS_TYPEEC. [FieldOffset(0)] public DNS_NSEC_DATA Nsec; /// The RR data type is DNS_DNSKEY_DATA. The value of wType is DNS_TYPE_DNSKEY. [FieldOffset(0)] public DNS_KEY_DATA DNSKEY; /// The RR data type is DNS_DNSKEY_DATA. The value of wType is DNS_TYPE_DNSKEY. [FieldOffset(0)] public DNS_KEY_DATA Dnskey; /// The RR data type is DNS_TKEY_DATA. The value of wType is DNS_TYPE_TKEY. [FieldOffset(0)] public DNS_TKEY_DATA TKEY; /// The RR data type is DNS_TKEY_DATA. The value of wType is DNS_TYPE_TKEY. [FieldOffset(0)] public DNS_TKEY_DATA Tkey; /// The RR data type is DNS_TSIG_DATA. The value of wType is DNS_TYPE_TSIG. [FieldOffset(0)] public DNS_TSIG_DATA TSIG; /// The RR data type is DNS_TSIG_DATA. The value of wType is DNS_TYPE_TSIG. [FieldOffset(0)] public DNS_TSIG_DATA Tsig; /// The RR data type is DNS_WINS_DATA. The value of wType is DNS_TYPE_WINS. [FieldOffset(0)] public DNS_WINS_DATA WINS; /// The RR data type is DNS_WINS_DATA. The value of wType is DNS_TYPE_WINS. [FieldOffset(0)] public DNS_WINS_DATA Wins; /// The RR data type is DNS_WINSR_DATA. The value of wType is DNS_TYPE_WINSR. [FieldOffset(0)] public DNS_WINSR_DATA WINSR; /// The RR data type is DNS_WINSR_DATA. The value of wType is DNS_TYPE_WINSR. [FieldOffset(0)] public DNS_WINSR_DATA WinsR; /// The RR data type is DNS_WINSR_DATA. The value of wType is DNS_TYPE_WINSR. [FieldOffset(0)] public DNS_WINSR_DATA NBSTAT; /// The RR data type is DNS_WINSR_DATA. The value of wType is DNS_TYPE_WINSR. [FieldOffset(0)] public DNS_WINSR_DATA Nbstat; /// The RR data type is DNS_DHCID_DATA. The value of wType is DNS_TYPE_DHCID. [FieldOffset(0)] public DNS_DHCID_DATA DHCID; /// The RR data type is DNS_NSEC3_DATA. The value of wType is DNS_TYPEEC3. [FieldOffset(0)] public DNS_NSEC3_DATA NSEC3; /// The RR data type is DNS_NSEC3_DATA. The value of wType is DNS_TYPEEC3. [FieldOffset(0)] public DNS_NSEC3_DATA Nsec3; /// The RR data type is DNS_NSEC3PARAM_DATA. The value of wType is DNS_TYPEEC3PARAM. [FieldOffset(0)] public DNS_NSEC3PARAM_DATA NSEC3PARAM; /// The RR data type is DNS_NSEC3PARAM_DATA. The value of wType is DNS_TYPEEC3PARAM. [FieldOffset(0)] public DNS_NSEC3PARAM_DATA Nsec3Param; /// The RR data type is DNS_TLSA_DATA. The value of wType is DNS_TYPE_TLSA. [FieldOffset(0)] public DNS_TLSA_DATA TLSA; /// The RR data type is DNS_TLSA_DATA. The value of wType is DNS_TYPE_TLSA. [FieldOffset(0)] public DNS_TLSA_DATA Tlsa; /// The RR data type is DNS_UNKNOWN_DATA. The value of wType is DNS_TYPE_UNKNOWN. [FieldOffset(0)] public DNS_UNKNOWN_DATA UNKNOWN; /// The RR data type is DNS_UNKNOWN_DATA. The value of wType is DNS_TYPE_UNKNOWN. [FieldOffset(0)] public DNS_UNKNOWN_DATA Unknown; /// [FieldOffset(0)] public IntPtr pDataPtr; } */ } /// The DNS_RECORD_FLAGS structure is used to set flags for use in the DNS_RECORD structure. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_record_flags typedef struct _DnsRecordFlags { DWORD // Section : 2; DWORD Delete : 1; DWORD CharSet : 2; DWORD Unused : 3; DWORD Reserved : 24; } DNS_RECORD_FLAGS; [PInvokeData("windns.h", MSDNShortId = "53c1c8bc-20b0-4b15-b2b6-9c9854f73ee3")] [StructLayout(LayoutKind.Sequential)] public struct DNS_RECORD_FLAGS { /// A value that contains a bitmap of DNS Record Flags. public uint DW; /// A DNS_SECTION value that specifies the section of interest returned from the DnsQuery function call. public uint Section { get => BitHelper.GetBits(DW, 0, 2); set => BitHelper.SetBits(ref DW, 0, 2, value); } /// Reserved. Do not use. public bool Delete { get => BitHelper.GetBit(DW, 2); set => BitHelper.SetBit(ref DW, 2, value); } /// A DNS_CHARSET value that specifies the character set used in the associated function call. public uint CharSet { get => BitHelper.GetBits(DW, 3, 2); set => BitHelper.SetBits(ref DW, 3, 2, value); } /// Reserved. Do not use. public uint Unused { get => BitHelper.GetBits(DW, 5, 3); set => BitHelper.SetBits(ref DW, 5, 3, value); } } /// The DNS_RRSET structure contains information about a DNS Resource Record (RR) set. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_rrset typedef struct _DnsRRSet { PDNS_RECORD pFirstRR; // PDNS_RECORD pLastRR; } DNS_RRSET, *PDNS_RRSET; [PInvokeData("windns.h", MSDNShortId = "bd87a8db-ca27-490b-85f4-912297b77a2b")] [StructLayout(LayoutKind.Sequential)] public struct DNS_RRSET { /// A pointer to a DNS_RECORD structure that contains the first DNS RR in the set. public IntPtr pFirstRR; /// A pointer to a DNS_RECORD structure that contains the last DNS RR in the set. public IntPtr pLastRR; } /// Contains the query parameters used in a call to DnsServiceBrowse. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_service_browse_request typedef struct // _DNS_SERVICE_BROWSE_REQUEST { ULONG Version; ULONG InterfaceIndex; PCWSTR QueryName; union { PDNS_SERVICE_BROWSE_CALLBACK // pBrowseCallback; DNS_QUERY_COMPLETION_ROUTINE *pBrowseCallbackV2; }; PVOID pQueryContext; } DNS_SERVICE_BROWSE_REQUEST, *PDNS_SERVICE_BROWSE_REQUEST; [PInvokeData("windns.h")] [StructLayout(LayoutKind.Sequential)] public struct DNS_SERVICE_BROWSE_REQUEST { /// /// The structure version must be either DNS_QUERY_REQUEST_VERSION1 or DNS_QUERY_REQUEST_VERSION2. The value /// determines which of or is active. /// public uint Version; /// /// A value that contains the interface index over which the query is sent. If is 0, then all interfaces will be considered. /// public uint InterfaceIndex; /// /// A pointer to a string that represents the service type whose matching services you wish to browse for. It takes the /// generalized form "_<ServiceType>._<TransportProtocol>.local". For example, "_http._tcp.local", which defines a /// query to browse for http services on the local link. /// [MarshalAs(UnmanagedType.LPWStr)] public string QueryName; /// The callback function based on . public DNS_SERVICE_BROWSE_REQUEST_CALLBACK Callback; /// The callback function based on . [StructLayout(LayoutKind.Explicit)] public struct DNS_SERVICE_BROWSE_REQUEST_CALLBACK { /// /// A pointer to a function (of type DNS_SERVICE_BROWSE_CALLBACK) that represents the callback to be invoked asynchronously. /// This field is used if is DNS_QUERY_REQUEST_VERSION1. /// [FieldOffset(0), MarshalAs(UnmanagedType.FunctionPtr)] public DNS_SERVICE_BROWSE_CALLBACK pBrowseCallback; /// /// A pointer to a function (of type DNS_QUERY_COMPLETION_ROUTINE) that represents the callback to be invoked /// asynchronously. This field is used if is DNS_QUERY_REQUEST_VERSION2. /// [FieldOffset(0), MarshalAs(UnmanagedType.FunctionPtr)] public DNS_QUERY_COMPLETION_ROUTINE pBrowseCallbackV2; } /// A pointer to a user context. public IntPtr pQueryContext; } /// Used to cancel an asynchronous DNS-SD operation. /// This structure is returned in the parameter from a previous call to DnsServiceBrowse, DnsServiceRegister, or DnsServiceResolve. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_service_cancel typedef struct _DNS_SERVICE_CANCEL { PVOID // reserved; } DNS_SERVICE_CANCEL, *PDNS_SERVICE_CANCEL; [PInvokeData("windns.h")] [StructLayout(LayoutKind.Sequential)] public struct DNS_SERVICE_CANCEL { /// /// Contains a handle associated with the asynchronous operation to cancel. Your application must not modify this value. /// public IntPtr reserved; } /// Represents a DNS service running on the network. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_service_instance typedef struct _DNS_SERVICE_INSTANCE { // #if ... DNSSD_RPC_STRING pszInstanceName; #else LPWSTR pszInstanceName; #endif #if ... DNSSD_RPC_STRING pszHostName; #else LPWSTR // pszHostName; #endif IP4_ADDRESS *ip4Address; IP6_ADDRESS *ip6Address; WORD wPort; WORD wPriority; WORD wWeight; DWORD // dwPropertyCount; #if ... DNSSD_RPC_STRING *keys; #if ... DNSSD_RPC_STRING *values; #else PWSTR *keys; #endif #else PWSTR *values; // #endif DWORD dwInterfaceIndex; } DNS_SERVICE_INSTANCE, *PDNS_SERVICE_INSTANCE; [PInvokeData("windns.h")] [StructLayout(LayoutKind.Sequential)] public struct DNS_SERVICE_INSTANCE { /// /// A string that represents the service name. This is a fully qualified domain name that begins with a service name, and ends /// with ".local". It takes the generalized form "<ServiceName>._<ServiceType>._<TransportProtocol>.local". /// For example, "MyMusicServer._http._tcp.local". /// [MarshalAs(UnmanagedType.LPWStr)] public string pszInstanceName; /// A string that represents the name of the host of the service. [MarshalAs(UnmanagedType.LPWStr)] public string pszHostName; /// A pointer to an IP4_ADDRESS structure that represents the service-associated IPv4 address. public IntPtr ip4Address; /// A pointer to an IP6_ADDRESS structure that represents the service-associated IPv6 address. public IntPtr ip6Address; /// A value that represents the port on which the service is running. public ushort wPort; /// A value that represents the service priority. public ushort wPriority; /// A value that represents the service weight. public ushort wWeight; /// The number of properties—defines the number of elements in the arrays of the and parameters. public uint dwPropertyCount; /// public IntPtr keys; /// public IntPtr values; /// A value that contains the interface index on which the service was discovered. public uint dwInterfaceIndex; } /// /// Contains the information necessary to advertise a service using DnsServiceRegister, or to stop advertising it using DnsServiceDeRegister. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_service_register_request typedef struct // _DNS_SERVICE_REGISTER_REQUEST { ULONG Version; ULONG InterfaceIndex; PDNS_SERVICE_INSTANCE pServiceInstance; // PDNS_SERVICE_REGISTER_COMPLETE pRegisterCompletionCallback; PVOID pQueryContext; HANDLE hCredentials; BOOL unicastEnabled; } // DNS_SERVICE_REGISTER_REQUEST, *PDNS_SERVICE_REGISTER_REQUEST; [PInvokeData("windns.h")] [StructLayout(LayoutKind.Sequential)] public struct DNS_SERVICE_REGISTER_REQUEST { /// The structure version must be DNS_QUERY_REQUEST_VERSION1. public uint Version; /// /// A value that contains the interface index over which the service is to be advertised. If is 0, then all interfaces will be considered. /// public uint InterfaceIndex; /// A pointer to a DNS_SERVICE_INSTANCE structure that describes the service to be registered. public IntPtr pServiceInstance; /// A pointer to a function (of type DNS_SERVICE_REGISTER_COMPLETE) that represents the callback to be invoked asynchronously. [MarshalAs(UnmanagedType.FunctionPtr)] public DNS_SERVICE_REGISTER_COMPLETE pRegisterCompletionCallback; /// A pointer to a user context. public IntPtr pQueryContext; /// Not used. public HANDLE hCredentials; /// /// if the DNS protocol should be used to advertise the service; if the mDNS /// protocol should be used. /// [MarshalAs(UnmanagedType.Bool)] public bool unicastEnabled; } /// /// Contains the query parameters used in a call to DnsServiceResolve. Use that function, and this structure, after you've found a /// specific service name that you'd like to connect to. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_service_resolve_request typedef struct // _DNS_SERVICE_RESOLVE_REQUEST { ULONG Version; ULONG InterfaceIndex; PWSTR QueryName; PDNS_SERVICE_RESOLVE_COMPLETE // pResolveCompletionCallback; PVOID pQueryContext; } DNS_SERVICE_RESOLVE_REQUEST, *PDNS_SERVICE_RESOLVE_REQUEST; [PInvokeData("windns.h")] [StructLayout(LayoutKind.Sequential)] public struct DNS_SERVICE_RESOLVE_REQUEST { /// The structure version must be DNS_QUERY_REQUEST_VERSION1. public uint Version; /// /// A value that contains the interface index over which the query is sent. If is 0, then all interfaces will be considered. /// public uint InterfaceIndex; /// /// A pointer to a string that represents the service name. This is a fully qualified domain name that begins with a service /// name, and ends with ".local". It takes the generalized form /// "<ServiceName>._<ServiceType>._<TransportProtocol>.local". For example, "MyMusicServer._http._tcp.local". /// [MarshalAs(UnmanagedType.LPWStr)] public string QueryName; /// A pointer to a function (of type DNS_SERVICE_RESOLVE_COMPLETE) that represents the callback to be invoked asynchronously. [MarshalAs(UnmanagedType.FunctionPtr)] public DNS_SERVICE_RESOLVE_COMPLETE pResolveCompletionCallback; /// A pointer to a user context. public IntPtr pQueryContext; } /// /// The DNS_RRSIG_DATA structure represents a DNS Security Extensions (DNSSEC) cryptographic signature (SIG) resource record /// (RR) as specified in RFC 4034. /// /// /// The DNS_RRSIG_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_sig_dataa typedef struct { WORD wTypeCovered; BYTE // chAlgorithm; BYTE chLabelCount; DWORD dwOriginalTtl; DWORD dwExpiration; DWORD dwTimeSigned; WORD wKeyTag; WORD wSignatureLength; // PSTR pNameSigner; #if ... BYTE Signature[]; #else BYTE Signature[1]; #endif } DNS_SIG_DATAA, *PDNS_SIG_DATAA, DNS_RRSIG_DATAA, *PDNS_RRSIG_DATAA; [PInvokeData("windns.h", MSDNShortId = "09c2f515-acc1-402f-8e62-a0d273031633")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(wSignatureLength))] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_SIG_DATA { /// The DNS Record Type of the signed RRs. public ushort wTypeCovered; /// /// /// A value that specifies the algorithm used to generate Signature. The possible values are shown in the following table. /// /// /// /// Value /// Meaning /// /// /// 1 /// RSA/MD5 (RFC 2537) /// /// /// 2 /// Diffie-Hellman (RFC 2539) /// /// /// 3 /// DSA (RFC 2536) /// /// /// 4 /// Elliptic curve cryptography /// /// /// 5 /// RSA/SHA-1 (RFC 3110) /// /// /// public byte chAlgorithm; /// The number of labels in the original signature RR owner name as specified in section 3.1.3 of RFC 4034. public byte chLabelCount; /// The Time-to-Live (TTL) value of the RR set signed by Signature. public uint dwOriginalTtl; /// /// The expiration date of Signature, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean Time /// (GMT), excluding leap seconds. /// public uint dwExpiration; /// /// The date and time at which Signature becomes valid, expressed in seconds since the beginning of January 1, 1970, /// Greenwich Mean Time (GMT), excluding leap seconds. /// public uint dwTimeSigned; /// /// A value that represents the method to choose which public key is used to verify Signature as specified Appendix B of /// RFC 4034. /// public ushort wKeyTag; /// public ushort wSignatureLength; /// A pointer to a string that represents the name of the Signature generator. [MarshalAs(UnmanagedType.LPTStr)] public string pNameSigner; /// A BYTE array that contains the RR set signature as specified in section 3.1.8 of RFC 4034. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] Signature; } /// /// The DNS_SOA_DATA structure represents a DNS start of authority (SOA) record as specified in section 3.3.13 of RFC 1035. /// /// /// The DNS_SOA_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_soa_dataa typedef struct { PSTR pNamePrimaryServer; PSTR // pNameAdministrator; DWORD dwSerialNo; DWORD dwRefresh; DWORD dwRetry; DWORD dwExpire; DWORD dwDefaultTtl; } DNS_SOA_DATAA, *PDNS_SOA_DATAA; [PInvokeData("windns.h", MSDNShortId = "715cbb70-91fe-47ac-a713-1fe0701d4f8c")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_SOA_DATA { /// /// A pointer to a string that represents the name of the authoritative DNS server for the zone to which the record belongs. /// [MarshalAs(UnmanagedType.LPTStr)] public string pNamePrimaryServer; /// A pointer to a string that represents the name of the responsible party for the zone to which the record belongs. [MarshalAs(UnmanagedType.LPTStr)] public string pNameAdministrator; /// The serial number of the SOA record. public uint dwSerialNo; /// The time, in seconds, before the zone containing this record should be refreshed. public uint dwRefresh; /// The time, in seconds, before retrying a failed refresh of the zone to which this record belongs. public uint dwRetry; /// The time, in seconds, before an unresponsive zone is no longer authoritative. public uint dwExpire; /// /// The lower limit on the time, in seconds, that a DNS server or caching resolver are allowed to cache any resource records /// (RR) from the zone to which this record belongs. /// public uint dwDefaultTtl; } /// The DNS_SRV_DATA structure represents a DNS service (SRV) record as specified in RFC 2782. /// /// The DNS_SRV_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_srv_dataa typedef struct { PSTR pNameTarget; WORD // wPriority; WORD wWeight; WORD wPort; WORD Pad; } DNS_SRV_DATAA, *PDNS_SRV_DATAA; [PInvokeData("windns.h", MSDNShortId = "212db7ac-a5e3-4e58-b1c2-0eb551403dfc")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_SRV_DATA { /// A pointer to a string that represents the target host. [MarshalAs(UnmanagedType.LPTStr)] public string pNameTarget; /// /// The priority of the target host specified in pNameTarget. Lower numbers imply higher priority to clients attempting /// to use this service. /// public ushort wPriority; /// /// The relative weight of the target host in pNameTarget to other hosts with the same wPriority. The chances of /// using this host should be proportional to its weight. /// public ushort wWeight; /// The port used on the target host for this service. public ushort wPort; /// Reserved for padding. Do not use. public ushort Pad; } /// /// The DNS_TKEY_DATA structure represents a DNS TKEY resource record, used to establish and delete an algorithm's /// shared-secret keys between a DNS resolver and server as specified in RFC 2930. /// /// /// The DNS_TKEY_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_tkey_dataa typedef struct { PSTR pNameAlgorithm; PBYTE // pAlgorithmPacket; PBYTE pKey; PBYTE pOtherData; DWORD dwCreateTime; DWORD dwExpireTime; WORD wMode; WORD wError; WORD wKeyLength; // WORD wOtherLength; UCHAR cAlgNameLength; BOOL bPacketPointers; } DNS_TKEY_DATAA, *PDNS_TKEY_DATAA; [PInvokeData("windns.h", MSDNShortId = "4dad3449-3e41-47d9-89c2-10fa6e51573b")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_TKEY_DATA { /// A pointer to a string that represents the name of the key as defined in section 2.1 of RFC 2930. [MarshalAs(UnmanagedType.LPTStr)] public string pNameAlgorithm; /// /// A pointer to a string representing the name of the algorithm as defined in section 2.3 of RFC 2930. pKey is used to /// derive the algorithm specific keys. /// public IntPtr pAlgorithmPacket; /// A pointer to the variable-length shared-secret key. public IntPtr pKey; /// Reserved. Do not use. public IntPtr pOtherData; /// /// The date and time at which the key was created, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean /// Time (GMT), excluding leap seconds. /// public uint dwCreateTime; /// /// The expiration date of the key, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean Time (GMT), /// excluding leap seconds. /// public uint dwExpireTime; /// /// /// A scheme used for key agreement or the purpose of the TKEY DNS Message. Possible values for wMode are listed below: /// /// /// /// Value /// Meaning /// /// /// DNS_TKEY_MODE_SERVER_ASSIGN /// The key is assigned by the DNS server and is not negotiated. /// /// /// DNS_TKEY_MODE_DIFFIE_HELLMAN /// The Diffie-Hellman key exchange algorithm is used to negotiate the key. /// /// /// DNS_TKEY_MODE_GSS /// The key is exchanged through Generic Security Services-Application Program Interface (GSS-API) negotiation. /// /// /// DNS_TKEY_MODE_RESOLVER_ASSIGN /// The key is assigned by the DNS resolver and is not negotiated. /// /// /// public DNS_TKEY_MODE wMode; /// /// An error, expressed in expanded RCODE format that covers TSIG and TKEY RR processing. /// /// /// Value /// Meaning /// /// /// DNS_RCODE_BADSIG /// The pSignature of the DNS_TSIG_DATA RR is bad. /// /// /// DNS_RCODE_BADKEY /// The pKey field is bad. /// /// /// DNS_RCODE_BADTIME /// A timestamp is bad. /// /// /// public DNS_RCODE wError; /// Length, in bytes, of the pKey member. public ushort wKeyLength; /// The length, in bytes, of the pOtherData member. public ushort wOtherLength; /// The length, in bytes, of the pNameAlgorithm member. public byte cAlgNameLength; /// Reserved. Do not use. [MarshalAs(UnmanagedType.Bool)] public bool bPacketPointers; } /// Undocumented. [PInvokeData("windns.h")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(bCertificateAssociationDataLength))] [StructLayout(LayoutKind.Sequential)] public struct DNS_TLSA_DATA { /// public byte bCertUsage; /// public byte bSelector; /// public byte bMatchingType; /// public ushort bCertificateAssociationDataLength; /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] bPad; // keep certificate association data field aligned /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] bCertificateAssociationData; } /// /// The DNS_TSIG_DATA structure represents a secret key transaction authentication (TSIG) resource record (RR) as specified /// in RFC 2845 and RFC 3645. /// /// /// The DNS_TSIG_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_tsig_dataa typedef struct { PSTR pNameAlgorithm; PBYTE // pAlgorithmPacket; PBYTE pSignature; PBYTE pOtherData; LONGLONG i64CreateTime; WORD wFudgeTime; WORD wOriginalXid; WORD wError; // WORD wSigLength; WORD wOtherLength; UCHAR cAlgNameLength; BOOL bPacketPointers; } DNS_TSIG_DATAA, *PDNS_TSIG_DATAA; [PInvokeData("windns.h", MSDNShortId = "32077169-d319-45c0-982f-8d470cd70111")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_TSIG_DATA { /// /// A pointer to a string that represents the name of the key used to generate pSignature as defined in section 2.3 of /// RFC 2845. /// [MarshalAs(UnmanagedType.LPTStr)] public string pNameAlgorithm; /// /// /// A pointer to a string that represents the name of the algorithm used to generate pSignature as defined in section 2.3 /// of RFC 2845. /// /// /// /// Value /// Meaning /// /// /// "gss.microsoft.com" /// /// Windows 2000 Server only: Generic Security Service Algorithm for Secret Key Transaction Authentication for DNS (GSS-API) as /// defined in RFC 3645. /// /// /// /// "gss-tsig" /// Generic Security Service Algorithm for Secret Key Transaction Authentication for DNS (GSS-API) as defined in RFC 3645. /// /// /// public IntPtr pAlgorithmPacket; /// /// A pointer to the Message Authentication Code (MAC) generated by the algorithm in pAlgorithmPacket. The length, in /// bytes, and composition of pSignature are determined by pAlgorithmPacket. /// public IntPtr pSignature; /// /// If wError contains the RCODE, BADTIME, pOtherData is a BYTE array that contains the server's current /// time, otherwise it is NULL. Time is expressed in seconds since the beginning of January 1, 1970, Greenwich Mean Time /// (GMT), excluding leap seconds. /// public IntPtr pOtherData; /// /// The time pSignature was generated, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean Time /// (GMT), excluding leap seconds. /// public int i64CreateTime; /// The time, in seconds, i64CreateTime may be in error. public ushort wFudgeTime; /// The Xid identifier of the original message. public ushort wOriginalXid; /// /// An error, expressed in expanded RCODE format that covers TSIG and TKEY RR processing. /// /// /// Value /// Meaning /// /// /// DNS_RCODE_BADSIG /// The pSignature field is bad. /// /// /// DNS_RCODE_BADKEY /// The pKey field of the DNS_TKEY_DATA RR is bad. /// /// /// DNS_RCODE_BADTIME /// A timestamp is bad. /// /// /// public DNS_RCODE wError; /// The length, in bytes, of the pSignature member. public ushort wSigLength; /// The length, in bytes, of the pOtherData member. public ushort wOtherLength; /// The length, in bytes, of the pAlgorithmPacket member. public byte cAlgNameLength; /// Reserved for future use. Do not use. [MarshalAs(UnmanagedType.Bool)] public bool bPacketPointers; } /// The DNS_TXT_DATA structure represents a DNS text (TXT) record as specified in section 3.3.14 of RFC 1035. /// /// The DNS_TXT_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_txt_dataa typedef struct { DWORD dwStringCount; #if ... // PSTR pStringArray[]; #else PSTR pStringArray[1]; #endif } DNS_TXT_DATAA, *PDNS_TXT_DATAA; [PInvokeData("windns.h", MSDNShortId = "3ff643e2-d736-45d5-8cf8-ab5e63caf44b")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(dwStringCount))] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_TXT_DATA { /// The number of strings represented in pStringArray. public uint dwStringCount; /// An array of strings representing the descriptive text of the TXT resource record. [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.LPTStr, SizeConst = 1)] public string[] pStringArray; } /// Undocumented. [PInvokeData("windns.h")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(dwByteCount))] [StructLayout(LayoutKind.Sequential)] public struct DNS_UNKNOWN_DATA { /// public uint dwByteCount; /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] bData; } /// The DNS_WINS_DATA structure represents a DNS Windows Internet Name Service (WINS) record. /// /// The DNS_WINS_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_wins_data typedef struct { DWORD dwMappingFlag; DWORD // dwLookupTimeout; DWORD dwCacheTimeout; DWORD cWinsServerCount; IP4_ADDRESS WinsServers[1]; } DNS_WINS_DATA, *PDNS_WINS_DATA; [PInvokeData("windns.h", MSDNShortId = "df41c397-e662-42b4-9193-6776f9071898")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(cWinsServerCount))] [StructLayout(LayoutKind.Sequential)] public struct DNS_WINS_DATA { /// /// /// The WINS mapping flag that specifies whether the record must be included in zone replication. dwMappingFlag must be /// one of these mutually exclusive values: /// /// /// /// Value /// Meaning /// /// /// DNS_WINS_FLAG_SCOPE /// Record is not local, replicate across zones. /// /// /// DNS_WINS_FLAG_LOCAL /// Record is local, do not replicate. /// /// /// public DNS_WINS_FLAG dwMappingFlag; /// The time, in seconds, that a DNS Server attempts resolution using WINS lookup. public uint dwLookupTimeout; /// The time, in seconds, that a DNS Server using WINS lookup may cache the WINS Server's response. public uint dwCacheTimeout; /// The number of WINS Servers listed in WinsServers. public uint cWinsServerCount; /// An array of IP4_ARRAY structures that contain the IPv4 address of the WINS lookup Servers. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public IP4_ADDRESS[] WinsServers; } /// The DNS_WINSR_DATA structure represents a DNS Windows Internet Name Service reverse-lookup (WINSR) record. /// /// The DNS_WINSR_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_winsr_dataa typedef struct { DWORD dwMappingFlag; DWORD // dwLookupTimeout; DWORD dwCacheTimeout; PSTR pNameResultDomain; } DNS_WINSR_DATAA, *PDNS_WINSR_DATAA; [PInvokeData("windns.h", MSDNShortId = "a7e79e30-905f-42a5-a4de-02d71adfe95e")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DNS_WINSR_DATA { /// /// /// The WINS mapping flag that specifies whether the record must be included into the zone replication. dwMappingFlag /// must be one of these mutually exclusive values: /// /// /// /// Value /// Meaning /// /// /// DNS_WINS_FLAG_SCOPE /// Record is not local, replicate across zones. /// /// /// DNS_WINS_FLAG_LOCAL /// Record is local, do not replicate. /// /// /// public DNS_WINS_FLAG dwMappingFlag; /// The time, in seconds, that a DNS Server attempts resolution using WINS lookup. public uint dwLookupTimeout; /// The time, in seconds, that a DNS Server using WINS lookup may cache the WINS Server's response. public uint dwCacheTimeout; /// A pointer to a string that represents the domain name to append to the name returned by a WINS reverse-lookup. [MarshalAs(UnmanagedType.LPTStr)] public string pNameResultDomain; } /// /// The DNS_WIRE_QUESTION structure contains information about a DNS question transmitted across the network as specified in /// section 4.1.2 of RFC 1035.. /// /// When constructing a DNS message, the question name must precede the DNS_WIRE_QUESTION structure. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_wire_question typedef struct _DNS_WIRE_QUESTION { WORD // QuestionType; WORD QuestionClass; } DNS_WIRE_QUESTION, *PDNS_WIRE_QUESTION; [PInvokeData("windns.h", MSDNShortId = "50498f20-0896-4471-8355-edd997aa4bcd")] [StructLayout(LayoutKind.Sequential)] public struct DNS_WIRE_QUESTION { /// A value that represents the question section's DNS Question Type. public ushort QuestionType; /// A value that represents the question section's DNS Question Class. public ushort QuestionClass; } /// /// The DNS_WIRE_RECORD structure contains information about a DNS wire record transmitted across the network as specified in /// section 4.1.3 of RFC 1035. /// /// /// When constructing a DNS message, the DNS_WIRE_RECORD structure is immediately followed by the record data and is preceded /// by the DNS RR's domain name. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_wire_record typedef struct _DNS_WIRE_RECORD { WORD // RecordType; WORD RecordClass; DWORD TimeToLive; WORD DataLength; } DNS_WIRE_RECORD, *PDNS_WIRE_RECORD; [PInvokeData("windns.h", MSDNShortId = "fb36930c-dd43-427a-8034-078c99497a3e")] [StructLayout(LayoutKind.Sequential)] public struct DNS_WIRE_RECORD { /// /// A value that represents the RR DNS Response Type. RecordType determines the format of record data that follows the /// DNS_WIRE_RECORD structure. For example, if the value of RecordType is DNS_TYPE_A, the data type of /// record data is DNS_A_DATA. /// public DNS_TYPE RecordType; /// A value that represents the RR DNS Record Class. public DNS_CLASS RecordClass; /// The DNS Resource Record's Time To Live value (TTL), in seconds. public uint TimeToLive; /// The length, in bytes, of the DNS record data that follows the DNS_WIRE_RECORD. public ushort DataLength; } /// /// The DNS_WKS_DATA structure represents a DNS well-known services (WKS) record as specified in section 3.4.2 of RFC 1035. /// /// /// The DNS_WKS_DATA structure is used in conjunction with the DNS_RECORD structure to programmatically manage DNS entries. /// // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-dns_wks_data typedef struct { IP4_ADDRESS IpAddress; UCHAR // chProtocol; BYTE BitMask[1]; } DNS_WKS_DATA, *PDNS_WKS_DATA; [PInvokeData("windns.h", MSDNShortId = "94477345-74e7-40bf-a75b-e4bf67f1c17b")] [StructLayout(LayoutKind.Sequential)] public struct DNS_WKS_DATA { /// An IP4_ADDRESS data type that contains the IPv4 address for this resource record (RR). public IP4_ADDRESS IpAddress; /// /// A value that represents the IP protocol for this RR as defined in RFC 1010. /// Transmission Control Protocol (TCP) (6) /// User Datagram Protocol (UDP) (17) /// public byte chProtocol; /// /// A variable-length bitmask whose bits correspond to the port number of well known services offered by the protocol specified /// in chProtocol. The bitmask has one bit for every port of the supported protocol, but must be a multiple of a /// BYTE. Bit 0 corresponds to port 1, bit 1 corresponds to port 2, and so forth for a maximum of 1024 bits. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] public byte[] BitMask; } /// The IP4_ARRAY structure stores an array of IPv4 addresses. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-ip4_array typedef struct _IP4_ARRAY { DWORD AddrCount; #if // ... IP4_ADDRESS AddrArray[]; #else IP4_ADDRESS AddrArray[1]; #endif } IP4_ARRAY, *PIP4_ARRAY; [PInvokeData("windns.h", MSDNShortId = "4273a739-129c-4951-b6df-aef4332ce0cb")] [VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), nameof(AddrCount))] [StructLayout(LayoutKind.Sequential)] public struct IP4_ARRAY { /// The number of IPv4 addresses in AddrArray. public uint AddrCount; /// An array of IP4_ADDRESS data types that contains a list of IPv4 address. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public IP4_ADDRESS[] AddrArray; /// Initializes a new instance of the struct. /// The list of IPv4 address. public IP4_ARRAY(params IP4_ADDRESS[] addrs) { AddrCount = (uint)(addrs?.Length ?? 0); AddrArray = addrs; } } /// Contains information related to an ongoing MDNS query. Your application must not modify its contents. /// This structure is for internal use only. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-mdns_query_handle typedef struct _MDNS_QUERY_HANDLE { WCHAR // nameBuf[DNS_MAX_NAME_BUFFER_LENGTH]; WORD wType; PVOID pSubscription; PVOID pWnfCallbackParams; ULONG stateNameData[2]; } // MDNS_QUERY_HANDLE, *PMDNS_QUERY_HANDLE; [PInvokeData("windns.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct MDNS_QUERY_HANDLE { /// A value representing the queried name. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = DNS_MAX_NAME_BUFFER_LENGTH)] public string nameBuf; /// A value representing the type of the query. public DNS_OPCODE wType; /// Reserved. Do not use. public IntPtr pSubscription; /// Reserved. Do not use. public IntPtr pWnfCallbackParams; /// Reserved. Do not use. public ulong stateNameData; } /// Contains the necessary information to perform an mDNS query. // https://docs.microsoft.com/en-us/windows/win32/api/windns/ns-windns-mdns_query_request typedef struct _MDNS_QUERY_REQUEST { ULONG // Version; ULONG ulRefCount; PCWSTR Query; WORD QueryType; ULONG64 QueryOptions; ULONG InterfaceIndex; PMDNS_QUERY_CALLBACK // pQueryCallback; PVOID pQueryContext; BOOL fAnswerReceived; ULONG ulResendCount; } MDNS_QUERY_REQUEST, *PMDNS_QUERY_REQUEST; [PInvokeData("windns.h")] [StructLayout(LayoutKind.Sequential)] public struct MDNS_QUERY_REQUEST { /// The structure version must be DNS_QUERY_REQUEST_VERSION1. public uint Version; /// Reserved. Do not use. public uint ulRefCount; /// A string representing the name to be queried over mDNS. [MarshalAs(UnmanagedType.LPWStr)] public string Query; /// A value representing the type of the records to be queried. See DNS_RECORD_TYPE for possible values. public DNS_TYPE QueryType; // Hack to make this the right size even though the enum is a UInt32. private ulong _QueryOptions; /// A value representing the query options. DNS_QUERY_STANDARD is the only supported value. public DNS_QUERY_OPTIONS QueryOptions { get => (DNS_QUERY_OPTIONS)_QueryOptions; set => _QueryOptions = (ulong)value; } /// /// A value that contains the interface index over which the service is to be advertised. If is 0, then all interfaces will be considered. /// public uint InterfaceIndex; /// /// A pointer to a function (of type MDNS_QUERY_CALLBACK) that represents the callback to be invoked asynchronously whenever /// mDNS results are available. /// [MarshalAs(UnmanagedType.FunctionPtr)] public MDNS_QUERY_CALLBACK pQueryCallback; /// A pointer to a user context. public IntPtr pQueryContext; /// Reserved. Do not use. [MarshalAs(UnmanagedType.Bool)] public bool fAnswerReceived; /// Reserved. Do not use. public uint ulResendCount; } /// Represents a DNS service running on the network. [PInvokeData("windns.h")] public class SafePDNS_SERVICE_INSTANCE : SafeHANDLE { private uint _dwInterfaceIndex; private IP4_ADDRESS? _ip4Address; private IP6_ADDRESS? _ip6Address; private string[] _keys; private string _pszHostName; private string _pszInstanceName; private string[] _values; private ushort _wPort; private ushort _wPriority; private ushort _wWeight; private bool populated = false; /// A value that contains the interface index on which the service was discovered. public uint dwInterfaceIndex => PopulateFetch(ref _dwInterfaceIndex); /// A pointer to an IP4_ADDRESS structure that represents the service-associated IPv4 address. public IP4_ADDRESS? ip4Address => PopulateFetch(ref _ip4Address); /// A pointer to an IP6_ADDRESS structure that represents the service-associated IPv6 address. public IP6_ADDRESS? ip6Address => PopulateFetch(ref _ip6Address); /// public string[] keys => PopulateFetch(ref _keys); /// A string that represents the name of the host of the service. public string pszHostName => PopulateFetch(ref _pszHostName); /// /// A string that represents the service name. This is a fully qualified domain name that begins with a service name, and ends /// with ".local". It takes the generalized form "<ServiceName>._<ServiceType>._<TransportProtocol>.local". /// For example, "MyMusicServer._http._tcp.local". /// public string pszInstanceName => PopulateFetch(ref _pszInstanceName); /// public string[] values => PopulateFetch(ref _values); /// A value that represents the port on which the service is running. public ushort wPort => PopulateFetch(ref _wPort); /// A value that represents the service priority. public ushort wPriority => PopulateFetch(ref _wPriority); /// A value that represents the service weight. public ushort wWeight => PopulateFetch(ref _wWeight); /// Performs an implicit conversion from to . /// The instance. /// The resulting instance from the conversion. public static implicit operator IntPtr(SafePDNS_SERVICE_INSTANCE instance) => instance.handle; /// protected override bool InternalReleaseHandle() { DnsServiceFreeInstance(handle); return true; } private T PopulateFetch(ref T value) { if (!populated && !IsInvalid && !IsClosed) { var val = handle.ToStructure(); _pszInstanceName = val.pszInstanceName; _pszHostName = val.pszHostName; _ip4Address = val.ip4Address.ToNullableStructure(); _ip6Address = val.ip6Address.ToNullableStructure(); _wPort = val.wPort; _wPriority = val.wPriority; _wWeight = val.wWeight; _keys = val.keys.ToStringEnum((int)val.dwPropertyCount, CharSet.Unicode).ToArray(); _values = val.values.ToStringEnum((int)val.dwPropertyCount, CharSet.Unicode).ToArray(); _dwInterfaceIndex = val.dwInterfaceIndex; populated = true; } return value; } } internal class DNS_MESSAGE_BUFFER_Marshaler : IVanaraMarshaler { public DNS_MESSAGE_BUFFER_Marshaler() { } SizeT IVanaraMarshaler.GetNativeSize() => Marshal.SizeOf(typeof(DNS_MESSAGE_BUFFER)); SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object managedObject) => SafeCoTaskMemHandle.Null; object IVanaraMarshaler.MarshalNativeToManaged(IntPtr pNativeData, SizeT allocatedBytes) { if (pNativeData == IntPtr.Zero) return null; using var s = new PDNS_MESSAGE_BUFFER(pNativeData, allocatedBytes); return s.Value; } } internal class PDNS_MESSAGE_BUFFER : SafeAnysizeStructBase { public PDNS_MESSAGE_BUFFER(IntPtr allocatedMemory, SizeT size) : base(allocatedMemory, size, false) { } protected override int GetArrayLength(in DNS_MESSAGE_BUFFER local) => Size - 12; } internal class SafeDNS_NSEC3_DATA : SafeAnysizeStructBase { internal SafeDNS_NSEC3_DATA(DNS_NSEC3_DATA value) : base(baseSz) => ToNative(value); internal SafeDNS_NSEC3_DATA(IntPtr allocatedMemory, SizeT size) : base(allocatedMemory, size, false) { if (allocatedMemory == IntPtr.Zero) throw new ArgumentNullException(nameof(allocatedMemory)); if (baseSz > size) throw new OutOfMemoryException(); } protected override int GetArrayLength(in DNS_NSEC3_DATA local) => local.bSaltLength + local.bHashLength + local.wTypeBitMapsLength; } internal class SafeDNS_NSEC3_DATAMarshaler : IVanaraMarshaler { /// Initializes a new instance of the class. /// The . public SafeDNS_NSEC3_DATAMarshaler(string _) { } SizeT IVanaraMarshaler.GetNativeSize() => Marshal.SizeOf(typeof(DNS_NSEC3_DATA)); SafeAllocatedMemoryHandle IVanaraMarshaler.MarshalManagedToNative(object managedObject) => managedObject is null ? SafeCoTaskMemHandle.Null : (SafeAllocatedMemoryHandle)new SafeDNS_NSEC3_DATA((DNS_NSEC3_DATA)managedObject); object IVanaraMarshaler.MarshalNativeToManaged(IntPtr pNativeData, SizeT allocatedBytes) { if (pNativeData == IntPtr.Zero) return null; using var s = new SafeDNS_NSEC3_DATA(pNativeData, allocatedBytes); return s.Value; } } } }