with DISABLE_FILESYSTEM, no default ns server is provided.
Closed this issue · 15 comments
If there is no filesystem, a default nameserver should be provided. API allowing to modify the default nameserver would also be nice to have.
How about an overridable #define NS_DEFAULT_NAMESERVER "8.8.8.8"
?
As I see, fossa already has default NS server:
static const char *ns_default_dns_server = "udp://8.8.8.8:53";
.....
if (nameserver == NULL && ns_dns_server[0] == '\0' &&
ns_get_ip_address_of_nameserver(ns_dns_server, sizeof(ns_dns_server)) ==
-1) {
strncpy(ns_dns_server, ns_default_dns_server, sizeof(ns_dns_server)); // <- here
}
So, the question is only about overriding it?
Would compile-time override be OK, e.g.
#ifndef NS_DEFAULT_NAMESERVER
#define NS_DEFAULT_NAMESERVER "8.8.8.8"
#endif
static const char *ns_default_dns_server = "udp://" NS_DEFAULT_NAMESERVER ":53";
?
Who do you ask?
Asking @danielinux :-)
I am sorry, I must have overlooked the default_ns option. Also, I think my configuration is broken because I include NS_DISABLE_RESOLVER.
It's a good idea to me to implement a compile time switch though:
#ifndef NS_DEFAULT_NAMESERVER
#define NS_DEFAULT_NAMESERVER "8.8.8.8"
#endif
As @cpq suggested, there is no way to use an external DNS (e.g. from TCP/IP API). I will make some test on my target with the current codebase and removing NS_DISABLE_RESOLVER from #ifdef PICOTCP block in fossa.h.
Will keep you posted on this.
OK, I am actually referring to the function
static int ns_get_ip_address_of_nameserver(char *name, size_t name_len)
Defined here:
https://github.com/cesanta/fossa/blob/master/fossa.c#L6642
This function gets called in my demo when trying to resolve the endpoint address, and does not have a valid option when !WIN32 and !NS_DISABLE_FILESYSTEM.
Perhaps this function should use the default nameserver when invoked with neither of these two options enabled?
Could you use ns_resolve_async
instead of ns_get_ip_address_of_nameserver
?
ns_resolve_async
uses default DNS if cannot find another options.
FYI @danielinux , Alex just pushed 561a760
@alashkin ns_resolve_async
calls ns_get_ip_address_of_nameserver
before giving the default nameserver, and I have the feeling that the latter returns 0 erroneously, thus resulting in an invalid dns setting. At least, if this is the expected behavior, I believe that ns_get_ip_address_of_nameserver
should return -1 when no options are configured.
My backtrace:
#0 ns_get_ip_address_of_nameserver (name=0x20001160 "", name_len=256)
#1 0x0806c522 in ns_resolve_async_opt (mgr=0x20004134 <mgr>, name=0x2001fe64 "test.mosquitto.org", query=1,
cb=0x8067de5 <resolve_cb>, data=0x20004440, opts=...) at fossa.c:6584
#2 0x0806c484 in ns_resolve_async (mgr=0x20004134 <mgr>, name=0x2001fe64 "test.mosquitto.org", query=1,
cb=0x8067de5 <resolve_cb>, data=0x20004440) at fossa.c:6558
#3 0x08067fc6 in ns_connect_opt (mgr=0x20004134 <mgr>, address=0x8099e14 <broker_address> "test.mosquitto.org:8883",
callback=0x80203cd <ev_handler>, opts=...) at fossa.c:2374
#4 0x08067eca in ns_connect (mgr=0x20004134 <mgr>, address=0x8099e14 <broker_address> "test.mosquitto.org:8883",
callback=0x80203cd <ev_handler>) at fossa.c:2342
double checked: changing the return value of ns_get_ip_address_of_nameserver
to -1
when neither option is enabled, solves the issue for me and takes the path you are suggesting to assign the default nameserver.
Thanks 👍