1
0

100-simultaneous-ipv4-ipv6.patch 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --- a/ipset-dns.c
  2. +++ b/ipset-dns.c
  3. @@ -307,19 +307,20 @@ int main(int argc, char *argv[])
  4. struct timeval tv;
  5. char msg[512];
  6. char ip[INET6_ADDRSTRLEN];
  7. - char *ipset;
  8. + char *ipset, *ipset6;
  9. int listen_sock, upstream_sock;
  10. int pos, i, size, af;
  11. socklen_t len;
  12. size_t received;
  13. pid_t child;
  14. - if (argc != 4) {
  15. - fprintf(stderr, "Usage: %s ipset port upstream\n", argv[0]);
  16. + if (argc != 5) {
  17. + fprintf(stderr, "Usage: %s ipv4-ipset ipv6-ipset port upstream\n", argv[0]);
  18. return 1;
  19. }
  20. ipset = argv[1];
  21. + ipset6 = argv[2];
  22. listen_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  23. if (listen_sock < 0) {
  24. @@ -329,7 +330,7 @@ int main(int argc, char *argv[])
  25. memset(&listen_addr, 0, sizeof(listen_addr));
  26. listen_addr.sin_family = AF_INET;
  27. - listen_addr.sin_port = htons(atoi(argv[2]));
  28. + listen_addr.sin_port = htons(atoi(argv[3]));
  29. listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  30. i = 1;
  31. setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
  32. @@ -341,7 +342,7 @@ int main(int argc, char *argv[])
  33. memset(&upstream_addr, 0, sizeof(upstream_addr));
  34. upstream_addr.sin_family = AF_INET;
  35. upstream_addr.sin_port = htons(53);
  36. - inet_aton(argv[3], &upstream_addr.sin_addr);
  37. + inet_aton(argv[4], &upstream_addr.sin_addr);
  38. /* TODO: Put all of the below code in several forks all listening on the same sock. */
  39. @@ -434,8 +435,11 @@ int main(int argc, char *argv[])
  40. continue;
  41. }
  42. + if ((af == AF_INET && !*ipset) || (af == AF_INET6 && !*ipset6))
  43. + continue;
  44. +
  45. printf("%s: %s\n", answer.dotted, ip);
  46. - if (add_to_ipset(ipset, answer.rdata, af) < 0)
  47. + if (add_to_ipset((af == AF_INET) ? ipset : ipset6, answer.rdata, af) < 0)
  48. perror("add_to_ipset");
  49. }