2 #include <arpa/nameser.h>
3 #include <lwres/lwres.h>
20 typedef struct ipnode
*iplist
;
28 pthread_mutex_t
*mutexp
;
29 pthread_mutex_t
*mutexoutput
;
31 char *dnsrbls
[MAXRBLS
];
32 int numrbls
, numthreads
, numqueries
;
36 lwres_context_t
*ctx
= NULL
;
37 lwres_grbnresponse_t
*response
= NULL
;
41 pthread_mutex_lock(mutexp
);
46 pthread_mutex_unlock(mutexp
);
49 //fprintf (stderr, "making query %s\n", tIP->IP); fflush(stderr);
50 if (lwres_context_create(&ctx
, NULL
, NULL
, NULL
, 0) != 0) {
51 fprintf (stderr
, "Couldn't create context\n");
54 lwres_conf_parse(ctx
, lwres_resolv_conf
);
55 //pthread_mutex_lock(mutexoutput);
56 n
= lwres_getrdatabyname(ctx
, tIP
->IP
, ns_c_in
, ns_t_a
, 0, &response
);
57 //pthread_mutex_unlock(mutexoutput);
58 if (n
== LWRES_R_SUCCESS
) {
59 printf ("%s,%d.%d.%d.%d,%d\n", tIP
->IP
,
60 response
->rdatas
[0][0], response
->rdatas
[0][1],
61 response
->rdatas
[0][2], response
->rdatas
[0][3],
63 //fprintf (stderr, "freeing response\n"); fflush(stderr);
64 lwres_grbnresponse_free(ctx
, &response
);
66 //fprintf (stderr, "Nothing found\n");
67 printf ("%s, %s, %d\n", tIP
->IP
, tIP
->IP
, DEFTTL
);
69 //fprintf (stderr, "freeing context\n"); fflush(stderr);
70 lwres_context_destroy(&ctx
);
71 //fprintf (stderr, "done freeing\n"); fflush(stderr);
74 pthread_mutex_lock(mutexp
);
79 pthread_mutex_unlock(mutexp
);
86 while ((fgets(instr
, MAXSTR
, stdin
) != NULL
) && (numrbls
< MAXRBLS
)) {
87 instr
[strlen(instr
)-1] = 0; // strip off newline
88 if (strncmp(instr
, "----------", 10) == 0) {
91 dnsrbls
[numrbls
] = (char *) malloc(strlen(instr
)+1);
92 if (dnsrbls
[numrbls
] == NULL
) {
93 fprintf (stderr
, "Couldn't allocate memory for %d DNS RBLs\n", numrbls
);
96 strcpy (dnsrbls
[numrbls
], instr
);
104 pthread_t threads
[MAXTHREADS
];
111 // for (loop1=0; loop1<numrbls; loop1++)
112 // fprintf (stderr, "%s\n", dnsrbls[loop1]);
113 // fprintf (stderr, "----------\n");
117 while (fgets(instr
, MAXSTR
, stdin
) != NULL
) {
118 instr
[strlen(instr
)-1] = 0;
119 for (loop1
= 0; loop1
< numrbls
; loop1
++) {
120 tIP
= (iplist
)malloc(sizeof(struct ipnode
));
121 tIP
->IP
= (char *)malloc(strlen(instr
)+strlen(dnsrbls
[loop1
])+2);
122 strcpy (tIP
->IP
, instr
);
123 strcat (tIP
->IP
, dnsrbls
[loop1
]);
130 // fprintf (stderr, "%d queries to make\n", numqueries);
132 // while (tIP != NULL) {
133 // fprintf (stderr, "%s\n", tIP->IP);
136 // fprintf (stderr, "done\n");
139 mutexp
=(pthread_mutex_t
*) malloc(sizeof(pthread_mutex_t
));
140 pthread_mutex_init(mutexp
, NULL
);
141 mutexoutput
=(pthread_mutex_t
*) malloc(sizeof(pthread_mutex_t
));
142 pthread_mutex_init(mutexoutput
, NULL
);
144 numthreads
= 0; // number of threads created successfully
145 for (loop1
= 0; ((loop1
<MAXTHREADS
) && (loop1
<numqueries
)); loop1
++) {
146 if (pthread_create(&threads
[loop1
], NULL
,
147 (void *) do_queries
, NULL
) != 0) {
148 fprintf (stderr
, "Couldn't make more than %d threads\n", numthreads
);
155 for (loop1
= 0; loop1
< numthreads
; loop1
++) {
156 pthread_join(threads
[loop1
], NULL
);