changeset 19621:cab5dd8da484

Handle the case where gethostname() fails or returns a null hostname. This really shouldn't happen on a properly configured system, but its failure also should not prevent us from being able to log into IRC. Fixes #2932
author Ethan Blanton <elb@pidgin.im>
date Mon, 03 Sep 2007 23:15:11 +0000
parents b4a4a0a09e0a
children 793973fedd02
files libpurple/protocols/irc/irc.c
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/irc/irc.c	Mon Sep 03 22:04:47 2007 +0000
+++ b/libpurple/protocols/irc/irc.c	Mon Sep 03 23:15:11 2007 +0000
@@ -347,6 +347,7 @@
 	const char *username, *realname;
 	struct irc_conn *irc = gc->proto_data;
 	const char *pass = purple_connection_get_password(gc);
+        int ret;
 
 	if (pass && *pass) {
 		buf = irc_format(irc, "vv", "PASS", pass);
@@ -359,8 +360,12 @@
 	}
 
 
-	gethostname(hostname, sizeof(hostname));
+	ret = gethostname(hostname, sizeof(hostname));
 	hostname[sizeof(hostname) - 1] = '\0';
+        if (ret < 0 || hostname[0] == '\0') {
+        	purple_debug_warning("irc", "gethostname() failed -- is your hostname set?");
+        	strcpy(hostname, "localhost");
+        }
 	realname = purple_account_get_string(irc->account, "realname", "");
 	username = purple_account_get_string(irc->account, "username", "");