static void slirp_guestfwd(SlirpState *s, Monitor *mon, 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 = qemu_malloc(sizeof(struct GuestFwd));

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

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

    if (!fwd->hd) {

        config_error(mon, "could not open guest forwarding device '%s'\n",

                     buf);

        qemu_free(fwd);

        return;

    }



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

        config_error(mon, "conflicting/invalid host:port in guest forwarding "

                     "rule '%s'\n", config_str);

        qemu_free(fwd);

        return;

    }

    fwd->server = server;

    fwd->port = port;

    fwd->slirp = s->slirp;



    qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,

                          NULL, fwd);

    return;



 fail_syntax:

    config_error(mon, "invalid guest forwarding rule '%s'\n", config_str);

}

static void slirp_guestfwd(SlirpState *s, Monitor *mon, 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 = qemu_malloc(sizeof(struct GuestFwd));

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

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

    if (!fwd->hd) {

        config_error(mon, "could not open guest forwarding device '%s'\n",

                     buf);

        qemu_free(fwd);

        return;

    }



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

        config_error(mon, "conflicting/invalid host:port in guest forwarding "

                     "rule '%s'\n", config_str);

        qemu_free(fwd);

        return;

    }

    fwd->server = server;

    fwd->port = port;

    fwd->slirp = s->slirp;



    qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,

                          NULL, fwd);

    return;



 fail_syntax:

    config_error(mon, "invalid guest forwarding rule '%s'\n", config_str);

}

static void slirp_guestfwd(SlirpState *s, Monitor *mon, const char *config_str, static void slirp_guestfwd(SlirpState *s, Monitor *mon, const char *config_str,                            int legacy_format)
static void FUNC_0(SlirpState *VAR_0, Monitor *VAR_1, const char *VAR_2,

                           int VAR_3)

{

    struct in_addr VAR_4 = { .s_addr = 0 };

    struct GuestFwd *VAR_5;

    const char *VAR_6;

    char VAR_7[128];

    char *VAR_8;

    int VAR_9;



    VAR_6 = VAR_2;

    if (VAR_3) {

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

            goto fail_syntax;

        }

    } else {

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

            goto fail_syntax;

        }

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

            goto fail_syntax;

        }

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

            goto fail_syntax;

        }

        if (VAR_7[0] != '\0' && !inet_aton(VAR_7, &VAR_4)) {

            goto fail_syntax;

        }

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

            goto fail_syntax;

        }

    }

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

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

        goto fail_syntax;

    }



    VAR_5 = qemu_malloc(sizeof(struct GuestFwd));

    snprintf(VAR_7, sizeof(VAR_7), "guestfwd.tcp:%d", VAR_9);

    VAR_5->hd = qemu_chr_open(VAR_7, VAR_6, NULL);

    if (!VAR_5->hd) {

        config_error(VAR_1, "could not open guest forwarding device '%VAR_0'\n",

                     VAR_7);

        qemu_free(VAR_5);

        return;

    }



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

        config_error(VAR_1, "conflicting/invalid host:VAR_9 in guest forwarding "

                     "rule '%VAR_0'\n", VAR_2);

        qemu_free(VAR_5);

        return;

    }

    VAR_5->VAR_4 = VAR_4;

    VAR_5->VAR_9 = VAR_9;

    VAR_5->slirp = VAR_0->slirp;



    qemu_chr_add_handlers(VAR_5->hd, guestfwd_can_read, guestfwd_read,

                          NULL, VAR_5);

    return;



 fail_syntax:

    config_error(VAR_1, "invalid guest forwarding rule '%VAR_0'\n", VAR_2);

}

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