So I am really stuck here, just trying to make a simple C program that gets the content of a webpage into a buffer, but I’m having some problems; consider the following:
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if(err != 0)
{
printf("could not find a usable winsock.dll");
return NULL;
}
if(LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2)
{
printf("could not find a usable winsock.dll");
WSACleanup();
return NULL;
}
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
struct sockaddr_in sa = { 0 };
sa.sin_port = htons(port);
sa.sin_addr.s_addr = inet_addr(ip);
connect(sock, (struct sockaddr*)&sa, sizeof(sa));
The variables ip, and port, are passed through from main. as you can see here:
readsite("http://www.pagetutor.com/html_tutor/index.html", "68.71.137.60", 80);
I get the error code “10047” from executing printf("\n%d", GetLastError()); directly below the line connect(sock, (struct sockaddr*)&sa, sizeof(sa)); and this code according to microsoft means “Addresses in the specified family cannot be used with this socket” so I am completely at a lost on what to do from here.
You didn’t set
sin_familyso it’s set toAF_UNSPEC(since you 0-initializedsa). Before connecting, try: