I am using the following source code to connect to a domain. However, at runtime the printf error trap reveals that connection fails. What is so wrong?
Code:
#include <winsock2.h>
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")
int main(){
WSADATA wsa;
SOCKET sock;
struct sockaddr_in info;
char buffer[1024];
char *hostname="www.domain.com";
if(WSAStartup(MAKEWORD(2,2), &wsa)==-1) return 0;
if(gethostbyname(hostname)==NULL) return 0;
info.sin_addr.s_addr=*(LPDWORD)gethostbyname((char *)hostname)->h_addr_list[0];
info.sin_port=htons(6667);
info.sin_family=AF_INET;
memset(info.sin_zero, 0, 8);
if(sock=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)==-1) return 0;
if (connect(sock, (struct sockaddr *)&info, sizeof(info))==-1){
printf("dfswefw");
getchar();}