5 * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
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.
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.
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
32 #include <connman/plugin.h>
33 #include <connman/driver.h>
34 #include <connman/log.h>
36 static int resolvfile_probe(struct connman_element *element)
38 const char *nameserver = NULL;
39 struct connman_element *internet;
43 DBG("element %p name %s", element, element->name);
45 connman_element_get_value(element,
46 CONNMAN_PROPERTY_TYPE_IPV4_NAMESERVER, &nameserver);
48 if (nameserver == NULL)
51 fd = open("/etc/resolv.conf", O_RDWR | O_CREAT,
52 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
56 err = ftruncate(fd, 0);
58 cmd = g_strdup_printf("nameserver %s\n", nameserver);
60 len = write(fd, cmd, strlen(cmd));
66 internet = connman_element_create();
68 internet->type = CONNMAN_ELEMENT_TYPE_INTERNET;
70 connman_element_set_data(element, internet);
72 connman_element_register(internet, element);
77 static void resolvfile_remove(struct connman_element *element)
79 struct connman_element *internet = connman_element_get_data(element);
81 DBG("element %p name %s", element, element->name);
83 connman_element_set_data(element, NULL);
85 connman_element_unregister(internet);
87 connman_element_unref(internet);
90 static struct connman_driver resolvfile_driver = {
92 .type = CONNMAN_ELEMENT_TYPE_RESOLVER,
93 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
94 .probe = resolvfile_probe,
95 .remove = resolvfile_remove,
98 static int resolvfile_init(void)
100 return connman_driver_register(&resolvfile_driver);
103 static void resolvfile_exit(void)
105 connman_driver_unregister(&resolvfile_driver);
108 CONNMAN_PLUGIN_DEFINE("resolvfile", "Name resolver plugin", VERSION,
109 resolvfile_init, resolvfile_exit)