Simple Winsock Code using DevCPP
I just need a little help before getting deep into network programming.. I am attempting to make what is nothing more than a "hello world" of winsock api by playing with a couple of functions.
The first problem is that I cannot get my code to compile using either the <winsock.h> or <winsock2.h> header. I have attached a pic of all compiler errors. I have browsed the, "include" folder located in DevCPP and have located both the winsock.h and winsock2.h header files. Compiler options are at default settings and provide paths to the devcpp 'include' folder.
There may be additional errors.. I am kinda new at winsock api and may have made a few syntactical mistakes.
Please help if ye' can.
Code:
#include<iostream>
#include<winsock2.h>
using namespace std;
int main()
{
WSADATA wsd;
WSAPROTOCOL_INFO *proto;
LPDWORD bufferlength = NULL;
WSAStartup(MAKEWORD(2,2), &wsd);
cout << "\n\nUsing winsock version " << wsd.wVersion;
//This call will fail, but will return the correct buffer size
WSAEnumProtocols(NULL, NULL, bufferlength);
//Allocate the correct buffer size of WSAPROTOCOL_INFO structures
proto = new WSAPROTOCOL_INFO[*bufferlength];
//Populate an array of system protocols
WSAEnumProtocols(NULL, proto, bufferlength);
//Step through the array and view some system supported protocol information
for(int i=0; i<*bufferlength; i++)
{
cout << "\n\n\nVersion: " << proto[i].iVersion;
cout << "\nAddress Family: " << proto[i].iAddressFamily;
cout << "\nMax Sockets: " << proto[i].iMaxSockAddr;
cout << "\nMin Sockets: " << proto[i].iMinSockAddr;
cout << "\nProtocol: " << proto[i].szProtocol;
}
WSACleanup();
return 0;
}
Thanx!!! It helped me a lot.
I read whole thread, It was helpful, Thanx again.