mirror of
https://github.com/kanjitalk755/macemu.git
synced 2025-08-10 09:25:03 +00:00
added port forwarding for Windows
This commit is contained in:
@@ -471,10 +471,6 @@ if [[ "x$WANT_GTK" = "xgtk" ]]; then
|
|||||||
AM_PATH_GTK(1.2.0, [
|
AM_PATH_GTK(1.2.0, [
|
||||||
GUI_CFLAGS="$GTK_CFLAGS"
|
GUI_CFLAGS="$GTK_CFLAGS"
|
||||||
GUI_LIBS="$GTK_LIBS"
|
GUI_LIBS="$GTK_LIBS"
|
||||||
dnl somehow, <gnome-i18n.h> would redefine gettext() to nothing if
|
|
||||||
dnl ENABLE_NLS is not set, thusly conflicting with C++ <string> which
|
|
||||||
dnl includes <libintl.h>
|
|
||||||
AM_GNU_GETTEXT
|
|
||||||
B2_PATH_GNOMEUI([
|
B2_PATH_GNOMEUI([
|
||||||
AC_DEFINE(HAVE_GNOMEUI, 1, [Define if libgnomeui is available.])
|
AC_DEFINE(HAVE_GNOMEUI, 1, [Define if libgnomeui is available.])
|
||||||
GUI_CFLAGS="$GUI_CFLAGS $GNOMEUI_CFLAGS"
|
GUI_CFLAGS="$GUI_CFLAGS $GNOMEUI_CFLAGS"
|
||||||
|
@@ -42,6 +42,7 @@
|
|||||||
// somehow util_windows undefines min
|
// somehow util_windows undefines min
|
||||||
#define min(x,y) ((x) < (y) ? (x) : (y))
|
#define min(x,y) ((x) < (y) ? (x) : (y))
|
||||||
#include "libslirp.h"
|
#include "libslirp.h"
|
||||||
|
#include "ctl.h"
|
||||||
|
|
||||||
// Define to let the slirp library determine the right timeout for select()
|
// Define to let the slirp library determine the right timeout for select()
|
||||||
#define USE_SLIRP_TIMEOUT 1
|
#define USE_SLIRP_TIMEOUT 1
|
||||||
@@ -200,6 +201,8 @@ static int16 ether_do_add_multicast(uint8 *addr);
|
|||||||
static int16 ether_do_del_multicast(uint8 *addr);
|
static int16 ether_do_del_multicast(uint8 *addr);
|
||||||
static int16 ether_do_write(uint32 arg);
|
static int16 ether_do_write(uint32 arg);
|
||||||
static void ether_do_interrupt(void);
|
static void ether_do_interrupt(void);
|
||||||
|
static void slirp_add_redirs();
|
||||||
|
static int slirp_add_redir(const char *redir_str);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -263,6 +266,7 @@ bool ether_init(void)
|
|||||||
WarningAlert(GetString(STR_SLIRP_NO_DNS_FOUND_WARN));
|
WarningAlert(GetString(STR_SLIRP_NO_DNS_FOUND_WARN));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
slirp_add_redirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open ethernet device
|
// Open ethernet device
|
||||||
@@ -1640,6 +1644,97 @@ static void ether_do_interrupt(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function for port forwarding
|
||||||
|
static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
|
||||||
|
{
|
||||||
|
const char *p, *p1;
|
||||||
|
int len;
|
||||||
|
p = *pp;
|
||||||
|
p1 = strchr(p, sep);
|
||||||
|
if (!p1)
|
||||||
|
return -1;
|
||||||
|
len = p1 - p;
|
||||||
|
p1++;
|
||||||
|
if (buf_size > 0) {
|
||||||
|
if (len > buf_size - 1)
|
||||||
|
len = buf_size - 1;
|
||||||
|
memcpy(buf, p, len);
|
||||||
|
buf[len] = '\0';
|
||||||
|
}
|
||||||
|
*pp = p1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up port forwarding for slirp
|
||||||
|
static void slirp_add_redirs()
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
const char *str;
|
||||||
|
while ((str = PrefsFindString("redir", index++)) != NULL) {
|
||||||
|
slirp_add_redir(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a port forward/redirection for slirp
|
||||||
|
static int slirp_add_redir(const char *redir_str)
|
||||||
|
{
|
||||||
|
// code adapted from qemu source
|
||||||
|
struct in_addr guest_addr = {0};
|
||||||
|
int host_port, guest_port;
|
||||||
|
const char *p;
|
||||||
|
char buf[256];
|
||||||
|
int is_udp;
|
||||||
|
char *end;
|
||||||
|
char str[256];
|
||||||
|
|
||||||
|
p = redir_str;
|
||||||
|
if (!p || get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
|
||||||
|
goto fail_syntax;
|
||||||
|
}
|
||||||
|
if (!strcmp(buf, "tcp") || buf[0] == '\0') {
|
||||||
|
is_udp = 0;
|
||||||
|
} else if (!strcmp(buf, "udp")) {
|
||||||
|
is_udp = 1;
|
||||||
|
} else {
|
||||||
|
goto fail_syntax;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
|
||||||
|
goto fail_syntax;
|
||||||
|
}
|
||||||
|
host_port = strtol(buf, &end, 0);
|
||||||
|
if (*end != '\0' || host_port < 1 || host_port > 65535) {
|
||||||
|
goto fail_syntax;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
|
||||||
|
goto fail_syntax;
|
||||||
|
}
|
||||||
|
// 0.0.0.0 doesn't seem to work, so default to a client address
|
||||||
|
// if none is specified
|
||||||
|
if (buf[0] == '\0' ?
|
||||||
|
!inet_pton(AF_INET, CTL_LOCAL, &guest_addr) :
|
||||||
|
!inet_pton(AF_INET, buf, &guest_addr)) {
|
||||||
|
goto fail_syntax;
|
||||||
|
}
|
||||||
|
|
||||||
|
guest_port = strtol(p, &end, 0);
|
||||||
|
if (*end != '\0' || guest_port < 1 || guest_port > 65535) {
|
||||||
|
goto fail_syntax;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slirp_redir(is_udp, host_port, guest_addr, guest_port) < 0) {
|
||||||
|
sprintf(str, "could not set up host forwarding rule '%s'", redir_str);
|
||||||
|
WarningAlert(str);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail_syntax:
|
||||||
|
sprintf(str, "invalid host forwarding rule '%s'", redir_str);
|
||||||
|
WarningAlert(str);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#pragma optimize("",on)
|
#pragma optimize("",on)
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user