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.

136 lines
4.2 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: This is the test program that tests the dhcpds functionality..
  5. //================================================================================
  6. #include <hdrmacro.h>
  7. #include <store.h>
  8. #include <dhcpapi.h>
  9. #include <dhcpbas.h>
  10. #include <rpcapi1.h>
  11. #include <rpcapi2.h>
  12. #include <dhcpds.h>
  13. //================================================================================
  14. // testing the DS functionality
  15. //================================================================================
  16. VOID
  17. PrintAndFreeServers(
  18. IN LPDHCPDS_SERVERS Servers
  19. )
  20. {
  21. DWORD i;
  22. for( i = 0; i < Servers->NumElements; i ++ ) {
  23. printf("Server %ws Address 0x%lx\n", Servers->Servers[i].ServerName, Servers->Servers[i].IpAddress);
  24. }
  25. LocalFree(Servers);
  26. // must do MIDL_user_free here..
  27. }
  28. void
  29. TestNew1(
  30. VOID
  31. )
  32. {
  33. DWORD Result;
  34. DWORD IpAddress;
  35. WCHAR ServerName[256];
  36. CHAR IpAddressString[256];
  37. LPDHCPDS_SERVERS Servers;
  38. LPDHCPDS_SERVER ThisServer;
  39. LPSTORE_HANDLE tDhcpGetGlobalDhcpRoot(VOID);
  40. Result = DhcpDsInit(
  41. 0,
  42. NULL
  43. );
  44. if( ERROR_SUCCESS != Result ) {
  45. printf("DhcpDsInit: %ld (0x%lx)\n", Result, Result);
  46. return;
  47. }
  48. Result = StoreCreateObject(
  49. /* hStore */ tDhcpGetGlobalDhcpRoot(),
  50. /* Reserved */ DDS_RESERVED_DWORD,
  51. /* NewObjName */ DHCP_ROOT_OBJECT_CN_NAME,
  52. /* ... */
  53. /* Identification */
  54. ADSTYPE_DN_STRING, ATTRIB_DN_NAME, DHCP_ROOT_OBJECT_NAME,
  55. ADSTYPE_DN_STRING, ATTRIB_OBJECT_CLASS, DEFAULT_DHCP_CLASS_ATTRIB_VALUE,
  56. /* systemMustContain */
  57. ADSTYPE_INTEGER, ATTRIB_DHCP_UNIQUE_KEY, 0,
  58. ADSTYPE_INTEGER, ATTRIB_DHCP_TYPE, 0,
  59. ADSTYPE_DN_STRING, ATTRIB_DHCP_IDENTIFICATION, L"This is a server",
  60. ADSTYPE_INTEGER, ATTRIB_DHCP_FLAGS, 0,
  61. ADSTYPE_INTEGER, ATTRIB_INSTANCE_TYPE, DEFAULT_INSTANCE_TYPE_ATTRIB_VALUE,
  62. /* terminator */
  63. ADSTYPE_INVALID
  64. );
  65. if( ERROR_SUCCESS != Result ) {
  66. printf("StoreCreateObject(ROOT): %ld\n", Result);
  67. }
  68. #if 0
  69. Servers = NULL;
  70. Result = DhcpDsEnumServers(
  71. &1,
  72. &Servers,
  73. NULL,
  74. NULL
  75. );
  76. printf("DhcpEnumServers:0x%lx (%ld)\n", Result, Result);
  77. if( ERROR_SUCCESS == Result ) PrintAndFreeServers(Servers);
  78. printf("ServerName: ");
  79. memset(ServerName, 0, sizeof(ServerName));
  80. scanf("%ws", ServerName);
  81. printf("ServerAddress: ");
  82. memset(IpAddressString, 0, sizeof(IpAddressString));
  83. scanf("%s", IpAddressString);
  84. ThisServer.ServerName = ServerName;
  85. ThisServer.ServerAddress = inet_addr(IpAddressString);
  86. printf("DhcpAddServer(%ws, %s): ", ThisServer.ServerName, inet_ntoa(*(struct in_addr *)&ThisServer.ServerAddress));
  87. Result = DhcpAddServer(0, NULL, &ThisServer, NULL, NULL);
  88. printf("0x%lx (%ld)\n", Result, Result);
  89. printf("ServerName: ");
  90. memset(ServerName, 0, sizeof(ServerName));
  91. scanf("%ws", ServerName);
  92. printf("ServerAddress: ");
  93. memset(IpAddressString, 0, sizeof(IpAddressString));
  94. scanf("%s", IpAddressString);
  95. ThisServer.ServerName = ServerName;
  96. ThisServer.ServerAddress = inet_addr(IpAddressString);
  97. printf("DhcpDeleteServer(%ws, %s): ", ThisServer.ServerName, inet_ntoa(*(struct in_addr *)&ThisServer.ServerAddress));
  98. Result = DhcpDeleteServer(0, NULL, &ThisServer, NULL, NULL);
  99. printf("0x%lx (%ld)\n", Result, Result);
  100. #endif 0
  101. DhcpDsCleanup();
  102. }
  103. VOID
  104. TestAll(
  105. VOID
  106. )
  107. {
  108. TestNew1();
  109. }
  110. void _cdecl main(
  111. VOID
  112. )
  113. {
  114. TestAll();
  115. }
  116. //================================================================================
  117. // end of file
  118. //================================================================================