Getting the computer's hostname as seen by the network

7 posts / 0 new
Last post
Hans
Hans's picture
Offline
Last seen: 2 months 3 weeks ago
Joined: 2010-12-09 22:04
Getting the computer's hostname as seen by the network

How do we get the local machine's hostname as seen by the rest of the network?

Annoyingly, gethostname() returns "localhost," which is useless, as does gethostbyname() and uname().

What I actually want is the hostname RoadShow registers with the DHCP server, and that Avast's Wifi Inspector detects when it scans the network. That is, I want the name that other computers on the LAN could use to identify the machine.

Hans

broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
Re: Getting the computer's hostname as seen by the network

This code

  1. #include <stdio.h>
  2.  
  3.  
  4. int main(int argc, char ** argv)
  5. {
  6. char host[256];
  7.  
  8. host[0] = 0;
  9.  
  10. gethostname(host,255);
  11.  
  12. printf("host: \"%s\"\n",host);
  13. }

returns the correct hostname for me

eg

ram:testhostname
host: "amiga"

Though that is not not quite what you want as that hostname is local to my SAM 440 on the rest of the network it's defeined as SAM in the various local hosts databases. Using fixed ips on my network so the router doesn't knw the hostnames of the machines.

So what does the hostname command return?

eg here on my SAM I get:

  1. 10.AmigaOS4:> hostname
  2. amiga

which matches up.

Do you actuall want the hostname or just the host address?

Hans
Hans's picture
Offline
Last seen: 2 months 3 weeks ago
Joined: 2010-12-09 22:04
Re: Getting the computer's hostname as seen by the network

Interesting. Is that what you defined in your Internet prefs "Hosts" section?

I really want the hostname that the machine will be identified as by other machines on the network, and NOT just the IP address (which can change; some routers even lack the functionality to choose static IPs).

Hans

http://hdrlab.org.nz/ - Amiga OS 4 projects, programming articles and more. Home of the RadeonHD driver for Amiga OS 4.x project.
http://keasigmadelta.co.nz/ - more of my software.

broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
Re: Getting the computer's hostname as seen by the network

Yes that is the domain associated with the machine IP in hosts.

broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
Re: Getting the computer's hostname as seen by the network

(which can change; some routers even lack the functionality to choose static IPs).

It may change from boot to boot, but should surely be constant for a given session?

I'm not sure how to get it if the domain name is unknown though.

Hans
Hans's picture
Offline
Last seen: 2 months 3 weeks ago
Joined: 2010-12-09 22:04
Re: Getting the computer's hostname as seen by the network

It may change from boot to boot, but should surely be constant for a given session?

Being constant for a given session isn't guaranteed. Even if it were, it's still not helpful. I need a human readable name, not an address.

Hans

http://hdrlab.org.nz/ - Amiga OS 4 projects, programming articles and more. Home of the RadeonHD driver for Amiga OS 4.x project.
http://keasigmadelta.co.nz/ - more of my software.

mritter0
mritter0's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2014-04-21 21:15
Re: Getting the computer's hostname as seen by the network

Hans,

In Workbench Explorer, turn on Preview Pane, go to Computer, what does the line "Network device name:" say for you? The name you want?

Log in or register to post comments