Mercurial > pidgin
comparison src/network.c @ 11195:3aeb85cc9cda
[gaim-migrate @ 13319]
*** empty log message ***
committer: Tailor Script <tailor@pidgin.im>
author | Adam Warrington <awarring> |
---|---|
date | Sun, 07 Aug 2005 17:54:19 +0000 |
parents | 50224ac8184d |
children | ff728e84d59a |
comparison
equal
deleted
inserted
replaced
11194:4c1f45ac00e9 | 11195:3aeb85cc9cda |
---|---|
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 "upnp.h" | |
32 | 33 |
33 const unsigned char * | 34 const unsigned char * |
34 gaim_network_ip_atoi(const char *ip) | 35 gaim_network_ip_atoi(const char *ip) |
35 { | 36 { |
36 static unsigned char ret[4]; | 37 static unsigned char ret[4]; |
132 | 133 |
133 const char * | 134 const char * |
134 gaim_network_get_my_ip(int fd) | 135 gaim_network_get_my_ip(int fd) |
135 { | 136 { |
136 const char *ip = NULL; | 137 const char *ip = NULL; |
138 const char *controlURL = NULL; | |
137 | 139 |
138 /* Check if the user specified an IP manually */ | 140 /* Check if the user specified an IP manually */ |
139 if (!gaim_prefs_get_bool("/core/network/auto_ip")) { | 141 if (!gaim_prefs_get_bool("/core/network/auto_ip")) { |
140 ip = gaim_network_get_public_ip(); | 142 ip = gaim_network_get_public_ip(); |
141 if (ip != NULL) | 143 if (ip != NULL) |
142 return ip; | 144 return ip; |
143 } | 145 } |
144 | 146 |
147 /* attempt to get the ip from a NAT device */ | |
148 if ((controlURL = gaim_upnp_discover()) != NULL) { | |
149 ip = gaim_upnp_get_public_ip(controlURL); | |
150 if (ip != NULL) | |
151 return ip; | |
152 } | |
153 | |
145 /* Just fetch the IP of the local system */ | 154 /* Just fetch the IP of the local system */ |
146 return gaim_network_get_local_system_ip(fd); | 155 return gaim_network_get_local_system_ip(fd); |
147 } | 156 } |
148 | 157 |
149 static int | 158 static int |
150 gaim_network_do_listen(unsigned short port) | 159 gaim_network_do_listen(unsigned short port) |
151 { | 160 { |
152 int listenfd = -1; | 161 int listenfd = -1; |
153 const int on = 1; | 162 const int on = 1; |
163 const char *controlURL = NULL; | |
154 #if HAVE_GETADDRINFO | 164 #if HAVE_GETADDRINFO |
155 int errnum; | 165 int errnum; |
156 struct addrinfo hints, *res, *next; | 166 struct addrinfo hints, *res, *next; |
157 char serv[6]; | 167 char serv[6]; |
158 | 168 |
164 hints.ai_flags = AI_PASSIVE; | 174 hints.ai_flags = AI_PASSIVE; |
165 hints.ai_family = AF_UNSPEC; | 175 hints.ai_family = AF_UNSPEC; |
166 hints.ai_socktype = SOCK_STREAM; | 176 hints.ai_socktype = SOCK_STREAM; |
167 errnum = getaddrinfo(NULL /* any IP */, serv, &hints, &res); | 177 errnum = getaddrinfo(NULL /* any IP */, serv, &hints, &res); |
168 if (errnum != 0) { | 178 if (errnum != 0) { |
169 #ifndef _WIN32 | |
170 gaim_debug_warning("network", "getaddrinfo: %s\n", gai_strerror(errnum)); | 179 gaim_debug_warning("network", "getaddrinfo: %s\n", gai_strerror(errnum)); |
171 if (errnum == EAI_SYSTEM) | 180 if (errnum == EAI_SYSTEM) |
172 gaim_debug_warning("network", "getaddrinfo: system error: %s\n", strerror(errno)); | 181 gaim_debug_warning("network", "getaddrinfo: system error: %s\n", strerror(errno)); |
173 #else | |
174 gaim_debug_warning("network", "getaddrinfo: Error Code = %d\n", errnum); | |
175 #endif | |
176 return -1; | 182 return -1; |
177 } | 183 } |
178 | 184 |
179 /* | 185 /* |
180 * Go through the list of addresses and attempt to listen on | 186 * Go through the list of addresses and attempt to listen on |
223 close(listenfd); | 229 close(listenfd); |
224 return -1; | 230 return -1; |
225 } | 231 } |
226 fcntl(listenfd, F_SETFL, O_NONBLOCK); | 232 fcntl(listenfd, F_SETFL, O_NONBLOCK); |
227 | 233 |
234 if((controlURL = gaim_upnp_discover()) != NULL) { | |
235 if(!gaim_upnp_set_port_mapping(controlURL, port, "TCP")) { | |
236 gaim_upnp_remove_port_mapping(controlURL, port, "TCP"); | |
237 gaim_upnp_set_port_mapping(controlURL, port, "TCP"); | |
238 } | |
239 } | |
240 | |
228 gaim_debug_info("network", "Listening on port: %hu\n", gaim_network_get_port_from_fd(listenfd)); | 241 gaim_debug_info("network", "Listening on port: %hu\n", gaim_network_get_port_from_fd(listenfd)); |
229 return listenfd; | 242 return listenfd; |
230 } | 243 } |
231 | 244 |
232 int | 245 int |
277 } | 290 } |
278 | 291 |
279 void | 292 void |
280 gaim_network_init(void) | 293 gaim_network_init(void) |
281 { | 294 { |
282 gaim_debug_register_category("network"); | |
283 | |
284 gaim_prefs_add_none ("/core/network"); | 295 gaim_prefs_add_none ("/core/network"); |
285 gaim_prefs_add_bool ("/core/network/auto_ip", TRUE); | 296 gaim_prefs_add_bool ("/core/network/auto_ip", TRUE); |
286 gaim_prefs_add_string("/core/network/public_ip", ""); | 297 gaim_prefs_add_string("/core/network/public_ip", ""); |
287 gaim_prefs_add_bool ("/core/network/ports_range_use", FALSE); | 298 gaim_prefs_add_bool ("/core/network/ports_range_use", FALSE); |
288 gaim_prefs_add_int ("/core/network/ports_range_start", 1024); | 299 gaim_prefs_add_int ("/core/network/ports_range_start", 1024); |