Mercurial > pidgin
comparison src/stun.c @ 11429:835dbb1b3337
[gaim-migrate @ 13666]
use async dns
committer: Tailor Script <tailor@pidgin.im>
author | Thomas Butter <tbutter> |
---|---|
date | Fri, 02 Sep 2005 19:48:26 +0000 |
parents | 54fa445aff32 |
children | d2e44c8085e0 |
comparison
equal
deleted
inserted
replaced
11428:c39a48818f66 | 11429:835dbb1b3337 |
---|---|
39 #include "internal.h" | 39 #include "internal.h" |
40 | 40 |
41 #include "debug.h" | 41 #include "debug.h" |
42 #include "account.h" | 42 #include "account.h" |
43 #include "dnssrv.h" | 43 #include "dnssrv.h" |
44 #include "proxy.h" | |
44 #include "stun.h" | 45 #include "stun.h" |
45 #include "prefs.h" | 46 #include "prefs.h" |
46 | 47 |
47 struct stun_nattype nattype = {-1, 0, "\0"}; | 48 struct stun_nattype nattype = {-1, 0, "\0"}; |
48 | 49 |
171 gaim_timeout_remove(timeout); | 172 gaim_timeout_remove(timeout); |
172 nattype.type = 2; | 173 nattype.type = 2; |
173 } | 174 } |
174 } | 175 } |
175 | 176 |
176 static void do_test1(struct srv_response *resp, int results, gpointer sdata) { | 177 static void hbn_cb(GSList *hosts, gpointer edata, const char *error_message) { |
177 char *servername = (char*)sdata; | |
178 static struct stun_header data; | 178 static struct stun_header data; |
179 int port = 3478; | |
180 int ret; | 179 int ret; |
181 struct hostent *host; | 180 |
182 | 181 if(!hosts) return; |
183 if(results) { | 182 if(!hosts->data) return; |
184 servername = resp[0].hostname; | |
185 port = resp[0].port; | |
186 } | |
187 gaim_debug_info("stun", "got %d SRV responses, server: %s, port: %d\n", results, servername, port); | |
188 | |
189 host = gethostbyname(servername); | |
190 if(!host->h_addr_list) { | |
191 return; | |
192 } | |
193 | 183 |
194 if((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { | 184 if((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
195 nattype.status = 0; | 185 nattype.status = 0; |
196 do_callbacks(); | 186 do_callbacks(); |
197 return; | 187 return; |
207 nattype.status = 0; | 197 nattype.status = 0; |
208 do_callbacks(); | 198 do_callbacks(); |
209 return; | 199 return; |
210 } | 200 } |
211 incb = gaim_input_add(fd, GAIM_INPUT_READ, reply_cb, NULL); | 201 incb = gaim_input_add(fd, GAIM_INPUT_READ, reply_cb, NULL); |
212 | 202 |
213 addr.sin_family = AF_INET; | 203 ret = GPOINTER_TO_INT(hosts->data); |
214 addr.sin_port = htons(port); | 204 hosts = g_slist_remove(hosts, hosts->data); |
215 memcpy(&addr.sin_addr.s_addr,*(host->h_addr_list),4); | 205 memcpy(&addr, hosts->data, sizeof(struct sockaddr_in)); |
216 | 206 g_free(hosts->data); |
207 hosts = g_slist_remove(hosts, hosts->data); | |
208 while(hosts) { | |
209 hosts = g_slist_remove(hosts, hosts->data); | |
210 g_free(hosts->data); | |
211 hosts = g_slist_remove(hosts, hosts->data); | |
212 } | |
213 | |
217 data.type = htons(0x0001); | 214 data.type = htons(0x0001); |
218 data.len = 0; | 215 data.len = 0; |
219 data.transid[0] = rand(); | 216 data.transid[0] = rand(); |
220 data.transid[1] = ntohl(((int)'g' << 24) + ((int)'a' << 16) + ((int)'i' << 8) + (int)'m'); | 217 data.transid[1] = ntohl(((int)'g' << 24) + ((int)'a' << 16) + ((int)'i' << 8) + (int)'m'); |
221 data.transid[2] = rand(); | 218 data.transid[2] = rand(); |
228 } | 225 } |
229 test = 1; | 226 test = 1; |
230 packet = &data; | 227 packet = &data; |
231 packetsize = sizeof(struct stun_header); | 228 packetsize = sizeof(struct stun_header); |
232 timeout = gaim_timeout_add(500, (GSourceFunc)timeoutfunc, NULL); | 229 timeout = gaim_timeout_add(500, (GSourceFunc)timeoutfunc, NULL); |
230 } | |
231 | |
232 static void do_test1(struct srv_response *resp, int results, gpointer sdata) { | |
233 char *servername = (char*)sdata; | |
234 int port = 3478; | |
235 | |
236 if(results) { | |
237 servername = resp[0].hostname; | |
238 port = resp[0].port; | |
239 } | |
240 gaim_debug_info("stun", "got %d SRV responses, server: %s, port: %d\n", results, servername, port); | |
241 | |
242 gaim_gethostbyname_async(servername, port, hbn_cb, NULL); | |
233 g_free(resp); | 243 g_free(resp); |
234 } | 244 } |
235 | 245 |
236 struct stun_nattype *gaim_stun_discover(StunCallback cb) { | 246 struct stun_nattype *gaim_stun_discover(StunCallback cb) { |
237 const char *servername = gaim_prefs_get_string("/core/network/stun_server"); | 247 char *servername = (char*)gaim_prefs_get_string("/core/network/stun_server"); |
238 | 248 |
239 gaim_debug_info("stun", "using server %s\n", servername); | 249 gaim_debug_info("stun", "using server %s\n", servername); |
240 if(nattype.status == 1) { /* currently discovering */ | 250 if(nattype.status == 1) { /* currently discovering */ |
241 if(cb) callbacks = g_slist_append(callbacks, cb); | 251 if(cb) callbacks = g_slist_append(callbacks, cb); |
242 return NULL; | 252 return NULL; |