[news.software.anu-news] getremhost

syrjanen@cs.Helsinki.FI (Seppo Syrjanen) (08/22/89)

What follows is the getremhost() function for NNTP_SERVER with
WIN/TCP. It uses getpeername() to get the address of remote host
followed by gethostbyname() to convert address to hostname.
At return remhost contains the name of remote host as it is received
from nameserver (NAMED), remuser is always "nntp" because TCP/IP
doesn't provide any way to obtain remote username.

  Seppo Syrjanen                      Internet : syrjanen@cc.Helsinki.FI
  Computing Center                    BITNET   : syrjanen@finuha.bitnet
  University of Helsinki              Phone    : +358 0 708 4132
  Finland       "Cyborg's gotta do what cyborg's programmed to do." -ABC

-------------------------------------------------------------------

/*
 * Get name of the host requesting new connection
 *
 * for NNTP_SERVER with WIN/TCP. Tested with WIN/TCP 5.0.2.
 *
 * unsigned short f_i contains socket number of the connection.
 */
  
int getremhost(remhost, remuser, unit)
char *remhost, *remuser;
int unit;
{
    struct hostent *hp;
    struct sockaddr name;
    int namelen;

    if (remuser) strcpy(remuser,"nntp");
    if (remhost) {
        namelen=sizeof(name);
        getpeername(f_i,&name,&namelen);
        hp = gethostbyaddr(&name.sa_data[2],4,AF_INET);
        if (hp == NULL) {
           fprintf (stderr,"gethostbyaddr: error %d \n",h_errno);
           strcpy(remhost,"TCP");
        } else                   
           strcpy(remhost,hp->h_name);
    };
}