6b4e90c9   
   From: barmar@alum.mit.edu   
      
   In article   
   ,   
    SpreadTooThin wrote:   
      
   > If I have a function that sends a message to a host name or IP   
   > address,   
   >   
   > void SendMessageTo(char *hostNameOrIPAddress, int port, char *msg, int   
   > msgSize);   
   >   
   > Should I try to determine if the hostNameOrIPAddress is a host name or   
   > IP Address...   
   > gethostbyname or gethostbyaddress.   
   >   
   > Or is one function call good for both?   
   >   
   > struct hostent *hp;   
   > struct sockaddr_in addr;   
   >   
   > if ((hp = gethostbyname(hostNameOrIPAddress)) == NULL) // It wasn't   
   > a host name... Maybe its an IP address?   
   > {   
   > addr.sin_addr.s_addr = inet_addr(hostNameOrIPAddress); // Convert   
   > dots to binary number?   
   > hp = gethostbyaddr((char *)&addr.sin_addr.s_addr, sizeof   
   > (addr.sin_addr.s_addr), AF_INET);   
      
   Why do you need to call gethostbyaddr()? inet_addr() gave you an   
   address, isn't that all you need to send the message?   
      
   > }   
   >   
   > if (hp == null) then what happened?   
      
   gethostbyaddr() uses reverse DNS to try to get the hostname associated   
   with the address. If it returns NULL it means there's no PTR record for   
   the address.   
      
   >   
   > If I understand the process this is done in stages   
   > hostNameOrIPAddress is assumed to look like host.domain.com   
   > if not its assumed to be 123.234.1.34 and then that is converted into   
   > a binary bit array.   
   >   
   > Have I missed something?   
      
   --   
   Barry Margolin, barmar@alum.mit.edu   
   Arlington, MA   
   *** PLEASE don't copy me on replies, I'll read them in the group ***   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|