I have a problem binding the socket. There is no error as such, not sure why if fails on if condition.
int result = WSAStartup(MAKEWORD(2,2), &wsadata);
if(result != NO_ERROR)
{
printf("\nThere is a problem at WSAStartup");
}
else
{
printf("\nWSAStartup was ok");
}
list_sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
if(list_sock == -1)
{
printf("\n Socket not created %d\n", list_sock);
}
else
{
printf("\nSocket was created Succesfully");
}
HOSTENT *thishost;
char *ip;
u_short port;
port = 55555;
thishost = gethostbyname("localhost");
printf("\n");
printf("\nHost name is:%s ",thishost->h_name);
ip = inet_ntoa(*(struct in_addr*)*thishost->h_addr_list);
printf("\nip address is %s\n ", ip);
printf("Address type is:%i",thishost->h_addrtype);
service.sin_family = AF_INET;
service.sin_addr.s_addr = inet_addr(ip);
service.sin_port = htons(port);
if(bind(list_sock,(SOCKADDR *)&service,sizeof(service))== SOCKET_ERROR)
{
printf("Error during bind %s", strerror(errno));
}
else
{
printf("All done");
}
WSACleanup();
return 0;
I get error at line
if(bind(list_sock,(SOCKADDR *)&service,sizeof(service))== SOCKET_ERROR)
But strerror(errno))
gives me: "No error". But it still fails on if condition and does not bind.
Any help?