static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,

                          const char *name, int restricted,

                          const char *vnetwork, const char *vhost,

                          const char *vhostname, const char *tftp_export,

                          const char *bootfile, const char *vdhcp_start,

                          const char *vnameserver, const char *smb_export,

                          const char *vsmbserver)

{

    /* default settings according to historic slirp */

    struct in_addr net  = { .s_addr = htonl(0x0a000200) }; /* 10.0.2.0 */

    struct in_addr mask = { .s_addr = htonl(0xffffff00) }; /* 255.255.255.0 */

    struct in_addr host = { .s_addr = htonl(0x0a000202) }; /* 10.0.2.2 */

    struct in_addr dhcp = { .s_addr = htonl(0x0a00020f) }; /* 10.0.2.15 */

    struct in_addr dns  = { .s_addr = htonl(0x0a000203) }; /* 10.0.2.3 */

#ifndef _WIN32

    struct in_addr smbsrv = { .s_addr = 0 };

#endif

    SlirpState *s;

    char buf[20];

    uint32_t addr;

    int shift;

    char *end;



    if (!tftp_export) {

        tftp_export = legacy_tftp_prefix;

    }

    if (!bootfile) {

        bootfile = legacy_bootp_filename;

    }



    if (vnetwork) {

        if (get_str_sep(buf, sizeof(buf), &vnetwork, '/') < 0) {

            if (!inet_aton(vnetwork, &net)) {

                return -1;

            }

            addr = ntohl(net.s_addr);

            if (!(addr & 0x80000000)) {

                mask.s_addr = htonl(0xff000000); /* class A */

            } else if ((addr & 0xfff00000) == 0xac100000) {

                mask.s_addr = htonl(0xfff00000); /* priv. 172.16.0.0/12 */

            } else if ((addr & 0xc0000000) == 0x80000000) {

                mask.s_addr = htonl(0xffff0000); /* class B */

            } else if ((addr & 0xffff0000) == 0xc0a80000) {

                mask.s_addr = htonl(0xffff0000); /* priv. 192.168.0.0/16 */

            } else if ((addr & 0xffff0000) == 0xc6120000) {

                mask.s_addr = htonl(0xfffe0000); /* tests 198.18.0.0/15 */

            } else if ((addr & 0xe0000000) == 0xe0000000) {

                mask.s_addr = htonl(0xffffff00); /* class C */

            } else {

                mask.s_addr = htonl(0xfffffff0); /* multicast/reserved */

            }

        } else {

            if (!inet_aton(buf, &net)) {

                return -1;

            }

            shift = strtol(vnetwork, &end, 10);

            if (*end != '\0') {

                if (!inet_aton(vnetwork, &mask)) {

                    return -1;

                }

            } else if (shift < 4 || shift > 32) {

                return -1;

            } else {

                mask.s_addr = htonl(0xffffffff << (32 - shift));

            }

        }

        net.s_addr &= mask.s_addr;

        host.s_addr = net.s_addr | (htonl(0x0202) & ~mask.s_addr);

        dhcp.s_addr = net.s_addr | (htonl(0x020f) & ~mask.s_addr);

        dns.s_addr  = net.s_addr | (htonl(0x0203) & ~mask.s_addr);

    }



    if (vhost && !inet_aton(vhost, &host)) {

        return -1;

    }

    if ((host.s_addr & mask.s_addr) != net.s_addr) {

        return -1;

    }



    if (vdhcp_start && !inet_aton(vdhcp_start, &dhcp)) {

        return -1;

    }

    if ((dhcp.s_addr & mask.s_addr) != net.s_addr ||

        dhcp.s_addr == host.s_addr || dhcp.s_addr == dns.s_addr) {

        return -1;

    }



    if (vnameserver && !inet_aton(vnameserver, &dns)) {

        return -1;

    }

    if ((dns.s_addr & mask.s_addr) != net.s_addr ||

        dns.s_addr == host.s_addr) {

        return -1;

    }



#ifndef _WIN32

    if (vsmbserver && !inet_aton(vsmbserver, &smbsrv)) {

        return -1;

    }

#endif



    s = qemu_mallocz(sizeof(SlirpState));

    s->slirp = slirp_init(restricted, net, mask, host, vhostname,

                          tftp_export, bootfile, dhcp, dns, s);

    TAILQ_INSERT_TAIL(&slirp_stacks, s, entry);



    while (slirp_configs) {

        struct slirp_config_str *config = slirp_configs;



        if (config->flags & SLIRP_CFG_HOSTFWD) {

            slirp_hostfwd(s, mon, config->str,

                          config->flags & SLIRP_CFG_LEGACY);

        } else {

            slirp_guestfwd(s, mon, config->str,

                           config->flags & SLIRP_CFG_LEGACY);

        }

        slirp_configs = config->next;

        qemu_free(config);

    }

#ifndef _WIN32

    if (!smb_export) {

        smb_export = legacy_smb_export;

    }

    if (smb_export) {

        slirp_smb(s, mon, smb_export, smbsrv);

    }

#endif



    s->vc = qemu_new_vlan_client(vlan, model, name, NULL, slirp_receive, NULL,

                                 net_slirp_cleanup, s);

    snprintf(s->vc->info_str, sizeof(s->vc->info_str),

             "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n');

    return 0;

}

static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,

                          const char *name, int restricted,

                          const char *vnetwork, const char *vhost,

                          const char *vhostname, const char *tftp_export,

                          const char *bootfile, const char *vdhcp_start,

                          const char *vnameserver, const char *smb_export,

                          const char *vsmbserver)

