static int slirp_guestfwd(SlirpState *s, const char *config_str,

                          int legacy_format)

{

    struct in_addr server = { .s_addr = 0 };

    struct GuestFwd *fwd;

    const char *p;

    char buf[128];

    char *end;

    int port;



    p = config_str;

    if (legacy_format) {

        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {

            goto fail_syntax;

        }

    } else {

        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {

            goto fail_syntax;

        }

        if (strcmp(buf, "tcp") && buf[0] != '\0') {

            goto fail_syntax;

        }

        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {

            goto fail_syntax;

        }

        if (buf[0] != '\0' && !inet_aton(buf, &server)) {

            goto fail_syntax;

        }

        if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) {

            goto fail_syntax;

        }

    }

    port = strtol(buf, &end, 10);

    if (*end != '\0' || port < 1 || port > 65535) {

        goto fail_syntax;

    }



    fwd = g_malloc(sizeof(struct GuestFwd));

    snprintf(buf, sizeof(buf), "guestfwd.tcp.%d", port);



    if ((strlen(p) > 4) && !strncmp(p, "cmd:", 4)) {

        if (slirp_add_exec(s->slirp, 0, &p[4], &server, port) < 0) {

            error_report("conflicting/invalid host:port in guest forwarding "

                         "rule '%s'", config_str);

            g_free(fwd);

            return -1;

        }

    } else {

        fwd->hd = qemu_chr_new(buf, p, NULL);

        if (!fwd->hd) {

            error_report("could not open guest forwarding device '%s'", buf);

            g_free(fwd);

            return -1;

        }



        if (slirp_add_exec(s->slirp, 3, fwd->hd, &server, port) < 0) {

            error_report("conflicting/invalid host:port in guest forwarding "

                         "rule '%s'", config_str);

            g_free(fwd);

            return -1;

        }

        fwd->server = server;

        fwd->port = port;

        fwd->slirp = s->slirp;



        qemu_chr_fe_claim_no_fail(fwd->hd);

        qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,

                              NULL, fwd);

    }

    return 0;



 fail_syntax:

    error_report("invalid guest forwarding rule '%s'", config_str);

    return -1;

}

static int slirp_guestfwd(SlirpState *s, const char *config_str,

                          int legacy_format)

{

    struct in_addr server = { .s_addr = 0 };

    struct GuestFwd *fwd;

    const char *p;

    char buf[128];

    char *end;

    int port;



    p = config_str;

    if (legacy_format) {

        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {

            goto fail_syntax;

        }

    } else {

        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {

            goto fail_syntax;

        }

        if (strcmp(buf, "tcp") && buf[0] != '\0') {

            goto fail_syntax;

        }

        if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {

            goto fail_syntax;

        }

        if (buf[0] != '\0' && !inet_aton(buf, &server)) {

            goto fail_syntax;

        }

        if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) {

            goto fail_syntax;

        }

    }

    port = strtol(buf, &end, 10);

    if (*end != '\0' || port < 1 || port > 65535) {

        goto fail_syntax;

    }



    fwd = g_malloc(sizeof(struct GuestFwd));

    snprintf(buf, sizeof(buf), "guestfwd.tcp.%d", port);



    if ((strlen(p) > 4) && !strncmp(p, "cmd:", 4)) {

        if (slirp_add_exec(s->slirp, 0, &p[4], &server, port) < 0) {

            error_report("conflicting/invalid host:port in guest forwarding "

                         "rule '%s'", config_str);

            g_free(fwd);

            return -1;

        }

    } else {

        fwd->hd = qemu_chr_new(buf, p, NULL);

        if (!fwd->hd) {

            error_report("could not open guest forwarding device '%s'", buf);

            g_free(fwd);

            return -1;

        }



        if (slirp_add_exec(s->slirp, 3, fwd->hd, &server, port) < 0) {

            error_report("conflicting/invalid host:port in guest forwarding "

                         "rule '%s'", config_str);

            g_free(fwd);

            return -1;

        }

        fwd->server = server;

        fwd->port = port;

        fwd->slirp = s->slirp;



        qemu_chr_fe_claim_no_fail(fwd->hd);

        qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,

                              NULL, fwd);

    }

    return 0;



 fail_syntax:

    error_report("invalid guest forwarding rule '%s'", config_str);

    return -1;

}

    fwd = g_malloc(sizeof(struct GuestFwd));             g_free(fwd);
static int FUNC_0(SlirpState *VAR_0, const char *VAR_1,

                          int VAR_2)

