Fully integrate the usage of resolver element
[framework/connectivity/connman.git] / plugins / resolvconf.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2008  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdlib.h>
27
28 #include <connman/plugin.h>
29 #include <connman/driver.h>
30 #include <connman/log.h>
31
32 static int resolvconf_probe(struct connman_element *element)
33 {
34         const char *nameserver = NULL;
35         gchar *cmd;
36         //int err;
37
38         DBG("element %p name %s", element, element->name);
39
40         connman_element_get_value(element,
41                         CONNMAN_PROPERTY_TYPE_IPV4_NAMESERVER, &nameserver);
42
43         if (nameserver == NULL)
44                 return -EINVAL;
45
46         cmd = g_strdup_printf("echo \"nameserver %s\" | resolvconf -a %s",
47                                         nameserver, element->netdev.name);
48
49         DBG("%s", cmd);
50
51         //err = system(cmd);
52
53         g_free(cmd);
54
55         return 0;
56 }
57
58 static void resolvconf_remove(struct connman_element *element)
59 {
60         gchar *cmd;
61         //int err;
62
63         DBG("element %p name %s", element, element->name);
64
65         cmd = g_strdup_printf("resolvconf -d %s", element->netdev.name);
66
67         DBG("%s", cmd);
68
69         //err = system(cmd);
70
71         g_free(cmd);
72 }
73
74 static struct connman_driver resolvconf_driver = {
75         .name           = "resolvconf",
76         .type           = CONNMAN_ELEMENT_TYPE_RESOLVER,
77         .probe          = resolvconf_probe,
78         .remove         = resolvconf_remove,
79 };
80
81 static int resolvconf_init(void)
82 {
83         return connman_driver_register(&resolvconf_driver);
84 }
85
86 static void resolvconf_exit(void)
87 {
88         connman_driver_unregister(&resolvconf_driver);
89 }
90
91 CONNMAN_PLUGIN_DEFINE("resolvconf", "Name resolver plugin", VERSION,
92                                         resolvconf_init, resolvconf_exit)