int inet_dgram_opts(QemuOpts *opts, Error **errp)

{

    struct addrinfo ai, *peer = NULL, *local = NULL;

    const char *addr;

    const char *port;

    int sock = -1, rc;



    /* lookup peer addr */

    memset(&ai,0, sizeof(ai));

    ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;

    ai.ai_family = PF_UNSPEC;

    ai.ai_socktype = SOCK_DGRAM;



    addr = qemu_opt_get(opts, "host");

    port = qemu_opt_get(opts, "port");

    if (addr == NULL || strlen(addr) == 0) {

        addr = "localhost";

    }

    if (port == NULL || strlen(port) == 0) {

        error_setg(errp, "remote port not specified");

        return -1;

    }



    if (qemu_opt_get_bool(opts, "ipv4", 0))

        ai.ai_family = PF_INET;

    if (qemu_opt_get_bool(opts, "ipv6", 0))

        ai.ai_family = PF_INET6;



    if (0 != (rc = getaddrinfo(addr, port, &ai, &peer))) {

        error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,

                   gai_strerror(rc));

	return -1;

    }



    /* lookup local addr */

    memset(&ai,0, sizeof(ai));

    ai.ai_flags = AI_PASSIVE;

    ai.ai_family = peer->ai_family;

    ai.ai_socktype = SOCK_DGRAM;



    addr = qemu_opt_get(opts, "localaddr");

    port = qemu_opt_get(opts, "localport");

    if (addr == NULL || strlen(addr) == 0) {

        addr = NULL;

    }

    if (!port || strlen(port) == 0)

        port = "0";



    if (0 != (rc = getaddrinfo(addr, port, &ai, &local))) {

        error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,

                   gai_strerror(rc));

        goto err;

    }



    /* create socket */

    sock = qemu_socket(peer->ai_family, peer->ai_socktype, peer->ai_protocol);

    if (sock < 0) {

        error_setg_errno(errp, errno, "Failed to create socket");

        goto err;

    }

    socket_set_fast_reuse(sock);



    /* bind socket */

    if (bind(sock, local->ai_addr, local->ai_addrlen) < 0) {

        error_setg_errno(errp, errno, "Failed to bind socket");

        goto err;

    }



    /* connect to peer */

    if (connect(sock,peer->ai_addr,peer->ai_addrlen) < 0) {

        error_setg_errno(errp, errno, "Failed to connect socket");

        goto err;

    }



    freeaddrinfo(local);

    freeaddrinfo(peer);

    return sock;



err:

    if (-1 != sock)

        closesocket(sock);

    if (local)

        freeaddrinfo(local);

    if (peer)

        freeaddrinfo(peer);

    return -1;

}

int inet_dgram_opts(QemuOpts *opts, Error **errp)

{

    struct addrinfo ai, *peer = NULL, *local = NULL;

    const char *addr;

    const char *port;

    int sock = -1, rc;



    

    memset(&ai,0, sizeof(ai));

    ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;

    ai.ai_family = PF_UNSPEC;

    ai.ai_socktype = SOCK_DGRAM;



    addr = qemu_opt_get(opts, "host");

    port = qemu_opt_get(opts, "port");

    if (addr == NULL || strlen(addr) == 0) {

        addr = "localhost";

    }

    if (port == NULL || strlen(port) == 0) {

        error_setg(errp, "remote port not specified");

        return -1;

    }



    if (qemu_opt_get_bool(opts, "ipv4", 0))

        ai.ai_family = PF_INET;

    if (qemu_opt_get_bool(opts, "ipv6", 0))

        ai.ai_family = PF_INET6;



    if (0 != (rc = getaddrinfo(addr, port, &ai, &peer))) {

        error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,

                   gai_strerror(rc));

	return -1;

    }



    

    memset(&ai,0, sizeof(ai));

    ai.ai_flags = AI_PASSIVE;

    ai.ai_family = peer->ai_family;

    ai.ai_socktype = SOCK_DGRAM;



    addr = qemu_opt_get(opts, "localaddr");

    port = qemu_opt_get(opts, "localport");

    if (addr == NULL || strlen(addr) == 0) {

        addr = NULL;

    }

    if (!port || strlen(port) == 0)

        port = "0";



    if (0 != (rc = getaddrinfo(addr, port, &ai, &local))) {

        error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,

                   gai_strerror(rc));

        goto err;

    }



    

    sock = qemu_socket(peer->ai_family, peer->ai_socktype, peer->ai_protocol);

    if (sock < 0) {

        error_setg_errno(errp, errno, "Failed to create socket");

        goto err;

    }

    socket_set_fast_reuse(sock);



    

    if (bind(sock, local->ai_addr, local->ai_addrlen) < 0) {

        error_setg_errno(errp, errno, "Failed to bind socket");

        goto err;

    }



    

    if (connect(sock,peer->ai_addr,peer->ai_addrlen) < 0) {

        error_setg_errno(errp, errno, "Failed to connect socket");

        goto err;

    }



    freeaddrinfo(local);

    freeaddrinfo(peer);

    return sock;



