6 years, 8 months ago.

lwip resolve dns gethostbyname

Hi Everybody,

I have trouble to resolve domain name to ip address with gethostbyname function in lwip. if I run the code, it shows that my dns server is filled in with a vallid dns server. but resolved comes back with 205.152.0.8

Anybody how has a suggestion how I can make it work?

This is the code I use:

#include "mbed.h"
#include "EthernetInterface.h"
#include "dns.h"

char* serverIpFromDns;

Serial pc(PC_6, PC_7);
EthernetInterface  eth;

int main() {

    eth.init(); //Use DHCP
    eth.connect();
    
ip_addr_t resolved;
dns_init();
    pc.printf("\n");
    pc.printf("dns ip-address:\n");
    pc.printf(inet_ntoa( dns_getserver(0) ) );
 
 dns_gethostbyname("www.google.com", &resolved, NULL, NULL);

    pc.printf("\n");
    pc.printf(eth.getIPAddress());
    pc.printf("\nSubnetmask:\n");
    pc.printf(eth.getNetworkMask());
    pc.printf("\nGateway:\n");
    pc.printf(eth.getGateway()); 
    pc.printf("\nMac address:\n"); 
    pc.printf(eth.getMACAddress()); 
    pc.printf("\nDNS server 1:\n");
    pc.printf(inet_ntoa( dns_getserver(0) ) );
    pc.printf("\nDNS server 2:\n");
    pc.printf(inet_ntoa( dns_getserver(1) ) );

 while(1) {
    
  pc.printf("\nServer address:\n");
  pc.printf("\n");
  pc.printf(inet_ntoa( resolved ) );
 
  wait(5.0);

    }
    }   
Be the first to answer this question.