libresolv.patch 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. musl does not implement res_ninit
  2. --- a/gweb/gresolv.c
  3. +++ b/gweb/gresolv.c
  4. @@ -877,8 +877,6 @@
  5. resolv->index = index;
  6. resolv->nameserver_list = NULL;
  7. - res_ninit(&resolv->res);
  8. -
  9. return resolv;
  10. }
  11. @@ -918,8 +916,6 @@
  12. flush_nameservers(resolv);
  13. - res_nclose(&resolv->res);
  14. -
  15. g_free(resolv);
  16. }
  17. @@ -1022,24 +1018,19 @@
  18. debug(resolv, "hostname %s", hostname);
  19. if (!resolv->nameserver_list) {
  20. - int i;
  21. -
  22. - for (i = 0; i < resolv->res.nscount; i++) {
  23. - char buf[100];
  24. - int family = resolv->res.nsaddr_list[i].sin_family;
  25. - void *sa_addr = &resolv->res.nsaddr_list[i].sin_addr;
  26. -
  27. - if (family != AF_INET &&
  28. - resolv->res._u._ext.nsaddrs[i]) {
  29. - family = AF_INET6;
  30. - sa_addr = &resolv->res._u._ext.nsaddrs[i]->sin6_addr;
  31. + FILE *f = fopen("/etc/resolv.conf", "r");
  32. + if (f) {
  33. + char line[256], *s;
  34. + int i;
  35. + while (fgets(line, sizeof(line), f)) {
  36. + if (strncmp(line, "nameserver", 10) || !isspace(line[10]))
  37. + continue;
  38. + for (s = &line[11]; isspace(s[0]); s++);
  39. + for (i = 0; s[i] && !isspace(s[i]); i++);
  40. + s[i] = 0;
  41. + g_resolv_add_nameserver(resolv, s, 53, 0);
  42. }
  43. -
  44. - if (family != AF_INET && family != AF_INET6)
  45. - continue;
  46. -
  47. - if (inet_ntop(family, sa_addr, buf, sizeof(buf)))
  48. - g_resolv_add_nameserver(resolv, buf, 53, 0);
  49. + fclose(f);
  50. }
  51. if (!resolv->nameserver_list)