LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   reverse DNS in C? (https://www.linuxquestions.org/questions/programming-9/reverse-dns-in-c-317623/)

Thinking 04-27-2005 04:32 AM

reverse DNS in C?
 
hiho@ll

i just wrote a server who needs to make a RDNS to get the hostname of the ip who just connected to my server
anybody knows a C-function or a prog, which could do this for me?

thx@ll

win32sux 04-27-2005 04:56 AM

i'm not a programmer, but from what i googled i think what you want might be:

Code:

gethostbyaddr()
just my two cents...



BTW, i've asked a moderator to move your thread to the programming forum so that it will be more exposed to programmers...


david_ross 04-27-2005 11:53 AM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

itsme86 04-27-2005 12:05 PM

I've used this in a program to do that:
Code:

char *ip_to_hostname(char *hostname)
{
  struct hostent *hent;
  struct in_addr addr;

  if(!inet_aton(hostname, &addr))
    return(hostname);

  if((hent = gethostbyaddr((char *)&(addr.s_addr), sizeof(addr.s_addr),
    AF_INET)))
  {
    strcpy(hostname, hent->h_name);
  }

  return(hostname);
}

hostname would initially hold the IP address.


All times are GMT -5. The time now is 07:12 PM.