{

    

    struct in_addr net  = { .s_addr = htonl(0x0a000200) }; 

    struct in_addr mask = { .s_addr = htonl(0xffffff00) }; 

    struct in_addr host = { .s_addr = htonl(0x0a000202) }; 

    struct in_addr dhcp = { .s_addr = htonl(0x0a00020f) }; 

    struct in_addr dns  = { .s_addr = htonl(0x0a000203) }; 

#ifndef _WIN32

    struct in_addr smbsrv = { .s_addr = 0 };

#endif

    SlirpState *s;

    char buf[20];

    uint32_t addr;

    int shift;

    char *end;



    if (!tftp_export) {

        tftp_export = legacy_tftp_prefix;

    }

    if (!bootfile) {

        bootfile = legacy_bootp_filename;

    }



    if (vnetwork) {

        if (get_str_sep(buf, sizeof(buf), &vnetwork, '/') < 0) {

            if (!inet_aton(vnetwork, &net)) {

                return -1;

            }

            addr = ntohl(net.s_addr);

            if (!(addr & 0x80000000)) {

                mask.s_addr = htonl(0xff000000); 

            } else if ((addr & 0xfff00000) == 0xac100000) {

                mask.s_addr = htonl(0xfff00000); 

            } else if ((addr & 0xc0000000) == 0x80000000) {

                mask.s_addr = htonl(0xffff0000); 

            } else if ((addr & 0xffff0000) == 0xc0a80000) {

                mask.s_addr = htonl(0xffff0000); 

            } else if ((addr & 0xffff0000) == 0xc6120000) {

                mask.s_addr = htonl(0xfffe0000); 

            } else if ((addr & 0xe0000000) == 0xe0000000) {

                mask.s_addr = htonl(0xffffff00); 

            } else {

                mask.s_addr = htonl(0xfffffff0); 

            }

        } else {

            if (!inet_aton(buf, &net)) {

                return -1;

            }

            shift = strtol(vnetwork, &end, 10);

            if (*end != '\0') {

                if (!inet_aton(vnetwork, &mask)) {

                    return -1;

                }

            } else if (shift < 4 || shift > 32) {

                return -1;

            } else {

                mask.s_addr = htonl(0xffffffff << (32 - shift));

            }

        }

        net.s_addr &= mask.s_addr;

        host.s_addr = net.s_addr | (htonl(0x0202) & ~mask.s_addr);

        dhcp.s_addr = net.s_addr | (htonl(0x020f) & ~mask.s_addr);

        dns.s_addr  = net.s_addr | (htonl(0x0203) & ~mask.s_addr);

    }



    if (vhost && !inet_aton(vhost, &host)) {

        return -1;

    }

    if ((host.s_addr & mask.s_addr) != net.s_addr) {

        return -1;

    }



    if (vdhcp_start && !inet_aton(vdhcp_start, &dhcp)) {

        return -1;

    }

    if ((dhcp.s_addr & mask.s_addr) != net.s_addr ||

        dhcp.s_addr == host.s_addr || dhcp.s_addr == dns.s_addr) {

        return -1;

    }



    if (vnameserver && !inet_aton(vnameserver, &dns)) {

        return -1;

    }

    if ((dns.s_addr & mask.s_addr) != net.s_addr ||

        dns.s_addr == host.s_addr) {

        return -1;

    }



#ifndef _WIN32

    if (vsmbserver && !inet_aton(vsmbserver, &smbsrv)) {

        return -1;

    }

#endif



    s = qemu_mallocz(sizeof(SlirpState));

    s->slirp = slirp_init(restricted, net, mask, host, vhostname,

                          tftp_export, bootfile, dhcp, dns, s);

    TAILQ_INSERT_TAIL(&slirp_stacks, s, entry);



    while (slirp_configs) {

        struct slirp_config_str *config = slirp_configs;



        if (config->flags & SLIRP_CFG_HOSTFWD) {

            slirp_hostfwd(s, mon, config->str,

                          config->flags & SLIRP_CFG_LEGACY);

        } else {

            slirp_guestfwd(s, mon, config->str,

                           config->flags & SLIRP_CFG_LEGACY);

        }

        slirp_configs = config->next;

        qemu_free(config);

    }

#ifndef _WIN32

    if (!smb_export) {

        smb_export = legacy_smb_export;

    }

    if (smb_export) {

        slirp_smb(s, mon, smb_export, smbsrv);

    }

#endif



    s->vc = qemu_new_vlan_client(vlan, model, name, NULL, slirp_receive, NULL,

                                 net_slirp_cleanup, s);

    snprintf(s->vc->info_str, sizeof(s->vc->info_str),

             "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n');

    return 0;

}

static int FUNC_0(Monitor *VAR_0, VLANState *VAR_1, const char *VAR_2,

                          const char *VAR_3, int VAR_4,

                          const char *VAR_5, const char *VAR_6,

                          const char *VAR_7, const char *VAR_8,

                          const char *VAR_9, const char *VAR_10,

                          const char *VAR_11, const char *VAR_12,

                          const char *VAR_13)

{

    

    struct in_addr VAR_14  = { .s_addr = htonl(0x0a000200) }; 

    struct in_addr VAR_15 = { .s_addr = htonl(0xffffff00) }; 

    struct in_addr VAR_16 = { .s_addr = htonl(0x0a000202) }; 

    struct in_addr VAR_17 = { .s_addr = htonl(0x0a00020f) }; 

    struct in_addr VAR_18  = { .s_addr = htonl(0x0a000203) }; 

#ifndef _WIN32

    struct in_addr VAR_19 = { .s_addr = 0 };

#endif

    SlirpState *s;

    char VAR_20[20];

    uint32_t addr;

    int VAR_21;

    char *VAR_22;



    if (!VAR_8) {

        VAR_8 = legacy_tftp_prefix;

    }

    if (!VAR_9) {

        VAR_9 = legacy_bootp_filename;

    }



    if (VAR_5) {

        if (get_str_sep(VAR_20, sizeof(VAR_20), &VAR_5, '/') < 0) {

            if (!inet_aton(VAR_5, &VAR_14)) {

                return -1;

            }

            addr = ntohl(VAR_14.s_addr);

            if (!(addr & 0x80000000)) {

                VAR_15.s_addr = htonl(0xff000000); 

            } else if ((addr & 0xfff00000) == 0xac100000) {

                VAR_15.s_addr = htonl(0xfff00000); 

            } else if ((addr & 0xc0000000) == 0x80000000) {

                VAR_15.s_addr = htonl(0xffff0000); 

            } else if ((addr & 0xffff0000) == 0xc0a80000) {

                VAR_15.s_addr = htonl(0xffff0000); 

            } else if ((addr & 0xffff0000) == 0xc6120000) {

                VAR_15.s_addr = htonl(0xfffe0000); 

            } else if ((addr & 0xe0000000) == 0xe0000000) {

                VAR_15.s_addr = htonl(0xffffff00); 

            } else {

                VAR_15.s_addr = htonl(0xfffffff0); 

            }

        } else {

            if (!inet_aton(VAR_20, &VAR_14)) {

                return -1;

            }

            VAR_21 = strtol(VAR_5, &VAR_22, 10);

            if (*VAR_22 != '\0') {

                if (!inet_aton(VAR_5, &VAR_15)) {

                    return -1;

                }

            } else if (VAR_21 < 4 || VAR_21 > 32) {

                return -1;

            } else {

                VAR_15.s_addr = htonl(0xffffffff << (32 - VAR_21));

            }

        }

        VAR_14.s_addr &= VAR_15.s_addr;

        VAR_16.s_addr = VAR_14.s_addr | (htonl(0x0202) & ~VAR_15.s_addr);

        VAR_17.s_addr = VAR_14.s_addr | (htonl(0x020f) & ~VAR_15.s_addr);

        VAR_18.s_addr  = VAR_14.s_addr | (htonl(0x0203) & ~VAR_15.s_addr);

    }



    if (VAR_6 && !inet_aton(VAR_6, &VAR_16)) {

        return -1;

    }

    if ((VAR_16.s_addr & VAR_15.s_addr) != VAR_14.s_addr) {

        return -1;

    }



    if (VAR_10 && !inet_aton(VAR_10, &VAR_17)) {

        return -1;

    }

    if ((VAR_17.s_addr & VAR_15.s_addr) != VAR_14.s_addr ||

        VAR_17.s_addr == VAR_16.s_addr || VAR_17.s_addr == VAR_18.s_addr) {

        return -1;

    }



    if (VAR_11 && !inet_aton(VAR_11, &VAR_18)) {

        return -1;

    }

    if ((VAR_18.s_addr & VAR_15.s_addr) != VAR_14.s_addr ||

        VAR_18.s_addr == VAR_16.s_addr) {

        return -1;

    }



#ifndef _WIN32

    if (VAR_13 && !inet_aton(VAR_13, &VAR_19)) {

        return -1;

    }

#endif



    s = qemu_mallocz(sizeof(SlirpState));

    s->slirp = slirp_init(VAR_4, VAR_14, VAR_15, VAR_16, VAR_7,

                          VAR_8, VAR_9, VAR_17, VAR_18, s);

    TAILQ_INSERT_TAIL(&slirp_stacks, s, entry);



    while (slirp_configs) {

        struct slirp_config_str *VAR_23 = slirp_configs;



        if (VAR_23->flags & SLIRP_CFG_HOSTFWD) {

            slirp_hostfwd(s, VAR_0, VAR_23->str,

                          VAR_23->flags & SLIRP_CFG_LEGACY);

        } else {

            slirp_guestfwd(s, VAR_0, VAR_23->str,

                           VAR_23->flags & SLIRP_CFG_LEGACY);

        }

        slirp_configs = VAR_23->next;

        qemu_free(VAR_23);

    }

#ifndef _WIN32

    if (!VAR_12) {

        VAR_12 = legacy_smb_export;

    }

    if (VAR_12) {

        slirp_smb(s, VAR_0, VAR_12, VAR_19);

    }

#endif



    s->vc = qemu_new_vlan_client(VAR_1, VAR_2, VAR_3, NULL, slirp_receive, NULL,

                                 net_slirp_cleanup, s);

    snprintf(s->vc->info_str, sizeof(s->vc->info_str),

             "VAR_14=%s, VAR_4=%c", inet_ntoa(VAR_14), VAR_4 ? 'y' : 'n');

    return 0;

}

static int FUNC_0(Monitor *VAR_0, VLANState *VAR_1, const char *VAR_2,
const char *VAR_3, int VAR_4,
const char *VAR_5, const char *VAR_6,
const char *VAR_7, const char *VAR_8,
const char *VAR_9, const char *VAR_10,
const char *VAR_11, const char *VAR_12,
const char *VAR_13)
{ struct in_addr VAR_14  = { .s_addr = htonl(0x0a000200) }; struct in_addr VAR_15 = { .s_addr = htonl(0xffffff00) }; struct in_addr VAR_16 = { .s_addr = htonl(0x0a000202) }; struct in_addr VAR_17 = { .s_addr = htonl(0x0a00020f) }; struct in_addr VAR_18  = { .s_addr = htonl(0x0a000203) }; #ifndef _WIN32
struct in_addr VAR_19 = { .s_addr = 0 }; #endif
SlirpState *s; char VAR_20[20]; uint32_t addr; int VAR_21; char *VAR_22; if (!VAR_8) { VAR_8 = legacy_tftp_prefix; } if (!VAR_9) { VAR_9 = legacy_bootp_filename; } if (VAR_5) { if (get_str_sep(VAR_20, sizeof(VAR_20), &VAR_5, '/') < 0) { if (!inet_aton(VAR_5, &VAR_14)) { return -1; } addr = ntohl(VAR_14.s_addr); if (!(addr & 0x80000000)) { VAR_15.s_addr = htonl(0xff000000); } else if ((addr & 0xfff00000) == 0xac100000) { VAR_15.s_addr = htonl(0xfff00000); } else if ((addr & 0xc0000000) == 0x80000000) { VAR_15.s_addr = htonl(0xffff0000); } else if ((addr & 0xffff0000) == 0xc0a80000) { VAR_15.s_addr = htonl(0xffff0000); } else if ((addr & 0xffff0000) == 0xc6120000) { VAR_15.s_addr = htonl(0xfffe0000); } else if ((addr & 0xe0000000) == 0xe0000000) { VAR_15.s_addr = htonl(0xffffff00); } else { VAR_15.s_addr = htonl(0xfffffff0); } } else { if (!inet_aton(VAR_20, &VAR_14)) { return -1; } VAR_21 = strtol(VAR_5, &VAR_22, 10); if (*VAR_22 != '\0') { if (!inet_aton(VAR_5, &VAR_15)) { return -1; } } else if (VAR_21 < 4 || VAR_21 > 32) { return -1; } else { VAR_15.s_addr = htonl(0xffffffff << (32 - VAR_21)); } } VAR_14.s_addr &= VAR_15.s_addr; VAR_16.s_addr = VAR_14.s_addr | (htonl(0x0202) & ~VAR_15.s_addr); VAR_17.s_addr = VAR_14.s_addr | (htonl(0x020f) & ~VAR_15.s_addr); VAR_18.s_addr  = VAR_14.s_addr | (htonl(0x0203) & ~VAR_15.s_addr); } if (VAR_6 && !inet_aton(VAR_6, &VAR_16)) { return -1; } if ((VAR_16.s_addr & VAR_15.s_addr) != VAR_14.s_addr) { return -1; } if (VAR_10 && !inet_aton(VAR_10, &VAR_17)) { return -1; } if ((VAR_17.s_addr & VAR_15.s_addr) != VAR_14.s_addr ||
VAR_17.s_addr == VAR_16.s_addr || VAR_17.s_addr == VAR_18.s_addr) { return -1; } if (VAR_11 && !inet_aton(VAR_11, &VAR_18)) { return -1; } if ((VAR_18.s_addr & VAR_15.s_addr) != VAR_14.s_addr ||
VAR_18.s_addr == VAR_16.s_addr) { return -1; } #ifndef _WIN32
if (VAR_13 && !inet_aton(VAR_13, &VAR_19)) { return -1; } #endif
s = qemu_mallocz(sizeof(SlirpState)); s->slirp = slirp_init(VAR_4, VAR_14, VAR_15, VAR_16, VAR_7,
VAR_8, VAR_9, VAR_17, VAR_18, s); TAILQ_INSERT_TAIL(&slirp_stacks, s, entry); while (slirp_configs) { struct slirp_config_str *VAR_23 = slirp_configs; if (VAR_23->flags & SLIRP_CFG_HOSTFWD) { slirp_hostfwd(s, VAR_0, VAR_23->str,
VAR_23->flags & SLIRP_CFG_LEGACY); } else { slirp_guestfwd(s, VAR_0, VAR_23->str,
VAR_23->flags & SLIRP_CFG_LEGACY); } slirp_configs = VAR_23->next; qemu_free(VAR_23); } #ifndef _WIN32
if (!VAR_12) { VAR_12 = legacy_smb_export; } if (VAR_12) { slirp_smb(s, VAR_0, VAR_12, VAR_19); } #endif
s->vc = qemu_new_vlan_client(VAR_1, VAR_2, VAR_3, NULL, slirp_receive, NULL,
net_slirp_cleanup, s); snprintf(s->vc->info_str, sizeof(s->vc->info_str),
"VAR_14=%s, VAR_4=%c", inet_ntoa(VAR_14), VAR_4 ? 'y' : 'n'); return 0; }