2 * misc.c Various miscellaneous functions.
4 * Version: @(#)misc.c 1.00 19-Jul-1999 miquels@cistron.nl
8 "@(#)misc.c 1.00 Copyright 1999 Cistron Internet Services B.V.";
12 #include <sys/types.h>
13 #include <sys/socket.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
27 #include "libradius.h"
34 * Return a printable host name (or IP address in dot notation)
35 * for the supplied IP address.
37 char * ip_hostname(UINT4 ipaddr)
40 static char hstname[128];
42 hp = gethostbyaddr((char *)&ipaddr, sizeof (struct in_addr), AF_INET);
44 ip_ntoa(hstname, ipaddr);
47 return (char *)hp->h_name;
52 * Return an IP address in from a host
53 * name or address in dot notation.
55 UINT4 ip_getaddr(char *host)
60 if ((a = ip_addr(host)) != 0)
63 if ((hp = gethostbyname(host)) == NULL)
66 return (*(UINT4 *)hp->h_addr);
71 * Return an IP address in standard dot notation
73 char *ip_ntoa(char *buffer, UINT4 ipaddr)
83 return buffer ? buffer : r;
88 * Return an IP address from
89 * one supplied in standard dot notation.
91 UINT4 ip_addr(char *ip_str)
95 if (inet_aton(ip_str, &in) == 0)