-
Notifications
You must be signed in to change notification settings - Fork 1
/
dnstest.c
49 lines (44 loc) · 1.28 KB
/
dnstest.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
/*
* This file is part of dnspq.
*
* dnspq is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* dnspq is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dnspq. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <netdb.h>
const char *pools[] = {
"xxxx",
"yyyy",
"zzzz"
};
const char domain[] = ".some-pool";
const size_t poolsnr = sizeof(pools) / sizeof(*pools);
int main() {
struct hostent *he;
char pool[256];
int last_addr = 0;
int i;
size_t dups = 0;
for (i = 0; i < 100000; i++) {
snprintf(pool, sizeof(pool), "%s%s", pools[i % poolsnr], domain);
if ((he = gethostbyname(pool)) != NULL) {
if (*((int *)he->h_addr) == last_addr)
dups++;
last_addr = *((int *)he->h_addr);
} else {
printf("error resolving %s\n", pool);
}
}
printf("dups: %zd\n", dups);
return 0;
}