Implement Dynamic domain name resolution service in Windows (3)

Source: Internet
Author: User
Tags query meaning utf 8 utf 8 encoding truncated

Dynamic domain name update using DNS APIs. The following describes the typical dns api function usage in detail. For more dns api function usage, refer to Microsoft's latest msdn knowledge base (vc2003, vc2005 has DNS api library files, and vc6.0 needs to manually copy windns. h, dnsapi. lib two files to the VC installation folder include and Lib folder, or install the latest SDK package, need these two files friends can contact me, my mailbox: world7th@163.com)

This section mainly introduces the following API functions:

Dnsquery, dnsrecordlistfree, dnsrecordcopyex, dnsmodifyrecordsinset

First, the original description of these functions in msdn is given.

1. dnsquery

The dnsquery function type is the generic query interface to the DNS namespace, and provides application developers with a DNS query resolution interface. like using DNS functions, the dnsquery function type is implemented in multiple forms to facilitate different character encoding.

Based on the character encoding involved, use one of the following functions:

Dnsquery_a (For ANSI encoding)
Dnsquery_w (for Unicode encoding)
Dnsquery_utf8 (for UTF-8 encoding)
If the dnsquery function type is called without its suffix (_ A, _ w, or _ utf8), a compiler error will occur.

Dns_status winapi dnsquery (
Pcstr lpstrname,
Word wtype,
DWORD foptions,
Pvoid pextra,
Pdns_record * ppqueryresultsset,
Pvoid * preserved
);

Parameters
Lpstrname
[In] the name of the owner of the record set that is queried.
Wtype
[In] the numeric representation of the type of record set that is queried, such as a value of 1 (0x0001) for an A record (dns_type_a ). for more information and a complete listing of record set types and their numeric representations, see the windns. h header file.
Foptions
[In] the query options. options can be combined and all options override dns_query_standard. The following table lists the available query options. query meaning
Dns_query_standard query.
Dns_query_accept_truncated_response returns truncated results. Does not retry under TCP.
Dns_query_use_tcp_only uses TCP only for the query.
Dns_query_no_recursion 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_bypass_cache bypasses the resolver cache on The lookup.
Dns_query_no_wire_query 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_local_name directs DNS to ignore the local name.
Windows 2000 Server and Windows 2000 Professional: this value is not supported.
Dns_query_no_hosts_file prevents the DNS query from consulting the hosts file.
Windows 2000 Server and Windows 2000 Professional: this value is not supported.
Dns_query_no_netbt prevents the DNS query from using netbt for resolution.
Windows 2000 Server and Windows 2000 Professional: this value is not supported.
Dns_query_treat_as_fqdn prevents the DNS response from attaching suffixes to the submitted name in a name resolution process.
Dns_query_wire_only 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_return_message directs DNS to return the entire DNS response message.
Windows 2000 Server and Windows 2000 Professional: this value is not supported.
Dns_query_dont_reset_ttl_values 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_reserved reserved.
Dns_query_multicast_only prevents the query from using DNS and uses only local link multicast name resolution (llmnr ).
Note this option is available only when using Windows Server "Longhorn" or Windows Vista.
 
Dns_query_multicast_verify 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 behaviour is not enabled ..
Note this option is available only when using Windows Server "Longhorn" or Windows Vista.
 
Dns_query_multicast_wait waits for a full timeout to collect all the responses from the local link. If not set, the default behaviour is to return with the first response.
Note this option is available only when using Windows Server "Longhorn" or Windows Vista.
 

Pextra
[In, out, optional] this parameter is reserved for future use and must be set to null.
Ppqueryresultsset
[In, out] optional. A pointer to a pointer that points to the list of RRS that comprise the response. For more information, see the remarks section.
Preserved
[In, out] this parameter is reserved for future use and must be set to null.
Return Value
Returns success Confirmation upon successful completion. Otherwise, returns the appropriate DNS-specific error code as defined in winerror. h.
Remarks
Applications that call the dnsquery function build a query using a fully-qualified DNS name and Resource Record (RR) type, and set query options depending on the type of service desired. when the dns_query_standard option is set, DNS uses the resolver cache, queries first with UDP, then retries with TCP if the response is truncated, and requests that the server to perform recursive resolution on behalf of the client to resolve the query.

Callers must free returned RR sets with the dnsrecordlistfree function.

Note when calling one of the dnsquery function types, be aware that a DNS server may return multiple records in response to a query. A computer that is multihomed, for example, will receive multiple a records for the same IP address. the caller must use as response of the returned records as necessary.

Consider the following scenario, in which multiple returned records require additional activity on behalf of the application: A dnsquery_a function call is made for a multihomed computer and the application finds that the address associated with the first a record is not responding. the application shoshould then attempt to use other IP addresses specified in the (additional) A records returned from the dnsquery_a function call.

If the ppqueryresultsset and preserved parameters are set to null, The dnsquery function fails with the error invalid_parameter.

Requirements
Client requires Windows Vista, Windows XP, or Windows 2000 Professional.
Server requires Windows Server "Longhorn", Windows Server 2003, or Windows 2000 Server.
Header declared in windns. h.
 
Library use dnsapi. Lib.
 
