Esempio n. 1
0
/*
 * void init_node( int argc, char *argv[] )
 *
 * Takes care of initializing a node for an IRC server
 * from the given command line arguments
 */
void init_node( int argc, char *argv[] )
{
    int i;

    if( argc < 3 )
    {
        printf( "%s <nodeID> <config file>\n", argv[0] );
        exit( 0 );
    }

    /* Parse nodeID */
    curr_nodeID = atol( argv[1] );

    /* Store  */
    rt_parse_config_file(argv[0], &curr_node_config_file, argv[2] );

    /* Get config file for this node */
    for( i = 0; i < curr_node_config_file.size; ++i )
        if( curr_node_config_file.entries[i].nodeID == curr_nodeID )
             curr_node_config_entry = &curr_node_config_file.entries[i];

    /* Check to see if nodeID is valid */
    if( !curr_node_config_entry )
    {
        printf( "Invalid NodeID\n" );
        exit(1);
    }
}
Esempio n. 2
0
/*
* void init_node( int argc, char *argv[] )
*
* Takes care of initializing a node for an IRC server
* from the given command line arguments
*/
void
init_node(char *nodeID, char *config_file)
{
  int i;

  curr_nodeID = atol(nodeID);
  rt_parse_config_file("sircd", &curr_node_config_file, config_file );

  /* Get config file for this node */
  for( i = 0; i < curr_node_config_file.size; ++i )
  if( curr_node_config_file.entries[i].nodeID == curr_nodeID )
  curr_node_config_entry = &curr_node_config_file.entries[i];

  /* Check to see if nodeID is valid */
  if( !curr_node_config_entry )
  {
    printf( "Invalid NodeID\n" );
    exit(1);
  }
}
Esempio n. 3
0
void rt_parse_command_line(rt_args_t *args, int argc, char *const *argv)
{
    int	c, i, found, old_optind;

    /* set defaults for arguments */
    bzero(args, sizeof(rt_args_t));

    args->nodeID = (unsigned long)-1;
    args->advertisement_cycle_time = 30;
    args->neighbor_timeout = 120;
    args->retransmission_timeout = 3;
    args->lsa_timeout = 120;
    
    /* parse command line */
    old_optind = optind;
    found = 0;
    while ((c = getopt(argc, argv, _rt_optstring)) != -1) {
	switch (c) {
	case 'i':
	    parse_long(optarg, &args->nodeID, argv[0], "nodeID");
	    break;
	case 'c':
	    found = 1;
	    rt_parse_config_file(argv[0], &args->config_file, optarg);
	    break;
	case 'G':
	    /* ignore -- this is only for grading */
	    break;
	case 'a':
	    parse_long(optarg, &args->advertisement_cycle_time, argv[0], 
			    "advertisement_cycle_time");
	    break;
	case 'n':
	    parse_long(optarg, &args->neighbor_timeout, argv[0], 
			    "neighbor_timeout");
	    break;
	case 'r':
	    parse_long(optarg, &args->retransmission_timeout, argv[0], 
			    "route_timeout");
	    break;
	case 't':
	    parse_long(optarg, &args->lsa_timeout, argv[0], 
			    "garbage_collect_timeout");
	    break;
	case '?':
	    exit(255);
	default:
	    fprintf(stderr, "%s: unknown argument -%c\n", argv[0], (char)c);
	    exit(255);
	    break;
	}
    }

    /* validate some of the arguments */
    if (args->nodeID == (unsigned long)-1) {
	fprintf(stderr, "%s: nodeID must be specified\n", argv[0]);
	exit(255);
    }
    if (args->neighbor_timeout % args->advertisement_cycle_time != 0) {
	fprintf(stderr, "%s: warning: neighbor_timeout (%lu) is not a "
		"multiple of advertisement_cycle_time (%lu)\n", argv[0], 
		args->neighbor_timeout, args->advertisement_cycle_time);
    }
    if (args->lsa_timeout % args->advertisement_cycle_time != 0) {
	fprintf(stderr, "%s: warning: lsa_timeout (%lu) is not a "
		"multiple of advertisement_cycle_time (%lu)\n", argv[0], 
		args->lsa_timeout, args->advertisement_cycle_time);
    }
    if (!found) {
	fprintf(stderr, "%s: you must specify a config_file\n", argv[0]);
	exit(0);
    }
    if (args->config_file.size < 2) {
	fprintf(stderr, "%s: warning: this node has no neighbors!\n", argv[0]);
    }
    found = 0;
    for (i=0; i<args->config_file.size; i++) {
	if (args->config_file.entries[i].nodeID == args->nodeID) {
	    found = 1;
	    break;
	}
    }
    if (!found) {
	fprintf(stderr, "%s: this node's nodeID (%lu) wasn't in the "
		"config file!\n", argv[0], args->nodeID);
	exit(255);
    }

    /* reset optind in case the caller wants to getopt some more */
    optind = old_optind;
}