Leaked source code of windows server 2003
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.

162 lines
4.9 KiB

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <wchar.h>
  4. #include <winsock2.h>
  5. #include "wlbsctrl.h"
  6. int __cdecl wmain (int argc, WCHAR ** argv) {
  7. NLBNotificationConnectionUp pfnConnectionUp = NULL;
  8. NLBNotificationConnectionDown pfnConnectionDown = NULL;
  9. NLBNotificationConnectionReset pfnConnectionReset = NULL;
  10. HINSTANCE hDLL = NULL;
  11. DWORD dwNLBStatus = 0;
  12. DWORD dwStatus = 0;
  13. struct in_addr daddr;
  14. char cluster[19];
  15. char *temp;
  16. bool bUp = false;
  17. bool bDown = false;
  18. bool bReset = false;
  19. DWORD clus = 0;
  20. char *base = "192.1.1.1";
  21. ULONG baseDec;
  22. ULONG baseI, baseJ, baseK;
  23. DWORD dwCount;
  24. int i;
  25. int j;
  26. int k;
  27. int counter;
  28. if (argc < 4) goto usage;
  29. if (!lstrcmpi(argv[1], L"-up")) {
  30. bUp = true;
  31. } else if (!lstrcmpi(argv[1], L"-down")) {
  32. bDown = true;
  33. } else if (!lstrcmpi(argv[1], L"-reset")) {
  34. bReset = true;
  35. } else goto usage;
  36. dwCount = _wtoi(argv[2]);
  37. if (dwCount == 0)
  38. goto usage;
  39. if (!WideCharToMultiByte(CP_ACP, 0, argv[3], -1, cluster, sizeof(cluster), NULL, NULL)) goto usage;
  40. clus = inet_addr(cluster);
  41. printf("cluster ip: %s (%08x)\n", cluster, clus);
  42. hDLL = LoadLibrary(L"wlbsctrl.dll");
  43. if (!hDLL) {
  44. dwStatus = GetLastError();
  45. printf("Unable to open wlbsctrl.dll... GetLastError() returned %u\n", dwStatus);
  46. return -1;
  47. }
  48. pfnConnectionUp = (NLBNotificationConnectionUp)GetProcAddress(hDLL, "WlbsConnectionUp");
  49. pfnConnectionDown = (NLBNotificationConnectionDown)GetProcAddress(hDLL, "WlbsConnectionDown");
  50. pfnConnectionReset = (NLBNotificationConnectionReset)GetProcAddress(hDLL, "WlbsConnectionReset");
  51. if (!pfnConnectionUp || !pfnConnectionDown || !pfnConnectionReset) {
  52. dwStatus = GetLastError();
  53. FreeLibrary(hDLL);
  54. printf("Unable to get procedure address... GetLastError() returned %u\n", dwStatus);
  55. return -1;
  56. }
  57. if (bUp) {
  58. baseDec = inet_addr(base);
  59. counter = 0;
  60. for( i = 0, baseI = baseDec; i < 255; ++i )
  61. {
  62. for( j = 0, baseJ = baseI; j < 255; ++j )
  63. {
  64. for( k = 0, baseK = baseJ; k < 254; ++k )
  65. {
  66. if( counter == dwCount )
  67. {
  68. goto end;
  69. }
  70. ++counter;
  71. daddr.s_addr = baseK;
  72. temp = inet_ntoa(daddr);
  73. dwStatus = (*pfnConnectionUp)(clus, htons(500), baseK, htons(500), 50, &dwNLBStatus);
  74. printf("(%s) UP -> Return value = %u, NLB extended status = %u\n", temp, dwStatus, dwNLBStatus);
  75. baseK += 0x10000;
  76. }
  77. baseJ += 0x100;
  78. }
  79. baseI += 0x1;
  80. }
  81. }
  82. if (bDown) {
  83. baseDec = inet_addr(base);
  84. counter = 0;
  85. for( i = 0, baseI = baseDec; i < 255; ++i )
  86. {
  87. for( j = 0, baseJ = baseI; j < 255; ++j )
  88. {
  89. for( k = 0, baseK = baseJ; k < 254; ++k )
  90. {
  91. if( counter == dwCount )
  92. {
  93. goto end;
  94. }
  95. ++counter;
  96. daddr.s_addr = baseK;
  97. temp = inet_ntoa(daddr);
  98. dwStatus = (*pfnConnectionUp)(clus, htons(500), baseK, htons(500), 50, &dwNLBStatus);
  99. printf("(%s) DOWN -> Return value = %u, NLB extended status = %u\n", temp, dwStatus, dwNLBStatus);
  100. baseK += 0x10000;
  101. }
  102. baseJ += 0x100;
  103. }
  104. baseI += 0x1;
  105. }
  106. }
  107. if (bReset) {
  108. baseDec = inet_addr(base);
  109. counter = 0;
  110. for( i = 0, baseI = baseDec; i < 255; ++i )
  111. {
  112. for( j = 0, baseJ = baseI; j < 255; ++j )
  113. {
  114. for( k = 0, baseK = baseJ; k < 254; ++k )
  115. {
  116. if( counter == dwCount )
  117. {
  118. goto end;
  119. }
  120. ++counter;
  121. daddr.s_addr = baseK;
  122. temp = inet_ntoa(daddr);
  123. dwStatus = (*pfnConnectionUp)(clus, htons(500), baseK, htons(500), 50, &dwNLBStatus);
  124. printf("(%s) RST -> Return value = %u, NLB extended status = %u\n", temp, dwStatus, dwNLBStatus);
  125. baseK += 0x10000;
  126. }
  127. baseJ += 0x100;
  128. }
  129. baseI += 0x1;
  130. }
  131. }
  132. return 0;
  133. end:
  134. FreeLibrary(hDLL);
  135. return 0;
  136. usage:
  137. printf("%ls [-up | -down | -reset] [count] [cluster ip]\n", argv[0]);
  138. return -1;
  139. }