#include <connman/plugin.h>
#include <connman/iface.h>
+#include "net.h"
+
static int iface_probe(struct connman_iface *iface)
{
- printf("[802.03] probe interface %s\n", iface->udi);
+ char *ifname;
+
+ ifname = __net_ifname(iface->sysfs);
+ if (ifname == NULL)
+ return -1;
+
+ printf("[802.03] probe interface %s\n", ifname);
iface->type = CONNMAN_IFACE_TYPE_80203;
iface->flags = CONNMAN_IFACE_FLAGS_CARRIER_DETECT |
CONNMAN_IFACE_FLAGS_IPV4;
+ __net_free(ifname);
+
return 0;
}
static void iface_remove(struct connman_iface *iface)
{
- printf("[802.03] remove interface %s\n", iface->udi);
+ char *ifname;
+
+ ifname = __net_ifname(iface->sysfs);
+ if (ifname == NULL)
+ return;
+
+ printf("[802.03] remove interface %s\n", ifname);
+
+ __net_free(ifname);
}
static struct connman_iface_driver iface_driver = {
#include <connman/plugin.h>
#include <connman/iface.h>
+#include "net.h"
+
static int iface_probe(struct connman_iface *iface)
{
- printf("[802.11] probe interface %s\n", iface->udi);
+ char *ifname;
+
+ ifname = __net_ifname(iface->sysfs);
+ if (ifname == NULL)
+ return -1;
+
+ printf("[802.11] probe interface %s\n", ifname);
iface->type = CONNMAN_IFACE_TYPE_80211;
iface->flags = CONNMAN_IFACE_FLAGS_IPV4;
+ __net_free(ifname);
+
return 0;
}
static void iface_remove(struct connman_iface *iface)
{
- printf("[802.11] remove interface %s\n", iface->udi);
+ char *ifname;
+
+ ifname = __net_ifname(iface->sysfs);
+ if (ifname == NULL)
+ return;
+
+ printf("[802.11] remove interface %s\n", ifname);
+
+ __net_free(ifname);
}
static struct connman_iface_driver iface_driver = {
plugin_LTLIBRARIES = libconnman-80203.la libconnman-80211.la
-libconnman_80203_la_SOURCES = 80203.c
+libconnman_80203_la_SOURCES = 80203.c net.h net.c
-libconnman_80211_la_SOURCES = 80211.c
+libconnman_80211_la_SOURCES = 80211.c net.h net.c
AM_LDFLAGS = -module -avoid-version -export-symbols-regex connman_plugin_desc
--- /dev/null
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2007 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+
+#include "net.h"
+
+static int __net_ifindex(const char *sysfs)
+{
+ char *pathname;
+ char buf[8];
+ size_t size;
+ ssize_t len;
+ int fd, val = -EIO;
+
+ if (sysfs == NULL)
+ return -1;
+
+ size = strlen(sysfs) + 9;
+
+ pathname = malloc(size);
+
+ sprintf(pathname, "%s/ifindex", sysfs);
+
+ fd = open(pathname, O_RDONLY);
+
+ free(pathname);
+
+ if (fd < 0)
+ return -errno;
+
+ memset(buf, 0, sizeof(buf));
+
+ len = read(fd, buf, sizeof(buf) - 1);
+ if (len < 0) {
+ val = -errno;
+ goto done;
+ }
+
+ val = atoi(buf);
+
+done:
+ close(fd);
+
+ return val;
+}
+
+char *__net_ifname(const char *sysfs)
+{
+ struct ifreq ifr;
+ int sk, err, ifindex;
+
+ ifindex = __net_ifindex(sysfs);
+ if (ifindex < 0)
+ return NULL;
+
+ sk = socket (PF_INET, SOCK_DGRAM, 0);
+ if (sk < 0)
+ return NULL;
+
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_ifindex = ifindex;
+
+ err = ioctl(sk, SIOCGIFNAME, &ifr);
+
+ close(sk);
+
+ if (err < 0)
+ return NULL;
+
+ return strdup(ifr.ifr_name);
+}
+
+void __net_free(void *ptr)
+{
+ if (ptr)
+ free(ptr);
+}
--- /dev/null
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2007 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+char *__net_ifname(const char *sysfs);
+void __net_free(void *ptr);