int uae_slirp_redir(int is_udp, int host_port, struct in_addr guest_addr, int guest_port) { #ifdef WITH_QEMU_SLIRP if (impl == QEMU_IMPLEMENTATION) { UAE_LOG_STUB(""); return 0; } #endif #ifdef WITH_BUILTIN_SLIRP if (impl == BUILTIN_IMPLEMENTATION) { return slirp_redir(is_udp, host_port, guest_addr, guest_port); } #endif return 0; }
void enet_slirp_start(void) { struct in_addr guest_addr; if (!slirp_inited) { Log_Printf(LOG_WARN, "Starting SLIRP"); #ifndef _WIN32 signal(SIGPIPE, SIG_IGN); #endif slirp_init(); slirpq = QueueCreate(); slirp_inited=1; //host_sleep_ms(500); slirp_mutex=SDL_CreateMutex(); tick_func_handle=SDL_CreateThread(tick_func,"SLiRPTickThread", (void *)NULL); inet_aton("10.0.2.15", &guest_addr); slirp_redir(0, 42323, guest_addr, 23); } }
static co_rc_t parse_redir_param (const char *p) { int iProto, iHostPort, iClientPort; struct in_addr guest_addr; if (!inet_aton(CTL_LOCAL, &guest_addr)) { co_terminal_print("conet-slirp-daemon: slirp redir setup guest_addr failed.\n"); return CO_RC(ERROR); } do { // minimal len is "tcp:x:x" if (strlen (p) < 7) return CO_RC(ERROR); iProto = (memicmp(p, "udp", 3) == 0) ? PARM_SLIRP_REDIR_UDP : PARM_SLIRP_REDIR_TCP; // search the first ':' p = strchr (p, ':'); if (!p) return CO_RC(ERROR); iHostPort = atol(p+1); // search the second ':' p = strchr (p+1, ':'); if (!p) return CO_RC(ERROR); iClientPort = atol(p+1); co_debug("slirp redir %d %d:%d\n", iProto, iHostPort, iClientPort); if (slirp_redir(iProto, iHostPort, guest_addr, iClientPort) < 0) { co_terminal_print("conet-slirp-daemon: slirp redir %d failed.\n", iClientPort); } // Next redirection? p = strchr (p, '/'); } while (p++); return CO_RC(OK); }
int ethernet_open (struct netdriverdata *ndd, void *vsd, void *user, ethernet_gotfunc *gotfunc, ethernet_getfunc *getfunc, int promiscuous) { switch (ndd->type) { case UAENET_SLIRP: case UAENET_SLIRP_INBOUND: { struct ethernet_data *ed = (struct ethernet_data*)vsd; ed->gotfunc = gotfunc; ed->getfunc = getfunc; ed->userdata = user; slirp_data = ed; uae_sem_init (&slirp_sem1, 0, 1); uae_sem_init (&slirp_sem2, 0, 1); slirp_init (); for (int i = 0; i < MAX_SLIRP_REDIRS; i++) { struct slirp_redir *sr = &currprefs.slirp_redirs[i]; if (sr->proto) { struct in_addr a; if (sr->srcport == 0) { inet_aton("10.0.2.15", &a); slirp_redir (0, sr->dstport, a, sr->dstport); } else { #ifdef HAVE_STRUCT_IN_ADDR_S_UN a.S_un.S_addr = sr->addr; #else a.s_addr = sr->addr; #endif slirp_redir (sr->proto == 1 ? 0 : 1, sr->dstport, a, sr->srcport); } } } if (ndd->type == UAENET_SLIRP_INBOUND) { struct in_addr a; inet_aton("10.0.2.15", &a); for (int i = 0; slirp_ports[i]; i++) { int port = slirp_ports[i]; int j; for (j = 0; j < MAX_SLIRP_REDIRS; j++) { struct slirp_redir *sr = &currprefs.slirp_redirs[j]; if (sr->proto && sr->dstport == port) break; } if (j == MAX_SLIRP_REDIRS) slirp_redir (0, port + SLIRP_PORT_OFFSET, a, port); } } netmode = ndd->type; slirp_start (); } return 1; #ifdef WITH_UAENET_PCAP case UAENET_PCAP: if (uaenet_open (vsd, ndd, user, gotfunc, getfunc, promiscuous)) { netmode = ndd->type; return 1; } return 0; #endif } return 0; }