C++ Compiling problems
I wrote this code (which is based off of the tutorial on port scanners) today, which is supposed to be a simple port scanner. (don't try to correct anything that i may have messed up… unless it contributes to the compiling problem). I have yet to be able to compile it. I keep getting a build error, but it wont tell me what the error is. While the file linking was turned on I got the error(s):[Linker Error] undefined reference to "WSAStartup@8" and it gave me like 6 of these for different winsock functions. I suppose that this has something to do with the build error as well. Anyway im using Bloodshed DEV-CPP. Never had this kind of problem with it before. Anyway here is the code:
#include <winsock.h>
#include <windows.h>
using namespace std;
int main()
{
SetConsoleTitle("Port Scanner" );
char ip[MAX_PATH];
cout << "Enter IP Address: ";
cin >> ip;
cout << endl;
SOCKET mysocket;
WSAData wsaData;
mysocket = WSAStartup (MAKEWORD(1,1),&wsaData);
if(mysocket == SOCKET_ERROR)
{
cout << "Socket Error...\n";
}else{
mysocket = socket (AF_INET, SOCK_STREAM, 0);
int x;
for(x=1; x<6000; x++)
{
SOCKADDR_IN server;
server.sin_port = htons(x);
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(ip);
connect(mysocket,(SOCKADDR*)(&server),sizeof(&server));
if(mysocket == SOCKET_ERROR)
{
cout << x << "\t Closed\n";
}else{
cout << x << "\t Open\n";
}
}
closesocket(mysocket);
WSACleanup();
}
}; ```
thanks for any help.
right, click the new project button, and label it as an empty project, name it whatever you like. then right click on the name of it in the box on the right and click add to project, and add a file containing this code to the project
then click project at the top menu bar, then project options, then parameters, then click "add library or object" and browse to dev-cpp/lib/wsock32.a