+static void net_slirp_redir_print(void *opaque, int is_udp,
+ struct in_addr *laddr, u_int lport,
+ struct in_addr *faddr, u_int fport)
+{
+ Monitor *mon = (Monitor *)opaque;
+ uint32_t h_addr;
+ uint32_t g_addr;
+ char buf[16];
+
+ h_addr = ntohl(faddr->s_addr);
+ g_addr = ntohl(laddr->s_addr);
+
+ monitor_printf(mon, " %s |", is_udp ? "udp" : "tcp" );
+ snprintf(buf, 15, "%d.%d.%d.%d", (h_addr >> 24) & 0xff,
+ (h_addr >> 16) & 0xff,
+ (h_addr >> 8) & 0xff,
+ (h_addr) & 0xff);
+ monitor_printf(mon, " %15s |", buf);
+ monitor_printf(mon, " %5d |", fport);
+
+ snprintf(buf, 15, "%d.%d.%d.%d", (g_addr >> 24) & 0xff,
+ (g_addr >> 16) & 0xff,
+ (g_addr >> 8) & 0xff,
+ (g_addr) & 0xff);
+ monitor_printf(mon, " %15s |", buf);
+ monitor_printf(mon, " %5d\n", lport);
+
+}
+
+static void net_slirp_redir_list(Monitor *mon)
+{
+ if (!mon)
+ return;
+
+ monitor_printf(mon, " Prot | Host Addr | HPort | Guest Addr | GPort\n");
+ monitor_printf(mon, " | | | | \n");
+ slirp_redir_loop(net_slirp_redir_print, mon);
+}
+
+static void net_slirp_redir_rm(Monitor *mon, const char *port_str)
+{
+ int host_port;
+ char buf[256] = "";
+ const char *p = port_str;
+ int is_udp = 0;
+ int n;
+
+ if (!mon)
+ return;
+
+ if (!port_str || !port_str[0])
+ goto fail_syntax;
+
+ get_str_sep(buf, sizeof(buf), &p, ':');
+
+ if (!strcmp(buf, "tcp") || buf[0] == '\0') {
+ is_udp = 0;
+ } else if (!strcmp(buf, "udp")) {
+ is_udp = 1;
+ } else {
+ goto fail_syntax;
+ }
+
+ host_port = atoi(p);
+
+ n = slirp_redir_rm(is_udp, host_port);
+
+ monitor_printf(mon, "removed %d redirections to %s port %d\n", n,
+ is_udp ? "udp" : "tcp", host_port);
+ return;
+
+ fail_syntax:
+ monitor_printf(mon, "invalid format\n");
+}
+
+void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2)