-
Notifications
You must be signed in to change notification settings - Fork 0
/
readfile.c
82 lines (61 loc) · 1.28 KB
/
readfile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
struct contents {
char vicip[40];
char vicmc[32];
char vicpt[32];
char attip[32];
char attmc[32];
char attpt[32];
char repvicip[32];
char repvicmc[32];
char repattip[32];
char repattmc[32];
char interface[32];
char timing[32];
};
// Replace newline with null character
void rmnl(char *s) {
while ( *s != '\n' && *s != '\0' )
s++;
*s = '\0';
}
struct contents *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);
}
fgets(p->vicip, 34, input);
rmnl(p->vicip);
/*
fscanf(input, p->vicmc);
fscanf(input, p->vicpt);
fscanf(input, p->attip);
fscanf(input, p->attmc);
fscanf(input, p->attpt);
fscanf(input, p->repvicip);
fscanf(input, p->repvicmc);
fscanf(input, p->repattip);
fscanf(input, p->repattmc);
fscanf(input, p->interface);
fscanf(input, p->timing);
*/
return p;
}
int main(int argc, char *argv[]) {
if(argc !=2){
fprintf(stderr, "USAGE: ./executable <config file>\n");
return(-1);
}
char *file;
file = argv[1];
struct contents *s;
s = readcfg(file);
printf("%s\n", s->vicip);
return(0);
}