static int _do_redirects (Slirp *slirp, struct redir_tcp_udp *head) { struct in_addr host_addr; int ret = 0; host_addr.s_addr = htonl(INADDR_ANY); if (head) { ret = _do_redirects (slirp, head->next); if (slirp_add_hostfwd (slirp, head->is_udp, host_addr, head->lport, head->inaddr, head->port) < 0) { sim_printf("Can't establish redirector for: redir %s =%d:%s:%d\n", tcpudp[head->is_udp], head->lport, inet_ntoa(head->inaddr), head->port); ++ret; } } return ret; }
static void redirPort(Slirp *slirp, const char *p, const char *procName) { do { Bool udp = False; char buf[256], *r; struct in_addr host_addr; struct in_addr guest_addr; int host_port, guest_port; memset(&host_addr, 0, sizeof(host_addr)); host_addr.s_addr = INADDR_ANY; if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) redirStringError("expected tcp: or udp:"); if (!strcmp(buf, "tcp")) { udp = 0; } else if (!strcmp(buf, "udp")) { udp = 1; } else { vmiMessage("F", PREFIX, "expected tcp: or udp:"); } if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) redirStringError("expected host port number"); host_port = strtol(buf, &r, 0); if (r == buf) redirStringError("expected host port number"); if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) redirStringError("expected guest ip address"); if (buf[0] == '\0') { strcpy(buf, "10.0.2.15"); } else { if (!inet_aton(buf, &guest_addr)) redirStringError("expected guest ip address"); } guest_port = strtol(p, &r, 0); if (r == p) redirStringError("expected guest port number"); Uns32 actualHostPort = 0; int res = slirp_add_hostfwd( slirp, udp, host_addr, host_port, guest_addr, guest_port, &actualHostPort ); if (res >= 0) { vmiMessage("I", PREFIX, "%s Listening on host %s port:%d. Redirecting to guest port:%d", procName, udp ? "udp" : "tcp", // host_port, actualHostPort, guest_port ); } else { vmiMessage("W", PREFIX, "Failed to set up redirection on port %d", guest_port); } p = r; if(*p != ',') break; p++; } while (1); }