X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Flocate_host.c;h=5ef13c8eb6df5f937bf76fef70e03ea0519c484e;hb=346f8cd942d1a0a48cc396651750945655fe8d39;hp=c95569dcf7cdb7a2d0adf7cfa08d4b32f16c7482;hpb=01008640a5b0d110e76db7e885accf45abfd20d9;p=citadel.git diff --git a/citadel/locate_host.c b/citadel/locate_host.c index c95569dcf..5ef13c8eb 100644 --- a/citadel/locate_host.c +++ b/citadel/locate_host.c @@ -25,12 +25,15 @@ #include "tools.h" #include "domain.h" -void locate_host(char *tbuf, size_t n, const struct in_addr *addr) +void locate_host(char *tbuf, size_t n, + char *abuf, size_t na, + const struct in_addr *addr) { struct hostent *ch; const char *i; char *j; int a1, a2, a3, a4; + char address_string[SIZ]; lprintf(9, "locate_host() called\n"); @@ -38,15 +41,21 @@ void locate_host(char *tbuf, size_t n, const struct in_addr *addr) begin_critical_section(S_NETDB); #endif - if ((ch = gethostbyaddr((const char *) addr, sizeof(*addr), AF_INET)) == - NULL) { - bad_dns: - i = (const char *) addr; - a1 = ((*i++) & 0xff); - a2 = ((*i++) & 0xff); - a3 = ((*i++) & 0xff); - a4 = ((*i++) & 0xff); - snprintf(tbuf, n, "%d.%d.%d.%d", a1, a2, a3, a4); + i = (const char *) addr; + a1 = ((*i++) & 0xff); + a2 = ((*i++) & 0xff); + a3 = ((*i++) & 0xff); + a4 = ((*i++) & 0xff); + sprintf(address_string, "%d.%d.%d.%d", a1, a2, a3, a4); + + if (abuf != NULL) { + safestrncpy(abuf, address_string, na); + } + + if ((ch = gethostbyaddr((const char *) addr, + sizeof(*addr), AF_INET)) == NULL) { +bad_dns: + safestrncpy(tbuf, address_string, n); goto end; /* because we might need to end the critical section */ }