-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_dns.c
More file actions
153 lines (141 loc) · 2.59 KB
/
check_dns.c
File metadata and controls
153 lines (141 loc) · 2.59 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "utils.h"
#define HOST 1
#define CNAME 2
#define MX 3
int isnumber(char *line);
static struct nlist *hashtab[HASHSIZE];
struct nlist {
char *firstColumn;
char *secondColumn;
struct nlist *next;
};
int main()
{
char * db = "db.10.10.150";//"db.dbs.co.il";/**/
FILE *fp;
char str[sysconf(_SC_LINE_MAX)];
char *tmp;
int size;
if ((fp=fopen(db, "r")) == NULL)
{
printf("file not found\n");
return(1);
}
while(fgets(str, sysconf(_SC_LINE_MAX), fp) != NULL)
{
if(isin(str) == 1)
{
size = strlen(str);
int i=0;
//printf("%c",str[i]);
}
}
fclose(fp);
return 0;
}
int isnumber(char *line)
{
char *str;
int count=0;
int alpha = -1;
int word=0;
str = (char *)malloc(sizeof(line));
for (*str = line[0];*str!='\0';str++, count++)
{
if(isspace(*str))
continue;
if(!isdigit(*str)
{
word = 1;
break;
}
}
}
struct nlist *install(char *firstColumn, char *secondColumn)
{
struct nlist *np;
unsigned hashval;
if ((np = lookup(firstColumn)) == NULL) /* not found */
{
np = (struct nlist *) malloc(sizeof(*np));
if (np == NULL || (np->firstColumn = strdup(firstColumn)) == NULL)
return NULL;
hashval = hash(firstColumn);
np->next = hashtab[hashval];
hashtab[hashval] = np;
}
else /* already there */
free((void *) np->secondColumn); /*free previous secondColumn */
if ((np->secondColumn = strdup(secondColumn)) == NULL)
return NULL;
return np;
}
struct nlist *lookup(char *s)
{
struct nlist *np;
for (np = hashtab[hash(s)]; np != NULL; np = np->next)
if (strcmp(s, np->firstColumn) == 0)
return np; /* found */
return NULL; /* not found */
}
unsigned hash(char *s)
{
unsigned hashval;
for (hashval = 0; *s != '\0'; s++)
hashval = *s + 31 * hashval;
return hashval % HASHSIZE;
}
int isin(char *line)
{
char *cur;
cur = strdup(line);
while(*cur != '\0')
{
if (*cur == '@')
return 0;
if (*cur == ';')
return 0;
if (*cur == 'I')
{
cur++;
if (*cur++ == 'N')
{
while(isspace(*cur))
cur++;
if (*cur == 'N')
{
cur++;
if (*cur == 'S')
return 0;
}
else if (*cur == 'C')
{
cur++;
if (*cur == 'N')
{
cur++;
if (*cur == 'A')
{
cur++;
if (*cur == 'M')
{
cur++;
if (*cur == 'E')
return 2;
}
}
}
}
else if (*cur == 'M')
{
cur++;
if (*cur == 'X')
return 3;
}
return 1;
}
}
cur++;
}
return 0;
}