a.sin_addr.s_addr = htonl(addr->address); a.sin_port = htons((short)port); if (connect (s, (struct sockaddr *)&a, sizeof(a)) == SOCKET_ERROR) {
Socket sk_new(SockAddr addr, int port, sk_receiver_t receiver) {    SOCKET s;    SOCKADDR_IN a;    DWORD err;    char *errstr;    Socket ret;    extern char *do_select(SOCKET skt, int startup);    /*     * Create Socket structure.     */    ret = smalloc(sizeof(struct Socket_tag));    ret->error = NULL;    ret->receiver = receiver;    ret->head = ret->tail = NULL;    ret->writable = 1;		       /* to start with */    ret->in_oob = FALSE;    ret->sending_oob = 0;    /*     * Open socket.     */    s = socket(AF_INET, SOCK_STREAM, 0);    ret->s = s;    if (s == INVALID_SOCKET) {	err = WSAGetLastError();        ret->error = winsock_error_string(err);	return ret;    }    /*     * Bind to local address.     */    a.sin_family = AF_INET;    a.sin_addr.s_addr = htonl(INADDR_ANY);    a.sin_port = htons(0);    if (bind (s, (struct sockaddr *)&a, sizeof(a)) == SOCKET_ERROR) {	err = WSAGetLastError();        ret->error = winsock_error_string(err);	return ret;    }    /*     * Connect to remote address.     */    a.sin_addr.s_addr = htonl(addr->address);    a.sin_port = htons((short)port);    if (connect (s, (struct sockaddr *)&a, sizeof(a)) == SOCKET_ERROR) {	err = WSAGetLastError();        ret->error = winsock_error_string(err);	return ret;    }    /* Set up a select mechanism. This could be an AsyncSelect on a     * window, or an EventSelect on an event object. */    errstr = do_select(s, 1);    if (errstr) {	ret->error = errstr;	return ret;    }    add234(sktree, ret);    return ret;}