diff --git a/src/config.c b/src/config.c index 4455f4ae4..52eb05dae 100644 --- a/src/config.c +++ b/src/config.c @@ -887,7 +887,9 @@ load_network(void) strcpy(nc->host_dev_name, "none"); sprintf(temp, "net_%02i_switch_group", c + 1); - nc->switch_group = ini_section_get_int(cat, temp, 0); + nc->switch_group = ini_section_get_int(cat, temp, NET_SWITCH_GRP_MIN); + if (nc->switch_group < NET_SWITCH_GRP_MIN) + nc->switch_group = NET_SWITCH_GRP_MIN; sprintf(temp, "net_%02i_promisc", c + 1); nc->promisc_mode = ini_section_get_int(cat, temp, 0); @@ -2986,7 +2988,7 @@ save_network(void) ini_section_set_int(cat, temp, nc->link_state); sprintf(temp, "net_%02i_switch_group", c + 1); - if (nc->switch_group == 0) + if (nc->switch_group == NET_SWITCH_GRP_MIN) ini_section_delete_var(cat, temp); else ini_section_set_int(cat, temp, nc->switch_group); diff --git a/src/include/86box/network.h b/src/include/86box/network.h index cad7b9128..0642c3f53 100644 --- a/src/include/86box/network.h +++ b/src/include/86box/network.h @@ -60,6 +60,8 @@ #define NET_QUEUE_COUNT 4 #define NET_CARD_MAX 4 #define NET_HOST_INTF_MAX 64 +#define NET_SWITCH_GRP_MIN 1 +#define NET_SWITCH_GRP_MAX 10 #define NET_PERIOD_10M 0.8 #define NET_PERIOD_100M 0.08 diff --git a/src/network/net_switch.c b/src/network/net_switch.c index 2f24735d3..5fc3a2091 100644 --- a/src/network/net_switch.c +++ b/src/network/net_switch.c @@ -469,7 +469,7 @@ net_switch_init(const netcard_t *card, const uint8_t *mac_addr, void *priv, char val = 0; setsockopt(netswitch->socket_rx, IPPROTO_IP, IP_MULTICAST_LOOP, (char *) &val, sizeof(val)); - netswitch->port_out = htons(SWITCH_MULTICAST_PORT + netcard->switch_group); + netswitch->port_out = htons(SWITCH_MULTICAST_PORT - NET_SWITCH_GRP_MIN + netcard->switch_group); struct sockaddr_in addr = { .sin_family = AF_INET, .sin_addr = { .s_addr = htonl(INADDR_ANY) }, diff --git a/src/qt/qt_settingsnetwork.cpp b/src/qt/qt_settingsnetwork.cpp index 929781075..878944e60 100644 --- a/src/qt/qt_settingsnetwork.cpp +++ b/src/qt/qt_settingsnetwork.cpp @@ -54,8 +54,8 @@ SettingsNetwork::enableElements(Ui::SettingsNetwork *ui) // auto *switch_group_hlayout = findChild(QString("HLayoutSwitch%1").arg(i + 1)); // auto *switch_group_hspacer = findChild(QString("horizontalSpacerSwitch%1").arg(i + 1)); auto *switch_group_value = findChild(QString("spinnerSwitch%1").arg(i + 1)); - switch_group_value->setMinimum(1); - switch_group_value->setMaximum(10); + switch_group_value->setMinimum(NET_SWITCH_GRP_MIN); + switch_group_value->setMaximum(NET_SWITCH_GRP_MAX); // Promiscuous option auto *promisc_label = findChild(QString("labelPromisc%1").arg(i + 1)); @@ -230,10 +230,10 @@ SettingsNetwork::save() else if (net_cards_conf[i].net_type == NET_TYPE_NRSWITCH) { memset(net_cards_conf[i].nrs_hostname, '\0', sizeof(net_cards_conf[i].nrs_hostname)); strncpy(net_cards_conf[i].nrs_hostname, hostname_value->text().toUtf8().constData(), sizeof(net_cards_conf[i].nrs_hostname) - 1); - net_cards_conf[i].switch_group = switch_group_value->value() - 1; + net_cards_conf[i].switch_group = switch_group_value->value(); } else if (net_cards_conf[i].net_type == NET_TYPE_NLSWITCH) { net_cards_conf[i].promisc_mode = promisc_value->isChecked(); - net_cards_conf[i].switch_group = switch_group_value->value() - 1; + net_cards_conf[i].switch_group = switch_group_value->value(); } } } @@ -350,12 +350,12 @@ SettingsNetwork::onCurrentMachineChanged(int machineId) auto *promisc_value = findChild(QString("boxPromisc%1").arg(i + 1)); promisc_value->setCheckState(net_cards_conf[i].promisc_mode == 1 ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); auto *switch_group_value = findChild(QString("spinnerSwitch%1").arg(i + 1)); - switch_group_value->setValue(net_cards_conf[i].switch_group + 1); + switch_group_value->setValue(net_cards_conf[i].switch_group); } else if (net_cards_conf[i].net_type == NET_TYPE_NRSWITCH) { auto *hostname_value = findChild(QString("hostnameSwitch%1").arg(i + 1)); hostname_value->setText(net_cards_conf[i].nrs_hostname); auto *switch_group_value = findChild(QString("spinnerSwitch%1").arg(i + 1)); - switch_group_value->setValue(net_cards_conf[i].switch_group + 1); + switch_group_value->setValue(net_cards_conf[i].switch_group); } } }