Updated documentation for 0.2 release
[mtetherd] / net.c
diff --git a/net.c b/net.c
index 788aff6..230b082 100644 (file)
--- a/net.c
+++ b/net.c
@@ -21,6 +21,7 @@
 #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))
 
@@ -31,10 +32,10 @@ static const guint MAX_DEVICES = 64;
 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;
@@ -121,13 +122,13 @@ void mtetherd_device_set_index(MTetherDDevice *self, guint index) {
                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);
                }
        }
 }
@@ -245,6 +246,7 @@ gboolean mtetherd_device_list_add(gpointer list, MTetherDDevice *device) {
                for (i = 0; i < MAX_DEVICES; i++) {
                        if (!array[i]) {
                                array[i] = (gpointer) device;
+                               mtetherd_device_set_index(device, i);
                                return TRUE;
                        }
                }
@@ -267,12 +269,15 @@ gboolean mtetherd_device_list_remove(gpointer list, const gchar *udi) {
 }
 
 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;
 }