static char * plugin_get_hostname (SCPluginIfcfg *plugin) { shvarFile *network; char *hostname; gboolean ignore_localhost; if (g_file_get_contents (HOSTNAME_FILE, &hostname, NULL, NULL)) { g_strchomp (hostname); return hostname; } network = svOpenFile (SC_NETWORK_FILE, NULL); if (!network) { _LOGW ("Could not get hostname: failed to read " SC_NETWORK_FILE); return NULL; } hostname = svGetValue (network, "HOSTNAME", FALSE); ignore_localhost = svTrueValue (network, "NM_IGNORE_HOSTNAME_LOCALHOST", FALSE); if (ignore_localhost) { /* Ignore a default hostname ('localhost[6]' or 'localhost[6].localdomain[6]') * to preserve 'network' service behavior. */ if (hostname && !nm_utils_is_specific_hostname (hostname)) { g_free (hostname); hostname = NULL; } } svCloseFile (network); return hostname; }
void nm_dhcp_manager_set_default_hostname (NMDhcpManager *manager, const char *hostname) { NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE (manager); g_clear_pointer (&priv->default_hostname, g_free); /* Never send 'localhost'-type names to the DHCP server */ if (!nm_utils_is_specific_hostname (hostname)) return; priv->default_hostname = g_strdup (hostname); }