What will the gethostname system call return on a machine with multiple network interfaces? Is it possible to configure this at the OS level?
The number of network interfaces used to connect the machine to the world is more or less independent of the number of host names. You can have multiple interfaces with a single name (even though it's somewhat unusual) or multiple names with a single interface (considerably more common).
As to what value it does return, MSDN says:
f the gethostname function is used on a cluster resource on Windows Server 2008, Windows Server 2003, or Windows 2000 Server and the _CLUSTER_NETWORK_NAME_ environment variable is defined, then the value in this environment variable overrides the actual hostname and is returned. On a cluster resource, the _CLUSTER_NETWORK_NAME_ environment variable contains the name of the cluster.
The gethostname function queries namespace providers to determine the local host name using the SVCID_HOSTNAME GUID defined in the Svgguid.h header file. If no namespace provider responds, then the gethostname function returns the NetBIOS name of the local computer.
As such, it's normally a question of DNS configuration, but for a member of a cluster you can set an environment variable.
http://beej.us/guide/bgnet/output/html/multipage/gethostnameman.html
there will be one hostname -> root name
The Hostname is stored at the OS Level .It doesn't matter how many NIC's your PC has, it will be the same for all of them.
Related
I'm currently looking into some ways to identify different machines using my software, I am working with a old gaming console in which I cannot access the typical unique identifiers most people would use (HWID, etc...).
After looking through the SDK required to compile software on this old gaming console I noticed I can get a users DHCP Host Name, (You can view your DHCP Host Name on a windows machine by entering "hostname.exe" within command prompt)
So my question is, would using the DHCP Host Name as a way to uniquely identify different machines accessing my software be effective in differentiating different users?
I have a system with multiple NIC and so multiple ip addresses and I've to use an SDK whose initialization that needs my local address and the remote address.
I want to autoselect the local endpoint. At the moment I'm enumerating all local addresses (via GetAdaptersAddresses) checking for the best match ( to be correct I should use the subnet mask).
But given that this job is done by the routing table is there any Windows API that given a remote address gives me back the right local endpoint ?
is there any Windows API that given a remote address gives me back the right local endpoint ?
Have a look at GetBestInterface() and GetBestInterfaceEx().
Both functions return an index to an interface. You can then retrieve the interface's IP by enumerating network interfaces with GetIpAddrTable(), or enumerating network adapters with GetAdaptersInfo()/GetAdaptersAddresses(), until you find an entry with a matching interface index.
I'm developing Spring MVC cluster website and emulating a cluster on one developer machine, running several instances of Jetty 9.2.2 on different local addresses:
127.0.0.10
127.0.0.11
127.0.0.12
and so on. To use CometD clustering solution, I need to know at runtime IP address of Jetty server, which is currently serving this particular runtime. I mean, would it be 127.0.0.10, or 127.0.0.12. I set this parameter in start.ini:
jetty.host=127.0.0.N
where N is different for every of 5 instances.
So, how do I know it at runtime?
The CometD Oort cluster supports three modes of discovering other nodes: automatic, static and manual.
The automatic way is based on multicast, so if you have multicast working on the hosts the problem should be solved.
With the static way, you just need one "well known" server to be up and running, and point all other nodes to that "well known" server.
With the manual way, you can use other discovery mechanisms (for example, lookup jetty.host in the System properties) and initialize the Oort instances with the discovered values.
It is all explained in the documentation.
I want to generate the list of IP addresses on the local machine using C++. I looked at boost and it doesn't seem to have any function to do so.
I need this because I want to see if the host name/IP address entered by the user is for the local machine.
I want to see if the host name/IP address entered by the user is for the local machine.
In general, you cannot do that. There could be any number of host names registered for the local machine. You could try to open a socket and see if ends up at yourself though.
If you are looking for portable solution, try ACE library. This library provide cross-platform functionality for network applications development.
Using the output of "ipconfig /all" i can get what I need but I want a more reliable technique to get ip of an interface (practically the interface has to be identified by it's name) in case of ipconfig was corrupted or was not available for any reason.
I'm not sure what you mean by "server and client", but if you're looking for an API that tells you the IP address(es) associated with the local machine's network interfaces, check out getifaddrs() (for Linux/MacOSX/POSIX) and GetAdaptersAddresses() (for Windows). If you want a usage example for those calls, have a look at the GetNetworkInterfaceInfos() function in this file.
(If you wanted to get the IP address of a client connected to the local machine, call getpeername() on the socket that is associated with that client's connection)
Since you mentioned ipconfig, I assume you want to do this on windows.
Windows has a set of IP Helper apis designed for retrieval and modify networking settings.
And here is a simple sample: http://msdn.microsoft.com/en-us/library/aa366298(VS.85).aspx