GNUnet 0.22.2
gnunet-zonewalk.c File Reference
#include "platform.h"
#include <gnunet_util_lib.h>
Include dependency graph for gnunet-zonewalk.c:

Go to the source code of this file.

Data Structures

struct  Request
 Request we should make. More...
 

Macros

#define THRESH   20
 Maximum number of queries pending at the same time. More...
 
#define TIME_THRESH   10
 TIME_THRESH is in usecs. More...
 
#define MAX_RETRIES   5
 How often do we retry a query before giving up for good? More...
 

Functions

static void process_record (struct Request *req, struct GNUNET_DNSPARSER_Record *rec)
 We received rec for req. More...
 
static void process_result (void *cls, const struct GNUNET_TUN_DnsHeader *dns, size_t dns_len)
 Function called with the result of a DNS resolution. More...
 
static int submit_req (struct Request *req)
 Submit a request to DNS unless we need to slow down because we are at the rate limit. More...
 
static void process_queue (void *cls)
 Process as many requests as possible from the queue. More...
 
static void do_shutdown (void *cls)
 Clean up and terminate the process. More...
 
static void run (void *cls)
 Process requests from the queue, then if the queue is not empty, try again. More...
 
static void queue (const char *hostname)
 Add hostname to the list of requests to be made. More...
 
int main (int argc, char **argv)
 Call with IP address of resolver to query. More...
 

Variables

static struct GNUNET_DNSSTUB_Contextctx
 Context for DNS resolution. More...
 
static unsigned int pending
 The number of queries that are outstanding. More...
 
static unsigned int lookups
 Number of lookups we performed overall. More...
 
static unsigned int failures
 Number of lookups that failed. More...
 
static unsigned int records
 Number of records we found. More...
 
static struct Requestreq_head
 Head of DLL of all requests to perform. More...
 
static struct Requestreq_tail
 Tail of DLL of all requests to perform. More...
 
static struct GNUNET_SCHEDULER_Taskt
 Main task. More...
 

Macro Definition Documentation

◆ THRESH

#define THRESH   20

Maximum number of queries pending at the same time.

Definition at line 124 of file gnunet-zonewalk.c.

◆ TIME_THRESH

#define TIME_THRESH   10

TIME_THRESH is in usecs.

How quickly do we submit fresh queries. Used as an additional throttle.

Definition at line 130 of file gnunet-zonewalk.c.

◆ MAX_RETRIES

#define MAX_RETRIES   5

How often do we retry a query before giving up for good?

Definition at line 135 of file gnunet-zonewalk.c.

Function Documentation

◆ process_record()

static void process_record ( struct Request req,
struct GNUNET_DNSPARSER_Record rec 
)
static

We received rec for req.

Remember the answer.

Parameters
reqrequest
recresponse

Definition at line 145 of file gnunet-zonewalk.c.

