add NULL checks to fqdn_get

This commit is contained in:
Doug MacEachern 2005-11-08 19:15:41 +00:00
parent 147c931d7d
commit 54754b2711
1 changed files with 19 additions and 3 deletions

View File

@ -1436,10 +1436,10 @@ static int fqdn_ip_get(sigar_t *sigar, char *name)
#endif #endif
#define IS_FQDN(name) \ #define IS_FQDN(name) \
strchr(name, '.') (name && strchr(name, '.'))
#define H_ALIAS_MATCH(alias, name) \ #define H_ALIAS_MATCH(alias, name) \
(IS_FQDN(alias) && strnEQ(alias, name, strlen(name))) (IS_FQDN(alias) && name && strnEQ(alias, name, strlen(name)))
#define FQDN_SET(fqdn) \ #define FQDN_SET(fqdn) \
SIGAR_STRNCPY(name, fqdn, namelen) SIGAR_STRNCPY(name, fqdn, namelen)
@ -1525,6 +1525,22 @@ SIGAR_DECLARE(int) sigar_fqdn_get(sigar_t *sigar, char *name, int namelen)
p->h_length, p->h_length,
p->h_addrtype); p->h_addrtype);
if (!q) {
if (SIGAR_LOG_IS_DEBUG(sigar)) {
char addr[INET6_ADDRSTRLEN];
struct in_addr *in =
(struct in_addr *)p->h_addr_list[i];
sigar_inet_ntoa(sigar, in->s_addr, addr);
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
"[fqdn] gethostbyaddr(%s) failed: %s",
addr,
sigar_strerror(sigar, errno));
}
continue;
}
if (IS_FQDN(q->h_name)) { if (IS_FQDN(q->h_name)) {
FQDN_SET(q->h_name); FQDN_SET(q->h_name);