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.

117 lines
2.9 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. VOID
  9. PrintIpAddress (
  10. IN DWORD dwIpAddress )
  11. {
  12. printf( " %d.%d.%d.%d\n",
  13. ((BYTE *) &dwIpAddress)[0],
  14. ((BYTE *) &dwIpAddress)[1],
  15. ((BYTE *) &dwIpAddress)[2],
  16. ((BYTE *) &dwIpAddress)[3] );
  17. }
  18. _cdecl
  19. main(int argc, char **argv)
  20. {
  21. DWORD Status = NO_ERROR;
  22. PDNS_RECORD pDNSRecord = NULL;
  23. WCHAR usName[MAX_PATH];
  24. LONG cch;
  25. LPSTR lpTemp = NULL, lpAddress = NULL;
  26. BYTE Part1, Part2, Part3, Part4;
  27. IP_ADDRESS ip;
  28. if ( argc != 3 )
  29. {
  30. printf( "\nUsage: dnsreg <DNS Name> <IP Address>\n" );
  31. printf( "\nWhere:\n" );
  32. printf( " DNS Name - Server_X.dbsd-test.microsoft.com\n" );
  33. printf( " IP Address - 121.55.54.121\n" );
  34. return(-1);
  35. }
  36. cch = MultiByteToWideChar(
  37. CP_ACP,
  38. 0L,
  39. argv[1],
  40. -1,
  41. usName,
  42. MAX_PATH
  43. );
  44. if (!cch)
  45. {
  46. return (GetLastError());
  47. }
  48. lpAddress = argv[2];
  49. lpTemp = strtok( lpAddress, "." );
  50. Part1 = (BYTE) atoi( lpTemp );
  51. lpTemp = strtok( NULL, "." );
  52. Part2 = (BYTE) atoi( lpTemp );
  53. lpTemp = strtok( NULL, "." );
  54. Part3 = (BYTE) atoi( lpTemp );
  55. lpTemp = strtok( NULL, "." );
  56. Part4 = (BYTE) atoi( lpTemp );
  57. printf( "\nRegistering DNS record with:\n" );
  58. printf( "Name: %S\n", usName );
  59. printf( "Address: %d.%d.%d.%d\n", Part1, Part2, Part3, Part4 );
  60. pDNSRecord = (PDNS_RECORD) LocalAlloc( LPTR, sizeof( DNS_RECORD ) );
  61. if ( !pDNSRecord )
  62. {
  63. printf( "LocalAlloc( sizeof( DNS_RECORD ) ) call failed.\n" );
  64. return(-1);
  65. }
  66. //
  67. // Prepare a DNS RRSet with a new A record to add ...
  68. //
  69. pDNSRecord->pNext = NULL;
  70. pDNSRecord->nameOwner = (DNS_NAME) usName;
  71. pDNSRecord->wType = DNS_TYPE_A;
  72. pDNSRecord->wDataLength = sizeof( DNS_A_DATA );
  73. // pDNSRecord->wReserved = 0;
  74. // pDNSRecord->Flags.W = 0;
  75. pDNSRecord->dwTtl = 240;
  76. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[0] = Part1;
  77. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[1] = Part2;
  78. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[2] = Part3;
  79. ((BYTE *) &pDNSRecord->Data.A.ipAddress)[3] = Part4;
  80. printf( "DnsRegisterRRSet( pDNSRecord, DNS_UPDATE_SHARED ) ...\n",
  81. usName );
  82. Status = DnsRegisterRRSet( pDNSRecord, DNS_UPDATE_SHARED, NULL );
  83. LocalFree( pDNSRecord );
  84. if ( Status )
  85. {
  86. printf( "DnsRegisterRRSet call failed with error: 0x%.8X\n",
  87. Status );
  88. return(-1);
  89. }
  90. printf( "DnsRegisterRRSet call succeeded!\n" );
  91. ip = DnsGetLastServerUpdateIP();
  92. printf( "Dns update was sent to server :" );
  93. PrintIpAddress( ip );
  94. return(0);
  95. }