summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Grandin <grandinp@gmail.com>2017-04-28 11:09:05 -0700
committerPierre Grandin <grandinp@gmail.com>2017-04-28 11:09:05 -0700
commit0844c020dc324a3ffff97fc86f080ffb7cf8f936 (patch)
treea19b535acbc5b48c7b0a6b9a26a163996dc0ef83
parent658060b86596efb270cfcd21e118a9071f5d5092 (diff)
downloadnavit-0844c020dc324a3ffff97fc86f080ffb7cf8f936.tar.gz
Add network info menu in gui/internal for Linux
-rw-r--r--navit/gui/internal/gui_internal_command.c56
-rw-r--r--navit/navit_shipped.xml1
2 files changed, 56 insertions, 1 deletions
diff --git a/navit/gui/internal/gui_internal_command.c b/navit/gui/internal/gui_internal_command.c
index d26bd677d..4ba81c03f 100644
--- a/navit/gui/internal/gui_internal_command.c
+++ b/navit/gui/internal/gui_internal_command.c
@@ -36,6 +36,10 @@
#include "gui_internal_search.h"
#include "gui_internal_poi.h"
#include "gui_internal_command.h"
+#ifndef OS_WINDOWS
+#include <ifaddrs.h>
+#include <arpa/inet.h>
+#endif
extern char *version;
@@ -776,6 +780,52 @@ gui_internal_cmd2_locale(struct gui_priv *this, char *function, struct attr **in
graphics_draw_mode(this->gra, draw_mode_end);
}
+/**
+ * @brief display basic networking information
+ *
+ * @return nothing
+ *
+ * This function displays basic networking information, currently
+ * only the interface name and the associated IP address(es).
+ * Currently only works on non Windows systems.
+ *
+ */
+static void
+gui_internal_cmd2_network_info(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
+{
+ struct widget *menu,*wb,*w;
+ char *text;
+
+ graphics_draw_mode(this->gra, draw_mode_begin);
+ menu=gui_internal_menu(this, _("Network info"));
+ menu->spx=this->spacing*10;
+ wb=gui_internal_box_new(this, gravity_top_center|orientation_vertical|flags_expand|flags_fill);
+ gui_internal_widget_append(menu, wb);
+
+ struct ifaddrs *addrs, *tmp;
+ getifaddrs(&addrs);
+ tmp = addrs;
+
+ while (tmp)
+ {
+ if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET)
+ {
+ struct sockaddr_in *pAddr = (struct sockaddr_in *)tmp->ifa_addr;
+ if(g_ascii_strncasecmp(tmp->ifa_name,"lo",2 ) ) {
+ text=g_strdup_printf("%s: %s", tmp->ifa_name, inet_ntoa(pAddr->sin_addr));
+ gui_internal_widget_append(wb, w=gui_internal_label_new(this, text));
+ w->flags=gravity_bottom_center|orientation_horizontal|flags_fill;
+ g_free(text);
+ }
+ }
+ tmp = tmp->ifa_next;
+ }
+ freeifaddrs(addrs);
+
+ gui_internal_menu_render(this);
+ graphics_draw_mode(this->gra, draw_mode_end);
+}
+
static void
gui_internal_cmd_formerdests(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
{
@@ -1220,6 +1270,8 @@ gui_internal_cmd2(struct gui_priv *this, char *function, struct attr **in, struc
gui_internal_cmd_formerdests(this, function, in, out, valid);
else if(!strcmp(function, "locale"))
gui_internal_cmd2_locale(this, function, in, out, valid);
+ else if(!strcmp(function, "network_info"))
+ gui_internal_cmd2_network_info(this, function, in, out, valid);
else if(!strcmp(function, "position"))
gui_internal_cmd2_position(this, function, in, out, valid);
else if(!strcmp(function, "pois"))
@@ -1279,7 +1331,9 @@ static struct command_table commands[] = {
{"waypoints",command_cast(gui_internal_cmd2)},
{"write",command_cast(gui_internal_cmd_write)},
{"about",command_cast(gui_internal_cmd2)},
-
+#ifndef OS_WINDOWS
+ {"network_info",command_cast(gui_internal_cmd2)},
+#endif
};
void
diff --git a/navit/navit_shipped.xml b/navit/navit_shipped.xml
index eb2191963..d627594a0 100644
--- a/navit/navit_shipped.xml
+++ b/navit/navit_shipped.xml
@@ -92,6 +92,7 @@ Navigation</text></img>
</a>
<a name='Tools'><text>Tools</text>
<img src='gui_actions' onclick='locale()'><text>Show Locale</text></img>
+ <img src='gui_tools' onclick='network_info()'><text>Network info</text></img>
</a>
<a name='Route'><text>Route</text>
<img src='gui_actions' onclick='route_description()'><text>Description</text></img>