int tcp_fconnect(struct socket *so)

{

  Slirp *slirp = so->slirp;

  int ret=0;



  DEBUG_CALL("tcp_fconnect");

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



  if( (ret = so->s = qemu_socket(AF_INET,SOCK_STREAM,0)) >= 0) {

    int opt, s=so->s;

    struct sockaddr_in addr;



    qemu_set_nonblock(s);

    socket_set_fast_reuse(s);

    opt = 1;

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



    addr.sin_family = AF_INET;

    if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) ==

        slirp->vnetwork_addr.s_addr) {

      

      if (so->so_faddr.s_addr == slirp->vnameserver_addr.s_addr) {

	if (get_dns_addr(&addr.sin_addr) < 0)

	  addr.sin_addr = loopback_addr;

      } else {

	addr.sin_addr = loopback_addr;

      }

    } else

      addr.sin_addr = so->so_faddr;

    addr.sin_port = so->so_fport;



    DEBUG_MISC((dfd, " connect()ing, addr.sin_port=%d, "

		"addr.sin_addr.s_addr=%.16s\n",

		ntohs(addr.sin_port), inet_ntoa(addr.sin_addr)));

    

    ret = connect(s,(struct sockaddr *)&addr,sizeof (addr));



    







    soisfconnecting(so);

  }



  return(ret);

}
