Mercurial > pidgin
comparison src/network.c @ 11391:d3755a7ddd82
[gaim-migrate @ 13620]
*** empty log message ***
committer: Tailor Script <tailor@pidgin.im>
author | Adam Warrington <awarring> |
---|---|
date | Wed, 31 Aug 2005 18:50:38 +0000 |
parents | 7d7dd22215ec |
children | 8caea199b018 |
comparison
equal
deleted
inserted
replaced
11390:869cef00a947 | 11391:d3755a7ddd82 |
---|---|
27 | 27 |
28 #include "debug.h" | 28 #include "debug.h" |
29 #include "account.h" | 29 #include "account.h" |
30 #include "network.h" | 30 #include "network.h" |
31 #include "prefs.h" | 31 #include "prefs.h" |
32 #include "stun.h" | |
33 #include "upnp.h" | 32 #include "upnp.h" |
33 | |
34 | 34 |
35 const unsigned char * | 35 const unsigned char * |
36 gaim_network_ip_atoi(const char *ip) | 36 gaim_network_ip_atoi(const char *ip) |
37 { | 37 { |
38 static unsigned char ret[4]; | 38 static unsigned char ret[4]; |
66 | 66 |
67 const char * | 67 const char * |
68 gaim_network_get_public_ip(void) | 68 gaim_network_get_public_ip(void) |
69 { | 69 { |
70 const char *ip; | 70 const char *ip; |
71 struct stun_nattype *stun; | 71 |
72 | |
73 ip = gaim_prefs_get_string("/core/network/public_ip"); | 72 ip = gaim_prefs_get_string("/core/network/public_ip"); |
74 | 73 |
75 if (ip == NULL || *ip == '\0') { | 74 if (ip == NULL || *ip == '\0') |
76 /* Check if STUN discovery was already done */ | 75 return NULL; |
77 stun = gaim_stun_discover(NULL); | |
78 if(stun && stun->status>1) | |
79 return stun->publicip; | |
80 return NULL; | |
81 } | |
82 | 76 |
83 return ip; | 77 return ip; |
84 } | 78 } |
85 | 79 |
86 static const char * | 80 static const char * |
140 | 134 |
141 const char * | 135 const char * |
142 gaim_network_get_my_ip(int fd) | 136 gaim_network_get_my_ip(int fd) |
143 { | 137 { |
144 const char *ip = NULL; | 138 const char *ip = NULL; |
145 char *controlURL = NULL; | 139 GaimUPnPControlInfo* controlInfo = NULL; |
146 | 140 |
147 /* Check if the user specified an IP manually */ | 141 /* Check if the user specified an IP manually */ |
148 if (!gaim_prefs_get_bool("/core/network/auto_ip")) { | 142 if (!gaim_prefs_get_bool("/core/network/auto_ip")) { |
149 ip = gaim_network_get_public_ip(); | 143 ip = gaim_network_get_public_ip(); |
150 if (ip != NULL) | 144 if (ip != NULL) |
151 return ip; | 145 return ip; |
152 } | 146 } |
153 | 147 |
154 /* attempt to get the ip from a NAT device */ | 148 /* attempt to get the ip from a NAT device */ |
155 if ((controlURL = gaim_upnp_discover()) != NULL) { | 149 if ((controlInfo = gaim_upnp_discover()) != NULL) { |
156 ip = gaim_upnp_get_public_ip(controlURL); | 150 ip = gaim_upnp_get_public_ip(controlInfo); |
157 free(controlURL); | 151 g_free(controlInfo->controlURL); |
158 if (ip != NULL) | 152 g_free(controlInfo->serviceType); |
153 g_free(controlInfo); | |
154 if (ip != NULL) { | |
159 return ip; | 155 return ip; |
156 } | |
160 } | 157 } |
161 | 158 |
162 /* Just fetch the IP of the local system */ | 159 /* Just fetch the IP of the local system */ |
163 return gaim_network_get_local_system_ip(fd); | 160 return gaim_network_get_local_system_ip(fd); |
164 } | 161 } |
165 | 162 |
163 | |
166 static int | 164 static int |
167 gaim_network_do_listen(unsigned short port) | 165 gaim_network_do_listen(unsigned short port) |
168 { | 166 { |
169 int listenfd = -1; | 167 int listenfd = -1; |
170 const int on = 1; | 168 const int on = 1; |
171 char *controlURL = NULL; | 169 GaimUPnPControlInfo* controlInfo = NULL; |
172 #if HAVE_GETADDRINFO | 170 #if HAVE_GETADDRINFO |
173 int errnum; | 171 int errnum; |
174 struct addrinfo hints, *res, *next; | 172 struct addrinfo hints, *res, *next; |
175 char serv[6]; | 173 char serv[6]; |
176 | 174 |
241 close(listenfd); | 239 close(listenfd); |
242 return -1; | 240 return -1; |
243 } | 241 } |
244 fcntl(listenfd, F_SETFL, O_NONBLOCK); | 242 fcntl(listenfd, F_SETFL, O_NONBLOCK); |
245 | 243 |
246 if((controlURL = gaim_upnp_discover()) != NULL) { | 244 if((controlInfo = gaim_upnp_discover()) != NULL) { |
247 if(!gaim_upnp_set_port_mapping(controlURL, gaim_network_get_port_from_fd(listenfd), "TCP")) { | 245 if(!gaim_upnp_set_port_mapping(controlInfo, |
248 gaim_upnp_remove_port_mapping(controlURL, gaim_network_get_port_from_fd(listenfd), "TCP"); | 246 gaim_network_get_port_from_fd(listenfd), |
249 gaim_upnp_set_port_mapping(controlURL, gaim_network_get_port_from_fd(listenfd), "TCP"); | 247 "TCP")) { |
250 } | 248 gaim_upnp_remove_port_mapping(controlInfo, |
251 free(controlURL); | 249 gaim_network_get_port_from_fd(listenfd), "TCP"); |
250 gaim_upnp_set_port_mapping(controlInfo, | |
251 gaim_network_get_port_from_fd(listenfd), "TCP"); | |
252 | |
253 } | |
254 g_free(controlInfo->serviceType); | |
255 g_free(controlInfo->controlURL); | |
256 g_free(controlInfo); | |
252 } | 257 } |
253 | 258 |
254 gaim_debug_info("network", "Listening on port: %hu\n", gaim_network_get_port_from_fd(listenfd)); | 259 gaim_debug_info("network", "Listening on port: %hu\n", gaim_network_get_port_from_fd(listenfd)); |
255 return listenfd; | 260 return listenfd; |
256 } | 261 } |