Commit 06adb1da authored by Jussi Kukkonen's avatar Jussi Kukkonen

modify the gateway-mac-address hack

Apparently netstat or /proc/net/arp isn't up-to-date
when NetworkManager signals "connection available"

this is a hack until I figure out how to do this
properly
parent 1d98f7e8
......@@ -21,7 +21,7 @@ provider_changed_cb (GeoclueMasterClient *client,
char *description,
gpointer userdata)
{
g_print ("%s provider changed: %s (%s)\n", iface, name, description);
g_print ("%s provider changed: %s\n", iface, name);
}
......
......@@ -20,7 +20,9 @@
#include <config.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <geoclue/gc-provider.h>
#include <geoclue/geoclue-error.h>
......@@ -136,6 +138,8 @@ geoclue_localnet_class_init (GeoclueLocalnetClass *klass)
p_class->shutdown = shutdown;
}
#define MAC_LEN 18
static char *
get_mac_address ()
{
......@@ -145,23 +149,32 @@ get_mac_address ()
* */
FILE *in;
char *mac;
int mac_len = sizeof (char) * 18;
if (!(in = popen ("ROUTER_IP=`netstat -rn | grep '^0.0.0.0 ' | awk '{ print $2 }'` && grep \"^$ROUTER_IP \" /proc/net/arp | awk '{print $4}'", "r"))) {
return NULL;
}
mac = g_malloc (mac_len);
if (fgets (mac, mac_len, in) == NULL) {
g_free (mac);
char mac[MAC_LEN];
int i;
/*for some reason netstat or /proc/net/arp isn't always ready
* when a connection is already up... Try a couple of times */
for (i=0; i<10; i++) {
if (!(in = popen ("ROUTER_IP=`netstat -rn | grep '^0.0.0.0 ' | awk '{ print $2 }'` && grep \"^$ROUTER_IP \" /proc/net/arp | awk '{print $4}'", "r"))) {
g_warning ("popen failed");
return NULL;
}
if (!(fgets (mac, MAC_LEN, in))) {
if (errno != ENOENT && errno != EAGAIN) {
g_debug ("error %d", errno);
return NULL;
}
/* try again */
pclose (in);
g_debug ("trying again...");
usleep (200);
continue;
}
pclose (in);
return NULL;
return g_strdup (mac);
}
pclose (in);
return mac;
return NULL;
}
......
......@@ -9,6 +9,8 @@
#include <config.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <glib-object.h>
#include <dbus/dbus-glib-bindings.h>
......@@ -72,32 +74,43 @@ geoclue_plazes_shutdown (GcIfaceGeoclue *iface,
return TRUE;
}
#define MAC_LEN 18
static char *
get_mac_address ()
{
/* this is an ugly hack, but it seems there is no easy
* ioctl-based way to get the mac address of the router. This
* implementation expects the system to have netstat, grep,
* awk, tr and /proc/net/arp */
* implementation expects the system to have netstat, grep and awk
* */
FILE *in;
char *mac;
int mac_len = sizeof (char) * 18;
if (!(in = popen ("ROUTER_IP=`netstat -rn | grep '^0.0.0.0 ' | awk '{ print $2 }'` && grep \"^$ROUTER_IP \" /proc/net/arp | awk '{print $4}' | tr A-Z a-z", "r"))) {
g_warning ("mac address lookup failed");
return NULL;
}
char mac[MAC_LEN];
int i;
mac = g_malloc (mac_len);
if (fgets (mac, mac_len, in) == NULL) {
g_debug ("mac address lookup returned nothing");
g_free (mac);
/*for some reason netstat or /proc/net/arp isn't always ready
* when a connection is already up... Try a couple of times */
for (i=0; i<10; i++) {
if (!(in = popen ("ROUTER_IP=`netstat -rn | grep '^0.0.0.0 ' | awk '{ print $2 }'` && grep \"^$ROUTER_IP \" /proc/net/arp | awk '{print $4}'", "r"))) {
g_warning ("popen failed");
return NULL;
}
if (!(fgets (mac, MAC_LEN, in))) {
if (errno != ENOENT && errno != EAGAIN) {
g_debug ("error %d", errno);
return NULL;
}
/* try again */
pclose (in);
g_debug ("trying again...");
usleep (200);
continue;
}
pclose (in);
return NULL;
return g_strdup (mac);
}
pclose (in);
return mac;
return NULL;
}
......
......@@ -192,7 +192,6 @@ status_change_requires_provider_change (GList *provider_list,
status == GEOCLUE_STATUS_AVAILABLE) {
return TRUE;
}
g_debug (gc_master_provider_get_name (current_provider));
if (current_provider == changed_provider &&
status != GEOCLUE_STATUS_AVAILABLE) {
return TRUE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment