-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInfra.c
executable file
·114 lines (91 loc) · 2.31 KB
/
Infra.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "Data.h"
#include "Cfg.h"
#include "Infra.h"
extern int errno;
extern int debug;
/* Return n-bit field of x that begins at position p
* Kernighan & Ritchie (1988)
*/
unsigned getbits(unsigned x, int p, int n)
{
return (x >> (p + 1 - n)) & ~(~0 << n);
}
void knowLayerTwo(char *dname)
{
DIR *dir;
struct dirent *dep;
char *file;
struct Prot *pr;
file = (char *)calloc(1024, sizeof(char));
if ((dir = opendir(dname)) == NULL) {
fprintf(stderr, "Layer II Knowledge Base Directory %s failed: %s\n",
dname, strerror(errno));
exit(-1);
}
while((dep = readdir(dir)) != NULL) {
if (strcmp(".", dep->d_name) == 0 || strcmp("..", dep->d_name) == 0)
continue;
pr = (struct Prot *)malloc(sizeof(prot));
sprintf(file, "%s/%s", dname, dep->d_name);
if (debug)
printf("Examining Layer II file %s...\n", dep->d_name);
loadConfig(pr, file);
ltwo[pr->id] = pr;
}
free(file);
}
void knowLayerThree(char *dname)
{
DIR *dir;
struct dirent *dep;
char *file;
struct Prot *pr;
file = (char *)calloc(1024, sizeof(char));
if ((dir = opendir(dname)) == NULL) {
fprintf(stderr, "Layer III Knowledge Base Directory %s failed: %s\n",
dname, strerror(errno));
exit(-1);
}
while((dep = readdir(dir)) != NULL) {
if (strcmp(".", dep->d_name) == 0 || strcmp("..", dep->d_name) == 0)
continue;
pr = (struct Prot *)malloc(sizeof(prot));
sprintf(file, "%s/%s", dname, dep->d_name);
if (debug)
printf("Examining Layer III file %s...\n", dep->d_name);
loadConfig(pr, file);
lthree[pr->id] = pr;
}
free(file);
}
void knowLayerFour(char *dname)
{
DIR *dir;
struct dirent *dep;
char *file;
struct Prot *pr;
file = (char *)calloc(1024, sizeof(char));
if ((dir = opendir(dname)) == NULL) {
fprintf(stderr, "Layer IV Knowledge Base Directory %s failed: %s\n",
dname, strerror(errno));
exit(-1);
}
while((dep = readdir(dir)) != NULL) {
if (strcmp(".", dep->d_name) == 0 || strcmp("..", dep->d_name) == 0)
continue;
pr = (struct Prot *)malloc(sizeof(prot));
sprintf(file, "%s/%s", dname, dep->d_name);
if (debug)
printf("Examining Layer IV file %s...\n", dep->d_name);
loadConfig(pr, file);
lfour[pr->id] = pr;
}
free(file);
}