Commit 8f522048 authored by Alexander Alashkin's avatar Alexander Alashkin Committed by Cesanta Bot

Use gethostbyname for localhost

PUBLISHED_FROM=97c58e8624e0d4fa0f043acf6b20e2a1a5ca1b51
parent 147c0951
......@@ -2037,8 +2037,24 @@ MG_INTERNAL int mg_parse_address(const char *str, union socket_address *sa,
sscanf(str, "%[^ :]:%u%n", host, &port, &len) == 2) {
sa->sin.sin_port = htons((uint16_t) port);
if (mg_resolve_from_hosts_file(host, sa) != 0) {
/*
* if resolving from hosts file failed and the host
* we are trying to resolve is `localhost` - we should
* try to resolve it using `gethostbyname` and do not try
* to resolve it via DNS server if gethostbyname has failed too
*/
if (mg_ncasecmp(host, "localhost", 9) != 0) {
return 0;
}
#ifndef MG_DISABLE_SYNC_RESOLVER
if (!mg_resolve2(host, &sa->sin.sin_addr)) {
return -1;
}
#else
return -1;
#endif
}
#endif
} else if (sscanf(str, ":%u%n", &port, &len) == 1 ||
sscanf(str, "%u%n", &port, &len) == 1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment