   Winsock 2.2 bind error
  I'm getting an error when using bind with winsock 2.2, WSAEAFNOSUPPORT. Quote: MSDN WSAEAFNOSUPPORT error explanationProtocol family not supported.    The protocol family has not been configured into the system or no implementation for it exists. This message has a slightly different meaning from WSAEAFNOSUPPORT. However, it is interchangeable in most cases, and all Windows Sockets functions that return one of these messages also specify WSAEAFNOSUPPORT.Here's my code:unsigned short PORT = 2195;int handle_error();int SendFile(char *filename, char *target_directory){    unsigned char *packet_buffer = (unsigned char*)malloc(5000);    WSADATA wsaData;    SOCKET sock;    sockaddr_in HostAddr;    sockaddr_in ClientAddr;    if(packet_buffer==NULL)    {   printf("Error: Failed to allocate memory.\n");   free(packet_buffer);   return 1;    }    memset(packet_buffer, 0, 5000);    memset(&HostAddr, 0, sizeof(sockaddr_in));    memset(&ClientAddr, 0, sizeof(sockaddr_in));    printf("File that will be sent is %s, target directory is %s\n", filename, target_directory);    WORD wVersionRequested = MAKEWORD( 2, 2 );    if (WSAStartup(wVersionRequested, &wsaData ) != 0)    {   free(packet_buffer);   return handle_error();    }    if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET)   return handle_error();    HostAddr.sin_family = IPPROTO_TCP;    HostAddr.sin_port = htons(PORT);    HostAddr.sin_addr.s_addr = htonl (INADDR_ANY);//I tried this, my IP address for Internet and local network, but all of these failed.    //HostAddr.sin_addr.S_un.S_un_b.s_b1 = xx; //  192    //HostAddr.sin_addr.S_un.S_un_b.s_b2 = xx; //  168    //HostAddr.sin_addr.S_un.S_un_b.s_b3 = xxx;//  0    //HostAddr.sin_addr.S_un.S_un_b.s_b1 = xxx;//  1    if (bind(sock, (sockaddr*)&HostAddr, sizeof(sockaddr_in)) == SOCKET_ERROR)    {   printf("Attempt to bind failed:\n");   free(packet_buffer);   handle_error();   return 1;    }    listen(sock, 1);    printf("Waiting for connection...\n");    SOCKET TempSock = SOCKET_ERROR;    while (TempSock == SOCKET_ERROR)    {   TempSock = accept(sock, NULL, NULL);    }    sock = TempSock;    int *clientaddrsz = (int*)malloc(sizeof(int));    *clientaddrsz = (int)sizeof(ClientAddr);    accept(sock, (sockaddr*)&ClientAddr, clientaddrsz);    printf("Got connection from %d.%d.%d.%d\n",    (int)ClientAddr.sin_addr.S_un.S_un_b.s_b1,    (int)ClientAddr.sin_addr.S_un.S_un_b.s_b2,    (int)ClientAddr.sin_addr.S_un.S_un_b.s_b3,    (int)ClientAddr.sin_addr.S_un.S_un_b.s_b1);    free(packet_buffer);    WSACleanup();    return 0;}
Quote:HostAddr.sin_family = IPPROTO_TCP;That should be AF_INET (or PF_INET, depending on your headers). The error says exactly what the problem is -- the address family value in the address struct is not supported.;  Thanks, changing that fixed my problem.   