Inetaddress.getlocalhost in Java ()
The final call in Inetaddress.getlocalhost () is Inet6addressimpl.java (depending on whether you use IPv4 or IPv6) Getlocalhostname code in native
Finally, in the native code,
Jniexport jstring jnicall
java_java_net_inet6addressimpl_getlocalhostname (jnienv *env, jobject this) {
char HOSTNAME[NI_MAXHOST+1];
Hostname[0] = ' the ';
if (Jvm_gethostname (hostname, Maxhostnamelen)) {/
* Something went wrong, maybe networking is not setup? */
strcpy (hostname, "localhost");
} else {
...
}}
Macro definition for Jvm_gethostname
Jvm_leaf (int, jvm_gethostname (char* name, int namelen))
jvmwrapper ("Jvm_gethostname");
Return Hpi::get_host_name (name, Namelen);
Jvm_end
Functions in Linux
inline int hpi::get_host_name (char* name, int namelen) {return
:: GetHostName (name, Namelen);
That is, by invoking the GetHostName kernel function in Linux
implementation of GetHostName in Linux
Hostname in Linux is a variable that is implemented in the Shell startup script "/etc/rc.d/rc.sysinit" when the system initializes, mainly reading "/etc/sysconfig/network" the value of the hostname in
Here are a few points to note:
1. If there is no hostname in the file, the default localhost is used
2. If the value of hostname is found to be localhost or localhost.localdomain, find the hostname of this IP in/etc/hosts according to their actual IP.
3. If not, use localhost or localhost.localdomain
You can use the command
hostname xxx
Modify the hostname and do not need to reboot.