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.

101 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. LPSTR lpTemp = NULL, lpAddress = NULL;
  15. BYTE Part1, Part2, Part3, Part4;
  16. LONG cch;
  17. if ( argc != 3 )
  18. {
  19. printf( "\nUsage: dnsrem <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. Status = GetLastError();
  35. return (Status);
  36. }
  37. lpAddress = argv[2];
  38. lpTemp = strtok( lpAddress, "." );
  39. Part1 = (BYTE) atoi( lpTemp );
  40. lpTemp = strtok( NULL, "." );
  41. Part2 = (BYTE) atoi( lpTemp );
  42. lpTemp = strtok( NULL, "." );
  43. Part3 = (BYTE) atoi( lpTemp );
  44. lpTemp = strtok( NULL, "." );
  45. Part4 = (BYTE) atoi( lpTemp );
  46. printf( "\nRemoving DNS record with:\n" );
  47. printf( "Name: %S\n", usName );
  48. printf( "Address: %d.%d.%d.%d\n", Part1, Part2, Part3, Part4 );
  49. pDNSRecord = (PDNS_RECORD) LocalAlloc( LPTR, sizeof( DNS_RECORD ) );
  50. if ( !pDNSRecord )
  51. {
  52. printf( "LocalAlloc( sizeof( DNS_RECORD ) ) call failed.\n" );
  53. return(-1);
  54. }
  55. //
  56. // Prepare a DNS RRSet with a new A record to remove ...
  57. //
  58. pDNSRecord->pNext = NULL;
  59. pDNSRecord->nameOwner = (DNS_NAME) usName;
  60. pDNSRecord->wType = DNS_TYPE_A;
  61. pDNSRecord->wDataLength = sizeof( DNS_A_DATA );
  62. // pDNSRecord->wReserved = 0;
  63. // pDNSRecord->Flags.W = 0;
  64. // pDNSRecord->dwTtl = 0;
  65. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[0] = Part1;
  66. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[1] = Part2;
  67. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[2] = Part3;
  68. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[3] = Part4;
  69. printf( "DnsRemoveRRSet( pDNSRecord ) ...\n" );
  70. Status = DnsRemoveRRSet( pDNSRecord, NULL );
  71. LocalFree( pDNSRecord );
  72. if ( Status )
  73. {
  74. printf( "DnsRemoveRRSet call failed with error: 0x%.8X\n",
  75. Status );
  76. return(-1);
  77. }
  78. printf( "DnsRemoveRRSet call succeeded!\n" );
  79. return(0);
  80. }