Operating System - OpenVMS
1760548 Members
2877 Online
108894 Solutions
New Discussion юеВ

gethostname() returns undisered name

 
SOLVED
Go to solution
Amit Levin
Occasional Advisor

gethostname() returns undisered name

Hi all,
I have a machine with 2 network interfaces.
10.10.x.x and 10.5.x.x, when I activate the gethostname() function the return name is the name associated with the 10.5 network.
how can I change it to 10.10 network?
attached is a sample program, you can compile and run it to simulate problem.
computers is the name and coding is the game, dont play the game, just say the name
5 REPLIES 5
Martin P.J. Zinser
Honored Contributor

Re: gethostname() returns undisered name

Hi Amit,

if you do a tcpip show int, which address is listed first? That should be the one gethostname reports on.

Greetings, Martin
Amit Levin
Occasional Advisor

Re: gethostname() returns undisered name

Hi Martin,
this is the output of tcpip show int:
73::users:[amit] tcpip show int
Packets
Interface IP_Addr Network mask Receive Send MTU

IE0 10.10.14.20 255.255.0.0 171934150 191212288 1500
LO0 127.0.0.1 255.0.0.0 35385744 35385744 4096
WE0 10.5.14.33 255.255.0.0 0 115 1500
what amazes me, is that the first interface listed is 10.10.14.20 that should return "cell73" in response to gethostname()
computers is the name and coding is the game, dont play the game, just say the name
Martin P.J. Zinser
Honored Contributor

Re: gethostname() returns undisered name

Hi Amit,
I think the key is that the interfaces are of different type. I've checked with a three interface system of ours (also various types IE0, WE1, WF0) and found a similar behaviour than reported by you. On systems with all WEx devices my observation is that the first one is picked.

As a pure guess: All the systems I looked at picked the alphabetically first configured IP interface to determine the hostname.

Greetings, Martin

P.S. That might not be very helpful in your case since switching interfaces might not be an option.

P.P.S. If you are really desparate you might want to redefine the tcpip$inet_hostaddr logical and see if this changes the translation. This is untested by me and might have sideeffects you do not like!
John Gillings
Honored Contributor
Solution

Re: gethostname() returns undisered name

gethostname returns the "real" host name. This is the catenation of LOCAL_HOST and DOMAIN values as defined in TCPIP Services.
See:

$ TCPIP SHOW CONFIGURATION COMMUNICATION

You can change these with:

$ TCPIP SET CONFIGURATION COMMUNICATION -
/LOCAL_HOST=name/DOMAIN=name

At runtime, gethostname translates the system executive logical names TCPIP$INET_NODE and TCPIP$INET_DOMAIN. (note group, process and job values are ignored). In practice changing these logical names will change the result of gethostname, but may cause other unpredictable side effects - this is NOT recommended.

Depending on what you're really trying to achieve, perhaps you should be using gethostbyaddr() using the 10.5 network address?

To get more general, you could use ioctl() to find the IP addresses associated with all interfaces on the host, then gethostbyaddr() to find out all possible host names?
A crucible of informative mistakes
Amit Levin
Occasional Advisor

Re: gethostname() returns undisered name

10x John, I am going to try it soon.
since this is a production system, i'll post a reply next wednsday or thursday and tell you how did it go.
computers is the name and coding is the game, dont play the game, just say the name