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.

106 lines
3.5 KiB

  1. /*
  2. * Filename: Main.cpp
  3. * Description:
  4. * Author: shouse, 04.10.01
  5. */
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include "wlbsctrl.h"
  9. #include "winsock2.h"
  10. #define STATIC_LINK
  11. int __cdecl wmain (int argc, WCHAR ** argv) {
  12. #if defined (DYNAMIC_LINK)
  13. NLBNotificationConnectionUp pfnConnectionUp = NULL;
  14. NLBNotificationConnectionDown pfnConnectionDown = NULL;
  15. NLBNotificationConnectionReset pfnConnectionReset = NULL;
  16. HINSTANCE hDLL = NULL;
  17. #endif
  18. DWORD dwNLBStatus = 0;
  19. DWORD dwStatus = 0;
  20. bool bUp = false;
  21. bool bDown = false;
  22. bool bReset = false;
  23. if (argc > 2) goto usage;
  24. if (argc > 1) {
  25. if (!lstrcmpi(argv[1], L"-up")) {
  26. bUp = true;
  27. } else if (!lstrcmpi(argv[1], L"-down")) {
  28. bDown = true;
  29. } else if (!lstrcmpi(argv[1], L"-reset")) {
  30. bReset = true;
  31. } else goto usage;
  32. }
  33. #if defined (DYNAMIC_LINK)
  34. hDLL = LoadLibrary(L"wlbsctrl.dll");
  35. if (!hDLL) {
  36. dwStatus = GetLastError();
  37. printf("Unable to open wlbsctrl.dll... GetLastError() returned %u\n", dwStatus);
  38. return -1;
  39. }
  40. pfnConnectionUp = (NLBNotificationConnectionUp)GetProcAddress(hDLL, "WlbsConnectionUp");
  41. pfnConnectionDown = (NLBNotificationConnectionDown)GetProcAddress(hDLL, "WlbsConnectionDown");
  42. pfnConnectionReset = (NLBNotificationConnectionReset)GetProcAddress(hDLL, "WlbsConnectionReset");
  43. if (!pfnConnectionUp || !pfnConnectionDown || !pfnConnectionReset) {
  44. dwStatus = GetLastError();
  45. FreeLibrary(hDLL);
  46. printf("Unable to get procedure address... GetLastError() returned %u\n", dwStatus);
  47. return -1;
  48. }
  49. if (bUp) {
  50. dwStatus = (*pfnConnectionUp)(inet_addr("12.12.4.2"), htons(500), inet_addr("12.12.4.165"), htons(500), 50, &dwNLBStatus);
  51. printf("UP -> Return value = %u, NLB extended status = %u\n", dwStatus, dwNLBStatus);
  52. }
  53. if (bDown) {
  54. dwStatus = (*pfnConnectionDown)(inet_addr("12.12.4.2"), htons(500), inet_addr("12.12.4.165"), htons(500), 50, &dwNLBStatus);
  55. printf("DOWN -> Return value = %u, NLB extended status = %u\n", dwStatus, dwNLBStatus);
  56. }
  57. if (bReset) {
  58. dwStatus = (*pfnConnectionReset)(inet_addr("12.12.4.2"), htons(500), inet_addr("12.12.4.165"), htons(500), 50, &dwNLBStatus);
  59. printf("RESET -> Return value = %u, NLB extended status = %u\n", dwStatus, dwNLBStatus);
  60. }
  61. FreeLibrary(hDLL);
  62. #endif
  63. #if defined (STATIC_LINK)
  64. if (bUp) {
  65. dwStatus = WlbsConnectionUp(inet_addr("12.12.4.2"), htons(80), inet_addr("12.12.4.165"), htons(5001), 6, &dwNLBStatus);
  66. printf("UP -> Return value = %u, NLB extended status = %u\n", dwStatus, dwNLBStatus);
  67. }
  68. if (bDown) {
  69. dwStatus = WlbsConnectionDown(inet_addr("12.12.4.2"), htons(80), inet_addr("12.12.4.165"), htons(5001), 6, &dwNLBStatus);
  70. printf("DOWN -> Return value = %u, NLB extended status = %u\n", dwStatus, dwNLBStatus);
  71. }
  72. if (bReset) {
  73. dwStatus = WlbsConnectionReset(inet_addr("12.12.4.2"), htons(80), inet_addr("12.12.4.165"), htons(5001), 6, &dwNLBStatus);
  74. printf("RESET -> Return value = %u, NLB extended status = %u\n", dwStatus, dwNLBStatus);
  75. }
  76. #endif
  77. return 0;
  78. usage:
  79. printf("%ls [-up | -down | -reset]\n", argv[0]);
  80. }