Mercurial > pidgin
comparison libpurple/protocols/bonjour/jabber.c @ 25947:4b8c4870b13a
propagate from branch 'im.pidgin.pidgin.next.minor' (head 7305b29db7bd00d3261f348c71674c93aa31b327)
to branch 'im.pidgin.pidgin' (head d8c03c68d591d9392607d954942ee58b8618d946)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Mon, 02 Mar 2009 04:18:40 +0000 |
parents | 716b14deee97 f38799160cfa |
children | 2b7604ede0e4 |
comparison
equal
deleted
inserted
replaced
25946:8998ca47e6d0 | 25947:4b8c4870b13a |
---|---|
684 | 684 |
685 gint | 685 gint |
686 bonjour_jabber_start(BonjourJabber *jdata) | 686 bonjour_jabber_start(BonjourJabber *jdata) |
687 { | 687 { |
688 struct sockaddr_in my_addr; | 688 struct sockaddr_in my_addr; |
689 int i; | |
690 gboolean bind_successful; | |
691 | 689 |
692 /* Open a listening socket for incoming conversations */ | 690 /* Open a listening socket for incoming conversations */ |
693 if ((jdata->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) | 691 if ((jdata->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) { |
694 { | |
695 purple_debug_error("bonjour", "Cannot open socket: %s\n", g_strerror(errno)); | 692 purple_debug_error("bonjour", "Cannot open socket: %s\n", g_strerror(errno)); |
696 purple_connection_error_reason (jdata->account->gc, | 693 purple_connection_error_reason(jdata->account->gc, |
697 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 694 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
698 _("Cannot open socket")); | 695 _("Cannot open socket")); |
699 return -1; | 696 return -1; |
700 } | 697 } |
701 | 698 |
702 memset(&my_addr, 0, sizeof(struct sockaddr_in)); | 699 memset(&my_addr, 0, sizeof(struct sockaddr_in)); |
703 my_addr.sin_family = AF_INET; | 700 my_addr.sin_family = AF_INET; |
704 | 701 |
705 /* Attempt to find a free port */ | 702 /* Try to use the specified port - if it isn't available, use a random port */ |
706 bind_successful = FALSE; | 703 my_addr.sin_port = htons(jdata->port); |
707 for (i = 0; i < 10; i++) | 704 if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) { |
708 { | 705 purple_debug_info("bonjour", "Unable to bind to specified port %u (%s).\n", jdata->port, g_strerror(errno)); |
709 my_addr.sin_port = htons(jdata->port); | 706 my_addr.sin_port = 0; |
710 if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == 0) | 707 if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) { |
711 { | 708 purple_debug_error("bonjour", "Unable to bind to system assigned port (%s).\n", g_strerror(errno)); |
712 bind_successful = TRUE; | 709 purple_connection_error_reason(jdata->account->gc, |
713 break; | 710 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
714 } | 711 _("Could not bind socket to port")); |
715 | 712 return -1; |
716 purple_debug_info("bonjour", "Unable to bind to port %u.(%s)\n", jdata->port, g_strerror(errno)); | 713 } |
717 jdata->port++; | 714 jdata->port = purple_network_get_port_from_fd(jdata->socket); |
718 } | |
719 | |
720 /* On no! We tried 10 ports and could not bind to ANY of them */ | |
721 if (!bind_successful) | |
722 { | |
723 purple_debug_error("bonjour", "Cannot bind socket: %s\n", g_strerror(errno)); | |
724 purple_connection_error_reason (jdata->account->gc, | |
725 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | |
726 _("Could not bind socket to port")); | |
727 return -1; | |
728 } | 715 } |
729 | 716 |
730 /* Attempt to listen on the bound socket */ | 717 /* Attempt to listen on the bound socket */ |
731 if (listen(jdata->socket, 10) != 0) | 718 if (listen(jdata->socket, 10) != 0) { |
732 { | |
733 purple_debug_error("bonjour", "Cannot listen on socket: %s\n", g_strerror(errno)); | 719 purple_debug_error("bonjour", "Cannot listen on socket: %s\n", g_strerror(errno)); |
734 purple_connection_error_reason (jdata->account->gc, | 720 purple_connection_error_reason(jdata->account->gc, |
735 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 721 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
736 _("Could not listen on socket")); | 722 _("Could not listen on socket")); |
737 return -1; | 723 return -1; |
738 } | 724 } |
739 | 725 |