示例#1
0
/* Send dummy STUN packet to open NAT ports ASAP. */
static void send_stun_packet(SenderData *d, bool_t enable_rtp, bool_t enable_rtcp)
{
	MSStunMessage *msg;
	mblk_t *mp;
	RtpSession *s = d->session;
	char *buf = NULL;
	int len;

	if (!d->stun_enabled) return;
	if (ms_is_multicast_addr((const struct sockaddr *)&s->rtcp.gs.loc_addr)) {
		ms_debug("Stun packet not sent for session [%p] because of multicast",s);
		return;
	}

	msg = ms_stun_binding_request_create();
	len = ms_stun_message_encode(msg, &buf);
	if (len > 0) {
		if (enable_rtp) {
			mp = allocb(len, BPRI_MED);
			memcpy(mp->b_wptr, buf, len);
			mp->b_wptr += len;
			ms_message("Stun packet sent for session [%p]",s);
			rtp_session_sendm_with_ts(s, mp, 0);
		}
		if (enable_rtcp) {
			mp = allocb(len, BPRI_MED);
			memcpy(mp->b_wptr, buf, len);
			mp->b_wptr += len;
			ms_message("Stun packet sent on rtcp for session [%p]",s);
			rtp_session_rtcp_sendm_raw(s,mp);
		}
	}
	if (buf != NULL) ms_free(buf);
	ms_stun_message_destroy(msg);
}
示例#2
0
bool_t ms_is_multicast(const char *address) {
	bool_t ret = FALSE;
	struct addrinfo hints, *res0;
	int err;

	memset(&hints, 0, sizeof(hints));
	hints.ai_family = PF_UNSPEC;
	hints.ai_socktype = SOCK_DGRAM;
	hints.ai_flags = AI_NUMERICHOST;
	err = getaddrinfo(address,"8000", &hints, &res0);
	if (err != 0) {
		ms_warning("ms_is_multicast(%s): %s", address, gai_strerror(err));
		return FALSE;
	}
	ret = ms_is_multicast_addr(res0->ai_addr);

	freeaddrinfo(res0);
	return ret;
}
示例#3
0
/* Send dummy STUN packet to open NAT ports ASAP. */
static void send_stun_packet(RtpSession *s)
{
	StunMessage msg;
	mblk_t *mp;
	char buf[STUN_MAX_MESSAGE_SIZE];
	int len = STUN_MAX_MESSAGE_SIZE;
	if (ms_is_multicast_addr((const struct sockaddr *)&s->rtcp.gs.loc_addr)) {
		ms_debug("Stun packet not sent for session [%p] because of multicast",s);
		return;
	}
	memset(&msg, 0, sizeof(StunMessage));
	stunBuildReqSimple(&msg, NULL, FALSE, FALSE, 1);
	len = stunEncodeMessage(&msg, buf, len, NULL);
	if (len > 0) {
		mp = allocb(len, BPRI_MED);
		memcpy(mp->b_wptr, buf, len);
		mp->b_wptr += len;
		ms_message("Stun packet sent for session [%p]",s);
		rtp_session_sendm_with_ts(s, mp, 0);
	}
}