142 char buf[INET6_ADDRSTRLEN];
149 if (
record->data.raw.data_len !=
sizeof(
struct in_addr))
150 format =
"<invalid>";
152 format = inet_ntop (AF_INET,
record->data.raw.data,
buf,
sizeof(
buf));
156 if (
record->data.raw.data_len !=
sizeof(
struct in6_addr))
157 format =
"<invalid>";
159 format = inet_ntop (AF_INET6,
record->data.raw.data,
buf,
sizeof(
buf));
165 format =
record->data.hostname;
169 if (NULL ==
record->data.soa)
170 format =
"<invalid>";
174 "origin: %s, mail: %s, serial = %u, refresh = %u s, retry = %u s, expire = %u s, minimum = %u s",
177 (
unsigned int)
record->data.soa->serial,
178 (
unsigned int)
record->data.soa->refresh,
179 (
unsigned int)
record->data.soa->retry,
180 (
unsigned int)
record->data.soa->expire,
181 (
unsigned int)
record->data.soa->minimum_ttl);
187 if (
record->data.mx == NULL)
188 format =
"<invalid>";
193 record->data.mx->preference,
200 if (NULL ==
record->data.srv)
201 format =
"<invalid>";
205 "priority %u, weight = %u, port = %u, target = %s",
206 (
unsigned int)
record->data.srv->priority,
207 (
unsigned int)
record->data.srv->weight,
208 (
unsigned int)
record->data.srv->port,
209 record->data.srv->target);
217 (
unsigned int)
record->data.raw.data_len,
218 (
char*)
record->data.raw.data);
223 format =
"<payload>";
227 "\t\t%s %s: %s = %s (%u s)\n",
265 size_t request_length,
268 static const char *return_codes[] = {
269 "No error",
"Format error",
"Server failure",
"Name error",
270 "Not implemented",
"Refused",
"YXDomain",
"YXRRset",
271 "NXRRset",
"NOT AUTH",
"NOT ZONE",
"<invalid>",
272 "<invalid>",
"<invalid>",
"<invalid>",
"<invalid>"
274 static const char *op_codes[] = {
275 "Query",
"Inverse query",
"Status",
"<invalid>",
276 "<invalid>",
"<invalid>",
"<invalid>",
"<invalid>",
277 "<invalid>",
"<invalid>",
"<invalid>",
"<invalid>",
278 "<invalid>",
"<invalid>",
"<invalid>",
"<invalid>"
286 fprintf (stderr,
"Received malformed DNS packet!\n");
292 "%s with ID: %5u Flags: %s%s%s%s%s%s, Return Code: %s, Opcode: %s\n",
293 p->flags.query_or_response ?
"Response" :
"Query",
295 p->flags.recursion_desired ?
"RD " :
"",
296 p->flags.message_truncated ?
"MT " :
"",
297 p->flags.authoritative_answer ?
"AA " :
"",
298 p->flags.checking_disabled ?
"CD " :
"",
299 p->flags.authenticated_data ?
"AD " :
"",
300 p->flags.recursion_available ?
"RA " :
"",
301 return_codes[
p->flags.return_code & 15],
302 op_codes[
p->flags.opcode & 15]);
303 if (
p->num_queries > 0)
306 for (i = 0; i <
p->num_queries; i++)
309 if (
p->num_answers > 0)
312 for (i = 0; i <
p->num_answers; i++)
314 fprintf (stdout,
"\n");
343 run (
void *cls,
char *
const *
args,
const char *cfgfile,
365 main (
int argc,
char *
const *argv)
387 (
"Monitor DNS queries."),
options,
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
#define gettext_noop(String)
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static void do_disconnect(void *cls)
Shutdown.
static const char * get_type(uint16_t type)
Convert numeric DNS record type to a string.
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 const char * get_class(uint16_t class)
Convert numeric DNS record class to a string.
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 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 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 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.
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
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.
#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_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.
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 request is given to other clients or the glob...
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.
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(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,...
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
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.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model