void readcfg(char *filename) {
	FILE *input;
	struct contents *p;
	//p = malloc(sizeof(struct contents));
	if((input = fopen(filename, "r")) == NULL){
		fprintf(stderr, "ERROR: fopen()\n");
		exit(-1);
	}
	if ( (err = load_address(input, vip, vhw, vpt, &vad, &vha,1)) < 0 ){
		load_error(err,"Original Victim");
	}
	if ( (err = load_address(input, aip, ahw, apt, &aad, &aha,1)) < 0 ){
		load_error(err,"Original Attacker");
	}
	if ( (err = load_address(input, rvip, rvmc, vpt, &revi_ip, &revi_mac,0)) < 0 ){
		load_error(err,"Replay Victim");
	}
	if ( (err = load_address(input, ratip, ratmac, apt, &reat_ip, &reat_mac,0)) < 0 ){
		load_error(err,"Replay Attacker");
	}
	if ( fgets(iface, sizeof(iface), input) == NULL ) {
		fprintf(stderr, "Interface too large\n");
		exit(-1);
	}
	rmnl(iface);
	if ( fgets(timing, sizeof(timing), input) == NULL ) {
		fprintf(stderr, "Timing in correct\n");
		exit(-1);
	}
	fclose(input);
	return;
}
int load_address(FILE *fp, char *ip, char *hw, char *pt, struct addr *ad, struct addr *ha, int swit) {
  if ( fgets(ip, 32, fp) == NULL ) 
    return(-1);
  rmnl(ip);
  if ( addr_aton(ip, ad) == -1 ) 
    return(-2);

  if ( fgets(hw, 32, fp) == NULL ) 
    return(-3);
  rmnl(hw);
  if ( addr_aton(hw, ha) == -1 ) {
    return(-4);
  }
  if(swit == 1){
     if ( fgets(pt, 32, fp) == NULL ) 
       return(-5);
     rmnl(pt);
  }
  return(0);
}
void readcfg1(char *filename) {
	FILE *input;
	
	if((input = fopen(filename, "r")) == NULL){
		fprintf(stderr, "ERROR: fopen()\n");
		exit(-1);
	}

	// Get victim ip, mac, port
	if ( (err = load_address(input, vip, vhw, vpt, &vad, &vha,1)) < 0 )
		load_error(err,"Original Victim");

	// Get attacker ip, mac, port
	if ( (err = load_address(input, aip, ahw, apt, &aad, &aha,1)) < 0 )
		load_error(err,"Original Attacker");

	// Get replay victim, ip, mac and then add original victim port
	if ( (err = load_address(input, rvip, rvmc, vpt, &revi_ip, &revi_mac,0)) < 0 )
		load_error(err,"Replay Victim");

	// Get replay attacker, ip, mac and then add original attacker port
	if ( (err = load_address(input, ratip, ratmac, apt, &reat_ip, &reat_mac,0)) < 0 )
		load_error(err,"Replay Attacker");

	// Get the interface
	if ( fgets(iface, sizeof(iface), input) == NULL ) {
		fprintf(stderr, "Interface too large\n");
		exit(-1);
	}
	rmnl(iface);

	// Get the timing
	if ( fgets(timing, sizeof(timing), input) == NULL ) {
		fprintf(stderr, "Timing in correct\n");
		exit(-1);
	}
	rmnl(timing);
	fclose(input);
}
Exemple #4
0
static void
fill_in_blanks(void)
{
	int i;
	char *cp;

again:
	if (name[0] != '\0') {
		printf("Entering as '%s'", name);
		if (team != ' ')
			printf(" on team %c.\n", team);
		else
			putchar('\n');
	} else {
		printf("Enter your code name: ");
		if (fgets(name, sizeof(name), stdin) == NULL)
			exit(1);
	}
	rmnl(name);
	if (name[0] == '\0') {
		name[0] = '\0';
		printf("You have to have a code name!\n");
		goto again;
	}
	for (cp = name; *cp != '\0'; cp++)
		if (!isprint((unsigned char)*cp)) {
			name[0] = '\0';
			printf("Illegal character in your code name.\n");
			goto again;
		}
	if (team == ' ') {
		printf("Enter your team (0-9 or nothing): ");
		i = getchar();
		if (isdigit(i))
			team = i;
		while (i != '\n' && i != EOF)
			i = getchar();
	}
}