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_register(internet, element);
75 static void resolvfile_remove(struct connman_element *element)
77 DBG("element %p name %s", element, element->name);
80 static struct connman_driver resolvfile_driver = {
82 .type = CONNMAN_ELEMENT_TYPE_RESOLVER,
83 .priority = CONNMAN_DRIVER_PRIORITY_LOW,
84 .probe = resolvfile_probe,
85 .remove = resolvfile_remove,
88 static int resolvfile_init(void)
90 return connman_driver_register(&resolvfile_driver);
93 static void resolvfile_exit(void)
95 connman_driver_unregister(&resolvfile_driver);
98 CONNMAN_PLUGIN_DEFINE("resolvfile", "Name resolver plugin", VERSION,
99 resolvfile_init, resolvfile_exit)