static int net_socket_connect_init(VLANState *vlan,

                                   const char *model,

                                   const char *name,

                                   const char *host_str)

{

    NetSocketState *s;

    int fd, connected, ret, err;

    struct sockaddr_in saddr;



    if (parse_host_port(&saddr, host_str) < 0)

        return -1;



    fd = socket(PF_INET, SOCK_STREAM, 0);

    if (fd < 0) {

        perror("socket");

        return -1;

    }

    socket_set_nonblock(fd);



    connected = 0;

    for(;;) {

        ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));

        if (ret < 0) {

            err = socket_error();

            if (err == EINTR || err == EWOULDBLOCK) {

            } else if (err == EINPROGRESS) {

                break;

#ifdef _WIN32

            } else if (err == WSAEALREADY) {

                break;

#endif

            } else {

                perror("connect");

                closesocket(fd);

                return -1;

            }

        } else {

            connected = 1;

            break;

        }

    }

    s = net_socket_fd_init(vlan, model, name, fd, connected);

    if (!s)

        return -1;

    snprintf(s->nc.info_str, sizeof(s->nc.info_str),

             "socket: connect to %s:%d",

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

    return 0;

}

static int net_socket_connect_init(VLANState *vlan,

                                   const char *model,

                                   const char *name,

                                   const char *host_str)

{

    NetSocketState *s;

    int fd, connected, ret, err;

    struct sockaddr_in saddr;



    if (parse_host_port(&saddr, host_str) < 0)

        return -1;



    fd = socket(PF_INET, SOCK_STREAM, 0);

    if (fd < 0) {

        perror("socket");

        return -1;

    }

    socket_set_nonblock(fd);



    connected = 0;

    for(;;) {

        ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));

        if (ret < 0) {

            err = socket_error();

            if (err == EINTR || err == EWOULDBLOCK) {

            } else if (err == EINPROGRESS) {

                break;

#ifdef _WIN32

            } else if (err == WSAEALREADY) {

                break;

#endif

            } else {

                perror("connect");

                closesocket(fd);

                return -1;

            }

        } else {

            connected = 1;

            break;

        }

    }

    s = net_socket_fd_init(vlan, model, name, fd, connected);

    if (!s)

        return -1;

    snprintf(s->nc.info_str, sizeof(s->nc.info_str),

             "socket: connect to %s:%d",

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

    return 0;

}

    fd = socket(PF_INET, SOCK_STREAM, 0);     fd = socket(PF_INET, SOCK_STREAM, 0);
static int FUNC_0(VLANState *VAR_0,

                                   const char *VAR_1,

                                   const char *VAR_2,

                                   const char *VAR_3)

{

    NetSocketState *s;

    int VAR_4, VAR_5, VAR_6, VAR_7;

    struct sockaddr_in VAR_8;



    if (parse_host_port(&VAR_8, VAR_3) < 0)

        return -1;



    VAR_4 = socket(PF_INET, SOCK_STREAM, 0);

    if (VAR_4 < 0) {

        perror("socket");

        return -1;

    }

    socket_set_nonblock(VAR_4);



    VAR_5 = 0;

    for(;;) {

        VAR_6 = connect(VAR_4, (struct sockaddr *)&VAR_8, sizeof(VAR_8));

        if (VAR_6 < 0) {

            VAR_7 = socket_error();

            if (VAR_7 == EINTR || VAR_7 == EWOULDBLOCK) {

            } else if (VAR_7 == EINPROGRESS) {

                break;

#ifdef _WIN32

            } else if (VAR_7 == WSAEALREADY) {

                break;

#endif

            } else {

                perror("connect");

                closesocket(VAR_4);

                return -1;

            }

        } else {

            VAR_5 = 1;

            break;

        }

    }

    s = net_socket_fd_init(VAR_0, VAR_1, VAR_2, VAR_4, VAR_5);

    if (!s)

        return -1;

    snprintf(s->nc.info_str, sizeof(s->nc.info_str),

             "socket: connect to %s:%d",

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

    return 0;

}

static int FUNC_0(VLANState *VAR_0,
const char *VAR_1,
const char *VAR_2,
const char *VAR_3)
{ NetSocketState *s; int VAR_4, VAR_5, VAR_6, VAR_7; struct sockaddr_in VAR_8; if (parse_host_port(&VAR_8, VAR_3) < 0)
return -1; VAR_4 = socket(PF_INET, SOCK_STREAM, 0); if (VAR_4 < 0) { perror("socket"); return -1; } socket_set_nonblock(VAR_4); VAR_5 = 0; for(;;) { VAR_6 = connect(VAR_4, (struct sockaddr *)&VAR_8, sizeof(VAR_8)); if (VAR_6 < 0) { VAR_7 = socket_error(); if (VAR_7 == EINTR || VAR_7 == EWOULDBLOCK) { } else if (VAR_7 == EINPROGRESS) { break; #ifdef _WIN32
} else if (VAR_7 == WSAEALREADY) { break; #endif
} else { perror("connect"); closesocket(VAR_4); return -1; } } else { VAR_5 = 1; break; } } s = net_socket_fd_init(VAR_0, VAR_1, VAR_2, VAR_4, VAR_5); if (!s)
return -1; snprintf(s->nc.info_str, sizeof(s->nc.info_str),
"socket: connect to %s:%d",
inet_ntoa(VAR_8.sin_addr), ntohs(VAR_8.sin_port)); return 0; }