MX7 force DNS

Post Reply
aabfm
Posts: 31
Joined: Mon Aug 14, 2017 4:28 pm
Location: UK

MX7 force DNS

Post by aabfm » Thu Aug 31, 2017 9:38 am

Hi,
Following the post "POST call on a mx7ck" I'm now facing another issue: how to force a specific DNS.
Yesterday I managed to have the IP resolved but I was using DHCP with my router, today I'm at a different location where I was given a fixed IP, subnet mask and gateway, however I couldn't get the response from the server, i.e. there was no TRUE return from the tcpClient.isEstablished() call... :(
The way around is this:

Code: Select all

IPv4 ip = {193,0,0,171};
IPv4 subnet = {255,255,255,0};
IPv4 gatew = {193,0,0,3};
IPv4 dns = {193,0,0,1};
long unsigned int maxdns;
maxdns=deIPcK.setDNS(deIPcK.getcMaxDNS(),dns);
deIPcK.setDNS(maxdns,dns);
con=deIPcK.begin(ip,gatew,subnet);
I hope you find this info useful!
Cheers.

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: MX7 force DNS

Post by majenko » Thu Aug 31, 2017 10:44 am

Looking at the code to setDNS:

Code: Select all

bool DEIPcK::setDNS(int index, const IPv4& ipDNS)
{
    // get it set up if not already
    if(_fBegun && ((uint32_t) index)  < cDNSMax)
    {
        return(DNSAddNS(_pLLAdp, &ipDNS, index));
    }
    return(false);
}
it looks like it will only do anything if you have already called `begin()` on your connection. So re-ordering your statements, and using 0 for the DNS index, should work:

Code: Select all

IPv4 ip = {193,0,0,171};
IPv4 subnet = {255,255,255,0};
IPv4 gatew = {193,0,0,3};
IPv4 dns = {193,0,0,1};
con=deIPcK.begin(ip,gatew,subnet);
deIPcK.setDNS(0,dns);
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

aabfm
Posts: 31
Joined: Mon Aug 14, 2017 4:28 pm
Location: UK

Re: MX7 force DNS

Post by aabfm » Thu Aug 31, 2017 12:12 pm

You are completely right! Thanks for the tip.

Post Reply