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.

112 lines
3.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 <windows.h>
  7. #include <dhcpds.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <wchar.h>
  11. #include <winsock.h>
  12. //================================================================================
  13. // testing the DS functionality
  14. //================================================================================
  15. VOID
  16. PrintAndFreeServers(
  17. IN LPDHCP_SERVER_INFO_ARRAY Servers
  18. )
  19. {
  20. DWORD i;
  21. for( i = 0; i < Servers->NumElements; i ++ ) {
  22. printf("Server %ws Address 0x%lx\n", Servers->Servers[i].ServerName, Servers->Servers[i].ServerAddress);
  23. }
  24. LocalFree(Servers);
  25. // must do MIDL_user_free here..
  26. }
  27. void
  28. TestNew1(
  29. VOID
  30. )
  31. {
  32. DWORD Result;
  33. DWORD IpAddress;
  34. WCHAR ServerName[256];
  35. CHAR IpAddressString[256];
  36. LPDHCP_SERVER_INFO_ARRAY Servers;
  37. DHCP_SERVER_INFO ThisServer = {
  38. 0 /* Flags */, 0 /* State */, NULL /* ServerName */, 0 /* ServerAddress */
  39. };
  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. Servers = NULL;
  49. Result = DhcpEnumServers(
  50. 0,
  51. NULL,
  52. &Servers,
  53. NULL,
  54. NULL
  55. );
  56. printf("DhcpEnumServers:0x%lx (%ld)\n", Result, Result);
  57. if( ERROR_SUCCESS == Result ) PrintAndFreeServers(Servers);
  58. printf("ServerName: ");
  59. memset(ServerName, 0, sizeof(ServerName));
  60. scanf("%ws", ServerName);
  61. printf("ServerAddress: ");
  62. memset(IpAddressString, 0, sizeof(IpAddressString));
  63. scanf("%s", IpAddressString);
  64. ThisServer.ServerName = ServerName;
  65. ThisServer.ServerAddress = inet_addr(IpAddressString);
  66. printf("DhcpAddServer(%ws, %s): ", ThisServer.ServerName, inet_ntoa(*(struct in_addr *)&ThisServer.ServerAddress));
  67. Result = DhcpAddServer(0, NULL, &ThisServer, NULL, NULL);
  68. printf("0x%lx (%ld)\n", Result, Result);
  69. printf("ServerName: ");
  70. memset(ServerName, 0, sizeof(ServerName));
  71. scanf("%ws", ServerName);
  72. printf("ServerAddress: ");
  73. memset(IpAddressString, 0, sizeof(IpAddressString));
  74. scanf("%s", IpAddressString);
  75. ThisServer.ServerName = ServerName;
  76. ThisServer.ServerAddress = inet_addr(IpAddressString);
  77. printf("DhcpDeleteServer(%ws, %s): ", ThisServer.ServerName, inet_ntoa(*(struct in_addr *)&ThisServer.ServerAddress));
  78. Result = DhcpDeleteServer(0, NULL, &ThisServer, NULL, NULL);
  79. printf("0x%lx (%ld)\n", Result, Result);
  80. DhcpDsCleanup();
  81. }
  82. VOID
  83. TestAll(
  84. VOID
  85. )
  86. {
  87. TestNew1();
  88. }
  89. void _cdecl main(
  90. VOID
  91. )
  92. {
  93. TestAll();
  94. }
  95. //================================================================================
  96. // end of file
  97. //================================================================================