summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2012-04-11 16:29:01 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-04-12 13:54:47 +0300
commitb1eebf293510bd89827343a5fc495ef0a9b6905d (patch)
tree06e32043564e4fd19b20e4987e71fe7834f3dd5e /src/main.c
parent8788bffdb5182bc7da70214273796d54cb7309bc (diff)
downloadconnman-b1eebf293510bd89827343a5fc495ef0a9b6905d.tar.gz
connman-b1eebf293510bd89827343a5fc495ef0a9b6905d.tar.bz2
connman-b1eebf293510bd89827343a5fc495ef0a9b6905d.zip
main: Implement 'FallbackNameservers' main.conf option
Implement 'FallbackNameservers' main.conf configuration file option. While parsing the list of nameservers, use only the ones in numeric format.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 9feab70e..61e35cb3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,6 +33,7 @@
#include <getopt.h>
#include <sys/stat.h>
#include <net/if.h>
+#include <netdb.h>
#include <gdbus.h>
@@ -47,11 +48,13 @@ static struct {
char **pref_timeservers;
unsigned int *auto_connect;
unsigned int *preferred_techs;
+ char **fallback_nameservers;
} connman_settings = {
.bg_scan = TRUE,
.pref_timeservers = NULL,
.auto_connect = NULL,
.preferred_techs = NULL,
+ .fallback_nameservers = NULL,
};
static GKeyFile *load_config(const char *file)
@@ -103,6 +106,35 @@ static uint *parse_service_types(char **str_list, gsize len)
return type_list;
}
+static char **parse_fallback_nameservers(char **nameservers, gsize len)
+{
+ char **servers;
+ int i, j;
+ struct addrinfo hints;
+ struct addrinfo *addr;
+
+ servers = g_try_new0(char *, len + 1);
+ if (servers == NULL)
+ return NULL;
+
+ i = 0;
+ j = 0;
+ while (nameservers[i] != NULL) {
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_flags = AI_NUMERICHOST;
+ addr = NULL;
+ if (getaddrinfo(nameservers[i], NULL, &hints, &addr) == 0) {
+ servers[j] = g_strdup(nameservers[i]);
+ j += 1;
+ }
+
+ freeaddrinfo(addr);
+ i += 1;
+ }
+
+ return servers;
+}
+
static void parse_config(GKeyFile *config)
{
GError *error = NULL;
@@ -159,6 +191,17 @@ static void parse_config(GKeyFile *config)
g_strfreev(str_list);
g_clear_error(&error);
+
+ str_list = g_key_file_get_string_list(config, "General",
+ "FallbackNameservers", &len, &error);
+
+ if (error == NULL)
+ connman_settings.fallback_nameservers =
+ parse_fallback_nameservers(str_list, len);
+
+ g_strfreev(str_list);
+
+ g_clear_error(&error);
}
static GMainLoop *main_loop = NULL;
@@ -314,6 +357,9 @@ char **connman_setting_get_string_list(const char *key)
if (g_str_equal(key, "FallbackTimeservers") == TRUE)
return connman_settings.pref_timeservers;
+ if (g_str_equal(key, "FallbackNameservers") == TRUE)
+ return connman_settings.fallback_nameservers;
+
return NULL;
}
@@ -514,6 +560,7 @@ int main(int argc, char *argv[])
g_free(connman_settings.auto_connect);
g_free(connman_settings.preferred_techs);
+ g_strfreev(connman_settings.fallback_nameservers);
g_free(option_debug);