diff src/ft.c @ 6263:3565ee7a5dd3

[gaim-migrate @ 6760] Renamed gaim_xfer_init() to gaim_xfers_init(), and added a function for returning the system's local IP address. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 22 Jul 2003 03:26:33 +0000
parents f0b0c5bca588
children 084e1f6610a8
line wrap: on
line diff
--- a/src/ft.c	Tue Jul 22 00:37:49 2003 +0000
+++ b/src/ft.c	Tue Jul 22 03:26:33 2003 +0000
@@ -51,6 +51,8 @@
 
 	if (ip != NULL && *ip != '\0')
 		xfer->local_ip = g_strdup(ip);
+	else
+		xfer->local_ip = gaim_xfers_get_local_ip();
 
 	ui_ops = gaim_xfer_get_ui_ops(xfer);
 
@@ -704,8 +706,33 @@
 	g_free(title);
 }
 
+/**************************************************************************
+ * File Transfer Subsystem API
+ **************************************************************************/
+char *
+gaim_xfers_get_local_ip(void)
+{
+	struct hostent *host;
+	char localhost[129];
+	long unsigned add;
+	char ip[46];
+
+	if (gethostname(localhost, 128) < 0)
+		return NULL;
+
+	if ((host = gethostbyname(localhost)) == NULL)
+		return NULL;
+
+	memcpy(&add, host->h_addr_list[0], 4);
+	add = htonl(add);
+
+	g_snprintf(ip, 11, "%lu", add);
+
+	return g_strdup(ip);
+}
+
 void
-gaim_xfer_init(void)
+gaim_xfers_init(void)
 {
 	gaim_prefs_add_none("/core/ft");
 	gaim_prefs_add_string("/core/ft/public_ip", "");