mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-11-26 10:49:21 +00:00
Add ether "tap" support to the GUI. Also fix "slirp" callback.
This commit is contained in:
parent
11ff11d205
commit
c9c21cf70d
@ -1402,6 +1402,13 @@ static void mn_ether_b2ether(GtkWidget *, const char *guid)
|
||||
PrefsReplaceString("etherguid", guid);
|
||||
}
|
||||
|
||||
// Ethernet option for Basilisk II driver selected
|
||||
static void mn_ether_tap(GtkWidget *, const char *guid)
|
||||
{
|
||||
PrefsReplaceString("ether", "tap");
|
||||
PrefsReplaceString("etherguid", guid);
|
||||
}
|
||||
|
||||
// Create ethernet interfaces menu
|
||||
static int create_ether_menu(GtkWidget *menu)
|
||||
{
|
||||
@ -1410,21 +1417,25 @@ static int create_ether_menu(GtkWidget *menu)
|
||||
const char *ether = PrefsFindString("ether");
|
||||
const char *etherguid = PrefsFindString("etherguid");
|
||||
|
||||
// No Ethernet
|
||||
add_menu_item(menu, STR_NONE_LAB, (GtkSignalFunc)mn_ether_none);
|
||||
if (ether == NULL)
|
||||
active = n_items;
|
||||
n_items++;
|
||||
|
||||
// Basilisk II Router
|
||||
add_menu_item(menu, "Basilisk II Router", (GtkSignalFunc)mn_ether_router);
|
||||
if (ether && strcmp(ether, "router") == 0)
|
||||
active = n_items;
|
||||
n_items++;
|
||||
|
||||
add_menu_item(menu, "Basilisk II Slirp", (GtkSignalFunc)mn_ether_router);
|
||||
// Basilisk II Slirp
|
||||
add_menu_item(menu, "Basilisk II Slirp", (GtkSignalFunc)mn_ether_slirp);
|
||||
if (ether && strcmp(ether, "slirp") == 0)
|
||||
active = n_items;
|
||||
n_items++;
|
||||
|
||||
// Basilisk II Ethernet Adapter
|
||||
PacketOpenAdapter("", 0);
|
||||
{
|
||||
ULONG sz;
|
||||
@ -1456,6 +1467,24 @@ static int create_ether_menu(GtkWidget *menu)
|
||||
}
|
||||
PacketCloseAdapter(NULL);
|
||||
|
||||
// TAP-Win32
|
||||
const char *tap_devices;
|
||||
if ((tap_devices = ether_tap_devices()) != NULL) {
|
||||
const char *guid = tap_devices;
|
||||
while (*guid) {
|
||||
const char *name = ether_guid_to_name(guid);
|
||||
if (name && (name = g_locale_to_utf8(name, -1, NULL, NULL, NULL))) {
|
||||
add_menu_item(menu, name, (GtkSignalFunc)mn_ether_tap, strdup(guid));
|
||||
if (etherguid && strcmp(guid, etherguid) == 0 &&
|
||||
ether && strcmp(ether, "tap") == 0)
|
||||
active = n_items;
|
||||
n_items++;
|
||||
}
|
||||
guid += strlen(guid) + 1;
|
||||
}
|
||||
free((char *)tap_devices);
|
||||
}
|
||||
|
||||
return active;
|
||||
}
|
||||
|
||||
|
@ -260,3 +260,119 @@ const char *ether_guid_to_name(const char *guid)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get TAP-Win32 adapters
|
||||
*/
|
||||
|
||||
#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
|
||||
|
||||
#define TAP_COMPONENT_ID "tap0801"
|
||||
|
||||
const char *ether_tap_devices(void)
|
||||
{
|
||||
HKEY adapter_key;
|
||||
LONG status;
|
||||
DWORD len;
|
||||
int i = 0;
|
||||
|
||||
status = RegOpenKeyEx(
|
||||
HKEY_LOCAL_MACHINE,
|
||||
ADAPTER_KEY,
|
||||
0,
|
||||
KEY_READ,
|
||||
&adapter_key);
|
||||
|
||||
if (status != ERROR_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
list<string> devices;
|
||||
|
||||
while (true) {
|
||||
char enum_name[256];
|
||||
char unit_string[256];
|
||||
HKEY unit_key;
|
||||
char component_id_string[] = "ComponentId";
|
||||
char component_id[256];
|
||||
char net_cfg_instance_id_string[] = "NetCfgInstanceId";
|
||||
char net_cfg_instance_id[256];
|
||||
DWORD data_type;
|
||||
|
||||
len = sizeof (enum_name);
|
||||
status = RegEnumKeyEx(
|
||||
adapter_key,
|
||||
i,
|
||||
enum_name,
|
||||
&len,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
if (status != ERROR_SUCCESS)
|
||||
break;
|
||||
|
||||
snprintf (unit_string, sizeof(unit_string), "%s\\%s",
|
||||
ADAPTER_KEY, enum_name);
|
||||
|
||||
status = RegOpenKeyEx(
|
||||
HKEY_LOCAL_MACHINE,
|
||||
unit_string,
|
||||
0,
|
||||
KEY_READ,
|
||||
&unit_key);
|
||||
|
||||
if (status == ERROR_SUCCESS) {
|
||||
len = sizeof (component_id);
|
||||
status = RegQueryValueEx(
|
||||
unit_key,
|
||||
component_id_string,
|
||||
NULL,
|
||||
&data_type,
|
||||
(BYTE *)component_id,
|
||||
&len);
|
||||
|
||||
if (status == ERROR_SUCCESS && data_type == REG_SZ) {
|
||||
len = sizeof (net_cfg_instance_id);
|
||||
status = RegQueryValueEx(
|
||||
unit_key,
|
||||
net_cfg_instance_id_string,
|
||||
NULL,
|
||||
&data_type,
|
||||
(BYTE *)net_cfg_instance_id,
|
||||
&len);
|
||||
|
||||
if (status == ERROR_SUCCESS && data_type == REG_SZ) {
|
||||
if (!strcmp (component_id, TAP_COMPONENT_ID))
|
||||
devices.push_back(net_cfg_instance_id);
|
||||
}
|
||||
}
|
||||
RegCloseKey (unit_key);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
RegCloseKey (adapter_key);
|
||||
|
||||
if (devices.empty())
|
||||
return NULL;
|
||||
|
||||
// The result is a '\0' separated list of strings
|
||||
list<string>::const_iterator it;
|
||||
len = 0;
|
||||
for (it = devices.begin(); it != devices.end(); it++)
|
||||
len += (*it).length() + 1;
|
||||
|
||||
char *names = (char *)malloc(len);
|
||||
if (names) {
|
||||
char *p = names;
|
||||
for (it = devices.begin(); it != devices.end(); it++) {
|
||||
len = (*it).length();
|
||||
strcpy(p, (*it).c_str());
|
||||
p[len] = '\0';
|
||||
p += len + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
@ -47,4 +47,7 @@ class mutex_t {
|
||||
extern const char *ether_name_to_guid(const char *name);
|
||||
extern const char *ether_guid_to_name(const char *guid);
|
||||
|
||||
// Get TAP-Win32 devices (caller free()s returned buffer)
|
||||
extern const char *ether_tap_devices(void);
|
||||
|
||||
#endif // _UTIL_WINDOWS_H
|
||||
|
Loading…
Reference in New Issue
Block a user