147{
148 char buf[INET6_ADDRSTRLEN];
149
150 records++;
151 switch (rec->type)
152 {
154 fprintf (stdout,
155 "%s A %s\n",
156 req->hostname,
157 inet_ntop (AF_INET,
158 rec->data.raw.data,
159 buf,
160 sizeof(buf)));
161 break;
162
164 fprintf (stdout,
165 "%s AAAA %s\n",
166 req->hostname,
167 inet_ntop (AF_INET6,
168 rec->data.raw.data,
169 buf,
170 sizeof(buf)));
171 break;
172
174 fprintf (stdout,
175 "%s NS %s\n",
176 req->hostname,
177 rec->data.hostname);
178 break;
179
181 fprintf (stdout,
182 "%s CNAME %s\n",
183 req->hostname,
184 rec->data.hostname);
185 break;
186
188 fprintf (stdout,
189 "%s MX %u %s\n",
190 req->hostname,
191 (unsigned int) rec->data.mx->preference,
192 rec->data.mx->mxhost);
193 break;
194
196 fprintf (stdout,
197 "%s SOA %s %s %u %u %u %u %u\n",
198 req->hostname,
199 rec->data.soa->mname,
200 rec->data.soa->rname,
201 (unsigned int) rec->data.soa->serial,
202 (unsigned int) rec->data.soa->refresh,
203 (unsigned int) rec->data.soa->retry,
204 (unsigned int) rec->data.soa->expire,
205 (unsigned int) rec->data.soa->minimum_ttl);
206 break;
207
209 fprintf (stdout,
210 "%s SRV %s %u %u %u\n",
211 req->hostname,
212 rec->data.srv->target,
213 rec->data.srv->priority,
214 rec->data.srv->weight,
215 rec->data.srv->port);
216 break;
217
219 fprintf (stdout,
220 "%s URI \"%s\" %u %u\n",
221 req->hostname,
222 rec->data.uri->target,
223 rec->data.uri->priority,
224 rec->data.uri->weight);
225 break;
226
228 fprintf (stdout,
229 "%s PTR %s\n",
230 req->hostname,
231 rec->data.hostname);
232 break;
233
235 fprintf (stdout,
236 "%s TXT %.*s\n",
237 req->hostname,
238 (int) rec->data.raw.data_len,
239 (char *) rec->data.raw.data);
240 break;
241
243 fprintf (stdout,
244 "%s DNAME %s\n",
245 req->hostname,
246 rec->data.hostname);
247 break;
248
249 /* obscure records */
260
261 /* DNSSEC */
270
271 /* DNSSEC payload */
278
279 /* obsolete records */
283 {
284 char *base32;
285
287 rec->data.raw.data_len);
288 fprintf (stdout,
289 "%s (%u) %s\n",
290 req->hostname,
291 rec->type,
292 base32);
293 GNUNET_free (base32);
294 }
295 break;
296
297 default:
298 fprintf (stderr,
299 "Unsupported type %u\n",
300 (unsigned int) rec->type);
301 break;
302 }
303}
static unsigned int records
Number of records we found.
#define GNUNET_DNSPARSER_TYPE_RRSIG
#define GNUNET_DNSPARSER_TYPE_SIG
#define GNUNET_DNSPARSER_TYPE_TKEY
#define GNUNET_DNSPARSER_TYPE_URI
#define GNUNET_DNSPARSER_TYPE_OPENPGPKEY
#define GNUNET_DNSPARSER_TYPE_TA
#define GNUNET_DNSPARSER_TYPE_IPSECKEY
#define GNUNET_DNSPARSER_TYPE_TLSA
#define GNUNET_DNSPARSER_TYPE_DHCID
#define GNUNET_DNSPARSER_TYPE_NSEC3
#define GNUNET_DNSPARSER_TYPE_SRV
#define GNUNET_DNSPARSER_TYPE_SSHFP
#define GNUNET_DNSPARSER_TYPE_SOA
#define GNUNET_DNSPARSER_TYPE_CERT
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_NSEC3PARAM
#define GNUNET_DNSPARSER_TYPE_SMIMEA
#define GNUNET_DNSPARSER_TYPE_NSEC
#define GNUNET_DNSPARSER_TYPE_DS
#define GNUNET_DNSPARSER_TYPE_PTR
#define GNUNET_DNSPARSER_TYPE_HIP
#define GNUNET_DNSPARSER_TYPE_DNSKEY
#define GNUNET_DNSPARSER_TYPE_TSIG
#define GNUNET_DNSPARSER_TYPE_NS
#define GNUNET_DNSPARSER_TYPE_NAPTR
#define GNUNET_DNSPARSER_TYPE_CNAME
#define GNUNET_DNSPARSER_TYPE_DNAME
#define GNUNET_DNSPARSER_TYPE_LOC
#define GNUNET_DNSPARSER_TYPE_RP
#define GNUNET_DNSPARSER_TYPE_CDS
#define GNUNET_DNSPARSER_TYPE_APL
#define GNUNET_DNSPARSER_TYPE_AAAA
#define GNUNET_DNSPARSER_TYPE_AFSDB
#define GNUNET_DNSPARSER_TYPE_KEY
#define GNUNET_DNSPARSER_TYPE_KX
#define GNUNET_DNSPARSER_TYPE_MX
#define GNUNET_DNSPARSER_TYPE_TXT
#define GNUNET_DNSPARSER_TYPE_CDNSKEY
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:787
char * mxhost
Name of the mail server.
uint16_t preference
Preference for this entry (lower value is higher preference).
void * data
Binary record data.
size_t data_len
Number of bytes in data.
struct GNUNET_DNSPARSER_SoaRecord * soa
SOA data for SOA records.
struct GNUNET_DNSPARSER_SrvRecord * srv
SRV data for SRV records.
struct GNUNET_DNSPARSER_MxRecord * mx
MX data for MX records.
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
union GNUNET_DNSPARSER_Record::@20 data
Payload of the record (which one of these is valid depends on the 'type').
struct GNUNET_DNSPARSER_UriRecord * uri
URI data for URI records.
uint32_t retry
Time interval that should elapse before a failed refresh should be retried.
char * mname
The domainname of the name server that was the original or primary source of data for this zone.
uint32_t refresh
Time interval before the zone should be refreshed.
uint32_t minimum_ttl
The bit minimum TTL field that should be exported with any RR from this zone.
char * rname
A domainname which specifies the mailbox of the person responsible for this zone.
uint32_t expire
Time value that specifies the upper limit on the time interval that can elapse before the zone is no ...
uint32_t serial
The version number of the original copy of the zone.
uint16_t port
TCP or UDP port of the service.
uint16_t weight
Relative weight for records with the same priority.
uint16_t priority
Preference for this entry (lower value is higher preference).
char * target
Hostname offering the service.
uint16_t priority
Preference for this entry (lower value is higher preference).
uint16_t weight
Relative weight for records with the same priority.
char * target
URI of the target, where the URI is as specified in RFC 3986.
char * hostname
Hostname we are resolving, allocated at the end of this struct (optimizing memory consumption by redu...

References GNUNET_DNSPARSER_RawRecord::data, GNUNET_DNSPARSER_Record::data, GNUNET_DNSPARSER_RawRecord::data_len, GNUNET_DNSPARSER_SoaRecord::expire, GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_DNSPARSER_TYPE_AFSDB, GNUNET_DNSPARSER_TYPE_APL, GNUNET_DNSPARSER_TYPE_CDNSKEY, GNUNET_DNSPARSER_TYPE_CDS, GNUNET_DNSPARSER_TYPE_CERT, GNUNET_DNSPARSER_TYPE_CNAME, GNUNET_DNSPARSER_TYPE_DHCID, GNUNET_DNSPARSER_TYPE_DNAME, GNUNET_DNSPARSER_TYPE_DNSKEY, GNUNET_DNSPARSER_TYPE_DS, GNUNET_DNSPARSER_TYPE_HIP, GNUNET_DNSPARSER_TYPE_IPSECKEY, GNUNET_DNSPARSER_TYPE_KEY, GNUNET_DNSPARSER_TYPE_KX, GNUNET_DNSPARSER_TYPE_LOC, GNUNET_DNSPARSER_TYPE_MX, GNUNET_DNSPARSER_TYPE_NAPTR, GNUNET_DNSPARSER_TYPE_NS, GNUNET_DNSPARSER_TYPE_NSEC, GNUNET_DNSPARSER_TYPE_NSEC3, GNUNET_DNSPARSER_TYPE_NSEC3PARAM, GNUNET_DNSPARSER_TYPE_OPENPGPKEY, GNUNET_DNSPARSER_TYPE_PTR, GNUNET_DNSPARSER_TYPE_RP, GNUNET_DNSPARSER_TYPE_RRSIG, GNUNET_DNSPARSER_TYPE_SIG, GNUNET_DNSPARSER_TYPE_SMIMEA, GNUNET_DNSPARSER_TYPE_SOA, GNUNET_DNSPARSER_TYPE_SRV, GNUNET_DNSPARSER_TYPE_SSHFP, GNUNET_DNSPARSER_TYPE_TA, GNUNET_DNSPARSER_TYPE_TKEY, GNUNET_DNSPARSER_TYPE_TLSA, GNUNET_DNSPARSER_TYPE_TSIG, GNUNET_DNSPARSER_TYPE_TXT, GNUNET_DNSPARSER_TYPE_URI, GNUNET_free, GNUNET_STRINGS_data_to_string_alloc(), Request::hostname, GNUNET_DNSPARSER_Record::hostname, GNUNET_DNSPARSER_SoaRecord::minimum_ttl, GNUNET_DNSPARSER_SoaRecord::mname, GNUNET_DNSPARSER_Record::mx, GNUNET_DNSPARSER_MxRecord::mxhost, GNUNET_DNSPARSER_SrvRecord::port, GNUNET_DNSPARSER_MxRecord::preference, GNUNET_DNSPARSER_SrvRecord::priority, GNUNET_DNSPARSER_UriRecord::priority, GNUNET_DNSPARSER_Record::raw, records, GNUNET_DNSPARSER_SoaRecord::refresh, GNUNET_DNSPARSER_SoaRecord::retry, GNUNET_DNSPARSER_SoaRecord::rname, GNUNET_DNSPARSER_SoaRecord::serial, GNUNET_DNSPARSER_Record::soa, GNUNET_DNSPARSER_Record::srv, GNUNET_DNSPARSER_SrvRecord::target, GNUNET_DNSPARSER_UriRecord::target, GNUNET_DNSPARSER_Record::type, GNUNET_DNSPARSER_Record::uri, GNUNET_DNSPARSER_SrvRecord::weight, and GNUNET_DNSPARSER_UriRecord::weight.

Referenced by process_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_result()

static void process_result ( void *  cls,
const struct GNUNET_TUN_DnsHeader dns,
size_t  dns_len 
)
static

Function called with the result of a DNS resolution.

Parameters
clsclosure with the struct Request
dnsdns response, never NULL
dns_lennumber of bytes in dns

Definition at line 314 of file gnunet-zonewalk.c.

317{
318 struct Request *req = cls;
320
321 if (NULL == dns)
322 {
323 /* stub gave up */
324 pending--;
326 "Stub gave up on DNS reply for `%s'\n",
327 req->hostname);
329 req_tail,
330 req);
331 if (req->issue_num > MAX_RETRIES)
332 {
333 failures++;
334 GNUNET_free (req->hostname);
335 GNUNET_free (req->raw);
336 GNUNET_free (req);
337 return;
338 }
340 req_tail,
341 req);
342 req->rs = NULL;
343 return;
344 }
345 if (req->id != dns->id)
346 return;
347 pending--;
349 req->rs = NULL;
351 req_tail,
352 req);
353 p = GNUNET_DNSPARSER_parse ((const char *) dns,
354 dns_len);
355 if (NULL == p)
356 {
358 "Failed to parse DNS reply for `%s'\n",
359 req->hostname);
360 if (req->issue_num > MAX_RETRIES)
361 {
362 failures++;
363 GNUNET_free (req->hostname);
364 GNUNET_free (req->raw);
365 GNUNET_free (req);
366 return;
367 }
369 req_tail,
370 req);
371 return;
372 }
373 for (unsigned int i = 0; i < p->num_answers; i++)
374 {
375 struct GNUNET_DNSPARSER_Record *rs = &p->answers[i];
376
377 process_record (req,
378 rs);
379 }
380 for (unsigned int i = 0; i < p->num_authority_records; i++)
381 {
382 struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i];
383
384 process_record (req,
385 rs);
386 }
387 for (unsigned int i = 0; i < p->num_additional_records; i++)
388 {
389 struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i];
390
391 process_record (req,
392 rs);
393 }
395 GNUNET_free (req->hostname);
396 GNUNET_free (req->raw);
397 GNUNET_free (req);
398}
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
static unsigned int pending
The number of queries that are outstanding.
static struct Request * req_tail
Tail of DLL of all requests to perform.
static struct Request * req_head
Head of DLL of all requests to perform.
#define MAX_RETRIES
How often do we retry a query before giving up for good?
static unsigned int failures
Number of lookups that failed.
static void process_record(struct Request *req, struct GNUNET_DNSPARSER_Record *rec)
We received rec for req.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:950
struct GNUNET_DNSPARSER_Packet * GNUNET_DNSPARSER_parse(const char *udp_payload, size_t udp_payload_length)
Parse a UDP payload of a DNS packet in to a nice struct for further processing and manipulation.
Definition: dnsparser.c:729
void GNUNET_DNSSTUB_resolve_cancel(struct GNUNET_DNSSTUB_RequestSocket *rs)
Cancel DNS resolution.
Definition: dnsstub.c:562
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_ERROR
Easy-to-process, parsed version of a DNS packet.
A DNS response record.
uint16_t id
Unique identifier for the request/response.
Request we should make.
void * raw
Raw DNS query.
struct GNUNET_DNSSTUB_RequestSocket * rs
Socket used to make the request, NULL if not active.
uint16_t id
random 16-bit DNS query identifier.
unsigned int issue_num
How often did we issue this query? (And failed, reset to zero once we were successful....

References failures, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_parse(), GNUNET_DNSSTUB_resolve_cancel(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, Request::hostname, Request::id, GNUNET_TUN_DnsHeader::id, Request::issue_num, MAX_RETRIES, p, pending, process_record(), Request::raw, req_head, req_tail, and Request::rs.

Referenced by submit_req().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ submit_req()

static int submit_req ( struct Request req)
static

Submit a request to DNS unless we need to slow down because we are at the rate limit.

Parameters
reqrequest to submit
Returns
GNUNET_OK if request was submitted GNUNET_NO if request was already submitted GNUNET_SYSERR if we are at the rate limit

Definition at line 411 of file gnunet-zonewalk.c.

412{
413 static struct timeval last_request;
414 struct timeval now;
415
416 if (NULL != req->rs)
417 return GNUNET_NO; /* already submitted */
418 gettimeofday (&now,
419 NULL);
420 if ((((now.tv_sec - last_request.tv_sec) == 0) &&
421 ((now.tv_usec - last_request.tv_usec) < TIME_THRESH)) ||
422 (pending >= THRESH))
423 return GNUNET_SYSERR;
424 GNUNET_assert (NULL == req->rs);
426 req->raw,
427 req->raw_len,
429 req);
430 GNUNET_assert (NULL != req->rs);
431 req->issue_num++;
432 last_request = now;
433 lookups++;
434 pending++;
435 req->time = time (NULL);
436 return GNUNET_OK;
437}
#define THRESH
Maximum number of queries pending at the same time.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static unsigned int lookups
Number of lookups we performed overall.
static void process_result(void *cls, const struct GNUNET_TUN_DnsHeader *dns, size_t dns_len)
Function called with the result of a DNS resolution.
#define TIME_THRESH
TIME_THRESH is in usecs.
struct GNUNET_DNSSTUB_RequestSocket * GNUNET_DNSSTUB_resolve(struct GNUNET_DNSSTUB_Context *ctx, const void *request, size_t request_len, GNUNET_DNSSTUB_ResultCallback rc, void *rc_cls)
Perform DNS resolution using our default IP from init.
Definition: dnsstub.c:526
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
time_t time
When did we last issue this request?
size_t raw_len
Number of bytes in raw.

References ctx, GNUNET_assert, GNUNET_DNSSTUB_resolve(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, Request::issue_num, lookups, pending, process_result(), Request::raw, Request::raw_len, Request::rs, THRESH, Request::time, and TIME_THRESH.

Referenced by process_queue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_queue()

static void process_queue ( void *  cls)
static

Process as many requests as possible from the queue.

Parameters
clsNULL

Definition at line 446 of file gnunet-zonewalk.c.

447{
448 (void) cls;
449 t = NULL;
450 for (struct Request *req = req_head;
451 NULL != req;
452 req = req->next)
453 {
454 if (GNUNET_SYSERR == submit_req (req))
455 break;
456 }
457 if (NULL != req_head)
460 NULL);
461 else
463}
static void process_queue(void *cls)
Process as many requests as possible from the queue.
static struct GNUNET_SCHEDULER_Task * t
Main task.
static int submit_req(struct Request *req)
Submit a request to DNS unless we need to slow down because we are at the rate limit.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1277
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct Request * next
Active requests are kept in a DLL.

References GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_TIME_UNIT_MILLISECONDS, Request::next, process_queue(), req_head, submit_req(), and t.

Referenced by process_queue(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Clean up and terminate the process.

Parameters
clsNULL

Definition at line 472 of file gnunet-zonewalk.c.

473{
474 (void) cls;
475 if (NULL != t)
476 {
478 t = NULL;
479 }
481 ctx = NULL;
482}
void GNUNET_DNSSTUB_stop(struct GNUNET_DNSSTUB_Context *ctx)
Cleanup DNSSTUB resolver.
Definition: dnsstub.c:705
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980

References ctx, GNUNET_DNSSTUB_stop(), GNUNET_SCHEDULER_cancel(), and t.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls)
static

Process requests from the queue, then if the queue is not empty, try again.

Parameters
clsNULL

Definition at line 492 of file gnunet-zonewalk.c.

493{
494 (void) cls;
495
497 NULL);
499 NULL);
500}
static void do_shutdown(void *cls)
Clean up and terminate the process.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1339
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1304

