4.5 Creating and Deleting a DNS Record
The following example specifies how to create a DNS record representing the IPv4 address "184.108.40.206" for the host named "host1" in the existing primary zone named "example.com". The new record will have a TTL of one hour.
The client formats a DNS_RPC_RECORD structure (section 220.127.116.11.5), stored on the stack or elsewhere using a buffer at least large enough to hold the DNS_RPC_RECORD structure plus the DNS_RPC_RECORD_DATA in the Buffer member, to represent the new record data as follows:
wDataLength is set to the size of the data that will be stored in the Buffer member. In this case, because the record data will be a DNS_RPC_RECORD_A (section 18.104.22.168.4.1) structure, the value of wDataLength is set to 4.
wType is set to the desired record type (section 22.214.171.124.1), in this case DNS_TYPE_A.
dwFlags, dwSerial, dwTimeStamp, and dwReserved are set to zero.
dwTtlSeconds is set to the desired TTL value in seconds, in this case 3600 for one hour.
The client formats the Buffer member as a DNS_RPC_RECORD_A structure. The byte values 0x01, 0x02, 0x03, and 0x04 are set in the four bytes of memory starting at the offset of Buffer.
The client calls R_DnssrvUpdateRecord2 and provides the following parameters:
DNS_RPC_CURRENT_CLIENT_VER as the client version.
Zero as the settings flag.
"example.com" as the zone name.
"host1" as the node name.
A pointer to the DNS_RPC_RECORD created above as the pAddRecord parameter.
A NULL pointer as the pDeleteRecord pointer.
The DNS server will return ERROR_SUCCESS if the record was successfully created or a Windows error code on failure.
To delete this DNS record, format a DNS_RPC_RECORD structure exactly as described above, and call R_DnssrvUpdateRecord2 in exactly the same way but pass NULL as the pAddRecord parameter and the DNS_RPC_RECORD pointer as the pDeleteRecord.