Discussion:
[omniORB] Cannot get the name of this host. - gethostname() fails ?
Martin B.
2009-11-26 22:24:22 UTC
Permalink
Hi there!

We have a Windows XP PC where we have installed omniORB 4.1.2 and when
we try to start omniNames, the following message is printed out and then
omninames terminates: (that's what they told me on the phone, so it may
not be accurate char for char)
<date>:
Error: Cannot get the name of this host.

Searching for "Cannot get the name of this host." in the omniORB sources
it seems this is printed when gethostname() fails (tcpEndpoint.cc:565).

I'm at a loss why this may fail. I have sent my colleague a short
testprogram and when he runs that on the machine, it correctly reports
the hostname. (Find the testprg below for reference)

We've set traceLevel:40 in the registry but he told me that there are
*no* trace loggings output by omninames, so maybe we didn't get that
right over the phone.

ANY ideas what might be broken here?


cheers,
Martin


## test code for gethostname() ##
-- main.cpp --
#include <winsock.h>

#define OMNIORB_HOSTNAME_MAX 512

int main()
{
WSADATA WSAData;
if( WSAStartup(MAKEWORD(1, 0), &WSAData) != 0) {
printf("WSA Startup failed!\n");
return 1;
}

char self[OMNIORB_HOSTNAME_MAX];
if (gethostname(&self[0],OMNIORB_HOSTNAME_MAX) == SOCKET_ERROR){
int err = ::WSAGetLastError();
printf("gethostname() failed! errorcode == %d\n", err);
}
else {
printf("gethostname() == %s\n", self);
}

WSACleanup();
return 0;
}
Martin B.
2009-11-27 13:44:06 UTC
Permalink
Post by Martin B.
Hi there!
We have a Windows XP PC where we have installed omniORB 4.1.2 and when
we try to start omniNames, the following message is printed out and then
omninames terminates: (that's what they told me on the phone, so it may
not be accurate char for char)
Error: cannot get the name of this host.
The exact error message is:
<date>

Error: cannot get the name of this host.
Post by Martin B.
Searching for "Cannot get the name of this host." in the omniORB sources
it seems this is printed when gethostname() fails (tcpEndpoint.cc:565).
It is not from tcpEndpoint, bt it is generated in
src\appl\omniNames\log.cc:239 by this code:
DWORD machineName_len = MAX_COMPUTERNAME_LENGTH;
CORBA::String_var machineName = CORBA::string_alloc(machineName_len);
if (!GetComputerName((LPTSTR)(char*)machineName, &machineName_len)) {
cerr << ts.t() << "Error: cannot get the name of this host." << endl;
exit(1);
}
Post by Martin B.
ANY ideas what might be broken here?
The problem is that GetComputerName must be passed
MAX_COMPUTERNAME_LENGTH + 1(!) length for long computernames.

I have checked and the fix is already in omniORB since Sep.2008 so I
guess that's a good opportunity to upgrade to a newer omniORB version.

br,
Martin

Loading...