SSCRIPT TECHNICAL PAPER
-----------------------


Like many other C function, the resolving ones don't have any clear and
simple documentation anywhere. So here it is, for IP and HOSTNAME
resolving.

A variable of type hostent is what contains the IP and host that goes
together. So the trick is to get the hostname in it, and ask for the IP,
or put the IP and ask for the host. You also need a sockaddr_in variable
to handle the change.

First you need to use gethostbyname() to put the hostname in the hostent
variable. Then use memcpy() to put the address from hostent to
sockaddr_in, which is a struct that contains the IP, host and other
things. Then you simply have to copy the IP form that struct into a
variable. Here is how to do it:

 struct hostent *hp;
 struct sockaddr_in from;
 memset(&from, 0, sizeof(struct sockaddr_in));
 from.sin_family = AF_INET; /* Internet address */
 hp=gethostbyname(in_var,0)); /* copy host in */
 if(hp==NULL) strcpy(out_var,"unknown");
 else
 {
  memcpy(&from.sin_addr,hp->h_addr,hp->h_length); /* copy hp to from */
  strcpy(out_var,inet_ntoa(from.sin_addr)); /* and we ask for sin_addr */
 }

If you need to change an IP to an host, its about the same process. Use
gethostbyaddr() to copy the IP into a variable, then ask for h_name,
which is the hostname that goes with that IP.

 struct hostent *hp;
 struct sockaddr_in from;
 from.sin_family = AF_INET;
 from.sin_addr.s_addr = inet_addr(in_var,0)); /* get the IP */
 hp=gethostbyaddr((char *)&from.sin_addr, sizeof(struct in_addr),
  from.sin_family); /* from to hp */
 if(hp==NULL) strcpy(out_var,"unknown");   /* does it exist? */
 else strcpy(out_var,(char *)hp->h_name); /* get that hostname */

There we go. That wasn't hard now was it?
