change net_info to work if /etc/resolv.conf does not exist

This commit is contained in:
Doug MacEachern 2007-04-05 17:00:28 +00:00
parent a2572d9510
commit e91faa5dbc
1 changed files with 22 additions and 25 deletions

View File

@ -1220,12 +1220,9 @@ int sigar_net_info_get(sigar_t *sigar,
char buffer[BUFSIZ], *ptr; char buffer[BUFSIZ], *ptr;
FILE *fp; FILE *fp;
if (!(fp = fopen("/etc/resolv.conf", "r"))) {
return errno;
}
SIGAR_ZERO(netinfo); SIGAR_ZERO(netinfo);
if ((fp = fopen("/etc/resolv.conf", "r"))) {
while ((ptr = fgets(buffer, sizeof(buffer), fp))) { while ((ptr = fgets(buffer, sizeof(buffer), fp))) {
int len; int len;
@ -1249,8 +1246,8 @@ int sigar_net_info_get(sigar_t *sigar,
break; break;
} }
} }
fclose(fp); fclose(fp);
} /* else /etc/resolv.conf may not exist if unplugged (MacOSX) */
size = sizeof(netinfo->host_name)-1; size = sizeof(netinfo->host_name)-1;
if (gethostname(netinfo->host_name, size) == 0) { if (gethostname(netinfo->host_name, size) == 0) {