diff --git a/src/config.c b/src/config.c index 52eb05dae..06049713c 100644 --- a/src/config.c +++ b/src/config.c @@ -27,6 +27,11 @@ * -DANSI_CFG for use on these systems. */ +#ifdef _WIN32 +# include +#else +# include +#endif #include #ifdef ENABLE_CONFIG_LOG #include @@ -886,6 +891,25 @@ load_network(void) } else strcpy(nc->host_dev_name, "none"); + if (nc->net_type == NET_TYPE_SLIRP) { + sprintf(temp, "net_%02i_addr", c + 1); + p = ini_section_get_string(cat, temp, ""); + if (p && *p) { + struct in_addr addr; + if (inet_pton(AF_INET, p, &addr)) { + uint8_t *bytes = (uint8_t *)&addr.s_addr; + bytes[3] = 0; + sprintf(nc->slirp_net, "%d.%d.%d.0", bytes[0], bytes[1], bytes[2]); + } else { + nc->slirp_net[0] = '\0'; + } + } else { + nc->slirp_net[0] = '\0'; + } + } else { + nc->slirp_net[0] = '\0'; + } + sprintf(temp, "net_%02i_switch_group", c + 1); nc->switch_group = ini_section_get_int(cat, temp, NET_SWITCH_GRP_MIN); if (nc->switch_group < NET_SWITCH_GRP_MIN) @@ -1458,7 +1482,7 @@ load_floppy_and_cdrom_drives(void) int c; int d; int count = cdrom_get_type_count(); - + #ifndef DISABLE_FDD_AUDIO fdd_audio_load_profiles(); #endif @@ -1532,7 +1556,7 @@ load_floppy_and_cdrom_drives(void) fdd_set_audio_profile(c, d); #else fdd_set_audio_profile(c, 0); -#endif +#endif for (int i = 0; i < MAX_PREV_IMAGES; i++) { fdd_image_history[c][i] = (char *) calloc((MAX_IMAGE_PATH_LEN + 1) << 1, sizeof(char)); @@ -2987,6 +3011,14 @@ save_network(void) else ini_section_set_int(cat, temp, nc->link_state); + if (nc->net_type == NET_TYPE_SLIRP && nc->slirp_net[0] != '\0') { + sprintf(temp, "net_%02i_addr", c + 1); + ini_section_set_string(cat, temp, nc->slirp_net); + } else { + sprintf(temp, "net_%02i_addr", c + 1); + ini_section_delete_var(cat, temp); + } + sprintf(temp, "net_%02i_switch_group", c + 1); if (nc->switch_group == NET_SWITCH_GRP_MIN) ini_section_delete_var(cat, temp); diff --git a/src/include/86box/network.h b/src/include/86box/network.h index 2c91a6d9f..f3f1b1f8a 100644 --- a/src/include/86box/network.h +++ b/src/include/86box/network.h @@ -99,6 +99,7 @@ typedef struct netcard_conf_t { uint32_t link_state; uint8_t switch_group; uint8_t promisc_mode; + char slirp_net[16]; char nrs_hostname[128]; } netcard_conf_t; diff --git a/src/network/net_slirp.c b/src/network/net_slirp.c index c7243baac..86c0896a7 100644 --- a/src/network/net_slirp.c +++ b/src/network/net_slirp.c @@ -43,6 +43,7 @@ #ifdef _WIN32 # define WIN32_LEAN_AND_MEAN # include +# include #else # include #endif @@ -493,13 +494,30 @@ net_slirp_init(const netcard_t *card, const uint8_t *mac_addr, UNUSED(void *priv slirp->pfd = calloc(1, slirp->pfd_size); #endif - /* Set the IP addresses to use. */ - struct in_addr net = { .s_addr = htonl(0x0a000000 | (slirp_card_num << 8)) }; /* 10.0.x.0 */ - struct in_addr mask = { .s_addr = htonl(0xffffff00) }; /* 255.255.255.0 */ - struct in_addr host = { .s_addr = htonl(0x0a000002 | (slirp_card_num << 8)) }; /* 10.0.x.2 */ - struct in_addr dhcp = { .s_addr = htonl(0x0a00000f | (slirp_card_num << 8)) }; /* 10.0.x.15 */ - struct in_addr dns = { .s_addr = htonl(0x0a000003 | (slirp_card_num << 8)) }; /* 10.0.x.3 */ - struct in_addr bind = { .s_addr = htonl(0x00000000) }; /* 0.0.0.0 */ + struct in_addr net; + struct in_addr host; + struct in_addr dhcp; + struct in_addr dns; + + /* Set the IP addresses to use. + Use a configured address if set, otherwise 10.0.x.0 */ + const char *slirp_net = net_cards_conf[card->card_num].slirp_net; + if (slirp_net[0] != '\0') { + struct in_addr addr; + inet_pton(AF_INET, slirp_net, &addr); + net.s_addr = htonl(ntohl(addr.s_addr) & 0xffffff00); + host.s_addr = htonl(ntohl(addr.s_addr) + 2); + dhcp.s_addr = htonl(ntohl(addr.s_addr) + 15); + dns.s_addr = htonl(ntohl(addr.s_addr) + 3); + } else { + net.s_addr = htonl(0x0a000000 | (slirp_card_num << 8)); /* 10.0.x.0 */ + host.s_addr = htonl(0x0a000002 | (slirp_card_num << 8)); /* 10.0.x.2 */ + dhcp.s_addr = htonl(0x0a00000f | (slirp_card_num << 8)); /* 10.0.x.15 */ + dns.s_addr = htonl(0x0a000003 | (slirp_card_num << 8)); /* 10.0.x.3 */ + } + + struct in_addr mask = { .s_addr = htonl(0xffffff00) }; /* 255.255.255.0 */ + struct in_addr bind = { .s_addr = htonl(0x00000000) }; /* 0.0.0.0 */ const SlirpConfig slirp_config = { #if SLIRP_CHECK_VERSION(4, 9, 0)