Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.5 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <dnsapi.h>
  8. _cdecl
  9. main(int argc, char **argv)
  10. {
  11. DWORD Status = NO_ERROR;
  12. PDNS_RECORD pDNSRecord = NULL;
  13. WCHAR usName[MAX_PATH];
  14. LONG cch;
  15. LPSTR lpTemp = NULL, lpAddress = NULL;
  16. BYTE Part1, Part2, Part3, Part4;
  17. if ( argc != 3 )
  18. {
  19. printf( "\nUsage: dnsreg <DNS Name> <IP Address>\n" );
  20. printf( "\nWhere:\n" );
  21. printf( " DNS Name - Server_X.dbsd-test.microsoft.com\n" );
  22. printf( " IP Address - 121.55.54.121\n" );
  23. return(-1);
  24. }
  25. cch = MultiByteToWideChar(
  26. CP_ACP,
  27. 0L,
  28. argv[1],
  29. -1,
  30. usName,
  31. MAX_PATH
  32. );
  33. if (!cch) {
  34. return (GetLastError());
  35. }
  36. lpAddress = argv[2];
  37. lpTemp = strtok( lpAddress, "." );
  38. Part1 = (BYTE) atoi( lpTemp );
  39. lpTemp = strtok( NULL, "." );
  40. Part2 = (BYTE) atoi( lpTemp );
  41. lpTemp = strtok( NULL, "." );
  42. Part3 = (BYTE) atoi( lpTemp );
  43. lpTemp = strtok( NULL, "." );
  44. Part4 = (BYTE) atoi( lpTemp );
  45. printf( "\nRegistering DNS record with:\n" );
  46. printf( "Name: %S\n", usName );
  47. printf( "Address: %d.%d.%d.%d\n", Part1, Part2, Part3, Part4 );
  48. pDNSRecord = (PDNS_RECORD) LocalAlloc( LPTR, sizeof( DNS_RECORD ) );
  49. if ( !pDNSRecord )
  50. {
  51. printf( "LocalAlloc( sizeof( DNS_RECORD ) ) call failed.\n" );
  52. return(-1);
  53. }
  54. //
  55. // Prepare a DNS RRSet with a new A record to add ...
  56. //
  57. pDNSRecord->pNext = NULL;
  58. pDNSRecord->nameOwner = (DNS_NAME) usName;
  59. pDNSRecord->wType = DNS_TYPE_A;
  60. pDNSRecord->wDataLength = sizeof( DNS_A_DATA );
  61. // pDNSRecord->wReserved = 0;
  62. // pDNSRecord->Flags.W = 0;
  63. pDNSRecord->dwTtl = 240;
  64. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[0] = Part1;
  65. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[1] = Part2;
  66. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[2] = Part3;
  67. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[3] = Part4;
  68. printf( "DnsAddRecordSet_W( pDNSRecord, 0 ) ...\n",
  69. usName );
  70. Status = DnsAddRecordSet_W( NULL, pDNSRecord, 0, NULL );
  71. LocalFree( pDNSRecord );
  72. if ( Status )
  73. {
  74. printf( "DnsAddRecordSet_W call failed with error: 0x%.8X\n",
  75. Status );
  76. return(-1);
  77. }
  78. printf( "DnsAddRecordSet_W call succeeded!\n" );
  79. return(0);
  80. }