144 char buf[INET6_ADDRSTRLEN];
151 if (
record->data.raw.data_len !=
sizeof(
struct in_addr))
152 format =
"<invalid>";
154 format = inet_ntop (AF_INET,
record->data.raw.data, buf,
sizeof(buf));
158 if (
record->data.raw.data_len !=
sizeof(
struct in6_addr))
159 format =
"<invalid>";
161 format = inet_ntop (AF_INET6,
record->data.raw.data, buf,
sizeof(buf));
167 format =
record->data.hostname;
171 if (NULL ==
record->data.soa)
172 format =
"<invalid>";
176 "origin: %s, mail: %s, serial = %u, refresh = %u s, retry = %u s, expire = %u s, minimum = %u s",
179 (
unsigned int)
record->data.soa->serial,
180 (
unsigned int)
record->data.soa->refresh,
181 (
unsigned int)
record->data.soa->retry,
182 (
unsigned int)
record->data.soa->expire,
183 (
unsigned int)
record->data.soa->minimum_ttl);
189 if (
record->data.mx == NULL)
190 format =
"<invalid>";
195 record->data.mx->preference,
202 if (NULL ==
record->data.srv)
203 format =
"<invalid>";
207 "priority %u, weight = %u, port = %u, target = %s",
208 (
unsigned int)
record->data.srv->priority,
209 (
unsigned int)
record->data.srv->weight,
210 (
unsigned int)
record->data.srv->port,
211 record->data.srv->target);
217 if (NULL ==
record->data.uri)
218 format =
"<invalid>";
222 "priority %u, weight = %u, target = \"%s\"",
223 (
unsigned int)
record->data.uri->priority,
224 (
unsigned int)
record->data.uri->weight,
225 record->data.uri->target);
234 (
unsigned int)
record->data.raw.data_len,
235 (
char*)
record->data.raw.data);
240 format =
"<payload>";
244 "\t\t%s %s: %s = %s (%u s)\n",
282 size_t request_length,
285 static const char *return_codes[] = {
286 "No error",
"Format error",
"Server failure",
"Name error",
287 "Not implemented",
"Refused",
"YXDomain",
"YXRRset",
288 "NXRRset",
"NOT AUTH",
"NOT ZONE",
"<invalid>",
289 "<invalid>",
"<invalid>",
"<invalid>",
"<invalid>"
291 static const char *op_codes[] = {
292 "Query",
"Inverse query",
"Status",
"<invalid>",
293 "<invalid>",
"<invalid>",
"<invalid>",
"<invalid>",
294 "<invalid>",
"<invalid>",
"<invalid>",
"<invalid>",
295 "<invalid>",
"<invalid>",
"<invalid>",
"<invalid>"
303 fprintf (stderr,
"Received malformed DNS packet!\n");
309 "%s with ID: %5u Flags: %s%s%s%s%s%s, Return Code: %s, Opcode: %s\n",
310 p->flags.query_or_response ?
"Response" :
"Query",
312 p->flags.recursion_desired ?
"RD " :
"",
313 p->flags.message_truncated ?
"MT " :
"",
314 p->flags.authoritative_answer ?
"AA " :
"",
315 p->flags.checking_disabled ?
"CD " :
"",
316 p->flags.authenticated_data ?
"AD " :
"",
317 p->flags.recursion_available ?
"RA " :
"",
318 return_codes[
p->flags.return_code & 15],
319 op_codes[
p->flags.opcode & 15]);
320 if (
p->num_queries > 0)
323 for (i = 0; i <
p->num_queries; i++)
326 if (
p->num_answers > 0)
329 for (i = 0; i <
p->num_answers; i++)
331 fprintf (stdout,
"\n");
360run (
void *cls,
char *
const *
args,
const char *cfgfile,
382main (
int argc,
char *
const *argv)
401 argc, argv,
"gnunet-dns-monitor",
403 (
"Monitor DNS queries."),
options,
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
#define gettext_noop(String)
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static void do_disconnect(void *cls)
Shutdown.
static unsigned int verbosity
Selected level of verbosity.
static void display_record(const struct GNUNET_DNSPARSER_Record *record)
Output the given DNS record to stdout.
static void display_query(const struct GNUNET_DNSPARSER_Query *query)
Output the given DNS query to stdout.
static int ret
Global return value (0 success).
static int inbound_only
Option -i.
static const char * get_class(uint16_t class)
Convert numeric DNS record class to a string.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
static int outbound_only
Option -o.
int main(int argc, char *const *argv)
static const char * get_type(uint16_t type)
Convert numeric DNS record type to a string.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void display_request(void *cls, struct GNUNET_DNS_RequestHandle *rh, size_t request_length, const char *request)
Signature of a function that is called whenever the DNS service encounters a DNS request and needs to...
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_OS_Process * p
Helper process we started.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
API to access the DNS service.
#define GNUNET_DNSPARSER_TYPE_URI
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
#define GNUNET_DNSPARSER_TYPE_SRV
#define GNUNET_DNSPARSER_TYPE_SOA
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_PTR
#define GNUNET_DNSPARSER_TYPE_NS
#define GNUNET_DNSPARSER_TYPE_CNAME
#define GNUNET_DNSPARSER_TYPE_AAAA
#define GNUNET_DNSPARSER_TYPE_MX
#define GNUNET_DNSPARSER_TYPE_TXT
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.
void GNUNET_DNS_disconnect(struct GNUNET_DNS_Handle *dh)
Disconnect from the DNS service.
void GNUNET_DNS_request_forward(struct GNUNET_DNS_RequestHandle *rh)
If a GNUNET_DNS_RequestHandler calls this function, the client has no desire to interfere with the re...
struct GNUNET_DNS_Handle * GNUNET_DNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_DNS_Flags flags, GNUNET_DNS_RequestHandler rh, void *rh_cls)
Connect to the service-dns.
GNUNET_DNS_Flags
Flags that specify when to call the client's handler.
@ GNUNET_DNS_FLAG_RESPONSE_MONITOR
Set this flag to see all requests just before they are returned to the network.
@ GNUNET_DNS_FLAG_REQUEST_MONITOR
Set this flag to see all requests first prior to resolution (for monitoring).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
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,...
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
#define GNUNET_TUN_DNS_CLASS_HESIOD
#define GNUNET_TUN_DNS_CLASS_CHAOS
#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...
Easy-to-process, parsed version of a DNS packet.
struct GNUNET_TUN_DnsFlags flags
Bitfield of DNS flags.
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
char * name
Name of the record that the query is for (0-terminated).
GNUNET_DNS_RequestHandler rh
Function to call to get replies.
Handle to identify an individual DNS request.
Definition of a command line option.
uint64_t rel_value_us
The actual value.