int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)

{

    TAPState *s;

    int fd, vnet_hdr = 0;



    if (qemu_opt_get(opts, "fd")) {

        if (qemu_opt_get(opts, "ifname") ||

            qemu_opt_get(opts, "script") ||

            qemu_opt_get(opts, "downscript") ||

            qemu_opt_get(opts, "vnet_hdr")) {

            qemu_error("ifname=, script=, downscript= and vnet_hdr= is invalid with fd=\n");

            return -1;

        }



        fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd"));

        if (fd == -1) {

            return -1;

        }



        fcntl(fd, F_SETFL, O_NONBLOCK);



        vnet_hdr = tap_probe_vnet_hdr(fd);

    } else {

        if (!qemu_opt_get(opts, "script")) {

            qemu_opt_set(opts, "script", DEFAULT_NETWORK_SCRIPT);

        }



        if (!qemu_opt_get(opts, "downscript")) {

            qemu_opt_set(opts, "downscript", DEFAULT_NETWORK_DOWN_SCRIPT);

        }



        fd = net_tap_init(opts, &vnet_hdr);

        if (fd == -1) {

            return -1;

        }

    }



    s = net_tap_fd_init(vlan, "tap", name, fd, vnet_hdr);

    if (!s) {

        close(fd);

        return -1;

    }



    if (tap_set_sndbuf(s->fd, opts) < 0) {

        return -1;

    }



    if (qemu_opt_get(opts, "fd")) {

        snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);

    } else {

        const char *ifname, *script, *downscript;



        ifname     = qemu_opt_get(opts, "ifname");

        script     = qemu_opt_get(opts, "script");

        downscript = qemu_opt_get(opts, "downscript");



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

                 "ifname=%s,script=%s,downscript=%s",

                 ifname, script, downscript);



        if (strcmp(downscript, "no") != 0) {

            snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);

            snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname);

        }

    }



    if (vlan) {

        vlan->nb_host_devs++;

    }



    return 0;

}

int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)

{

    TAPState *s;

    int fd, vnet_hdr = 0;



    if (qemu_opt_get(opts, "fd")) {

        if (qemu_opt_get(opts, "ifname") ||

            qemu_opt_get(opts, "script") ||

            qemu_opt_get(opts, "downscript") ||

            qemu_opt_get(opts, "vnet_hdr")) {

            qemu_error("ifname=, script=, downscript= and vnet_hdr= is invalid with fd=\n");

            return -1;

        }



        fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd"));

        if (fd == -1) {

            return -1;

        }



        fcntl(fd, F_SETFL, O_NONBLOCK);



        vnet_hdr = tap_probe_vnet_hdr(fd);

    } else {

        if (!qemu_opt_get(opts, "script")) {

            qemu_opt_set(opts, "script", DEFAULT_NETWORK_SCRIPT);

        }



        if (!qemu_opt_get(opts, "downscript")) {

            qemu_opt_set(opts, "downscript", DEFAULT_NETWORK_DOWN_SCRIPT);

        }



        fd = net_tap_init(opts, &vnet_hdr);

        if (fd == -1) {

            return -1;

        }

    }



    s = net_tap_fd_init(vlan, "tap", name, fd, vnet_hdr);

    if (!s) {

        close(fd);

        return -1;

    }



    if (tap_set_sndbuf(s->fd, opts) < 0) {

        return -1;

    }



    if (qemu_opt_get(opts, "fd")) {

        snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);

    } else {

        const char *ifname, *script, *downscript;



        ifname     = qemu_opt_get(opts, "ifname");

        script     = qemu_opt_get(opts, "script");

        downscript = qemu_opt_get(opts, "downscript");



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

                 "ifname=%s,script=%s,downscript=%s",

                 ifname, script, downscript);



        if (strcmp(downscript, "no") != 0) {

            snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);

            snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname);

        }

    }



    if (vlan) {

        vlan->nb_host_devs++;

    }



    return 0;

}

int FUNC_0(QemuOpts *VAR_0, Monitor *VAR_1, const char *VAR_2, VLANState *VAR_3)

