1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-12-04 14:46:31 -05:00

Cleanup: Decluttered resolver API

This commit is contained in:
Philipp Schafft 2018-11-18 11:53:16 +00:00
parent 2fb3f2a051
commit 21c5d21b53
2 changed files with 0 additions and 59 deletions

View File

@ -43,7 +43,6 @@ extern "C" {
** **
*/ */
char *igloo_resolver_getname(const char *ip, char *buff, int len);
char *igloo_resolver_getip(const char *name, char *buff, int len); char *igloo_resolver_getip(const char *name, char *buff, int len);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -80,37 +80,6 @@ static int _isip(const char *what)
#if defined (HAVE_GETNAMEINFO) && defined (HAVE_GETADDRINFO) #if defined (HAVE_GETNAMEINFO) && defined (HAVE_GETADDRINFO)
char *igloo_resolver_getname(const char *ip, char *buff, int len)
{
struct addrinfo *head = NULL, hints;
char *ret = NULL;
if (!_isip(ip)) {
strncpy(buff, ip, len);
buff [len-1] = '\0';
return buff;
}
memset (&hints, 0, sizeof (hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
if (getaddrinfo (ip, NULL, &hints, &head))
return NULL;
if (head)
{
if (getnameinfo(head->ai_addr, head->ai_addrlen, buff, len, NULL,
0, NI_NAMEREQD) == 0)
ret = buff;
freeaddrinfo (head);
}
return ret;
}
char *igloo_resolver_getip(const char *name, char *buff, int len) char *igloo_resolver_getip(const char *name, char *buff, int len)
{ {
struct addrinfo *head, hints; struct addrinfo *head, hints;
@ -141,33 +110,6 @@ char *igloo_resolver_getip(const char *name, char *buff, int len)
#else #else
char *igloo_resolver_getname(const char *ip, char *buff, int len)
{
struct hostent *host;
char *ret = NULL;
struct in_addr addr;
if (! _isip(ip))
{
strncpy(buff, ip, len);
buff [len-1] = '\0';
return buff;
}
igloo_thread_mutex_lock(&igloo__resolver_mutex);
if (inet_aton (ip, &addr)) {
/* casting &addr to const char* as it is recommended on win* */
if ((host=gethostbyaddr ((const char *)&addr, sizeof (struct in_addr), AF_INET)))
{
ret = strncpy (buff, host->h_name, len);
buff [len-1] = '\0';
}
}
igloo_thread_mutex_unlock(&igloo__resolver_mutex);
return ret;
}
char *igloo_resolver_getip(const char *name, char *buff, int len) char *igloo_resolver_getip(const char *name, char *buff, int len)
{ {
struct hostent *host; struct hostent *host;