From a5541065ee14e6582402ce586009c3144fcff33f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 24 Mar 2008 11:02:49 +0100 Subject: [PATCH] Add resolver plugin using resolvconf helper tool --- plugins/Makefile.am | 4 +- plugins/resolvconf.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 plugins/resolvconf.c diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 2f789ec..87464b0 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -2,7 +2,7 @@ plugindir = $(libdir)/connman/plugins plugin_LTLIBRARIES = libconnman-80203.la libconnman-80211.la \ - libconnman-dhclient.la + libconnman-dhclient.la libconnman-resolvconf.la libconnman_80203_la_SOURCES = 80203.c @@ -11,6 +11,8 @@ libconnman_80211_la_SOURCES = 80211.c supplicant.h supplicant.c libconnman_dhclient_la_SOURCES = dhclient.c libconnman_dhclient_la_LIBADD = @GDBUS_LIBS@ +libconnman_resolvconf_la_SOURCES = resolvconf.c + AM_LDFLAGS = -module -avoid-version -export-symbols-regex connman_plugin_desc statedir = $(localstatedir)/run/connman diff --git a/plugins/resolvconf.c b/plugins/resolvconf.c new file mode 100644 index 0000000..732db4f --- /dev/null +++ b/plugins/resolvconf.c @@ -0,0 +1,118 @@ +/* + * + * 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 +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +static int resolvconf_append(struct connman_iface *iface, const char *nameserver) +{ + struct ifreq ifr; + char cmd[128]; + int sk, err; + + sk = socket(PF_INET, SOCK_DGRAM, 0); + if (sk < 0) + return -1; + + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_ifindex = iface->index; + + err = ioctl(sk, SIOCGIFNAME, &ifr); + + close(sk); + + if (err < 0) + return -1; + + DBG("ifname %s", ifr.ifr_name); + + snprintf(cmd, sizeof(cmd), "echo \"nameserver %s\" | resolvconf -a %s", + nameserver, ifr.ifr_name); + + DBG("%s", cmd); + + err = system(cmd); + + return 0; +} + +static int resolvconf_remove(struct connman_iface *iface) +{ + struct ifreq ifr; + char cmd[128]; + int sk, err; + + sk = socket(PF_INET, SOCK_DGRAM, 0); + if (sk < 0) + return -1; + + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_ifindex = iface->index; + + err = ioctl(sk, SIOCGIFNAME, &ifr); + + close(sk); + + if (err < 0) + return -1; + + DBG("ifname %s", ifr.ifr_name); + + snprintf(cmd, sizeof(cmd), "resolvconf -d %s", ifr.ifr_name); + + DBG("%s", cmd); + + err = system(cmd); + + return 0; +} + +static struct connman_resolver_driver resolvconf_driver = { + .name = "resolvconf", + .append = resolvconf_append, + .remove = resolvconf_remove, +}; + +static int resolvconf_init(void) +{ + return connman_resolver_register(&resolvconf_driver); +} + +static void resolvconf_exit(void) +{ + connman_resolver_unregister(&resolvconf_driver); +} + +CONNMAN_PLUGIN_DEFINE("resolvconf", "Name resolver plugin", VERSION, + resolvconf_init, resolvconf_exit) -- 1.7.9.5