DLL requires dnsapi. dll.

2. dnsrecordlistfree

The dnsrecordlistfree function frees memory allocated for DNS records obtained using the dnsquery function.

Void winapi dnsrecordlistfree (
Pdns_record precordlist,
Dns_free_type FreeType
);

Parameters
Precordlist
[In, out] a pointer to the list of DNS records to be freed.
FreeType
[In] a specifier of how the record list shoshould be freed. the only type currently supported is a deep freeing of the entire record list. for more information and a list of values, see the dns_free_type enumeration.
Return Value
This function does not return a value.
Remarks
The dnsrecordlistfree function can be used to free memory allocated from query results obtained using a dnsquery function call; it cannot free memory allocated for DNS record lists created manually.

Requirements
Client requires Windows Vista, Windows XP, or Windows 2000 Professional.
Server requires Windows Server "Longhorn", Windows Server 2003, or Windows 2000 Server.
Header declared in windns. h.
 
Library use dnsapi. Lib.
 
DLL requires dnsapi. dll.

3. dnsrecordcopyex

The dnsrecordcopyex function creates a copy of a specified RR. The dnsrecordcopyex function is also capable of converting the character encoding during the copy operation.

Pdns_record winapi dnsrecordcopyex (
Pdns_record precord,
Dns_charset charsetin,
Dns_charset charsetout
);

Parameters
Precord
[In] pointer to the RR to be copied.
Charsetin
[In] character encoding of the source RR.
Charsetout
[In] character encoding required of the destination record.
Return Value
Successful execution returns a pointer to the (newly created) Destination record. Otherwise, returns NULL.

Remarks
The charsetin parameter is used only if the character encoding of the source RR is not specified in precord.

Requirements
Client requires Windows Vista, Windows XP, or Windows 2000 Professional.
Server requires Windows Server "Longhorn", Windows Server 2003, or Windows 2000 Server.
Header declared in windns. h.
 
Library use dnsapi. Lib.
 
DLL requires dnsapi. dll.

4. dnsmodifyrecordsinset

The dnsmodifyrecordsinsetfunction adds, modifies or removes a resource record (RR) set that may have been previusly registered with DNS servers.

Like Alibaba DNS functions, the dnsmodifyrecordsinset function type is implemented in multiple forms to facilitate different character encoding.

Based on the character encoding involved, use one of the following functions:

Dnsmodifyrecordsinset_a (_ A For ANSI encoding)
Dnsmodifyrecordsinset_w (_ w for Unicode encoding)
Dnsmodifyrecordsinset_utf8 (_ utf8 for UTF 8 encoding)
If the dnsmodifyrecordsinset function type is called without its suffix (_ A, _ w, or _ utf8), a compiler error will occur.

Dns_status winapi dnsmodifyrecordsinset (
Pdns_record paddrecords,
Pdns_record pdeleterecords,
DWORD options,
Handle hcontext,
Pvoid pextralist,
Pvoid preserved
);

Parameters
Paddrecords
[In] a pointer to the dns_record structure that contains the RRS to be added to the RR set.
Pdeleterecords
[In] a pointer to the dns_record structure that contains the RRS to be deleted from the RR set.
Options
[In] options to apply to the operation. Options consist of the following, and may be combined. Option meaning
Dns_update_security_use_default uses the default behavior, which is specified in the registry, for secure dynamic dns updates.
Dns_update_security_off does not attempt secure dynamic updates.
Dns_update_security_on attempts nonsecure dynamic update; if refused, attempts secure dynamic update.
Dns_update_security_only attempts secure dynamic updates only.
Dns_update_cache_security_context caches the security context for use in future transactions.
Dns_update_test_use_local_sys_acct uses credentials of the Local Computer Account.
Dns_update_force_security_nego does not use cached security context.
Dns_update_reserved reserved for future use.

Hcontext
[In] a handle to the credentials of a specific account. used when secure dynamic update is required. This parameter is optional.
Pextralist
[In, out, optional] this parameter is reserved for future use and must be set to null.
Preserved
This parameter is reserved for future use and must be set to null.
Return Value
Returns success Confirmation upon successful completion. Otherwise, it returns the appropriate DNS-specific error code as defined in winerror. h.

Remarks
The dnsmodifyrecordsinset function type executes in the following steps.

Records specified in pdeleterecords are deleted. If pdeleterecords is empty or does not contain records that exist in the current set, the dnsmodifyrecordinset function goes to the next step.
Records specified in paddrecords are added. If paddrecords is empty, the Operation completes without adding any records.
To add a new record, provide no records in pdeleterecords, and provide the record to be added in paddrecords. to modify a record, specify the record being modified in pdeleterecords, then add the modified version of that record by placing it in paddrecords. to delete records, specify only records to be deleted. multiple records can be added or deleted in a single call to dnsmodifyrecordinset. if a record specified in paddrecords is already present, no change occurs.

If no server list is specified, the default name server is queried.

Requirements
Client requires Windows Vista, Windows XP, or Windows 2000 Professional.
Server requires Windows Server "Longhorn", Windows Server 2003, or Windows 2000 Server.
Header declared in windns. h.
 
Library use dnsapi. Lib.
 
DLL requires dnsapi. dll.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.