]> granicus.if.org Git - libevent/commit
dns-example: allow to set ns from args
authorAzat Khuzhin <a3at.mail@gmail.com>
Sat, 8 Nov 2014 12:51:49 +0000 (15:51 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Sat, 8 Nov 2014 13:18:52 +0000 (16:18 +0300)
commitdf19a970e1f49e362dabd4f848b778d6bc2b7518
treece8cf686000de6cd4636fd42c9e6e0376621350f
parent32f8592c8b18da0d499cb8c03e427369cd5b3ba7
dns-example: allow to set ns from args

We can't do this using resolv.conf:
$ dns-example -v -c <(echo nameserver 127.0.0.1:10053) ya.ru
Because of how evutil_read_file_() works (using fstat())

And actually glibc for example will not use port from nameserver line, and
because of inet_aton() it will fail if nameserver will have arbitary port:
(gdb) p inet_aton("127.0.0.1", malloc(10000))
$1 = 1
(gdb) p inet_aton("127.0.0.1:53", malloc(10000))
$2 = 0

From glibc/resolv/res_init.c:
  if (MATCH(buf, "nameserver") && nserv < MAXNS) {
      struct in_addr a;
      cp = buf + sizeof("nameserver") - 1;
      while (*cp == ' ' || *cp == '\t')
          cp++;
      if ((*cp != '\0') && (*cp != '\n')
          && __inet_aton(cp, &a)) {
          statp->nsaddr_list[nservall].sin_addr = a;
          statp->nsaddr_list[nservall].sin_family = AF_INET;
          statp->nsaddr_list[nservall].sin_port =
                  htons(NAMESERVER_PORT);
sample/dns-example.c