Mercurial > pidgin
comparison libpurple/protocols/bonjour/jabber.c @ 23567:a9db0aec7e59
Fix running several Bonjour instances on the same machine.
The server socket had SO_REUSEADDR set, which was causing all the instances to
share the same port (and therefore it was indeterminate who would actually get
the incoming connection).
Fixes #6231
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Sat, 19 Jul 2008 00:18:18 +0000 |
parents | ef0bcbe33689 |
children | 0dd3df365017 |
comparison
equal
deleted
inserted
replaced
23566:0fd0c52364a2 | 23567:a9db0aec7e59 |
---|---|
670 | 670 |
671 gint | 671 gint |
672 bonjour_jabber_start(BonjourJabber *jdata) | 672 bonjour_jabber_start(BonjourJabber *jdata) |
673 { | 673 { |
674 struct sockaddr_in my_addr; | 674 struct sockaddr_in my_addr; |
675 int yes = 1; | |
676 int i; | 675 int i; |
677 gboolean bind_successful; | 676 gboolean bind_successful; |
678 | 677 |
679 /* Open a listening socket for incoming conversations */ | 678 /* Open a listening socket for incoming conversations */ |
680 if ((jdata->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) | 679 if ((jdata->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) |
681 { | 680 { |
682 purple_debug_error("bonjour", "Cannot open socket: %s\n", g_strerror(errno)); | 681 purple_debug_error("bonjour", "Cannot open socket: %s\n", g_strerror(errno)); |
683 purple_connection_error_reason (jdata->account->gc, | 682 purple_connection_error_reason (jdata->account->gc, |
684 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 683 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
685 _("Cannot open socket")); | 684 _("Cannot open socket")); |
686 return -1; | |
687 } | |
688 | |
689 /* Make the socket reusable */ | |
690 if (setsockopt(jdata->socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) != 0) | |
691 { | |
692 purple_debug_error("bonjour", "Error setting socket options: %s\n", g_strerror(errno)); | |
693 purple_connection_error_reason (jdata->account->gc, | |
694 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | |
695 _("Error setting socket options")); | |
696 return -1; | 685 return -1; |
697 } | 686 } |
698 | 687 |
699 memset(&my_addr, 0, sizeof(struct sockaddr_in)); | 688 memset(&my_addr, 0, sizeof(struct sockaddr_in)); |
700 my_addr.sin_family = AF_INET; | 689 my_addr.sin_family = AF_INET; |
707 if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == 0) | 696 if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == 0) |
708 { | 697 { |
709 bind_successful = TRUE; | 698 bind_successful = TRUE; |
710 break; | 699 break; |
711 } | 700 } |
701 | |
702 purple_debug_info("bonjour", "Unable to bind to port %u.(%s)\n", jdata->port, g_strerror(errno)); | |
712 jdata->port++; | 703 jdata->port++; |
713 } | 704 } |
714 | 705 |
715 /* On no! We tried 10 ports and could not bind to ANY of them */ | 706 /* On no! We tried 10 ports and could not bind to ANY of them */ |
716 if (!bind_successful) | 707 if (!bind_successful) |