GNUnet 0.22.2
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 31 of file gnunet-resolver.c.

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 47 of file gnunet-resolver.c.

49{
50 (void) cls;
51 if (NULL == hostname)
52 return;
53 fprintf (stdout,
54 "%s\n",
55 hostname);
56}

Referenced by run().

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 67 of file gnunet-resolver.c.

70{
71 (void) cls;
72 if (NULL == addr)
73 return;
74 fprintf (stdout,
75 "%s\n",
76 GNUNET_a2s (addr,
77 addrlen));
78}
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).

References GNUNET_a2s().

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,
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 90 of file gnunet-resolver.c.

94{
95 const struct sockaddr *sa;
96 socklen_t salen;
97 struct sockaddr_in v4;
98 struct sockaddr_in6 v6;
99
100 (void) cls;
101 (void) cfgfile;
102 (void) cfg;
103 if (NULL == args[0])
104 return;
105 if (! reverse)
106 {
108 AF_UNSPEC,
111 NULL);
112 return;
113 }
114
115 sa = NULL;
116 memset (&v4, 0, sizeof(v4));
117 v4.sin_family = AF_INET;
118#if HAVE_SOCKADDR_IN_SIN_LEN
119 v4.sin_len = sizeof(v4);
120#endif
121 if (1 == inet_pton (AF_INET,
122 args[0],
123 &v4.sin_addr))
124 {
125 sa = (struct sockaddr *) &v4;
126 salen = sizeof(v4);
127 }
128 memset (&v6, 0, sizeof(v6));
129 v6.sin6_family = AF_INET6;
130#if HAVE_SOCKADDR_IN_SIN_LEN
131 v6.sin6_len = sizeof(v6);
132#endif
133 if (1 == inet_pton (AF_INET6,
134 args[0],
135 &v6.sin6_addr))
136 {
137 sa = (struct sockaddr *) &v6;
138 salen = sizeof(v6);
139 }
140 if (NULL == sa)
141 {
142 fprintf (stderr,
143 "`%s' is not a valid IP: %s\n",
144 args[0],
145 strerror (errno));
146 return;
147 }
152 NULL);
153}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static void print_sockaddr(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Callback function to display address.
static void print_hostname(void *cls, const char *hostname)
Prints each hostname obtained from DNS.
static int reverse
Flag for reverse lookup.
#define GET_TIMEOUT
@ GNUNET_YES
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:940
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.

References consensus-simulation::args, cfg, GET_TIMEOUT, GNUNET_RESOLVER_hostname_get(), GNUNET_RESOLVER_ip_get(), GNUNET_YES, print_hostname(), print_sockaddr(), and reverse.

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 *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 164 of file gnunet-resolver.c.

165{
168 "reverse",
169 gettext_noop ("perform a reverse lookup"),
170 &reverse),
172 };
173 int ret;
174
175 ret = (GNUNET_OK ==
177 argc, argv,
178 "gnunet-resolver [hostname]",
179 gettext_noop ("Use built-in GNUnet stub resolver"),
180 options,
181 &run, NULL)) ? 0 : 1;
182 return ret;
183}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:74
static int ret
Final status code.
Definition: gnunet-arm.c:93
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.
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.
@ GNUNET_OK
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,...
Definition: program.c:407
Definition of a command line option.

References gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), options, ret, reverse, and run().

Here is the call graph for this function:

Variable Documentation

◆ reverse

int reverse
static

Flag for reverse lookup.

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

Referenced by main(), and run().