Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make an network-ip scan in c++?
    primarykey
    data
    text
    <p>I am experimenting with C++ winsockets. I want to create a method with which I can find the server on the network, without knowing it's IP. To do this I simply loop my connect method through IP adresses 192.168.1.0 to 192.168.1.255. However, the time between each connect is quite large, the program tends to wait at the: connect(nBytes, (sockaddr*)&amp;server, sizeof(server)) statement for at least 30 seconds if not longer. My questions are the following: Why is this happening, how can I solve this and might there be an entirely different, better way to find the server?</p> <p>my connect method:</p> <pre><code>SOCKET connect(char *ipAdress) { WSAData wsaData; if ((WSAStartup(MAKEWORD(2, 2), &amp;wsaData)) == SOCKET_ERROR) return errorReport("Could not create startup struct"); nBytes = socket(AF_INET, SOCK_STREAM, 0); if (nBytes == SOCKET_ERROR) return errorReport("Socket could not be created"); struct hostent *host_entry; if ((host_entry = gethostbyname(ipAdress)) == NULL) return errorReport("Cannot find server."); struct sockaddr_in server; server.sin_family = AF_INET; server.sin_port = htons(1337); server.sin_addr.s_addr = *(unsigned long*) host_entry-&gt;h_addr; if (connect(nBytes, (sockaddr*)&amp;server, sizeof(server)) == SOCKET_ERROR) { WSACleanup(); return errorReport("Failed to connect to server."); } if (nBytes == -1) { WSACleanup(); disconnect(nBytes); return errorReport("Could not connect"); } return 0; } </code></pre> <p>Also, feel free to tell me anything I'm doing wrong in the current connect method.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload