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.

173 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. utestcly.c
  5. Abstract:
  6. UDP stress test client. Fires datagrams at a specific UDP port
  7. on a machine.
  8. Author:
  9. Mike Massa (mikemas) Feb 24, 1992
  10. Revision History:
  11. Who When What
  12. -------- -------- ----------------------------------------------
  13. mikemas 02-24-92 created
  14. Notes:
  15. --*/
  16. #include <windows.h>
  17. #include <winsock2.h>
  18. #include <wsclus.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. static char szTestPattern [] = "data" ;
  22. #define TESTPATTERN_LEN 4
  23. #define MAX_PACKET_SIZE (65535-20-68)
  24. WSADATA WsaData;
  25. // void _CRTAPI1
  26. int _cdecl
  27. main(int argc, char **argv, char **envp)
  28. {
  29. SOCKET serve_me;
  30. u_long dstNode;
  31. u_short dstPort;
  32. struct sockaddr addr;
  33. int remotelen;
  34. SOCKADDR_CLUSTER remoteaddr;
  35. PSOCKADDR_CLUSTER clus_addr = (PSOCKADDR_CLUSTER) &addr;
  36. int count;
  37. int pktsize;
  38. char *buf;
  39. int i, j;
  40. int err;
  41. WORD versionRequested = MAKEWORD(2, 0);
  42. DWORD bytesReturned = 0;
  43. if(argc<5){
  44. printf("usage: cdpcli node port pktsize pktcnt\n");
  45. printf(" Pktcnt of -1 will loop forever\n");
  46. exit(4);
  47. }
  48. dstNode = (u_long) atoi(argv[1]);
  49. dstPort = (u_short) atoi(argv[2]);
  50. pktsize = atoi(argv[3]);
  51. count = atoi(argv[4]);
  52. if (pktsize > MAX_PACKET_SIZE) {
  53. printf("max packet size is 1460\n");
  54. exit(1);
  55. }
  56. err = WSAStartup( versionRequested, &WsaData );
  57. if ( err != ERROR_SUCCESS ) {
  58. printf("udpcli: WSAStartup %d:", err);
  59. exit(1);
  60. }
  61. if ((buf = malloc(pktsize)) == NULL) {
  62. printf("out of memory\n");
  63. exit(1);
  64. }
  65. i = 0 ;
  66. while (i < pktsize)
  67. {
  68. for (j=0; j < TESTPATTERN_LEN && i < pktsize; i++, j++)
  69. buf [i] = szTestPattern [j] ;
  70. }
  71. serve_me = socket(AF_CLUSTER, SOCK_DGRAM, CLUSPROTO_CDP);
  72. if(serve_me == INVALID_SOCKET){
  73. printf(
  74. "Died on socket(), status %u\n",
  75. WSAGetLastError()
  76. );
  77. exit(4);
  78. }
  79. memset(&addr,0,sizeof(addr));
  80. clus_addr->sac_family = AF_CLUSTER;
  81. clus_addr->sac_port = 0;
  82. clus_addr->sac_node = 0;
  83. clus_addr->sac_zero = 0;
  84. if(bind(serve_me, &addr, sizeof(addr))==SOCKET_ERROR){
  85. printf("Died on bind(), status %u\n", WSAGetLastError());
  86. closesocket(serve_me);
  87. exit(9);
  88. }
  89. err = WSAIoctl(
  90. serve_me,
  91. SIO_CLUS_IGNORE_NODE_STATE,
  92. NULL,
  93. 0,
  94. NULL,
  95. 0,
  96. &bytesReturned,
  97. NULL,
  98. NULL
  99. );
  100. if (err == SOCKET_ERROR) {
  101. printf("Died on WSHIoctl(), status %u\n", WSAGetLastError());
  102. closesocket(serve_me);
  103. exit(9);
  104. }
  105. memset(&addr,0,sizeof(addr));
  106. clus_addr->sac_family = AF_CLUSTER;
  107. clus_addr->sac_port = dstPort;
  108. clus_addr->sac_node = dstNode;
  109. for(i=0; i < count || count == -1; i++) {
  110. if( sendto(
  111. serve_me,
  112. buf,
  113. pktsize,
  114. 0,
  115. &addr,
  116. sizeof(addr)
  117. )
  118. ==SOCKET_ERROR
  119. ){
  120. printf("sendto failed %d\n",WSAGetLastError());
  121. exit(9);
  122. }
  123. }
  124. closesocket(serve_me);
  125. }
  126. int init_net()
  127. {
  128. WORD wVersionRequired;
  129. WSADATA versionInfo;
  130. wVersionRequired = 1<<8 | 0;
  131. if(WSAStartup(wVersionRequired, &versionInfo)){
  132. printf("died in WSAStartup() %d\n",WSAGetLastError());
  133. exit(9);
  134. }
  135. return 0;
  136. }