err:

    if (-1 != sock)

        closesocket(sock);

    if (local)

        freeaddrinfo(local);

    if (peer)

        freeaddrinfo(peer);

    return -1;

}

    ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;     ai.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;
int FUNC_0(QemuOpts *VAR_0, Error **VAR_1)

{

    struct addrinfo VAR_2, *VAR_3 = NULL, *VAR_4 = NULL;

    const char *VAR_5;

    const char *VAR_6;

    int VAR_7 = -1, VAR_8;



    

    memset(&VAR_2,0, sizeof(VAR_2));

    VAR_2.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;

    VAR_2.ai_family = PF_UNSPEC;

    VAR_2.ai_socktype = SOCK_DGRAM;



    VAR_5 = qemu_opt_get(VAR_0, "host");

    VAR_6 = qemu_opt_get(VAR_0, "VAR_6");

    if (VAR_5 == NULL || strlen(VAR_5) == 0) {

        VAR_5 = "localhost";

    }

    if (VAR_6 == NULL || strlen(VAR_6) == 0) {

        error_setg(VAR_1, "remote VAR_6 not specified");

        return -1;

    }



    if (qemu_opt_get_bool(VAR_0, "ipv4", 0))

        VAR_2.ai_family = PF_INET;

    if (qemu_opt_get_bool(VAR_0, "ipv6", 0))

        VAR_2.ai_family = PF_INET6;



    if (0 != (VAR_8 = getaddrinfo(VAR_5, VAR_6, &VAR_2, &VAR_3))) {

        error_setg(VAR_1, "address resolution failed for %s:%s: %s", VAR_5, VAR_6,

                   gai_strerror(VAR_8));

	return -1;

    }



    

    memset(&VAR_2,0, sizeof(VAR_2));

    VAR_2.ai_flags = AI_PASSIVE;

    VAR_2.ai_family = VAR_3->ai_family;

    VAR_2.ai_socktype = SOCK_DGRAM;



    VAR_5 = qemu_opt_get(VAR_0, "localaddr");

    VAR_6 = qemu_opt_get(VAR_0, "localport");

    if (VAR_5 == NULL || strlen(VAR_5) == 0) {

        VAR_5 = NULL;

    }

    if (!VAR_6 || strlen(VAR_6) == 0)

        VAR_6 = "0";



    if (0 != (VAR_8 = getaddrinfo(VAR_5, VAR_6, &VAR_2, &VAR_4))) {

        error_setg(VAR_1, "address resolution failed for %s:%s: %s", VAR_5, VAR_6,

                   gai_strerror(VAR_8));

        goto err;

    }



    

    VAR_7 = qemu_socket(VAR_3->ai_family, VAR_3->ai_socktype, VAR_3->ai_protocol);

    if (VAR_7 < 0) {

        error_setg_errno(VAR_1, errno, "Failed to create socket");

        goto err;

    }

    socket_set_fast_reuse(VAR_7);



    

    if (bind(VAR_7, VAR_4->ai_addr, VAR_4->ai_addrlen) < 0) {

        error_setg_errno(VAR_1, errno, "Failed to bind socket");

        goto err;

    }



    

    if (connect(VAR_7,VAR_3->ai_addr,VAR_3->ai_addrlen) < 0) {

        error_setg_errno(VAR_1, errno, "Failed to connect socket");

        goto err;

    }



    freeaddrinfo(VAR_4);

    freeaddrinfo(VAR_3);

    return VAR_7;



err:

    if (-1 != VAR_7)

        closesocket(VAR_7);

    if (VAR_4)

        freeaddrinfo(VAR_4);

    if (VAR_3)

        freeaddrinfo(VAR_3);

    return -1;

}

