/* 4m v2.15 (getaddr.c)
 * (C) Copyright 1990 by Carrick Sean Casey
 * (C) Copyright 1993 by Scott Chasin and Michaeljon Miller
 *
 * 3-22-93 See file COPYING for copyright information.
 *
 * Translate remote address
 *
 */

#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include "../h/config.h"


extern long unsigned int inet_addr (/* ??? */);

struct in_addr *
    _getaddress(s)
     char *s;
{
    static struct in_addr iaddr;
    struct hostent *hp;

 /* handle case of "[num.num.num.num]" */
    if (*s == '[') {
        char *p;

        s++;
        for (p = s; *p != '\0'; p++)
            if (*p == ']') {
                *p = '\0';
                break;
            }
    }
 /* handle case of "num.num.num.num" */
    if (*s >= '0' && *s <= '9') {
        if ((iaddr.s_addr = (unsigned long) inet_addr(s)) == -1)
            return (0);
        return (&iaddr);
    }
 /* handle a symbolic address */
    if ((hp = gethostbyname(s)) == (struct hostent *) 0)
        return (0);

 /* copy address into inet address struct */
    memcpy((char *) &iaddr.s_addr, hp->h_addr, (unsigned int) hp->h_length);

    return ((struct in_addr *) & iaddr);
}
