GithubHelp home page GithubHelp logo

Comments (5)

cpq avatar cpq commented on July 20, 2024

Thanks.
As far as I understand, the fix would be to trim the IP on the first comma, is that correct?

from fossa.

zapline avatar zapline commented on July 20, 2024

But the first ip is not necessarily the best nameserver, 蛋疼

from fossa.

cpq avatar cpq commented on July 20, 2024

Thanks.
If first IP might not be the best server, what would be the best algorithm to pick one?

from fossa.

mkmik avatar mkmik commented on July 20, 2024

On linux the default behaviour is to to try the second (and the third, see MAXNS) name after attempts number of attempts (default 2), unless the rotate option is present in resolv.conf. On windows I guess there is a similar behaviour but I didn't check.

from fossa.

ki7chen avatar ki7chen commented on July 20, 2024

Sorry for my poor English.

Following is code of function ns_get_ip_address_of_nameserver() started at fossa.c line 4384.

static int ns_get_ip_address_of_nameserver(char *name, size_t name_len) {
  int  ret = 0;

#ifdef _WIN32
  int  i;
  LONG  err;
  HKEY  hKey, hSub;
  char  subkey[512], dhcpns[512], ns[512], value[128], *key =
  "SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters\\Interfaces";

  if ((err = RegOpenKey(HKEY_LOCAL_MACHINE,
      key, &hKey)) != ERROR_SUCCESS) {
    fprintf(stderr, "cannot open reg key %s: %d\n", key, err);
    ret--;
  } else {
    for (ret--, i = 0; RegEnumKey(hKey, i, subkey,
        sizeof(subkey)) == ERROR_SUCCESS; i++) {
      DWORD type, len = sizeof(value);
      if (RegOpenKey(hKey, subkey, &hSub) == ERROR_SUCCESS &&
          (RegQueryValueEx(hSub, "NameServer", 0,
          &type, value, &len) == ERROR_SUCCESS ||
          RegQueryValueEx(hSub, "DhcpNameServer", 0,
          &type, value, &len) == ERROR_SUCCESS)) {
        strncpy(name, value, name_len);
        ret++;
        RegCloseKey(hSub);
        break;
      }
    }
    RegCloseKey(hKey);
  }
#else
  /* linux version */
#endif /* _WIN32 */

  return ret;
}

looking at line strncpy(name, value, name_len),
the value can be an empty string, or IP addresses seperated by comma (e.g 8.8.8.8, 8.8.8.4).

that's the point.

from fossa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.