Hi Patrik,
On 04/10/2012 03:25 PM, [email protected] wrote:
From: Patrik Flykt<[email protected]>
Implement 'FallbackNameservers' main.conf configuration file
option. While parsing the list of nameservers, use only the ones
in numeric format.
---
src/main.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/src/main.c b/src/main.c
index 828df54..7da5802 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;
@@ -162,6 +194,15 @@ 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);
Memory leak here. str_list is not freed.
+
+ g_clear_error(&error);
}
static GMainLoop *main_loop = NULL;
@@ -317,6 +358,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;
}
@@ -517,6 +561,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);
Cheers,
Jukka
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman