summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre GRANDIN <pgrandin@users.noreply.github.com>2017-04-29 10:57:42 -0700
committerGitHub <noreply@github.com>2017-04-29 10:57:42 -0700
commit283ae3e7e4b1479a5e3b135bbc4ebb0c5a25c113 (patch)
tree7a2f955638045468b5b2208f99dbd6c57ef16b49
parent658060b86596efb270cfcd21e118a9071f5d5092 (diff)
downloadnavit-283ae3e7e4b1479a5e3b135bbc4ebb0c5a25c113.tar.gz
Add network info menu in gui/internal for Linux (#228)
* Add network info menu in gui/internal for Linux * Ensures that ifaddrs.h is available before enabling network info code * Add network info to sailfish config as well * Prevent linker and undefined reference errors for non-unix builds
-rwxr-xr-xCMakeLists.txt6
-rw-r--r--config.h.cmake2
-rwxr-xr-xcontrib/sailfish/navit.xml1
-rw-r--r--navit/gui/internal/gui_internal_command.c60
-rw-r--r--navit/navit_shipped.xml1
5 files changed, 69 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 310639de1..e4e5ed7aa 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -495,6 +495,7 @@ add_feature(USE_ROUTING "default" TRUE)
add_feature(USE_SVG "default" TRUE)
add_feature(SVG2PNG "default" TRUE)
add_feature(SAMPLE_MAP "default" TRUE)
+add_feature(NETWORK_INFO "default" FALSE)
IF(NOT svg2png_scaling)
IF(NOT ANDROID)
@@ -657,6 +658,11 @@ if (SAMPLE_MAP)
endif(CMAKE_CROSSCOMPILING)
endif(SAMPLE_MAP)
+check_symbol_exists (getifaddrs "sys/types.h;ifaddrs.h" HAS_IFADDRS)
+if (HAS_IFADDRS)
+ cfg_feature(NETWORK_INFO "ifaddrs.h found" TRUE)
+endif(HAS_IFADDRS)
+
if(ANDROID)
find_program(ANDROID_LOCATION NAMES android android.bat)
find_program(ANT_LOCATION NAMES ant)
diff --git a/config.h.cmake b/config.h.cmake
index 4774efbaf..fa096b58c 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -93,3 +93,5 @@
#cmakedefine HAVE_SHMEM 1
#cmakedefine HAVE_IMLIB2 1
+
+#cmakedefine HAS_IFADDRS 1
diff --git a/contrib/sailfish/navit.xml b/contrib/sailfish/navit.xml
index 831043d4d..89b58835c 100755
--- a/contrib/sailfish/navit.xml
+++ b/contrib/sailfish/navit.xml
@@ -93,6 +93,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>
diff --git a/navit/gui/internal/gui_internal_command.c b/navit/gui/internal/gui_internal_command.c
index d26bd677d..43e788c10 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"
+#if HAS_IFADDRS
+#include <ifaddrs.h>
+#include <arpa/inet.h>
+#endif
extern char *version;
@@ -776,6 +780,56 @@ 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)
+{
+#if HAS_IFADDRS
+ 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);
+#else
+ dbg(lvl_error, "Cannot show network info: ifaddr.h not found\n");
+#endif
+}
+
static void
gui_internal_cmd_formerdests(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
{
@@ -1220,6 +1274,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 +1335,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)},
-
+#if HAS_IFADDRS
+ {"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>