2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport/gnunet-transport-list-connections.c
24 * @brief Print all known address information about other peers.
26 * Lists all peers and connections that the transport service is
27 * aware of. Pretty prints addresses, peer id's, and whether
28 * or not the _address_ is connected. Note that these are not
29 * core level connections, only transport level connections.
31 * @author Nathan Evans
34 #include "gnunet_crypto_lib.h"
35 #include "gnunet_configuration_lib.h"
36 #include "gnunet_getopt_lib.h"
37 #include "gnunet_transport_service.h"
38 #include "gnunet_program_lib.h"
41 static int no_resolve;
44 static unsigned int connection_count;
47 static const struct GNUNET_CONFIGURATION_Handle *cfg;
50 * Function to call with a human-readable format of an address
53 * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
56 process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
57 const char *transport, const void *addr, size_t addrlen)
62 if ((peer != NULL) || (transport != NULL) ||
63 ((addr != NULL) && (addrlen > 0)))
64 fprintf (stdout, "Peer `%s' plugin: `%s' address `%s'\n",
65 (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>",
66 (transport != NULL) ? transport : "<unknown>", ((addr != NULL) &&
70 "how do i resolve the name without transport service?" :
76 * Main function that will be run by the scheduler.
79 * @param args remaining command-line arguments
80 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
81 * @param c configuration
84 run (void *cls, char *const *args, const char *cfgfile,
85 const struct GNUNET_CONFIGURATION_Handle *c)
91 fprintf (stderr, _("Invalid command line argument `%s'\n"), args[0]);
95 GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES,
96 &process_address, NULL);
101 * The main function to obtain peer information.
103 * @param argc number of arguments from the command line
104 * @param argv command line arguments
105 * @return 0 ok, 1 on error
108 main (int argc, char *const *argv)
110 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
111 {'n', "numeric", NULL,
112 gettext_noop ("don't resolve host names"),
113 0, &GNUNET_GETOPT_set_one, &no_resolve},
114 GNUNET_GETOPT_OPTION_END
117 GNUNET_PROGRAM_run (argc, argv, "gnunet-list-connections",
119 ("Print information about connected peers."),
120 options, &run, NULL)) ? 0 : 1;
123 /* end of gnunet-transport-list-connections.c */