[omniORB] gethostbyname/addr on win32.

Daniel Bell Daniel.Bell@colorbus.com.au
Thu Dec 19 00:11:01 2002


Hi, 

In november, Luke Deller posted a patch for using gethostbyname() on win32
with string representations of IP numbers. See
http://www.omniorb-support.com/pipermail/omniorb-list/2002-November/022161.h
tml. On Win32, the doco specifies that gethostbyname() function should not
be used to get host information when the host name is an IP number. In that
case inet_addr() and gethostbyaddr() should be used. I have applied this
patch to omniorb 4.0.0 code and have been using it.

However, if the win32 machine does not have a reverse DNS entry for it in
the DNS, then the host information is failed to be retrieved. 

For example, on my NT4 box:

    ~/src/c++ $ nslookup gx300
    Server:  cb-mlb-svr03.colorbus.com.au
    Address:  203.6.240.3

    Name:    gx300.colorbus.com.au
    Address:  203.6.240.210

    ~/src/c++ $ nslookup 203.6.240.210
    *** cb-mlb-svr03.colorbus.com.au can't find 203.6.240.210: Non-existent
domain
    Server:  cb-mlb-svr03.colorbus.com.au
    Address:  203.6.240.3

When I attempt to start omninames on this box, it fails with the error
message:

	c:> omniNames -start 3163
	omniORB: Cannot get the address of host 203.6.240.210
	omniORB: Error: Unable to create an endpoint of this description:
giop:tcp::3163

If the code in libcWrapper.cc:203 is changed from 

      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);

to

      struct hostent *hp = NULL;

    #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);
	if ( hp == NULL )
          hp = ::gethostbyname(name);

then the error goes away in this instance. (The hostname returned in the
hostent structure is the original IP address, rather than a hostname
though.) However, the failed gethostbyaddr() function call is quite slow
(about 3-5 seconds on our system).

Any ideas on how to better solve this problem?

Thanks,
Daniel.

- Daniel Bell
- Software Engineer, Colorbus Pty Ltd
- Email: daniel.bell@colorbus.com.au
- Phone: 61 3 8574 8035
- WWW:   http://www.colorbus.com