From: Marcel Holtmann Date: Mon, 1 Sep 2008 19:11:01 +0000 (+0200) Subject: Add INET helper functions X-Git-Tag: accepted/2.0alpha-wayland/20121110.002834~4711 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=135f8ccd37f76068bc75e21f23fb68e74be57c0e;p=profile%2Fivi%2Fconnman.git Add INET helper functions --- diff --git a/plugins/Makefile.am b/plugins/Makefile.am index d210f46..b4e9805 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -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 index 0000000..e14d33e --- /dev/null +++ b/plugins/inet.c @@ -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 +#endif + +#include +#include +#include +#include +#include +#include +#include + +#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 index 0000000..aafd55b --- /dev/null +++ b/plugins/inet.h @@ -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);