| 684 bonjour_jabber_start(BonjourJabber *jdata) |
684 bonjour_jabber_start(BonjourJabber *jdata) |
| 685 { |
685 { |
| 686 struct sockaddr_in my_addr; |
686 struct sockaddr_in my_addr; |
| 687 |
687 |
| 688 /* Open a listening socket for incoming conversations */ |
688 /* Open a listening socket for incoming conversations */ |
| 689 if ((jdata->socket = socket(PF_INET, SOCK_STREAM, 0)) < 0) { |
689 jdata->socket = socket(PF_INET, SOCK_STREAM, 0); |
| 690 purple_debug_error("bonjour", "Cannot open socket: %s\n", g_strerror(errno)); |
690 if (jdata->socket < 0) { |
| |
691 gchar *buf = g_strdup_printf(_("Unable to create socket: %s"), |
| |
692 g_strerror(errno)); |
| 691 purple_connection_error_reason(jdata->account->gc, |
693 purple_connection_error_reason(jdata->account->gc, |
| 692 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
694 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, buf); |
| 693 _("Cannot open socket")); |
695 g_free(buf); |
| 694 return -1; |
696 return -1; |
| 695 } |
697 } |
| 696 |
698 |
| 697 memset(&my_addr, 0, sizeof(struct sockaddr_in)); |
699 memset(&my_addr, 0, sizeof(struct sockaddr_in)); |
| 698 my_addr.sin_family = AF_INET; |
700 my_addr.sin_family = AF_INET; |
| 699 |
701 |
| 700 /* Try to use the specified port - if it isn't available, use a random port */ |
702 /* Try to use the specified port - if it isn't available, use a random port */ |
| 701 my_addr.sin_port = htons(jdata->port); |
703 my_addr.sin_port = htons(jdata->port); |
| 702 if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) { |
704 if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) |
| 703 purple_debug_info("bonjour", "Unable to bind to specified port %u (%s).\n", jdata->port, g_strerror(errno)); |
705 { |
| |
706 purple_debug_info("bonjour", "Unable to bind to specified " |
| |
707 "port %i: %s\n", jdata->port, g_strerror(errno)); |
| 704 my_addr.sin_port = 0; |
708 my_addr.sin_port = 0; |
| 705 if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) { |
709 if (bind(jdata->socket, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) != 0) |
| 706 purple_debug_error("bonjour", "Unable to bind to system assigned port (%s).\n", g_strerror(errno)); |
710 { |
| |
711 gchar *buf = g_strdup_printf(_("Unable to bind socket " |
| |
712 "to port: %s"), g_strerror(errno)); |
| 707 purple_connection_error_reason(jdata->account->gc, |
713 purple_connection_error_reason(jdata->account->gc, |
| 708 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
714 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, buf); |
| 709 _("Could not bind socket to port")); |
715 g_free(buf); |
| 710 return -1; |
716 return -1; |
| 711 } |
717 } |
| 712 jdata->port = purple_network_get_port_from_fd(jdata->socket); |
718 jdata->port = purple_network_get_port_from_fd(jdata->socket); |
| 713 } |
719 } |
| 714 |
720 |
| 715 /* Attempt to listen on the bound socket */ |
721 /* Attempt to listen on the bound socket */ |
| 716 if (listen(jdata->socket, 10) != 0) { |
722 if (listen(jdata->socket, 10) != 0) |
| 717 purple_debug_error("bonjour", "Cannot listen on socket: %s\n", g_strerror(errno)); |
723 { |
| |
724 gchar *buf = g_strdup_printf(_("Unable to listen on socket: %s"), |
| |
725 g_strerror(errno)); |
| 718 purple_connection_error_reason(jdata->account->gc, |
726 purple_connection_error_reason(jdata->account->gc, |
| 719 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
727 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, buf); |
| 720 _("Could not listen on socket")); |
728 g_free(buf); |
| 721 return -1; |
729 return -1; |
| 722 } |
730 } |
| 723 |
731 |
| 724 #if 0 |
732 #if 0 |
| 725 /* TODO: Why isn't this being used? */ |
733 /* TODO: Why isn't this being used? */ |