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.

109 lines
2.7 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. LPSTR lpTemp = NULL, lpAddress = NULL;
  15. BYTE Part1, Part2, Part3, Part4;
  16. LONG cch;
  17. if ( argc != 3 )
  18. {
  19. printf( "\nUsage: dnsrep <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. printf( " - or -\n" );
  24. printf( " IP Address - 0.0.0.0 to nuke entry\n" );
  25. return(-1);
  26. }
  27. cch = MultiByteToWideChar(
  28. CP_ACP,
  29. 0L,
  30. argv[1],
  31. -1,
  32. usName,
  33. MAX_PATH
  34. );
  35. if (!cch) {
  36. return (GetLastError());
  37. }
  38. lpAddress = argv[2];
  39. lpTemp = strtok( lpAddress, "." );
  40. Part1 = (BYTE) atoi( lpTemp );
  41. lpTemp = strtok( NULL, "." );
  42. Part2 = (BYTE) atoi( lpTemp );
  43. lpTemp = strtok( NULL, "." );
  44. Part3 = (BYTE) atoi( lpTemp );
  45. lpTemp = strtok( NULL, "." );
  46. Part4 = (BYTE) atoi( lpTemp );
  47. printf( "\nReplacing all DNS records with:\n" );
  48. printf( "Name: %S\n", usName );
  49. printf( "Address: %d.%d.%d.%d\n", Part1, Part2, Part3, Part4 );
  50. pDNSRecord = (PDNS_RECORD) LocalAlloc( LPTR, sizeof( DNS_RECORD ) );
  51. if ( !pDNSRecord )
  52. {
  53. printf( "LocalAlloc( sizeof( DNS_RECORD ) ) call failed.\n" );
  54. return(-1);
  55. }
  56. //
  57. // Prepare a DNS RRSet with a new A record to replace with ...
  58. //
  59. pDNSRecord->pNext = NULL;
  60. pDNSRecord->nameOwner = (DNS_NAME) usName;
  61. pDNSRecord->wType = DNS_TYPE_A;
  62. if ( Part1 || Part2 || Part3 || Part4 )
  63. {
  64. pDNSRecord->wDataLength = sizeof( DNS_A_DATA );
  65. // pDNSRecord->wReserved = 0;
  66. // pDNSRecord->Flags.W = 0;
  67. pDNSRecord->dwTtl = 240;
  68. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[0] = Part1;
  69. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[1] = Part2;
  70. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[2] = Part3;
  71. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[3] = Part4;
  72. }
  73. else
  74. {
  75. pDNSRecord->wDataLength = 0;
  76. }
  77. printf( "DnsReplaceRRSet( pDNSRecord ) ...\n" );
  78. Status = DnsReplaceRRSet( pDNSRecord, NULL );
  79. LocalFree( pDNSRecord );
  80. if ( Status )
  81. {
  82. printf( "DnsReplaceRRSet call failed with error: 0x%.8X\n",
  83. Status );
  84. return(-1);
  85. }
  86. printf( "DnsReplaceRRSet call succeeded!\n" );
  87. return(0);
  88. }