Add INET helper functions
authorMarcel Holtmann <marcel@holtmann.org>
Mon, 1 Sep 2008 19:11:01 +0000 (21:11 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 1 Sep 2008 19:11:01 +0000 (21:11 +0200)
plugins/Makefile.am
plugins/inet.c [new file with mode: 0644]
plugins/inet.h [new file with mode: 0644]

index d210f46..b4e9805 100644 (file)
@@ -8,7 +8,7 @@ rtnllink_la_SOURCES = rtnllink.c
 
 ethernet_la_SOURCES = ethernet.c
 
-wifi_la_SOURCES = wifi.c supplicant.h supplicant.c
+wifi_la_SOURCES = wifi.c inet.h inet.c supplicant.h supplicant.c
 
 bluetooth_la_SOURCES = bluetooth.c
 bluetooth_la_LIBADD = @GDBUS_LIBS@
@@ -19,7 +19,7 @@ dhclient_la_CFLAGS = @GLIB_CFLAGS@ @GDBUS_CFLAGS@ -DDHCLIENT=\"@DHCLIENT@\" \
 
 ipv4_la_SOURCES = ipv4.c
 
-resolvconf_la_SOURCES = resolvconf.c
+resolvconf_la_SOURCES = resolvconf.c inet.h inet.c
 
 resolvfile_la_SOURCES = resolvfile.c
 
diff --git a/plugins/inet.c b/plugins/inet.c
new file mode 100644 (file)
index 0000000..e14d33e
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2008  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 <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <net/if.h>
+
+#include "inet.h"
+
+char *inet_index2name(int index)
+{
+       struct ifreq ifr;
+       int sk, err;
+
+       if (index < 0)
+               return NULL;
+
+       sk = socket(PF_INET, SOCK_DGRAM, 0);
+       if (sk < 0)
+               return NULL;
+
+       memset(&ifr, 0, sizeof(ifr));
+       ifr.ifr_ifindex = index;
+
+       err = ioctl(sk, SIOCGIFNAME, &ifr);
+
+       close(sk);
+
+       if (err < 0)
+               return NULL;
+
+       return strdup(ifr.ifr_name);
+}
diff --git a/plugins/inet.h b/plugins/inet.h
new file mode 100644 (file)
index 0000000..aafd55b
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2008  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 *inet_index2name(int index);