comparison libpurple/nat-pmp.c @ 21563:1b174854bb80

merge of '30fcf2f336afb635b62a5c3ed3adb3e1fa1dd2d1' and 'bb60447c0a8c79afca320f4dc689096f4788e7fa'
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 17 Nov 2007 01:55:21 +0000
parents 35b4f1dc4c8d
children 8972581c2326
comparison
equal deleted inserted replaced
20755:774f4924e74e 21563:1b174854bb80
310 310
311 /* TODO: Non-blocking! */ 311 /* TODO: Non-blocking! */
312 312
313 if (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) < 0) 313 if (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) < 0)
314 { 314 {
315 purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP public IP request! (%s)\n", strerror(errno)); 315 purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP public IP request! (%s)\n", g_strerror(errno));
316 g_free(gateway); 316 g_free(gateway);
317 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER; 317 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER;
318 return NULL; 318 return NULL;
319 } 319 }
320 320
321 if (setsockopt(sendfd, SOL_SOCKET, SO_RCVTIMEO, &req_timeout, sizeof(req_timeout)) < 0) 321 if (setsockopt(sendfd, SOL_SOCKET, SO_RCVTIMEO, &req_timeout, sizeof(req_timeout)) < 0)
322 { 322 {
323 purple_debug_info("nat-pmp", "There was an error setting the socket's options! (%s)\n", strerror(errno)); 323 purple_debug_info("nat-pmp", "There was an error setting the socket's options! (%s)\n", g_strerror(errno));
324 g_free(gateway); 324 g_free(gateway);
325 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER; 325 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER;
326 return NULL; 326 return NULL;
327 } 327 }
328 328
330 len = sizeof(struct sockaddr_in); 330 len = sizeof(struct sockaddr_in);
331 if (recvfrom(sendfd, &resp, sizeof(PurplePmpIpResponse), 0, (struct sockaddr *)(&addr), &len) < 0) 331 if (recvfrom(sendfd, &resp, sizeof(PurplePmpIpResponse), 0, (struct sockaddr *)(&addr), &len) < 0)
332 { 332 {
333 if (errno != EAGAIN) 333 if (errno != EAGAIN)
334 { 334 {
335 purple_debug_info("nat-pmp", "There was an error receiving the response from the NAT-PMP device! (%s)\n", strerror(errno)); 335 purple_debug_info("nat-pmp", "There was an error receiving the response from the NAT-PMP device! (%s)\n", g_strerror(errno));
336 g_free(gateway); 336 g_free(gateway);
337 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER; 337 pmp_info.status = PURPLE_PMP_STATUS_UNABLE_TO_DISCOVER;
338 return NULL; 338 return NULL;
339 } 339 }
340 } 340 }
430 #endif 430 #endif
431 431
432 /* TODO: Non-blocking! */ 432 /* TODO: Non-blocking! */
433 success = (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) >= 0); 433 success = (sendto(sendfd, &req, sizeof(req), 0, (struct sockaddr *)(gateway), sizeof(struct sockaddr)) >= 0);
434 if (!success) 434 if (!success)
435 purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP mapping request! (%s)\n", strerror(errno)); 435 purple_debug_info("nat-pmp", "There was an error sending the NAT-PMP mapping request! (%s)\n", g_strerror(errno));
436 436
437 if (success) 437 if (success)
438 { 438 {
439 success = (setsockopt(sendfd, SOL_SOCKET, SO_RCVTIMEO, &req_timeout, sizeof(req_timeout)) >= 0); 439 success = (setsockopt(sendfd, SOL_SOCKET, SO_RCVTIMEO, &req_timeout, sizeof(req_timeout)) >= 0);
440 if (!success) 440 if (!success)
441 purple_debug_info("nat-pmp", "There was an error setting the socket's options! (%s)\n", strerror(errno)); 441 purple_debug_info("nat-pmp", "There was an error setting the socket's options! (%s)\n", g_strerror(errno));
442 } 442 }
443 443
444 if (success) 444 if (success)
445 { 445 {
446 /* The original code treats EAGAIN as a reason to iterate.. but I've removed iteration. This may be a problem */ 446 /* The original code treats EAGAIN as a reason to iterate.. but I've removed iteration. This may be a problem */
447 /* TODO: Non-blocking! */ 447 /* TODO: Non-blocking! */
448 success = ((recvfrom(sendfd, resp, sizeof(PurplePmpMapResponse), 0, NULL, NULL) >= 0) || 448 success = ((recvfrom(sendfd, resp, sizeof(PurplePmpMapResponse), 0, NULL, NULL) >= 0) ||
449 (errno == EAGAIN)); 449 (errno == EAGAIN));
450 if (!success) 450 if (!success)
451 purple_debug_info("nat-pmp", "There was an error receiving the response from the NAT-PMP device! (%s)\n", strerror(errno)); 451 purple_debug_info("nat-pmp", "There was an error receiving the response from the NAT-PMP device! (%s)\n", g_strerror(errno));
452 } 452 }
453 453
454 if (success) 454 if (success)
455 { 455 {
456 success = (resp->opcode == (req.opcode + 128)); 456 success = (resp->opcode == (req.opcode + 128));