Mercurial > pidgin
changeset 13129:d0ae6489a0fb
[gaim-migrate @ 15491]
Remove some sillyness when attempting to autodetect our IP address
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 06 Feb 2006 04:20:30 +0000 |
parents | 8adf78fc630c |
children | 66268ae5b94a |
files | src/core.c src/gtkprefs.c src/network.c src/protocols/simple/simple.c |
diffstat | 4 files changed, 22 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core.c Sun Feb 05 22:31:48 2006 +0000 +++ b/src/core.c Mon Feb 06 04:20:30 2006 +0000 @@ -99,6 +99,9 @@ gaim_dbus_init(); #endif + /* Call this early on to try to auto-detect our IP address */ + gaim_network_get_my_ip(-1); + /* Initialize all static protocols. */ static_proto_init();
--- a/src/gtkprefs.c Sun Feb 05 22:31:48 2006 +0000 +++ b/src/gtkprefs.c Mon Feb 06 04:20:30 2006 +0000 @@ -986,9 +986,13 @@ g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(network_ip_changed), NULL); - if (gaim_network_get_public_ip() != NULL) + /* + * TODO: This could be better by showing the autodeteced + * IP separately from the user-specified IP. + */ + if (gaim_network_get_my_ip(-1) != NULL) gtk_entry_set_text(GTK_ENTRY(entry), - gaim_network_get_public_ip()); + gaim_network_get_my_ip(-1)); gaim_set_accessible_label (entry, label);
--- a/src/network.c Sun Feb 05 22:31:48 2006 +0000 +++ b/src/network.c Mon Feb 06 04:20:30 2006 +0000 @@ -76,20 +76,7 @@ const char * gaim_network_get_public_ip(void) { - const char *ip; - GaimStunNatDiscovery *stun; - - ip = gaim_prefs_get_string("/core/network/public_ip"); - - if (ip == NULL || *ip == '\0') { - /* Check if STUN discovery was already done */ - stun = gaim_stun_discover(NULL); - if (stun != NULL && stun->status == GAIM_STUN_STATUS_DISCOVERED) - return stun->publicip; - return NULL; - } - - return ip; + return gaim_prefs_get_string("/core/network/public_ip"); } static const char * @@ -129,6 +116,7 @@ if (tmp) return tmp; + /* TODO: Make this avoid using localhost/127.0.0.1 */ if (gethostname(localhost, 128) < 0) return NULL; @@ -156,22 +144,19 @@ /* Check if the user specified an IP manually */ if (!gaim_prefs_get_bool("/core/network/auto_ip")) { ip = gaim_network_get_public_ip(); - if (ip != NULL) + if ((ip != NULL) && (*ip != '\0')) return ip; } - if (ip == NULL || *ip == '\0') { - /* Check if STUN discovery was already done */ - stun = gaim_stun_discover(NULL); - if (stun != NULL && stun->status == GAIM_STUN_STATUS_DISCOVERED) - return stun->publicip; + /* Check if STUN discovery was already done */ + stun = gaim_stun_discover(NULL); + if ((stun != NULL) && (stun->status == GAIM_STUN_STATUS_DISCOVERED)) + return stun->publicip; - /* attempt to get the ip from a NAT device */ - ip = gaim_upnp_get_public_ip(); - - if (ip != NULL) - return ip; - } + /* Attempt to get the IP from a NAT device using UPnP */ + ip = gaim_upnp_get_public_ip(); + if (ip != NULL) + return ip; /* Just fetch the IP of the local system */ return gaim_network_get_local_system_ip(fd);
--- a/src/protocols/simple/simple.c Sun Feb 05 22:31:48 2006 +0000 +++ b/src/protocols/simple/simple.c Mon Feb 06 04:20:30 2006 +0000 @@ -61,17 +61,6 @@ rand() & 0xFFFF, rand() & 0xFFFF); } -static char *get_my_ip() { - static char my_ip[42]; - const char *tmp = gaim_network_get_public_ip(); - - if(!tmp || !strcmp(tmp,"0.0.0.0")) { - tmp = gaim_network_get_my_ip(-1); - } - strcpy(my_ip, tmp ? tmp : "0.0.0.0"); - return my_ip; -} - static const char *simple_list_icon(GaimAccount *a, GaimBuddy *b) { return "simple"; } @@ -590,7 +579,7 @@ method, url, sip->udp ? "UDP" : "TCP", - get_my_ip(), + gaim_network_get_my_ip(-1), sip->listenport, branch, sip->username, @@ -621,7 +610,7 @@ static void do_register_exp(struct simple_account_data *sip, int expire) { char *uri = g_strdup_printf("sip:%s",sip->servername); char *to = g_strdup_printf("sip:%s@%s",sip->username,sip->servername); - char *contact = g_strdup_printf("Contact: <sip:%s@%s:%d;transport=%s>;methods=\"MESSAGE, SUBSCRIBE, NOTIFY\"\r\nExpires: %d\r\n", sip->username, get_my_ip(), sip->listenport, sip->udp ? "udp" : "tcp", expire); + char *contact = g_strdup_printf("Contact: <sip:%s@%s:%d;transport=%s>;methods=\"MESSAGE, SUBSCRIBE, NOTIFY\"\r\nExpires: %d\r\n", sip->username, gaim_network_get_my_ip(-1), sip->listenport, sip->udp ? "udp" : "tcp", expire); sip->registerstatus = 1;