]> git.sesse.net Git - jam/commitdiff
Generalize the file reading, and store the IPs in memory.
authorsgunderson@bigfoot.com <>
Wed, 31 Jan 2007 18:21:23 +0000 (19:21 +0100)
committersgunderson@bigfoot.com <>
Wed, 31 Jan 2007 18:21:23 +0000 (19:21 +0100)
jam.c

diff --git a/jam.c b/jam.c
index 8a6414675b25199efa38fd2ececb938b56efd4bd..a80246a1ca5553243d38ab8d6b7c36d9658fbe60 100644 (file)
--- 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);