summaryrefslogtreecommitdiffstats
path: root/meta/recipes-connectivity/connman/connman/0002-resolve-musl-does-not-implement-res_ninit.patch
blob: 639ccfa2a20b6047edb1957601b8fceff687aed3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From 10b0d16d04b811b1ccd1f9b0cfe757bce8d876a1 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Mon, 6 Apr 2015 23:02:21 -0700
Subject: [PATCH 2/3] resolve: musl does not implement res_ninit

ported from
http://git.alpinelinux.org/cgit/aports/plain/testing/connman/libresolv.patch

Upstream-Status: Pending

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 gweb/gresolv.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/gweb/gresolv.c b/gweb/gresolv.c
index 5cf7a9a..3ad8e70 100644
--- a/gweb/gresolv.c
+++ b/gweb/gresolv.c
@@ -36,6 +36,7 @@
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
 #include <net/if.h>
+#include <ctype.h>
 
 #include "gresolv.h"
 
@@ -875,8 +875,6 @@ GResolv *g_resolv_new(int index)
 	resolv->index = index;
 	resolv->nameserver_list = NULL;
 
-	res_ninit(&resolv->res);
-
 	return resolv;
 }
 
@@ -916,8 +914,6 @@ void g_resolv_unref(GResolv *resolv)
 
 	flush_nameservers(resolv);
 
-	res_nclose(&resolv->res);
-
 	g_free(resolv);
 }
 
@@ -1020,24 +1016,19 @@ guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname,
 	debug(resolv, "hostname %s", hostname);
 
 	if (!resolv->nameserver_list) {
-		int i;
-
-		for (i = 0; i < resolv->res.nscount; i++) {
-			char buf[100];
-			int family = resolv->res.nsaddr_list[i].sin_family;
-			void *sa_addr = &resolv->res.nsaddr_list[i].sin_addr;
-
-			if (family != AF_INET &&
-					resolv->res._u._ext.nsaddrs[i]) {
-				family = AF_INET6;
-				sa_addr = &resolv->res._u._ext.nsaddrs[i]->sin6_addr;
+		FILE *f = fopen("/etc/resolv.conf", "r");
+		if (f) {
+			char line[256], *s;
+			int i;
+			while (fgets(line, sizeof(line), f)) {
+				if (strncmp(line, "nameserver", 10) || !isspace(line[10]))
+					continue;
+				for (s = &line[11]; isspace(s[0]); s++);
+				for (i = 0; s[i] && !isspace(s[i]); i++);
+				s[i] = 0;
+				g_resolv_add_nameserver(resolv, s, 53, 0);
 			}
-
-			if (family != AF_INET && family != AF_INET6)
-				continue;
-
-			if (inet_ntop(family, sa_addr, buf, sizeof(buf)))
-				g_resolv_add_nameserver(resolv, buf, 53, 0);
+			fclose(f);
 		}
 
 		if (!resolv->nameserver_list)
-- 
2.5.1