{

    struct in_addr VAR_3 = { .s_addr = 0 };

    struct GuestFwd *VAR_4;

    const char *VAR_5;

    char VAR_6[128];

    char *VAR_7;

    int VAR_8;



    VAR_5 = VAR_1;

    if (VAR_2) {

        if (get_str_sep(VAR_6, sizeof(VAR_6), &VAR_5, ':') < 0) {

            goto fail_syntax;

        }

    } else {

        if (get_str_sep(VAR_6, sizeof(VAR_6), &VAR_5, ':') < 0) {

            goto fail_syntax;

        }

        if (strcmp(VAR_6, "tcp") && VAR_6[0] != '\0') {

            goto fail_syntax;

        }

        if (get_str_sep(VAR_6, sizeof(VAR_6), &VAR_5, ':') < 0) {

            goto fail_syntax;

        }

        if (VAR_6[0] != '\0' && !inet_aton(VAR_6, &VAR_3)) {

            goto fail_syntax;

        }

        if (get_str_sep(VAR_6, sizeof(VAR_6), &VAR_5, '-') < 0) {

            goto fail_syntax;

        }

    }

    VAR_8 = strtol(VAR_6, &VAR_7, 10);

    if (*VAR_7 != '\0' || VAR_8 < 1 || VAR_8 > 65535) {

        goto fail_syntax;

    }



    VAR_4 = g_malloc(sizeof(struct GuestFwd));

    snprintf(VAR_6, sizeof(VAR_6), "guestfwd.tcp.%d", VAR_8);



    if ((strlen(VAR_5) > 4) && !strncmp(VAR_5, "cmd:", 4)) {

        if (slirp_add_exec(VAR_0->slirp, 0, &VAR_5[4], &VAR_3, VAR_8) < 0) {

            error_report("conflicting/invalid host:VAR_8 in guest forwarding "

                         "rule '%VAR_0'", VAR_1);

            g_free(VAR_4);

            return -1;

        }

    } else {

        VAR_4->hd = qemu_chr_new(VAR_6, VAR_5, NULL);

        if (!VAR_4->hd) {

            error_report("could not open guest forwarding device '%VAR_0'", VAR_6);

            g_free(VAR_4);

            return -1;

        }



        if (slirp_add_exec(VAR_0->slirp, 3, VAR_4->hd, &VAR_3, VAR_8) < 0) {

            error_report("conflicting/invalid host:VAR_8 in guest forwarding "

                         "rule '%VAR_0'", VAR_1);

            g_free(VAR_4);

            return -1;

        }

        VAR_4->VAR_3 = VAR_3;

        VAR_4->VAR_8 = VAR_8;

        VAR_4->slirp = VAR_0->slirp;



        qemu_chr_fe_claim_no_fail(VAR_4->hd);

        qemu_chr_add_handlers(VAR_4->hd, guestfwd_can_read, guestfwd_read,

                              NULL, VAR_4);

    }

    return 0;



 fail_syntax:

    error_report("invalid guest forwarding rule '%VAR_0'", VAR_1);

    return -1;

}

static int FUNC_0(SlirpState *VAR_0, const char *VAR_1,
int VAR_2)
{ struct in_addr VAR_3 = { .s_addr = 0 }; struct GuestFwd *VAR_4; const char *VAR_5; char VAR_6[128]; char *VAR_7; int VAR_8; VAR_5 = VAR_1; if (VAR_2) { if (get_str_sep(VAR_6, sizeof(VAR_6), &VAR_5, ':') < 0) { goto fail_syntax; } } else { if (get_str_sep(VAR_6, sizeof(VAR_6), &VAR_5, ':') < 0) { goto fail_syntax; } if (strcmp(VAR_6, "tcp") && VAR_6[0] != '\0') { goto fail_syntax; } if (get_str_sep(VAR_6, sizeof(VAR_6), &VAR_5, ':') < 0) { goto fail_syntax; } if (VAR_6[0] != '\0' && !inet_aton(VAR_6, &VAR_3)) { goto fail_syntax; } if (get_str_sep(VAR_6, sizeof(VAR_6), &VAR_5, '-') < 0) { goto fail_syntax; } } VAR_8 = strtol(VAR_6, &VAR_7, 10); if (*VAR_7 != '\0' || VAR_8 < 1 || VAR_8 > 65535) { goto fail_syntax; } VAR_4 = g_malloc(sizeof(struct GuestFwd)); snprintf(VAR_6, sizeof(VAR_6), "guestfwd.tcp.%d", VAR_8); if ((strlen(VAR_5) > 4) && !strncmp(VAR_5, "cmd:", 4)) { if (slirp_add_exec(VAR_0->slirp, 0, &VAR_5[4], &VAR_3, VAR_8) < 0) { error_report("conflicting/invalid host:VAR_8 in guest forwarding "
"rule '%VAR_0'", VAR_1); g_free(VAR_4); return -1; } } else { VAR_4->hd = qemu_chr_new(VAR_6, VAR_5, NULL); if (!VAR_4->hd) { error_report("could not open guest forwarding device '%VAR_0'", VAR_6); g_free(VAR_4); return -1; } if (slirp_add_exec(VAR_0->slirp, 3, VAR_4->hd, &VAR_3, VAR_8) < 0) { error_report("conflicting/invalid host:VAR_8 in guest forwarding "
"rule '%VAR_0'", VAR_1); g_free(VAR_4); return -1; } VAR_4->VAR_3 = VAR_3; VAR_4->VAR_8 = VAR_8; VAR_4->slirp = VAR_0->slirp; qemu_chr_fe_claim_no_fail(VAR_4->hd); qemu_chr_add_handlers(VAR_4->hd, guestfwd_can_read, guestfwd_read,
NULL, VAR_4); } return 0; fail_syntax:
error_report("invalid guest forwarding rule '%VAR_0'", VAR_1); return -1; }