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.

157 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. cdpsrv.c
  5. Abstract:
  6. Author:
  7. Mike Massa (mikemas) Feb 24, 1992
  8. Revision History:
  9. Who When What
  10. -------- -------- ----------------------------------------------
  11. mikemas 02-24-92 created
  12. Notes:
  13. --*/
  14. #include <windows.h>
  15. #include <winsock2.h>
  16. #include <wsclus.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #define MAX_PACKET_SIZE 65535-20-68
  20. static char szTestPattern [] = "data" ;
  21. #define TESTPATTERN_LEN 4
  22. int count = 0;
  23. WSADATA WsaData;
  24. // void _CRTAPI1
  25. int _cdecl
  26. main(int argc, char **argv, char **envp)
  27. {
  28. SOCKET serve_me;
  29. u_short Port;
  30. struct sockaddr addr, recvaddr;
  31. int addrlen, recv_addrlen;
  32. SOCKADDR_CLUSTER *clus_addr = (PSOCKADDR_CLUSTER)&addr;
  33. char *buf;
  34. int err;
  35. int i, j;
  36. WORD versionRequested = MAKEWORD(2, 0);
  37. DWORD bytesReturned = 0;
  38. if(argc<2){
  39. printf("usage: cdpsrv port\n");
  40. exit(4);
  41. }
  42. Port = (u_short) atoi(argv[1]);
  43. err = WSAStartup( versionRequested, &WsaData );
  44. if ( err != ERROR_SUCCESS ) {
  45. printf("cdpsrv: WSAStartup %d:", err);
  46. exit(1);
  47. }
  48. if ((buf = malloc(MAX_PACKET_SIZE)) == NULL) {
  49. printf("out of memory\n");
  50. exit(1);
  51. }
  52. memset(&addr,0,sizeof(addr));
  53. clus_addr->sac_family = AF_CLUSTER;
  54. clus_addr->sac_port = Port;
  55. clus_addr->sac_node = 0;
  56. serve_me=socket(AF_CLUSTER, SOCK_DGRAM, CLUSPROTO_CDP);
  57. if (serve_me == INVALID_SOCKET){
  58. printf("\nsocket failed (%d)\n", WSAGetLastError());
  59. exit(1);
  60. }
  61. err = WSAIoctl(
  62. serve_me,
  63. SIO_CLUS_IGNORE_NODE_STATE,
  64. NULL,
  65. 0,
  66. NULL,
  67. 0,
  68. &bytesReturned,
  69. NULL,
  70. NULL
  71. );
  72. if (err == SOCKET_ERROR) {
  73. printf("Died on WSHIoctl(), status %u\n", WSAGetLastError());
  74. closesocket(serve_me);
  75. exit(9);
  76. }
  77. if (bind(serve_me, &addr, sizeof(addr))==SOCKET_ERROR){
  78. printf("\nbind failed (%d) on port %d\n",
  79. WSAGetLastError(), Port);
  80. closesocket(serve_me);
  81. exit(1);
  82. }
  83. while(1) {
  84. recv_addrlen = sizeof(SOCKADDR_CLUSTER);
  85. err = recvfrom(
  86. serve_me,
  87. buf,
  88. MAX_PACKET_SIZE,
  89. 0,
  90. &recvaddr,
  91. &recv_addrlen
  92. );
  93. if (err == SOCKET_ERROR) {
  94. printf("\nrecvfrom failed (%d)\n", WSAGetLastError());
  95. break;
  96. }
  97. i = 0 ;
  98. while (i < err)
  99. {
  100. for (j=0; j < TESTPATTERN_LEN && i < err; i++, j++)
  101. if (buf [i] != szTestPattern [j])
  102. {
  103. printf ("Received Length is %d\n", err) ;
  104. while (i < err)
  105. {
  106. printf ("Char at %d is %d %c\n", i, buf[i], buf[i]) ;
  107. i++ ;
  108. }
  109. exit (1) ;
  110. }
  111. }
  112. if ((++count % 50) == 0) {
  113. printf("#");
  114. }
  115. }
  116. closesocket(serve_me);
  117. }