--- trunk/src/emul_parse.c 2007/10/08 16:18:22 9 +++ trunk/src/emul_parse.c 2007/10/08 16:18:27 10 @@ -25,13 +25,13 @@ * SUCH DAMAGE. * * - * $Id: emul_parse.c,v 1.29 2005/03/14 19:14:04 debug Exp $ + * $Id: emul_parse.c,v 1.32 2005/06/24 09:33:34 debug Exp $ * * Set up an emulation by parsing a config file. * - * * TODO: This could be extended to support XML config files as well, but - * XML is ugly. + * XML is ugly. It is ugly right now as well. The question is: which + * solution is the least ugly? */ #include @@ -198,6 +198,11 @@ static char cur_net_ipv4net[50]; static char cur_net_ipv4len[50]; +static char cur_net_local_port[10]; +#define MAX_N_REMOTE 20 +#define MAX_REMOTE_LEN 100 +static char *cur_net_remote[MAX_N_REMOTE]; +static int cur_net_n_remote; static char cur_machine_name[50]; static char cur_machine_cpu[50]; @@ -339,8 +344,10 @@ line, EXPECT_LEFT_PARENTHESIS); /* Default net: */ - strcpy(cur_net_ipv4net, "10.0.0.0"); - strcpy(cur_net_ipv4len, "8"); + strlcpy(cur_net_ipv4net, "10.0.0.0", sizeof(cur_net_ipv4net)); + strlcpy(cur_net_ipv4len, "8", sizeof(cur_net_ipv4len)); + strlcpy(cur_net_local_port, "", sizeof(cur_net_local_port)); + cur_net_n_remote = 0; return; } @@ -390,7 +397,9 @@ /* * parse__net(): * - * Simple words: ipv4net, ipv4len + * Simple words: ipv4net, ipv4len, local_port + * + * Complex: add_remote * * TODO: more words? for example an option to disable the gateway? that would * have to be implemented correctly in src/net.c first. @@ -398,6 +407,8 @@ static void parse__net(struct emul *e, FILE *f, int *in_emul, int *line, int *parsestate, char *word, size_t maxbuflen) { + int i; + if (word[0] == ')') { /* Finished with the 'net' section. Let's create the net: */ if (e->net != NULL) { @@ -406,8 +417,14 @@ exit(1); } + if (!cur_net_local_port[0]) + strlcpy(cur_net_local_port, "0", + sizeof(cur_net_local_port)); + e->net = net_init(e, NET_INIT_FLAG_GATEWAY, - cur_net_ipv4net, atoi(cur_net_ipv4len)); + cur_net_ipv4net, atoi(cur_net_ipv4len), + cur_net_remote, cur_net_n_remote, + atoi(cur_net_local_port)); if (e->net == NULL) { fatal("line %i: fatal error: could not create" @@ -415,12 +432,38 @@ exit(1); } + for (i=0; i= MAX_N_REMOTE) { + fprintf(stderr, "too many remote networks\n"); + exit(1); + } + cur_net_remote[cur_net_n_remote] = malloc(MAX_REMOTE_LEN); + if (cur_net_remote[cur_net_n_remote] == NULL) { + fprintf(stderr, "out of memory\n"); + exit(1); + } + read_one_word(f, cur_net_remote[cur_net_n_remote], + MAX_REMOTE_LEN, line, EXPECT_WORD); + cur_net_n_remote ++; + read_one_word(f, word, maxbuflen, line, + EXPECT_RIGHT_PARENTHESIS); + return; + } fatal("line %i: not expecting '%s' in a 'net' section\n", *line, word); exit(1); @@ -440,7 +483,8 @@ struct machine *m; if (!cur_machine_name[0]) - strcpy(cur_machine_name, "no_name"); + strlcpy(cur_machine_name, "no_name", + sizeof(cur_machine_name)); m = emul_add_machine(e, cur_machine_name); @@ -453,30 +497,36 @@ m->cpu_name = strdup(cur_machine_cpu); if (!cur_machine_use_x11[0]) - strcpy(cur_machine_use_x11, "no"); + strlcpy(cur_machine_use_x11, "no", + sizeof(cur_machine_use_x11)); m->use_x11 = parse_on_off(cur_machine_use_x11); if (!cur_machine_slowsi[0]) - strcpy(cur_machine_slowsi, "no"); + strlcpy(cur_machine_slowsi, "no", + sizeof(cur_machine_slowsi)); m->slow_serial_interrupts_hack_for_linux = parse_on_off(cur_machine_slowsi); if (!cur_machine_debugger_on_badaddr[0]) - strcpy(cur_machine_debugger_on_badaddr, "no"); + strlcpy(cur_machine_debugger_on_badaddr, "no", + sizeof(cur_machine_debugger_on_badaddr)); m->single_step_on_bad_addr = parse_on_off(cur_machine_debugger_on_badaddr); if (!cur_machine_prom_emulation[0]) - strcpy(cur_machine_prom_emulation, "yes"); + strlcpy(cur_machine_prom_emulation, "yes", + sizeof(cur_machine_prom_emulation)); m->prom_emulation = parse_on_off(cur_machine_prom_emulation); if (!cur_machine_random_mem[0]) - strcpy(cur_machine_random_mem, "no"); + strlcpy(cur_machine_random_mem, "no", + sizeof(cur_machine_random_mem)); m->random_mem_contents = parse_on_off(cur_machine_random_mem); if (!cur_machine_random_cpu[0]) - strcpy(cur_machine_random_cpu, "no"); + strlcpy(cur_machine_random_cpu, "no", + sizeof(cur_machine_random_cpu)); m->use_random_bootstrap_cpu = parse_on_off(cur_machine_random_cpu); @@ -495,12 +545,14 @@ } if (!cur_machine_bintrans[0]) - strcpy(cur_machine_bintrans, "yes"); + strlcpy(cur_machine_bintrans, "yes", + sizeof(cur_machine_bintrans)); m->bintrans_enable = m->bintrans_enabled_from_start = parse_on_off(cur_machine_bintrans); if (!cur_machine_old_bintrans[0]) - strcpy(cur_machine_old_bintrans, "no"); + strlcpy(cur_machine_old_bintrans, "yes", + sizeof(cur_machine_old_bintrans)); m->old_bintrans_enable = parse_on_off(cur_machine_old_bintrans); if (!m->bintrans_enable && m->old_bintrans_enable) { @@ -518,16 +570,19 @@ atoi(cur_machine_bintrans_size); if (!cur_machine_force_netboot[0]) - strcpy(cur_machine_force_netboot, "no"); + strlcpy(cur_machine_force_netboot, "no", + sizeof(cur_machine_force_netboot)); m->force_netboot = parse_on_off(cur_machine_force_netboot); if (!cur_machine_start_paused[0]) - strcpy(cur_machine_start_paused, "no"); + strlcpy(cur_machine_start_paused, "no", + sizeof(cur_machine_start_paused)); m->start_paused = parse_on_off(cur_machine_start_paused); /* NOTE: Default nr of CPUs is 0: */ if (!cur_machine_ncpus[0]) - strcpy(cur_machine_ncpus, "0"); + strlcpy(cur_machine_ncpus, "0", + sizeof(cur_machine_ncpus)); m->ncpus = atoi(cur_machine_ncpus); if (cur_machine_n_gfx_cards[0]) @@ -546,7 +601,8 @@ /* NOTE: Default nr of CPUs is 0: */ if (!cur_machine_memory[0]) - strcpy(cur_machine_memory, "0"); + strlcpy(cur_machine_memory, "0", + sizeof(cur_machine_memory)); m->physical_ram_in_mb = atoi(cur_machine_memory); if (!cur_machine_x11_scaledown[0])