fork download
  1. void CFastScanDlg::OnBnClickedButton1()
  2. {
  3. char tStr[255];
  4. SOCKET sock[MAX_SOCKETS];
  5. int busy[MAX_SOCKETS], port[MAX_SOCKETS];
  6. int iStartPort, iEndPort, iBusySocks = 0;
  7. struct sockaddr_in addr;
  8. fd_set fdWaitSet;
  9.  
  10. WSADATA wsd;
  11. if (WSAStartup(MAKEWORD(2,2), &wsd) != 0)
  12. {
  13. SetDlgItemText(IDC_STATUSTEXT, "Can't load WinSock");
  14. return;
  15. }
  16.  
  17. SetDlgItemText(IDC_STATUSTEXT, "Resolving host");
  18.  
  19. chStartPort.GetWindowText(tStr, 255);
  20. iStartPort = atoi(tStr);
  21. chEndPort.GetWindowText(tStr, 255);
  22. iEndPort = atoi(tStr);
  23.  
  24. chHostName.GetWindowText(tStr, 255);
  25.  
  26. struct hostent *host=NULL;
  27. host = gethostbyname(tStr);
  28. if (host == NULL)
  29. {
  30. SetDlgItemText(IDC_STATUSTEXT,
  31. "Unable to resolve host");
  32. return;
  33. }
  34.  
  35. for (int i = 0; i < MAX_SOCKETS; i++)
  36. busy[i] = 0;
  37.  
  38. SetDlgItemText(IDC_STATUSTEXT, "Scanning");
  39.  
  40. while (((iBusySocks) || (iStartPort <= iEndPort)))
  41. {
  42. for (int i = 0; i < MAX_SOCKETS; i++)
  43. {
  44. if (busy[i] == 0 && iStartPort <= iEndPort)
  45. {
  46. sock[i] = socket (AF_INET,
  47. SOCK_STREAM, IPPROTO_TCP);
  48. if (sock[i] < 0)
  49. {
  50. SetDlgItemText(IDC_STATUSTEXT,
  51. "Socket filed");
  52. return;
  53. }
  54. iBusySocks++;
  55. addr.sin_family = AF_INET;
  56. addr.sin_port = htons (iStartPort);
  57. CopyMemory(&addr.sin_addr, host->h_addr_list[0],
  58. host->h_length);
  59.  
  60. ULONG ulBlock;
  61. ulBlock = 1;
  62. if (ioctlsocket(sock[i], FIONBIO, &ulBlock) ==
  63. SOCKET_ERROR)
  64. {
  65. return;
  66. }
  67.  
  68. connect(sock[i], (struct sockaddr *) &addr,
  69. sizeof (addr));
  70. if (WSAGetLastError() == WSAEINPROGRESS)
  71. {
  72. closesocket (sock[i]);
  73. iBusySocks--;
  74. }
  75. else
  76. {
  77. busy[i] = 1;
  78. port[i] = iStartPort;
  79. }
  80. iStartPort++;
  81. }
  82. }
  83. FD_ZERO (&fdWaitSet);
  84. for (int i = 0; i < MAX_SOCKETS; i++)
  85. {
  86. if (busy[i] == 1)
  87. FD_SET (sock[i], &fdWaitSet);
  88. }
  89.  
  90. struct timeval tv;
  91. tv.tv_sec = 1;
  92. tv.tv_usec = 0;
  93.  
  94. if (select (1, NULL, &fdWaitSet, NULL, &tv) == SOCKET_ERROR)
  95. {
  96. SetDlgItemText(IDC_STATUSTEXT, "Select error");
  97. return;
  98. }
  99.  
  100. for (int i = 0; i < MAX_SOCKETS; i++)
  101. {
  102. if (busy[i] == 1)
  103. {
  104. if (FD_ISSET (sock[i], &fdWaitSet))
  105. {
  106. int opt;
  107. int Len = sizeof(opt);
  108. if (getsockopt(sock[i], SOL_SOCKET,
  109. SO_ERROR, (char*)&opt, &Len) ==
  110. SOCKET_ERROR)
  111. SetDlgItemText(IDC_STATUSTEXT,
  112. "getsockopt error");
  113.  
  114. if (opt == 0)
  115. {
  116. struct servent *tec;
  117. itoa(port[i],tStr, 10);
  118. strcat(tStr, " (");
  119. tec = getservbyport(htons (port[i]),
  120. "tcp");
  121. if (tec==NULL)
  122. strcat(tStr, "Unknown");
  123. else
  124. strcat(tStr, tec->s_name);
  125.  
  126. strcat(tStr, ") - open");
  127. m_PortList.AddString(tStr);
  128. busy[i] = 0;
  129. shutdown(sock[i], SD_BOTH);
  130. closesocket(sock[i]);
  131. }
  132. busy[i] = 0;
  133. shutdown (sock[i], SD_BOTH);
  134. closesocket (sock[i]);
  135. iBusySocks--;
  136. }
  137. else
  138. {
  139. busy[i] = 0;
  140. closesocket(sock[i]);
  141. iBusySocks--;
  142. }
  143. }
  144. }
  145. ProcessMessages();
  146. }
  147. WSACleanup();
  148. SetDlgItemText(IDC_STATUSTEXT, "Scaning complete");
  149. return;
  150. }
  151.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1: error: 'CFastScanDlg' has not been declared
