patch (was Re: [omniORB] Problem Running OmniNames - Cannot get the Address of host 127.0. 0.1 - SOLVED..)

Luke Deller ldeller@xplantechnology.com
Fri Nov 1 03:29:01 2002


This is a multi-part message in MIME format.
--------------060403000309040802080808
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

I also encountered this problem.  When trying to use omniORB on a Win98 
machine with no network adapters, this error message was shown:

	omniORB Cannot get the address of host 127.0.0.1

Andrews solution of adding a network adapter to the system is not a really 
satisfactory in general.

Looking at the source code, this error is produced when a call to 
gethostbyname() fails.  I investigated this a little, and discovered that 
gethostbyname() shouldn't be called with a numeric address such as 
"127.0.0.1"  in win32 (according to Microsoft's documentation).

[Some experiments showed me that in fact this does work when a network 
adapter is active, but fails otherwise.]

A correct win32 implementation should call inet_addr() and gethostbyaddr() 
rather than calling gethostbyname() for a numeric address.  Please find 
attached a patch to libcWrapper.cc in omniORB-4.0.0 which fixes this problem.

Luke.

Olden A (SApS) wrote:
> Hello Everybody,
> 
>  
> 
> I've got it to work, by simulating a network, what seems to happen is 
> that the system (at least under windowsXP and 2000) has to be on the 
> network, - it seems that it doesn't like the IP address 127.0.0.1, but 
> by throwing in a Wifi Card and setting a weird IP address (from the 
> private set) so that it works fine
> 
>  
> 
>  
> 
>  
> 
> -----Original Message-----
> *From:* Olden A (SApS) [mailto:aolden@glam.ac.uk]
> *Sent:* 03 October 2002 09:24
> *To:* 'omniorb-list@omniorb-support.com'
> *Subject:* [omniORB] Problem Running OmniNames - Cannot get the Address 
> of host 127.0. 0.1
> 
>  
> 
> Hi Everybody,
> 
>  
> 
> Thanks to Ulf and Duncun I've got the examples to compile, but I have a 
> problem with getting the OmniNames system to run, if I'm connected to 
> the internet then the system runs without any problems, but if the 
> system isn't connected then when I try to run I get the following error:
> 
>  
> 
> omniORB Cannot get the address of host 127.0.0.1
> 
> omniORB Error: Unable To Create An endpoint of the description: 
> giop:tcp:2807.
> 
>  
> 
>  
> 
> Failed To initialize POAs - Is Omni Names Already running.
> 
>  
> 
> Any suggestion on what I've missed out in the configuration?
> 
>  
> 
> Thanks
> 
> Andrew
> 
>  
> 

--------------060403000309040802080808
Content-Type: text/plain;
 name="gethostbyname.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="gethostbyname.diff"

--- omniORB-4.0.0/src/lib/omniORB/orbcore/libcWrapper.cc	2002-02-25 22:17:13.000000000 +1100
+++ fixed/src/lib/omniORB/orbcore/libcWrapper.cc	2002-11-01 14:09:16.000000000 +1100
@@ -202,15 +202,27 @@
 
   struct hostent *hp;
 
+#ifdef __WIN32__  
+  long IP;
+
+  // avoid using a numeric address with gethostbyname()
+  if ((IP = ::inet_addr(name)) != INADDR_NONE)
+      hp = ::gethostbyaddr((char*)&IP, sizeof(IP), AF_INET);
+  else
+      hp = ::gethostbyname(name);
+#else
+  hp = ::gethostbyname(name);
+#endif
+  
 #ifdef __atmos__
-  if ((hp = ::gethostbyname(name)) <= 0)
+  if (hp <= 0)
     {
       rc = 0;
       non_reentrant.unlock();
       return -1;
     }
 #else
-  if ((hp = ::gethostbyname(name)) == NULL)
+  if (hp == NULL)
     {
 #if defined(__WIN32__) || defined(__vms) && __VMS_VER < 70000000
     rc = 0;

--------------060403000309040802080808--