changeset 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 4fcfe659568a
children a5a43d03cb51
files src/ft.c src/ft.h src/main.c
diffstat 3 files changed, 47 insertions(+), 3 deletions(-) [+]
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", "");
--- a/src/ft.h	Tue Jul 22 00:37:49 2003 +0000
+++ b/src/ft.h	Tue Jul 22 03:26:33 2003 +0000
@@ -462,10 +462,27 @@
  */
 void gaim_xfer_error(GaimXferType type, const char *who, const char *msg);
 
+/*@}*/
+
+/**************************************************************************/
+/** @name File Transfer Subsystem API                                     */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Returns the IP address of the local system.
+ *
+ * @note The returned IP address must be g_free()'d when no longer
+ *       in use.
+ *
+ * @return The local IP address.
+ */
+char *gaim_xfers_get_local_ip(void);
+
 /**
  * Initializes the file transfer subsystem.
  */
-void gaim_xfer_init(void);
+void gaim_xfers_init(void);
 
 /*@}*/
 
--- a/src/main.c	Tue Jul 22 00:37:49 2003 +0000
+++ b/src/main.c	Tue Jul 22 03:26:33 2003 +0000
@@ -507,7 +507,7 @@
 	gaim_gtk_blist_init();
 	gaim_gtk_conversation_init();
 	gaim_gtk_pounces_init();
-	gaim_gtk_xfer_init();
+	gaim_gtk_xfers_init();
 }
 
 static void