References do_shutdown(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), process_queue(), and t.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue()

static void queue ( const char *  hostname)
static

Add hostname to the list of requests to be made.

Parameters
hostnamename to resolve

Definition at line 509 of file gnunet-zonewalk.c.

510{
513 struct Request *req;
514 char *raw;
515 size_t raw_size;
516 int ret;
517
518 if (GNUNET_OK !=
520 {
522 "Refusing invalid hostname `%s'\n",
523 hostname);
524 return;
525 }
526 q.name = (char *) hostname;
528 q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
529
530 memset (&p,
531 0,
532 sizeof(p));
533 p.num_queries = 1;
534 p.queries = &q;
536 UINT16_MAX);
538 UINT16_MAX,
539 &raw,
540 &raw_size);
541 if (GNUNET_OK != ret)
542 {
543 if (GNUNET_NO == ret)
546 "Failed to pack query for hostname `%s'\n",
547 hostname);
548 return;
549 }
550
551 req = GNUNET_new (struct Request);
552 req->hostname = strdup (hostname);
553 req->raw = raw;
554 req->raw_len = raw_size;
555 req->id = p.id;
557 req_tail,
558 req);
559}
static int ret
Final status code.
Definition: gnunet-arm.c:93
static int raw
raw output
Definition: gnunet-gns.c:78
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
int GNUNET_DNSPARSER_check_name(const char *name)
Check if a hostname in UTF-8 format can be coded into valid IDNA.
Definition: dnsparser.c:79
int GNUNET_DNSPARSER_pack(const struct GNUNET_DNSPARSER_Packet *p, uint16_t max, char **buf, size_t *buf_length)
Given a DNS packet p, generate the corresponding UDP payload.
Definition: dnsparser.c:1400
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_TUN_DNS_CLASS_INTERNET
A few common DNS classes (ok, only one is common, but I list a couple more to make it clear what we'r...

References GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_DNSPARSER_check_name(), GNUNET_DNSPARSER_pack(), GNUNET_DNSPARSER_TYPE_NS, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_TUN_DNS_CLASS_INTERNET, Request::hostname, Request::id, p, q, raw, Request::raw, Request::raw_len, req_head, req_tail, and ret.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Call with IP address of resolver to query.

Parameters
argcshould be 2
argv[1]should contain IP address
Returns
0 on success

Definition at line 570 of file gnunet-zonewalk.c.

572{
573 char hn[256];
574
575 if (2 != argc)
576 {
577 fprintf (stderr,
578 "Missing required configuration argument\n");
579 return -1;
580 }
582 if (NULL == ctx)
583 {
584 fprintf (stderr,
585 "Failed to initialize GNUnet DNS STUB\n");
586 return 1;
587 }
588 if (GNUNET_OK !=
590 argv[1]))
591 {
592 fprintf (stderr,
593 "Failed to use `%s' for DNS resolver\n",
594 argv[1]);
595 return 1;
596 }
597
598 while (NULL !=
599 fgets (hn,
600 sizeof(hn),
601 stdin))
602 {
603 if (strlen (hn) > 0)
604 hn[strlen (hn) - 1] = '\0'; /* eat newline */
605 queue (hn);
606 }
608 NULL);
609 fprintf (stderr,
610 "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n",
611 lookups,
612 records,
613 failures,
614 pending);
615 return 0;
616}
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
static void run(void *cls)
Process requests from the queue, then if the queue is not empty, try again.
struct GNUNET_DNSSTUB_Context * GNUNET_DNSSTUB_start(unsigned int num_sockets)
Start a DNS stub resolver.
Definition: dnsstub.c:586
int GNUNET_DNSSTUB_add_dns_ip(struct GNUNET_DNSSTUB_Context *ctx, const char *dns_ip)
Add nameserver for use by the DNSSTUB.
Definition: dnsstub.c:613
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:725

