+
+/*******************************************************************
+convert a string to an IP address. The string can be a name or
+dotted decimal number
+ ******************************************************************/
+struct in_addr *ip_address(const char *str)
+{
+ static struct in_addr ret;
+ struct hostent *hp;
+
+ /* try as an IP address */
+ if (inet_aton(str, &ret) != 0) {
+ return &ret;
+ }
+
+ /* otherwise assume it's a network name of some sort and use
+ gethostbyname */
+ if ((hp = gethostbyname(str)) == 0) {
+ rprintf(FERROR, "gethostbyname: Unknown host. %s\n",str);
+ return NULL;
+ }
+
+ if (hp->h_addr == NULL) {
+ rprintf(FERROR, "gethostbyname: host address is invalid for host %s\n",str);
+ return NULL;
+ }
+
+ if (hp->h_length > sizeof(ret)) {
+ rprintf(FERROR, "gethostbyname: host address is too large\n");
+ return NULL;
+ }
+
+ memcpy(&ret.s_addr, hp->h_addr, hp->h_length);
+
+ return(&ret);
+}