prog.cpp: In function 'void OnBnClickedButton1()':
prog.cpp:4: error: 'SOCKET' was not declared in this scope
prog.cpp:4: error: expected `;' before 'sock'
prog.cpp:5: error: 'MAX_SOCKETS' was not declared in this scope
prog.cpp:7: error: aggregate 'sockaddr_in addr' has incomplete type and cannot be defined
prog.cpp:8: error: 'fd_set' was not declared in this scope
prog.cpp:8: error: expected `;' before 'fdWaitSet'
prog.cpp:10: error: 'WSADATA' was not declared in this scope
prog.cpp:10: error: expected `;' before 'wsd'
prog.cpp:11: error: 'MAKEWORD' was not declared in this scope
prog.cpp:11: error: 'wsd' was not declared in this scope
prog.cpp:11: error: 'WSAStartup' was not declared in this scope
prog.cpp:13: error: 'IDC_STATUSTEXT' was not declared in this scope
prog.cpp:13: error: 'SetDlgItemText' was not declared in this scope
prog.cpp:17: error: 'IDC_STATUSTEXT' was not declared in this scope
prog.cpp:17: error: 'SetDlgItemText' was not declared in this scope
prog.cpp:19: error: 'chStartPort' was not declared in this scope
prog.cpp:20: error: 'atoi' was not declared in this scope
prog.cpp:21: error: 'chEndPort' was not declared in this scope
prog.cpp:24: error: 'chHostName' was not declared in this scope
prog.cpp:26: error: 'NULL' was not declared in this scope
prog.cpp:27: error: 'gethostbyname' was not declared in this scope
prog.cpp:36: error: 'busy' was not declared in this scope
prog.cpp:44: error: 'busy' was not declared in this scope
prog.cpp:46: error: 'sock' was not declared in this scope
prog.cpp:46: error: 'AF_INET' was not declared in this scope
prog.cpp:47: error: 'SOCK_STREAM' was not declared in this scope
prog.cpp:47: error: 'IPPROTO_TCP' was not declared in this scope
prog.cpp:47: error: 'socket' was not declared in this scope
prog.cpp:56: error: 'htons' was not declared in this scope
prog.cpp:57: error: invalid use of incomplete type 'struct hostent'
prog.cpp:26: error: forward declaration of 'struct hostent'
prog.cpp:58: error: invalid use of incomplete type 'struct hostent'
prog.cpp:26: error: forward declaration of 'struct hostent'
prog.cpp:58: error: 'CopyMemory' was not declared in this scope
prog.cpp:60: error: 'ULONG' was not declared in this scope
prog.cpp:60: error: expected `;' before 'ulBlock'
prog.cpp:61: error: 'ulBlock' was not declared in this scope
prog.cpp:62: error: 'FIONBIO' was not declared in this scope
prog.cpp:62: error: 'ioctlsocket' was not declared in this scope
prog.cpp:63: error: 'SOCKET_ERROR' was not declared in this scope
prog.cpp:69: error: 'connect' was not declared in this scope
prog.cpp:70: error: 'WSAGetLastError' was not declared in this scope
prog.cpp:70: error: 'WSAEINPROGRESS' was not declared in this scope
prog.cpp:72: error: 'closesocket' was not declared in this scope
prog.cpp:78: error: 'port' was not declared in this scope
prog.cpp:83: error: 'fdWaitSet' was not declared in this scope
prog.cpp:83: error: 'FD_ZERO' was not declared in this scope
prog.cpp:86: error: 'busy' was not declared in this scope
prog.cpp:87: error: 'sock' was not declared in this scope
prog.cpp:87: error: 'FD_SET' was not declared in this scope
prog.cpp:90: error: aggregate 'timeval tv' has incomplete type and cannot be defined
prog.cpp:94: error: 'select' was not declared in this scope
prog.cpp:94: error: 'SOCKET_ERROR' was not declared in this scope
prog.cpp:102: error: 'busy' was not declared in this scope
prog.cpp:104: error: 'sock' was not declared in this scope
prog.cpp:104: error: 'FD_ISSET' was not declared in this scope
prog.cpp:108: error: 'SOL_SOCKET' was not declared in this scope
prog.cpp:109: error: 'SO_ERROR' was not declared in this scope
prog.cpp:109: error: 'getsockopt' was not declared in this scope
prog.cpp:110: error: 'SOCKET_ERROR' was not declared in this scope
prog.cpp:117: error: 'port' was not declared in this scope
prog.cpp:117: error: 'itoa' was not declared in this scope
prog.cpp:118: error: 'strcat' was not declared in this scope
prog.cpp:119: error: 'htons' was not declared in this scope
prog.cpp:120: error: 'getservbyport' was not declared in this scope
prog.cpp:124: error: invalid use of incomplete type 'struct servent'
prog.cpp:116: error: forward declaration of 'struct servent'
prog.cpp:127: error: 'm_PortList' was not declared in this scope
prog.cpp:129: error: 'SD_BOTH' was not declared in this scope
prog.cpp:129: error: 'shutdown' was not declared in this scope
prog.cpp:130: error: 'closesocket' was not declared in this scope
prog.cpp:133: error: 'SD_BOTH' was not declared in this scope
prog.cpp:133: error: 'shutdown' was not declared in this scope
prog.cpp:134: error: 'closesocket' was not declared in this scope
prog.cpp:140: error: 'closesocket' was not declared in this scope
prog.cpp:145: error: 'ProcessMessages' was not declared in this scope
prog.cpp:147: error: 'WSACleanup' was not declared in this scope
stdout
Standard output is empty