void tcp_connect(struct socket *inso)

{

    Slirp *slirp = inso->slirp;

    struct socket *so;

    struct sockaddr_in addr;

    socklen_t addrlen = sizeof(struct sockaddr_in);

    struct tcpcb *tp;

    int s, opt;



    DEBUG_CALL("tcp_connect");

    DEBUG_ARG("inso = %p", inso);



    /*

     * If it's an SS_ACCEPTONCE socket, no need to socreate()

     * another socket, just use the accept() socket.

     */

    if (inso->so_state & SS_FACCEPTONCE) {

        /* FACCEPTONCE already have a tcpcb */

        so = inso;

    } else {

        so = socreate(slirp);

        if (so == NULL) {

            /* If it failed, get rid of the pending connection */

            closesocket(accept(inso->s, (struct sockaddr *)&addr, &addrlen));

            return;

        }

        if (tcp_attach(so) < 0) {

            free(so); /* NOT sofree */

            return;

        }

        so->so_lfamily = AF_INET;

        so->so_laddr = inso->so_laddr;

        so->so_lport = inso->so_lport;

    }



    tcp_mss(sototcpcb(so), 0);



    s = accept(inso->s, (struct sockaddr *)&addr, &addrlen);

    if (s < 0) {

        tcp_close(sototcpcb(so)); /* This will sofree() as well */

        return;

    }

    qemu_set_nonblock(s);

    socket_set_fast_reuse(s);

    opt = 1;

    qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));

    socket_set_nodelay(s);



    so->so_ffamily = AF_INET;

    so->so_fport = addr.sin_port;

    so->so_faddr = addr.sin_addr;

    /* Translate connections from localhost to the real hostname */

    if (so->so_faddr.s_addr == 0 ||

        (so->so_faddr.s_addr & loopback_mask) ==

        (loopback_addr.s_addr & loopback_mask)) {

        so->so_faddr = slirp->vhost_addr;

    }



    /* Close the accept() socket, set right state */

    if (inso->so_state & SS_FACCEPTONCE) {

        /* If we only accept once, close the accept() socket */

        closesocket(so->s);



        /* Don't select it yet, even though we have an FD */

        /* if it's not FACCEPTONCE, it's already NOFDREF */

        so->so_state = SS_NOFDREF;

    }

    so->s = s;

    so->so_state |= SS_INCOMING;



    so->so_iptos = tcp_tos(so);

    tp = sototcpcb(so);



    tcp_template(tp);



    tp->t_state = TCPS_SYN_SENT;

    tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;

    tp->iss = slirp->tcp_iss;

    slirp->tcp_iss += TCP_ISSINCR/2;

    tcp_sendseqinit(tp);

    tcp_output(tp);

}

void tcp_connect(struct socket *inso)

{

    Slirp *slirp = inso->slirp;

    struct socket *so;

    struct sockaddr_in addr;

    socklen_t addrlen = sizeof(struct sockaddr_in);

    struct tcpcb *tp;

    int s, opt;



    DEBUG_CALL("tcp_connect");

    DEBUG_ARG("inso = %p", inso);



    







    if (inso->so_state & SS_FACCEPTONCE) {

        

        so = inso;

    } else {

        so = socreate(slirp);

        if (so == NULL) {

            

            closesocket(accept(inso->s, (struct sockaddr *)&addr, &addrlen));

            return;

        }

        if (tcp_attach(so) < 0) {

            free(so); 

            return;

        }

        so->so_lfamily = AF_INET;

        so->so_laddr = inso->so_laddr;

        so->so_lport = inso->so_lport;

    }



    tcp_mss(sototcpcb(so), 0);



    s = accept(inso->s, (struct sockaddr *)&addr, &addrlen);

    if (s < 0) {

        tcp_close(sototcpcb(so)); 

        return;

    }

    qemu_set_nonblock(s);

    socket_set_fast_reuse(s);

    opt = 1;

    qemu_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));

    socket_set_nodelay(s);



    so->so_ffamily = AF_INET;

    so->so_fport = addr.sin_port;

    so->so_faddr = addr.sin_addr;

    

    if (so->so_faddr.s_addr == 0 ||

        (so->so_faddr.s_addr & loopback_mask) ==

        (loopback_addr.s_addr & loopback_mask)) {

        so->so_faddr = slirp->vhost_addr;

    }



    

    if (inso->so_state & SS_FACCEPTONCE) {

        

        closesocket(so->s);



        

        

        so->so_state = SS_NOFDREF;

    }

    so->s = s;

    so->so_state |= SS_INCOMING;



    so->so_iptos = tcp_tos(so);

    tp = sototcpcb(so);



    tcp_template(tp);



    tp->t_state = TCPS_SYN_SENT;

    tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;

    tp->iss = slirp->tcp_iss;

    slirp->tcp_iss += TCP_ISSINCR/2;

    tcp_sendseqinit(tp);

    tcp_output(tp);

}

void FUNC_0(struct socket *VAR_0)

