#include <string.h>
#include <netinet/in.h>
#include "net.h"
+#include "plugin.h"
#define MTETHERD_DEVICE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_MTETHERD_DEVICE, MTetherDDevicePrivate))
static const in_addr_t HOST_BASE_ADDRESS = 0xc0a8ff00;
// Host order 255.255.255.252
static const in_addr_t HOST_NETMASK = 0xfffffffc;
-// Host order 0.0.0.2
-static const in_addr_t HOST_ROUTER = 0x00000002;
// Host order 0.0.0.1
-static const in_addr_t HOST_DHCP = 0x00000001;
+static const in_addr_t HOST_ROUTER = 0x00000001;
+// Host order 0.0.0.1
+static const in_addr_t HOST_DHCP = 0x00000002;
struct _MTetherDDevicePrivate {
gchar *interface;
if (index < 64) {
in_addr_t subnet = HOST_BASE_ADDRESS | (index << 2);
in_addr_t addr = subnet | HOST_ROUTER;
- in_addr_t start = subnet | HOST_DHCP;
+ in_addr_t end = subnet | HOST_DHCP;
self->priv->addr = htonl(addr);
self->priv->netmask = htonl(HOST_NETMASK);
- self->priv->dhcp_start = htonl(start);
- self->priv->dhcp_end = htonl(addr);
+ self->priv->dhcp_start = htonl(addr);
+ self->priv->dhcp_end = htonl(end);
} else {
- g_warning("Invalid subnet index: %u (0..%u expected)", index, MAX_DEVICES - 1);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Invalid subnet index: %u (0..%u expected)", index, MAX_DEVICES - 1);
}
}
}
for (i = 0; i < MAX_DEVICES; i++) {
if (!array[i]) {
array[i] = (gpointer) device;
+ mtetherd_device_set_index(device, i);
return TRUE;
}
}
}
gboolean mtetherd_device_ok(const gchar *interface) {
- if (strncmp("usb", interface, sizeof("usb")) == 0) {
+ if (g_str_has_prefix(interface, "usb")) {
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s has prefix %s", interface, "usb");
return TRUE;
}
- if (strncmp("bnep", interface, sizeof("bnep")) == 0) {
+ if (g_str_has_prefix(interface, "bnep")) {
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s has prefix %s", interface, "bnep");
return TRUE;
}
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s has unknown prefix :(", interface);
return FALSE;
}