[erlang-patches] erl_call can now use an IP address for remote node name

Michael Santos michael.santos@REDACTED
Mon Oct 4 22:44:44 CEST 2010


On Mon, Oct 04, 2010 at 07:11:23PM +0200, Julien Barbot wrote:

>> Here is a minimal patch that fixes Julien's problem. The return value
>> of inet_addr() is always big endian.
>
> So be it :) This is more simple than my solution. I do not have time to  
> check it now, nor time to check it on a Windows version less than  
> Windows Vista.

Is the get_hostent() function even needed? On Unix and Windows,
gethostbyname() works with IPv4 addresses as well as hostnames and getting
rid of get_hostent() will fix the bug with hostnames that begin with a
number mentioned in the comments. I did some light testing, but maybe
I am missing something subtle. If no one sees a problem, I'll send in
a properly formatted patch later.


diff --git a/lib/erl_interface/src/prog/erl_call.c b/lib/erl_interface/src/prog/erl_call.c
index 448de9a..33ff6da 100644
--- a/lib/erl_interface/src/prog/erl_call.c
+++ b/lib/erl_interface/src/prog/erl_call.c
@@ -119,5 +119,4 @@ static void usage_error(const char *progname, const char *switchname);
 static void usage(const char *progname);
 static int get_module(char **mbuf, char **mname);
-static struct hostent* get_hostent(char *host);
 static int do_connect(ei_cnode *ec, char *nodename, struct call_flags *flags);
 static int read_stdin(char **buf);
@@ -368,6 +367,6 @@ int erl_call(int argc, char **argv)
      */
     /* FIXME better error string */
-    if ((hp = get_hostent(host)) == 0) {
-	fprintf(stderr,"erl_call: can't get_hostent(%s)\n", host);
+    if ((hp = ei_gethostbyname(host)) == 0) {
+	fprintf(stderr,"erl_call: can't ei_gethostbyname(%s)\n", host);
 	exit(1);
     }
@@ -605,30 +604,4 @@ int erl_call(int argc, char **argv)
  ***************************************************************************/
 
-/*
- * Get host entry (by address or name)
- */
-/* FIXME: will fail on names like '2fun4you'.  */
-static struct hostent* get_hostent(char *host)
-{
-  if (isdigit((int)*host)) {
-    struct in_addr ip_addr;
-    int b1, b2, b3, b4;
-    long addr;
-      
-    /* FIXME: Use inet_aton() (or inet_pton() and get v6 for free). */
-    if (sscanf(host, "%d.%d.%d.%d", &b1, &b2, &b3, &b4) != 4) {
-	return NULL;
-    }
-    addr = inet_addr(host);
-    ip_addr.s_addr = htonl(addr);
-      
-    return ei_gethostbyaddr((char *)&ip_addr,sizeof(struct in_addr), AF_INET);
-  }
-
-  return ei_gethostbyname(host);
-} /* get_hostent */
-
-
-
 
 /* 


More information about the erlang-patches mailing list