{

    TAPState *s;

    int VAR_4, VAR_5 = 0;



    if (qemu_opt_get(VAR_0, "VAR_4")) {

        if (qemu_opt_get(VAR_0, "VAR_6") ||

            qemu_opt_get(VAR_0, "VAR_7") ||

            qemu_opt_get(VAR_0, "VAR_8") ||

            qemu_opt_get(VAR_0, "VAR_5")) {

            qemu_error("VAR_6=, VAR_7=, VAR_8= and VAR_5= is invalid with VAR_4=\n");

            return -1;

        }



        VAR_4 = net_handle_fd_param(VAR_1, qemu_opt_get(VAR_0, "VAR_4"));

        if (VAR_4 == -1) {

            return -1;

        }



        fcntl(VAR_4, F_SETFL, O_NONBLOCK);



        VAR_5 = tap_probe_vnet_hdr(VAR_4);

    } else {

        if (!qemu_opt_get(VAR_0, "VAR_7")) {

            qemu_opt_set(VAR_0, "VAR_7", DEFAULT_NETWORK_SCRIPT);

        }



        if (!qemu_opt_get(VAR_0, "VAR_8")) {

            qemu_opt_set(VAR_0, "VAR_8", DEFAULT_NETWORK_DOWN_SCRIPT);

        }



        VAR_4 = net_tap_init(VAR_0, &VAR_5);

        if (VAR_4 == -1) {

            return -1;

        }

    }



    s = net_tap_fd_init(VAR_3, "tap", VAR_2, VAR_4, VAR_5);

    if (!s) {

        close(VAR_4);

        return -1;

    }



    if (tap_set_sndbuf(s->VAR_4, VAR_0) < 0) {

        return -1;

    }



    if (qemu_opt_get(VAR_0, "VAR_4")) {

        snprintf(s->nc.info_str, sizeof(s->nc.info_str), "VAR_4=%d", VAR_4);

    } else {

        const char *VAR_6, *VAR_7, *VAR_8;



        VAR_6     = qemu_opt_get(VAR_0, "VAR_6");

        VAR_7     = qemu_opt_get(VAR_0, "VAR_7");

        VAR_8 = qemu_opt_get(VAR_0, "VAR_8");



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

                 "VAR_6=%s,VAR_7=%s,VAR_8=%s",

                 VAR_6, VAR_7, VAR_8);



        if (strcmp(VAR_8, "no") != 0) {

            snprintf(s->down_script, sizeof(s->down_script), "%s", VAR_8);

            snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", VAR_6);

        }

    }



    if (VAR_3) {

        VAR_3->nb_host_devs++;

    }



    return 0;

}

int FUNC_0(QemuOpts *VAR_0, Monitor *VAR_1, const char *VAR_2, VLANState *VAR_3)
{ TAPState *s; int VAR_4, VAR_5 = 0; if (qemu_opt_get(VAR_0, "VAR_4")) { if (qemu_opt_get(VAR_0, "VAR_6") ||
qemu_opt_get(VAR_0, "VAR_7") ||
qemu_opt_get(VAR_0, "VAR_8") ||
qemu_opt_get(VAR_0, "VAR_5")) { qemu_error("VAR_6=, VAR_7=, VAR_8= and VAR_5= is invalid with VAR_4=\n"); return -1; } VAR_4 = net_handle_fd_param(VAR_1, qemu_opt_get(VAR_0, "VAR_4")); if (VAR_4 == -1) { return -1; } fcntl(VAR_4, F_SETFL, O_NONBLOCK); VAR_5 = tap_probe_vnet_hdr(VAR_4); } else { if (!qemu_opt_get(VAR_0, "VAR_7")) { qemu_opt_set(VAR_0, "VAR_7", DEFAULT_NETWORK_SCRIPT); } if (!qemu_opt_get(VAR_0, "VAR_8")) { qemu_opt_set(VAR_0, "VAR_8", DEFAULT_NETWORK_DOWN_SCRIPT); } VAR_4 = net_tap_init(VAR_0, &VAR_5); if (VAR_4 == -1) { return -1; } } s = net_tap_fd_init(VAR_3, "tap", VAR_2, VAR_4, VAR_5); if (!s) { close(VAR_4); return -1; } if (tap_set_sndbuf(s->VAR_4, VAR_0) < 0) { return -1; } if (qemu_opt_get(VAR_0, "VAR_4")) { snprintf(s->nc.info_str, sizeof(s->nc.info_str), "VAR_4=%d", VAR_4); } else { const char *VAR_6, *VAR_7, *VAR_8; VAR_6     = qemu_opt_get(VAR_0, "VAR_6"); VAR_7     = qemu_opt_get(VAR_0, "VAR_7"); VAR_8 = qemu_opt_get(VAR_0, "VAR_8"); snprintf(s->nc.info_str, sizeof(s->nc.info_str),
"VAR_6=%s,VAR_7=%s,VAR_8=%s",
VAR_6, VAR_7, VAR_8); if (strcmp(VAR_8, "no") != 0) { snprintf(s->down_script, sizeof(s->down_script), "%s", VAR_8); snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", VAR_6); } } if (VAR_3) { VAR_3->nb_host_devs++; } return 0; }