Enable hosts and resolv.conf lookups on UNIX only

Not relevant for other platforms

PUBLISHED_FROM=65b8959ee677555e2fb330c84d443e0a93d9fd1c
This commit is contained in:
Deomid Ryabkov 2017-04-18 23:27:32 +01:00 committed by Cesanta Bot
parent 84907d5bc4
commit f868fc861b
2 changed files with 12 additions and 4 deletions

View File

@ -10872,11 +10872,11 @@ static int mg_get_ip_address_of_nameserver(char *name, size_t name_len) {
}
RegCloseKey(hKey);
}
#elif MG_ENABLE_FILESYSTEM
#elif MG_ENABLE_FILESYSTEM && defined(MG_RESOLV_CONF_FILE_NAME)
FILE *fp;
char line[512];
if ((fp = mg_fopen("/etc/resolv.conf", "r")) == NULL) {
if ((fp = mg_fopen(MG_RESOLV_CONF_FILE_NAME, "r")) == NULL) {
ret = -1;
} else {
/* Try to figure out what nameserver to use */
@ -10898,7 +10898,7 @@ static int mg_get_ip_address_of_nameserver(char *name, size_t name_len) {
}
int mg_resolve_from_hosts_file(const char *name, union socket_address *usa) {
#if MG_ENABLE_FILESYSTEM
#if MG_ENABLE_FILESYSTEM && defined(MG_HOSTS_FILE_NAME)
/* TODO(mkm) cache /etc/hosts */
FILE *fp;
char line[1024];
@ -10907,7 +10907,7 @@ int mg_resolve_from_hosts_file(const char *name, union socket_address *usa) {
unsigned int a, b, c, d;
int len = 0;
if ((fp = mg_fopen("/etc/hosts", "r")) == NULL) {
if ((fp = mg_fopen(MG_HOSTS_FILE_NAME, "r")) == NULL) {
return -1;
}

View File

@ -460,6 +460,14 @@ typedef struct stat cs_stat_t;
#define MG_NET_IF MG_NET_IF_SOCKET
#endif
#ifndef MG_HOSTS_FILE_NAME
#define MG_HOSTS_FILE_NAME "/etc/hosts"
#endif
#ifndef MG_RESOLV_CONF_FILE_NAME
#define MG_RESOLV_CONF_FILE_NAME "/etc/resolv.conf"
#endif
#endif /* CS_PLATFORM == CS_P_UNIX */
#endif /* CS_COMMON_PLATFORMS_PLATFORM_UNIX_H_ */
#ifdef MG_MODULE_LINES