src/ft.c

changeset 6263
6fec763a314c
parent 6242
3f9a64e8dd2f
child 6268
6bfd8d16d6a3
--- 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", "");

mercurial