Am facut o functie care returneaza numele unui IP. Am o nedumerire:
gethostbyaddr returneaza un pointer la o structura de tip "struct hostent".
Eu nu aloc spatiu pentru aceasta structura, ci se pare ca de asta se ocupa
gethostbyaddr. Dar asta nu inseamna ca se face un malloc pe undeva? Dar nu
pot sa fac free(hp) ca zice "aparch in free(): warning: junk pointer, too
high to make sense" (am FreeBSD). Nu pricep, asta nu inseamna ca functia mea
face "leak memory"?
const char *get_host(const char *ip)
{
static char host[513];
struct in_addr in;
struct hostent *hp;
memset(host, '\0', sizeof(host));
strcpy(host, ip);
if(inet_aton(ip, &in))
if(hp = gethostbyaddr((char*)&in.s_addr,sizeof(in.s_addr),AF_INET))
strcpy(host, hp->h_name);
return host;
}
--
Serghei.
---
Detalii despre listele noastre de mail: http://www.lug.ro/