mirror of
https://github.com/86Box/86Box.git
synced 2026-02-21 17:15:32 -07:00
SLiRP: Support for changing the network.
Since the default 10.0.2.0/24 (or 10.0.3.0... etc) address can conflict with a LAN (as it does in my case), this feature now adds the ability to set custom network prefixes in the configuration file. I believe this is an “advanced” usage feature (like port forwarding) and should not be exposed in the GUI, therefore no GUI changes have been made. In the `[Network]` section of 86box.cfg, each of the four NICs can be set to have a custom address like such: ``` net_01_addr = 10.80.88.0 net_02_addr = 10.82.86.0 net_03_addr = 10.84.86.0 net_04_addr = 10.85.86.0 ``` The last octet of the address is effectively ignored and always set to 0 again when the configuration file is saved. Only a /24 CIDR (netmask 255.255.255.0) is supported. IPv4 has three local-scope ranges: 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0. Finding a network prefix within these that do not conflict with your real LAN should not pose a problem.
This commit is contained in:
36
src/config.c
36
src/config.c
@@ -27,6 +27,11 @@
|
||||
* -DANSI_CFG for use on these systems.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <winsock.h>
|
||||
#else
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
#ifdef ENABLE_CONFIG_LOG
|
||||
#include <stdarg.h>
|
||||
@@ -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_aton(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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -493,13 +493,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_aton(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)
|
||||
|
||||
Reference in New Issue
Block a user