| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include <libdex.h> |
| 24 |
|
| 25 |
static DexFuture * |
| 26 |
resolve_address (gpointer user_data) |
| 27 |
{ |
| 28 |
GResolver *resolver = g_resolver_get_default (); |
| 29 |
const char *addr = user_data; |
| 30 |
g_autoptr(GError) error = NULL; |
| 31 |
g_autolist(GInetAddress) addrs = NULL; |
| 32 |
|
| 33 |
addrs = dex_await_boxed (dex_resolver_lookup_by_name (resolver, addr), &error); |
| 34 |
|
| 35 |
if (error != NULL) |
| 36 |
{ |
| 37 |
g_printerr ("%s: %s\n", addr, error->message); |
| 38 |
return NULL; |
| 39 |
} |
| 40 |
|
| 41 |
for (const GList *iter = addrs; iter; iter = iter->next) |
| 42 |
{ |
| 43 |
GInetAddress *inet_address = iter->data; |
| 44 |
g_autofree char *str = g_inet_address_to_string (inet_address); |
| 45 |
|
| 46 |
g_print ("%s has address %s\n", addr, str); |
| 47 |
} |
| 48 |
|
| 49 |
return NULL; |
| 50 |
} |
| 51 |
|
| 52 |
static DexFuture * |
| 53 |
quit_cb (DexFuture *completed, |
| 54 |
gpointer user_data) |
| 55 |
{ |
| 56 |
GMainLoop *main_loop = user_data; |
| 57 |
g_main_loop_quit (main_loop); |
| 58 |
return NULL; |
| 59 |
} |
| 60 |
|
| 61 |
int |
| 62 |
main (int argc, |
| 63 |
char *argv[]) |
| 64 |
{ |
| 65 |
g_autoptr(GMainLoop) main_loop = g_main_loop_new (NULL, FALSE); |
| 66 |
g_autoptr(GPtrArray) futures = g_ptr_array_new (); |
| 67 |
g_autoptr(DexFuture) future = NULL; |
| 68 |
|
| 69 |
dex_init (); |
| 70 |
|
| 71 |
if (argc < 2) |
| 72 |
{ |
| 73 |
g_printerr ("usage: %s HOSTNAME...\n", argv[0]); |
| 74 |
return 1; |
| 75 |
} |
| 76 |
|
| 77 |
for (guint i = 1; i < argc; i++) |
| 78 |
{ |
| 79 |
const char *addr = argv[i]; |
| 80 |
|
| 81 |
g_ptr_array_add (futures, |
| 82 |
dex_scheduler_spawn (NULL, 0, resolve_address, g_strdup (addr), g_free)); |
| 83 |
} |
| 84 |
|
| 85 |
future = dex_future_allv ((DexFuture **)futures->pdata, futures->len); |
| 86 |
future = dex_future_finally (future, quit_cb, main_loop, NULL); |
| 87 |
|
| 88 |
g_main_loop_run (main_loop); |
| 89 |
|
| 90 |
return 0; |
| 91 |
} |