GNUnet  0.11.x
Macros | Functions | Variables
gnunet-resolver.c File Reference

tool to test resolver More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_resolver_service.h"
Include dependency graph for gnunet-resolver.c:

Go to the source code of this file.

Macros

#define GET_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 

Functions

static void print_hostname (void *cls, const char *hostname)
 Prints each hostname obtained from DNS. More...
 
static void print_sockaddr (void *cls, const struct sockaddr *addr, socklen_t addrlen)
 Callback function to display address. More...
 
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. More...
 
int main (int argc, char *const *argv)
 The main function to access GNUnet's DNS resolver. More...
 

Variables

static int reverse
 Flag for reverse lookup. More...
 

Detailed Description

tool to test resolver

Author
Christian Grothoff

Definition in file gnunet-resolver.c.

Macro Definition Documentation

◆ GET_TIMEOUT

Definition at line 30 of file gnunet-resolver.c.

Referenced by run().

Function Documentation

◆ print_hostname()

static void print_hostname ( void *  cls,
const char *  hostname 
)
static

Prints each hostname obtained from DNS.

Parameters
clsclosure (unused)
hostnameone of the names for the host, NULL on the last call to the callback

Definition at line 46 of file gnunet-resolver.c.

Referenced by run().

48 {
49  (void) cls;
50  if (NULL == hostname)
51  return;
52  fprintf (stdout,
53  "%s\n",
54  hostname);
55 }
static char * hostname
Our hostname; we give this to all the peers we start.
Here is the caller graph for this function:

◆ print_sockaddr()

static void print_sockaddr ( void *  cls,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

Callback function to display address.

Parameters
clsclosure (unused)
addrone of the addresses of the host, NULL for the last address
addrlenlength of the address

Definition at line 66 of file gnunet-resolver.c.

References GNUNET_a2s().

Referenced by run().

69 {
70  (void) cls;
71  if (NULL == addr)
72  return;
73  fprintf (stdout,
74  "%s\n",
75  GNUNET_a2s (addr,
76  addrlen));
77 }
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

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

References GET_TIMEOUT, GNUNET_RESOLVER_hostname_get(), GNUNET_RESOLVER_ip_get(), GNUNET_YES, print_hostname(), print_sockaddr(), and reverse.

Referenced by main().

93 {
94  const struct sockaddr *sa;
95  socklen_t salen;
96  struct sockaddr_in v4;
97  struct sockaddr_in6 v6;
98 
99  (void) cls;
100  (void) cfgfile;
101  (void) cfg;
102  if (NULL == args[0])
103  return;
104  if (! reverse)
105  {
107  AF_UNSPEC,
108  GET_TIMEOUT,
110  NULL);
111  return;
112  }
113 
114  sa = NULL;
115  memset (&v4, 0, sizeof(v4));
116  v4.sin_family = AF_INET;
117 #if HAVE_SOCKADDR_IN_SIN_LEN
118  v4.sin_len = sizeof(v4);
119 #endif
120  if (1 == inet_pton (AF_INET,
121  args[0],
122  &v4.sin_addr))
123  {
124  sa = (struct sockaddr *) &v4;
125  salen = sizeof(v4);
126  }
127  memset (&v6, 0, sizeof(v6));
128  v6.sin6_family = AF_INET6;
129 #if HAVE_SOCKADDR_IN_SIN_LEN
130  v6.sin6_len = sizeof(v6);
131 #endif
132  if (1 == inet_pton (AF_INET6,
133  args[0],
134  &v6.sin6_addr))
135  {
136  sa = (struct sockaddr *) &v6;
137  salen = sizeof(v6);
138  }
139  if (NULL == sa)
140  {
141  fprintf (stderr,
142  "`%s' is not a valid IP: %s\n",
143  args[0],
144  strerror (errno));
145  return;
146  }
147  GNUNET_RESOLVER_hostname_get (sa, salen,
148  GNUNET_YES,
149  GET_TIMEOUT,
151  NULL);
152 }
static void print_sockaddr(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Callback function to display address.
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_ip_get(const char *hostname, int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *callback_cls)
Convert a string to one or more IP addresses.
Definition: resolver_api.c:939
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_hostname_get(const struct sockaddr *sa, socklen_t salen, int do_resolve, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_HostnameCallback callback, void *cls)
Perform a reverse DNS lookup.
static int reverse
Flag for reverse lookup.
static void print_hostname(void *cls, const char *hostname)
Prints each hostname obtained from DNS.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GET_TIMEOUT
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function to access GNUnet's DNS resolver.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 163 of file gnunet-resolver.c.

References gettext_noop, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), ret, reverse, and run().

164 {
167  "reverse",
168  gettext_noop ("perform a reverse lookup"),
169  &reverse),
171  };
172  int ret;
173 
174  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
175  return 2;
176 
177  ret = (GNUNET_OK ==
178  GNUNET_PROGRAM_run (argc, argv, "gnunet-resolver [hostname]",
179  gettext_noop ("Use build-in GNUnet stub resolver"),
180  options, &run, NULL)) ? 0 : 1;
181  GNUNET_free ((void*) argv);
182  return ret;
183 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1438
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 ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static int reverse
Flag for reverse lookup.
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 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, parse options).
Definition: program.c:367
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ reverse

int reverse
static

Flag for reverse lookup.

Definition at line 35 of file gnunet-resolver.c.

Referenced by main(), and run().