WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 0 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
/* Tell the user that we couldn't find a usable */
/* WinSock DLL. */
return NULL;
}
/* Confirm that the WinSock DLL supports 2.0.*/
/* Note that if the DLL supports versions greater */
/* than 2.0 in addition to 2.0, it will still return */
/* 2.0 in wVersion since that is the version we */
/* requested. */
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 0 )
{
/* Tell the user that we couldn't find a usable */
/* WinSock DLL. */
WSACleanup( );
return NULL;
}
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
MessageBox(NULL, "Wrong WinSock Version.", "Error", MB_OK);
return;
}
const int iChkIpTimes = 26;
int localIPnums = 0;
char hostName[80];
LPHOSTENT lpHostEnt;
struct in_addr addr[iChkIpTimes];
for ( int i=0; i<iChkIpTimes; i++)
{
memset(&addr[i], 0, sizeof(in_addr));
}
for ( int i=0; i<localIPnums; i++)
{
cout << "Local IP Address " << i << " : " << inet_ntoa(addr[i]) << endl;
}
if ( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 )
{
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
WSACleanup();
return;
}
}