B
Basilevs
Необходимо написать программу, выводящую информацию о хосте. Пишу на C++ в MVS 2005. Возникают ошибки
fatal error LNK112Error
error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function _main HostInfo.obj
...... и так далее в том же духе!
Помогите исправить причину! Заранее спасибо!
Вот код:
#include <stdio.h>
#include <winsock2.h>
int main(int argc, char* argv[])
{
WORD wVersionRequested;
wVersionRequested = MAKEWORD(2, 0);
WSADATA wsa;
if(WSAStartup(wVersionRequested, &wsa))
{
printf("Startup failed\n");
WSACleanup();
return 1;
};
printf("Winsocks initialized\n");
hostent* host;
char* hostName;
unsigned int address;
printf("Input name of host:\n");
hostName = (char*) malloc((sizeof(char*)) * 16);
fgets(hostName, 16, stdin);
if(isalpha(hostName[0]))
{
hostName[strlen(hostName)-1]='\0"';
host = gethostbyname(hostName);
}
else
{
address = inet_addr(hostName);
host = gethostbyaddr((char*) address, 4, AF_INET);
}
if (WSAGetLastError() != 0)
{
if (WSAGetLastError() == 11001)
{
printf("Host not found...\nExiting.\n");
}
else
{
printf("error#:%ld\n", WSAGetLastError());
}
return 1;
}
char * str;
int i = 0;
str = host->h_aliases;
printf("\n");
return 0;
}
fatal error LNK112Error
error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function _main HostInfo.obj
...... и так далее в том же духе!
Помогите исправить причину! Заранее спасибо!
Вот код:
#include <stdio.h>
#include <winsock2.h>
int main(int argc, char* argv[])
{
WORD wVersionRequested;
wVersionRequested = MAKEWORD(2, 0);
WSADATA wsa;
if(WSAStartup(wVersionRequested, &wsa))
{
printf("Startup failed\n");
WSACleanup();
return 1;
};
printf("Winsocks initialized\n");
hostent* host;
char* hostName;
unsigned int address;
printf("Input name of host:\n");
hostName = (char*) malloc((sizeof(char*)) * 16);
fgets(hostName, 16, stdin);
if(isalpha(hostName[0]))
{
hostName[strlen(hostName)-1]='\0"';
host = gethostbyname(hostName);
}
else
{
address = inet_addr(hostName);
host = gethostbyaddr((char*) address, 4, AF_INET);
}
if (WSAGetLastError() != 0)
{
if (WSAGetLastError() == 11001)
{
printf("Host not found...\nExiting.\n");
}
else
{
printf("error#:%ld\n", WSAGetLastError());
}
return 1;
}
char * str;
int i = 0;
str = host->h_aliases;
printf("\n");
return 0;
}