int FUNC_0(QemuOpts *VAR_0, Error **VAR_1)
{ struct addrinfo VAR_2, *VAR_3 = NULL, *VAR_4 = NULL; const char *VAR_5; const char *VAR_6; int VAR_7 = -1, VAR_8; memset(&VAR_2,0, sizeof(VAR_2)); VAR_2.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; VAR_2.ai_family = PF_UNSPEC; VAR_2.ai_socktype = SOCK_DGRAM; VAR_5 = qemu_opt_get(VAR_0, "host"); VAR_6 = qemu_opt_get(VAR_0, "VAR_6"); if (VAR_5 == NULL || strlen(VAR_5) == 0) { VAR_5 = "localhost"; } if (VAR_6 == NULL || strlen(VAR_6) == 0) { error_setg(VAR_1, "remote VAR_6 not specified"); return -1; } if (qemu_opt_get_bool(VAR_0, "ipv4", 0))
VAR_2.ai_family = PF_INET; if (qemu_opt_get_bool(VAR_0, "ipv6", 0))
VAR_2.ai_family = PF_INET6; if (0 != (VAR_8 = getaddrinfo(VAR_5, VAR_6, &VAR_2, &VAR_3))) { error_setg(VAR_1, "address resolution failed for %s:%s: %s", VAR_5, VAR_6,
gai_strerror(VAR_8)); return -1; } memset(&VAR_2,0, sizeof(VAR_2)); VAR_2.ai_flags = AI_PASSIVE; VAR_2.ai_family = VAR_3->ai_family; VAR_2.ai_socktype = SOCK_DGRAM; VAR_5 = qemu_opt_get(VAR_0, "localaddr"); VAR_6 = qemu_opt_get(VAR_0, "localport"); if (VAR_5 == NULL || strlen(VAR_5) == 0) { VAR_5 = NULL; } if (!VAR_6 || strlen(VAR_6) == 0)
VAR_6 = "0"; if (0 != (VAR_8 = getaddrinfo(VAR_5, VAR_6, &VAR_2, &VAR_4))) { error_setg(VAR_1, "address resolution failed for %s:%s: %s", VAR_5, VAR_6,
gai_strerror(VAR_8)); goto err; } VAR_7 = qemu_socket(VAR_3->ai_family, VAR_3->ai_socktype, VAR_3->ai_protocol); if (VAR_7 < 0) { error_setg_errno(VAR_1, errno, "Failed to create socket"); goto err; } socket_set_fast_reuse(VAR_7); if (bind(VAR_7, VAR_4->ai_addr, VAR_4->ai_addrlen) < 0) { error_setg_errno(VAR_1, errno, "Failed to bind socket"); goto err; } if (connect(VAR_7,VAR_3->ai_addr,VAR_3->ai_addrlen) < 0) { error_setg_errno(VAR_1, errno, "Failed to connect socket"); goto err; } freeaddrinfo(VAR_4); freeaddrinfo(VAR_3); return VAR_7; err:
if (-1 != VAR_7)
closesocket(VAR_7); if (VAR_4)
freeaddrinfo(VAR_4); if (VAR_3)
freeaddrinfo(VAR_3); return -1; }