Missing Glib::get_host_name() function
The g_get_host_name()
function was introduced in glib
2.8. It is supposed to return a host name.
https://developer.gnome.org/glib/stable/glib-Miscellaneous-Utility-Functions.html#g-get-host-name
Return a name for the machine.
However, glibmm
doesn't provide anything like this. There is no Glib::get_host_name()
or anything similar.
https://github.com/GNOME/glib/blob/3ad375a629c91a27d0165a31f0ed298fd553de0a/glib/gutils.h
https://github.com/GNOME/glib/blob/3ad375a629c91a27d0165a31f0ed298fd553de0a/glib/gutils.c
Why? Is this an oversight?
Example values:
user_name: scx
host_name: zeus
Temporary patch:
diff --git a/glib/src/miscutils.ccg b/glib/src/miscutils.ccg
index 90043af..5e00234 100644
--- a/glib/src/miscutils.ccg
+++ b/glib/src/miscutils.ccg
@@ -93,6 +93,12 @@ get_real_name()
}
std::string
+get_host_name()
+{
+ return convert_const_gchar_ptr_to_stdstring(g_get_host_name());
+}
+
+std::string
get_home_dir()
{
return convert_const_gchar_ptr_to_stdstring(g_get_home_dir());
diff --git a/glib/src/miscutils.hg b/glib/src/miscutils.hg
index ffc87f3..932f6c8 100644
--- a/glib/src/miscutils.hg
+++ b/glib/src/miscutils.hg
@@ -163,6 +163,25 @@ std::string get_user_name();
*/
std::string get_real_name();
+/** Return a name for the machine.
+ *
+ * The returned name is not necessarily a fully-qualified domain name,
+ * or even present in DNS or some other name service at all. It need
+ * not even be unique on your local network or site, but usually it
+ * is. Callers should not rely on the return value having any specific
+ * properties like uniqueness for security purposes. Even if the name
+ * of the machine is changed while an application is running, the
+ * return value from this function does not change. The returned
+ * string is owned by GLib and should not be modified or freed. If no
+ * name can be determined, a default fixed string "localhost" is
+ * returned.
+ *
+ * @return The host name of the machine.
+ *
+ * @newin{2,64}
+ */
+std::string get_host_name();
+
/** Gets the current user's home directory.
* @return The current user's home directory or an empty string if not defined.
*/
PR is on the way.