comparison src/network.c @ 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 a85c8c11bfab
children 66268ae5b94a
comparison
equal deleted inserted replaced
13128:8adf78fc630c 13129:d0ae6489a0fb
74 } 74 }
75 75
76 const char * 76 const char *
77 gaim_network_get_public_ip(void) 77 gaim_network_get_public_ip(void)
78 { 78 {
79 const char *ip; 79 return gaim_prefs_get_string("/core/network/public_ip");
80 GaimStunNatDiscovery *stun;
81
82 ip = gaim_prefs_get_string("/core/network/public_ip");
83
84 if (ip == NULL || *ip == '\0') {
85 /* Check if STUN discovery was already done */
86 stun = gaim_stun_discover(NULL);
87 if (stun != NULL && stun->status == GAIM_STUN_STATUS_DISCOVERED)
88 return stun->publicip;
89 return NULL;
90 }
91
92 return ip;
93 } 80 }
94 81
95 static const char * 82 static const char *
96 gaim_network_get_local_ip_from_fd(int fd) 83 gaim_network_get_local_ip_from_fd(int fd)
97 { 84 {
127 tmp = gaim_network_get_local_ip_from_fd(fd); 114 tmp = gaim_network_get_local_ip_from_fd(fd);
128 115
129 if (tmp) 116 if (tmp)
130 return tmp; 117 return tmp;
131 118
119 /* TODO: Make this avoid using localhost/127.0.0.1 */
132 if (gethostname(localhost, 128) < 0) 120 if (gethostname(localhost, 128) < 0)
133 return NULL; 121 return NULL;
134 122
135 if ((host = gethostbyname(localhost)) == NULL) 123 if ((host = gethostbyname(localhost)) == NULL)
136 return NULL; 124 return NULL;
154 GaimStunNatDiscovery *stun; 142 GaimStunNatDiscovery *stun;
155 143
156 /* Check if the user specified an IP manually */ 144 /* Check if the user specified an IP manually */
157 if (!gaim_prefs_get_bool("/core/network/auto_ip")) { 145 if (!gaim_prefs_get_bool("/core/network/auto_ip")) {
158 ip = gaim_network_get_public_ip(); 146 ip = gaim_network_get_public_ip();
159 if (ip != NULL) 147 if ((ip != NULL) && (*ip != '\0'))
160 return ip; 148 return ip;
161 } 149 }
162 150
163 if (ip == NULL || *ip == '\0') { 151 /* Check if STUN discovery was already done */
164 /* Check if STUN discovery was already done */ 152 stun = gaim_stun_discover(NULL);
165 stun = gaim_stun_discover(NULL); 153 if ((stun != NULL) && (stun->status == GAIM_STUN_STATUS_DISCOVERED))
166 if (stun != NULL && stun->status == GAIM_STUN_STATUS_DISCOVERED) 154 return stun->publicip;
167 return stun->publicip; 155
168 156 /* Attempt to get the IP from a NAT device using UPnP */
169 /* attempt to get the ip from a NAT device */ 157 ip = gaim_upnp_get_public_ip();
170 ip = gaim_upnp_get_public_ip(); 158 if (ip != NULL)
171 159 return ip;
172 if (ip != NULL)
173 return ip;
174 }
175 160
176 /* Just fetch the IP of the local system */ 161 /* Just fetch the IP of the local system */
177 return gaim_network_get_local_system_ip(fd); 162 return gaim_network_get_local_system_ip(fd);
178 } 163 }
179 164