pmlag

Poor man's link aggregation
git clone git://git.finwo.net/app/pmlag
Log | Files | Refs | LICENSE

main.c (1211B)


      1 #include <stdint.h>
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 
      5 #include "cofyc/argparse.h"
      6 
      7 #include "util/config.h"
      8 
      9 static const char *const usage[] = {
     10   __NAME " [options]",
     11   NULL
     12 };
     13 
     14 int main(int argc, const char **argv) {
     15   char *config_file="/etc/pmlag/pmlag.conf";
     16 
     17   // Seed random
     18   uint32_t seed;
     19   FILE* urandom = fopen("/dev/urandom", "r");
     20   fread(&seed, sizeof(uint32_t), 1, urandom);
     21   fclose(urandom);
     22   srand(seed);
     23 
     24   // Define which options we support
     25   struct argparse_option options[] = {
     26     OPT_HELP(),
     27     OPT_STRING('c', "config", &config_file, "Config file to use", NULL, 0, 0),
     28     OPT_END(),
     29   };
     30 
     31   // Parse command line arguments
     32   struct argparse argparse;
     33   argparse_init(&argparse, options, usage, 0);
     34   argparse_describe(&argparse, NULL,
     35       // TODO: format to terminal width
     36       "\n" __NAME " is a tool for bonding network interfaces together when the "
     37       "hardware\non the other side of the cable(s) doesn't support it."
     38       "\n"
     39   );
     40   argc = argparse_parse(&argparse, argc, argv);
     41 
     42   struct pmlag_configuration *config = calloc(1, sizeof(struct pmlag_configuration));
     43 
     44   printf("Config file: %s\n", config_file);
     45   config_load(config_file, config);
     46 
     47   return 0;
     48 }