comparison src/network.c @ 11213:ff728e84d59a

[gaim-migrate @ 13344] Changes by Adam Warrington Fixes a crash on UPnP timeout committer: Tailor Script <tailor@pidgin.im>
author Thomas Butter <tbutter>
date Mon, 08 Aug 2005 21:43:44 +0000
parents 3aeb85cc9cda
children 986160f7b6ca
comparison
equal deleted inserted replaced
11212:46086fcc82b7 11213:ff728e84d59a
132 } 132 }
133 133
134 const char * 134 const char *
135 gaim_network_get_my_ip(int fd) 135 gaim_network_get_my_ip(int fd)
136 { 136 {
137 const char *ip = NULL; 137 char *ip = NULL;
138 const char *controlURL = NULL; 138 char *controlURL = NULL;
139 139
140 /* Check if the user specified an IP manually */ 140 /* Check if the user specified an IP manually */
141 if (!gaim_prefs_get_bool("/core/network/auto_ip")) { 141 if (!gaim_prefs_get_bool("/core/network/auto_ip")) {
142 ip = gaim_network_get_public_ip(); 142 ip = gaim_network_get_public_ip();
143 if (ip != NULL) 143 if (ip != NULL)
145 } 145 }
146 146
147 /* attempt to get the ip from a NAT device */ 147 /* attempt to get the ip from a NAT device */
148 if ((controlURL = gaim_upnp_discover()) != NULL) { 148 if ((controlURL = gaim_upnp_discover()) != NULL) {
149 ip = gaim_upnp_get_public_ip(controlURL); 149 ip = gaim_upnp_get_public_ip(controlURL);
150 free(controlURL);
150 if (ip != NULL) 151 if (ip != NULL)
151 return ip; 152 return ip;
152 } 153 }
153 154
154 /* Just fetch the IP of the local system */ 155 /* Just fetch the IP of the local system */
158 static int 159 static int
159 gaim_network_do_listen(unsigned short port) 160 gaim_network_do_listen(unsigned short port)
160 { 161 {
161 int listenfd = -1; 162 int listenfd = -1;
162 const int on = 1; 163 const int on = 1;
163 const char *controlURL = NULL; 164 char *controlURL = NULL;
164 #if HAVE_GETADDRINFO 165 #if HAVE_GETADDRINFO
165 int errnum; 166 int errnum;
166 struct addrinfo hints, *res, *next; 167 struct addrinfo hints, *res, *next;
167 char serv[6]; 168 char serv[6];
168 169
234 if((controlURL = gaim_upnp_discover()) != NULL) { 235 if((controlURL = gaim_upnp_discover()) != NULL) {
235 if(!gaim_upnp_set_port_mapping(controlURL, port, "TCP")) { 236 if(!gaim_upnp_set_port_mapping(controlURL, port, "TCP")) {
236 gaim_upnp_remove_port_mapping(controlURL, port, "TCP"); 237 gaim_upnp_remove_port_mapping(controlURL, port, "TCP");
237 gaim_upnp_set_port_mapping(controlURL, port, "TCP"); 238 gaim_upnp_set_port_mapping(controlURL, port, "TCP");
238 } 239 }
240 free(controlURL);
239 } 241 }
240 242
241 gaim_debug_info("network", "Listening on port: %hu\n", gaim_network_get_port_from_fd(listenfd)); 243 gaim_debug_info("network", "Listening on port: %hu\n", gaim_network_get_port_from_fd(listenfd));
242 return listenfd; 244 return listenfd;
243 } 245 }