/* Copyright 2021 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ // // This module is used to query the DNS server address from the OS // function windows_dns() { // // Reference for GetNetworkParams() can be found at: // https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getnetworkparams // var ret = []; var ip = require('_GenericMarshal').CreateNativeProxy('Iphlpapi.dll'); ip.CreateMethod('GetNetworkParams'); var data = require('_GenericMarshal').CreateVariable(1024); var len = require('_GenericMarshal').CreateVariable(4); len.toBuffer().writeUInt32LE(1024); if (ip.GetNetworkParams(data, len).Val == 0) { var dnsList = data.Deref(require('_GenericMarshal').PointerSize == 8 ? 272 : 268, 48); do { ret.push(dnsList.Deref(require('_GenericMarshal').PointerSize, 16).toBuffer().toString()); } while ((dnsList = dnsList.Deref(0, require('_GenericMarshal').PointerSize).Deref().Deref(0, 48)).Val != 0); // Itereate the list } return (ret); } function linux_dns() { // // The linux implementation will look for the dns address in /etc/resolve.conf // var child = require('child_process').execFile('/bin/sh', ['sh']); child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); child.stderr.on('data', function () { }); child.stdin.write("cat /etc/resolv.conf | grep nameserver | tr '\n' '`' | awk -F'`' '"); child.stdin.write('{'); child.stdin.write(' DEL="";'); child.stdin.write(' printf "[";'); child.stdin.write(' for(i=1;i