From aac5c9a1e0ab0fdf17c987502c8e288392714055 Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Wed, 31 Jan 2007 19:21:23 +0100 Subject: [PATCH] Generalize the file reading, and store the IPs in memory. --- jam.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jam.c b/jam.c index 8a64146..a80246a 100644 --- a/jam.c +++ b/jam.c @@ -19,7 +19,7 @@ const static struct option longopts[] = { { NULL, 0, NULL, 0 } }; -void read_destination_list(char *filename) +void read_ip_list(char *filename, struct in_addr **addr_list, unsigned *num, unsigned *room) { char buf[256]; FILE *in = fopen(filename, "r"); @@ -58,7 +58,17 @@ void read_destination_list(char *filename) // just pick the first for now memcpy(&addr.s_addr, he->h_addr_list[0], sizeof(addr.s_addr)); - // FIXME: store here + if (*num >= *room) { + if (*room == 0) { + *room = 16; + } else { + *room <<= 1; + } + *addr_list = (struct in_addr *)realloc(*addr_list, *room * sizeof(struct in_addr)); + } + + (*addr_list)[*num] = addr; + ++*num; } fclose(in); @@ -72,7 +82,7 @@ void parse_options(int argc, char **argv) int c = getopt_long(argc, argv, "d:p:", longopts, &option_index); switch (c) { case 'd': - read_destination_list(optarg); + read_ip_list(optarg, &destinations, &num_destinations, &room_destinations); break; case 'p': port = atoi(optarg); -- 2.39.2