{

    Slirp *slirp = VAR_0->slirp;

    struct socket *VAR_1;

    struct sockaddr_in VAR_2;

    socklen_t addrlen = sizeof(struct sockaddr_in);

    struct tcpcb *VAR_3;

    int VAR_4, VAR_5;



    DEBUG_CALL("FUNC_0");

    DEBUG_ARG("VAR_0 = %p", VAR_0);



    







    if (VAR_0->so_state & SS_FACCEPTONCE) {

        

        VAR_1 = VAR_0;

    } else {

        VAR_1 = socreate(slirp);

        if (VAR_1 == NULL) {

            

            closesocket(accept(VAR_0->VAR_4, (struct sockaddr *)&VAR_2, &addrlen));

            return;

        }

        if (tcp_attach(VAR_1) < 0) {

            free(VAR_1); 

            return;

        }

        VAR_1->so_lfamily = AF_INET;

        VAR_1->so_laddr = VAR_0->so_laddr;

        VAR_1->so_lport = VAR_0->so_lport;

    }



    tcp_mss(sototcpcb(VAR_1), 0);



    VAR_4 = accept(VAR_0->VAR_4, (struct sockaddr *)&VAR_2, &addrlen);

    if (VAR_4 < 0) {

        tcp_close(sototcpcb(VAR_1)); 

        return;

    }

    qemu_set_nonblock(VAR_4);

    socket_set_fast_reuse(VAR_4);

    VAR_5 = 1;

    qemu_setsockopt(VAR_4, SOL_SOCKET, SO_OOBINLINE, &VAR_5, sizeof(int));

    socket_set_nodelay(VAR_4);



    VAR_1->so_ffamily = AF_INET;

    VAR_1->so_fport = VAR_2.sin_port;

    VAR_1->so_faddr = VAR_2.sin_addr;

    

    if (VAR_1->so_faddr.s_addr == 0 ||

        (VAR_1->so_faddr.s_addr & loopback_mask) ==

        (loopback_addr.s_addr & loopback_mask)) {

        VAR_1->so_faddr = slirp->vhost_addr;

    }



    

    if (VAR_0->so_state & SS_FACCEPTONCE) {

        

        closesocket(VAR_1->VAR_4);



        

        

        VAR_1->so_state = SS_NOFDREF;

    }

    VAR_1->VAR_4 = VAR_4;

    VAR_1->so_state |= SS_INCOMING;



    VAR_1->so_iptos = tcp_tos(VAR_1);

    VAR_3 = sototcpcb(VAR_1);



    tcp_template(VAR_3);



    VAR_3->t_state = TCPS_SYN_SENT;

    VAR_3->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;

    VAR_3->iss = slirp->tcp_iss;

    slirp->tcp_iss += TCP_ISSINCR/2;

    tcp_sendseqinit(VAR_3);

    tcp_output(VAR_3);

}

void FUNC_0(struct socket *VAR_0)
{ Slirp *slirp = VAR_0->slirp; struct socket *VAR_1; struct sockaddr_in VAR_2; socklen_t addrlen = sizeof(struct sockaddr_in); struct tcpcb *VAR_3; int VAR_4, VAR_5; DEBUG_CALL("FUNC_0"); DEBUG_ARG("VAR_0 = %p", VAR_0); if (VAR_0->so_state & SS_FACCEPTONCE) { VAR_1 = VAR_0; } else { VAR_1 = socreate(slirp); if (VAR_1 == NULL) { closesocket(accept(VAR_0->VAR_4, (struct sockaddr *)&VAR_2, &addrlen)); return; } if (tcp_attach(VAR_1) < 0) { free(VAR_1); return; } VAR_1->so_lfamily = AF_INET; VAR_1->so_laddr = VAR_0->so_laddr; VAR_1->so_lport = VAR_0->so_lport; } tcp_mss(sototcpcb(VAR_1), 0); VAR_4 = accept(VAR_0->VAR_4, (struct sockaddr *)&VAR_2, &addrlen); if (VAR_4 < 0) { tcp_close(sototcpcb(VAR_1)); return; } qemu_set_nonblock(VAR_4); socket_set_fast_reuse(VAR_4); VAR_5 = 1; qemu_setsockopt(VAR_4, SOL_SOCKET, SO_OOBINLINE, &VAR_5, sizeof(int)); socket_set_nodelay(VAR_4); VAR_1->so_ffamily = AF_INET; VAR_1->so_fport = VAR_2.sin_port; VAR_1->so_faddr = VAR_2.sin_addr; if (VAR_1->so_faddr.s_addr == 0 ||
(VAR_1->so_faddr.s_addr & loopback_mask) ==
(loopback_addr.s_addr & loopback_mask)) { VAR_1->so_faddr = slirp->vhost_addr; } if (VAR_0->so_state & SS_FACCEPTONCE) { closesocket(VAR_1->VAR_4); VAR_1->so_state = SS_NOFDREF; } VAR_1->VAR_4 = VAR_4; VAR_1->so_state |= SS_INCOMING; VAR_1->so_iptos = tcp_tos(VAR_1); VAR_3 = sototcpcb(VAR_1); tcp_template(VAR_3); VAR_3->t_state = TCPS_SYN_SENT; VAR_3->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; VAR_3->iss = slirp->tcp_iss; slirp->tcp_iss += TCP_ISSINCR/2; tcp_sendseqinit(VAR_3); tcp_output(VAR_3); }