Exemple #1
0
SWITCH_DECLARE(switch_status_t) switch_mcast_loopback(switch_socket_t *sock, uint8_t opt)
{
	return apr_mcast_loopback(sock, opt);
}
static apr_status_t ma_group_join(const char *addr, apr_port_t port,
                                  const char *bindaddr, apr_port_t bindport,
                                  apr_pool_t *pool, server_rec *s)
{
    apr_status_t rv;

    if ((rv = apr_sockaddr_info_get(&ma_mgroup_sa, addr,
                                    APR_UNSPEC, port,
                                    APR_UNSPEC, pool)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                     "mod_advertise: ma_group_join apr_sockaddr_info_get(%s:%d) failed",
                     addr, port);
        return rv;
    }
    if ((rv = apr_sockaddr_info_get(&ma_listen_sa, bindaddr,
                                    ma_mgroup_sa->family, bindport,
                                    APR_UNSPEC, pool)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                     "mod_advertise: ma_group_join apr_sockaddr_info_get(%s:%d) failed", bindaddr, bindport);
        return rv;
    }
    if ((rv = apr_sockaddr_info_get(&ma_niface_sa, NULL,
                                    ma_mgroup_sa->family, 0,
                                    APR_UNSPEC, pool)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                     "mod_advertise: ma_group_join apr_sockaddr_info_get(0.0.0.0:0) failed");
        return rv;
    }
    if ((rv = apr_socket_create(&ma_mgroup_socket,
                                ma_mgroup_sa->family,
                                SOCK_DGRAM,
                                APR_PROTO_UDP,
                                pool)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                     "mod_advertise: ma_group_join apr_socket_create failed");
        return rv;
    }
    if ((rv = apr_socket_opt_set(ma_mgroup_socket,
                                 APR_SO_REUSEADDR, 1)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                     "mod_advertise: ma_group_join apr_socket_opt_set failed");
        return rv;
    }
    if ((rv = apr_socket_bind(ma_mgroup_socket, ma_listen_sa)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                     "mod_advertise: ma_group_join apr_socket_bind failed");
        return rv;
    }
    if ((rv = apr_mcast_join(ma_mgroup_socket, ma_mgroup_sa,
                             ma_niface_sa, NULL)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, s,
                     "mod_advertise: ma_group_join apr_mcast_join failed");
        if ((rv = apr_mcast_loopback(ma_mgroup_socket, 1)) != APR_SUCCESS) {
            ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s,
                         "mod_advertise: ma_group_join apr_mcast_loopback failed");
            apr_socket_close(ma_mgroup_socket);
            return rv;
        }     
    }
    if ((rv = apr_mcast_hops(ma_mgroup_socket,
                             MA_ADVERTISE_HOPS)) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                     "mod_advertise: ma_group_join apr_mcast_hops failed");
        /* Due a bug in apr (fixed by r1309332) apr_mcast_hops may fail */
        apr_mcast_leave(ma_mgroup_socket, ma_mgroup_sa,
                        NULL, NULL);
        apr_socket_close(ma_mgroup_socket);
        return rv;
    }
    return APR_SUCCESS;
}