References ctx, failures, GNUNET_DNSSTUB_add_dns_ip(), GNUNET_DNSSTUB_start(), GNUNET_OK, GNUNET_SCHEDULER_run(), Request::hn, lookups, pending, queue(), records, and run().

Here is the call graph for this function:

Variable Documentation

◆ ctx

struct GNUNET_DNSSTUB_Context* ctx
static

Context for DNS resolution.

Definition at line 84 of file gnunet-zonewalk.c.

Referenced by do_shutdown(), main(), and submit_req().

◆ pending

unsigned int pending
static

The number of queries that are outstanding.

Definition at line 89 of file gnunet-zonewalk.c.

Referenced by main(), process_result(), and submit_req().

◆ lookups

unsigned int lookups
static

Number of lookups we performed overall.

Definition at line 94 of file gnunet-zonewalk.c.

Referenced by main(), and submit_req().

◆ failures

unsigned int failures
static

Number of lookups that failed.

Definition at line 99 of file gnunet-zonewalk.c.

Referenced by main(), and process_result().

◆ records

unsigned int records
static

Number of records we found.

Definition at line 104 of file gnunet-zonewalk.c.

Referenced by main(), and process_record().

◆ req_head

struct Request* req_head
static

Head of DLL of all requests to perform.

Definition at line 109 of file gnunet-zonewalk.c.

Referenced by process_queue(), process_result(), and queue().

◆ req_tail

struct Request* req_tail
static

Tail of DLL of all requests to perform.

Definition at line 114 of file gnunet-zonewalk.c.

Referenced by process_result(), and queue().

◆ t

struct GNUNET_SCHEDULER_Task* t
static

Main task.

Definition at line 119 of file gnunet-zonewalk.c.

Referenced by do_shutdown(), process_queue(), and run().