Commit e62fff1b authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Parse received STUN packets.

parent 23ffe0f9
......@@ -385,7 +385,7 @@ MS2_PUBLIC void ice_session_pair_candidates(IceSession *session);
void ice_check_list_process(IceCheckList *cl, RtpSession *rtp_session);
void ice_handle_stun_packet(IceCheckList *cl, RtpSession *session, mblk_t *m);
void ice_handle_stun_packet(IceCheckList *cl, RtpSession *session, OrtpEventData *evt_data);
/**
* Dump an ICE session in the traces (debug function).
......
......@@ -225,7 +225,7 @@ void audio_stream_iterate(AudioStream *stream){
ms_quality_indicator_update_local(stream->qi);
ms_message("audio_stream_iterate(): local statistics available\n\tLocal's current jitter buffer size:%f ms",rtp_session_get_jitter_stats(stream->session)->jitter_buffer_size_ms);
}else if ((evt==ORTP_EVENT_STUN_PACKET_RECEIVED)&&(stream->ice_check_list)){
ice_handle_stun_packet(stream->ice_check_list,stream->session,ortp_event_get_data(ev)->packet);
ice_handle_stun_packet(stream->ice_check_list,stream->session,ortp_event_get_data(ev));
}
ortp_event_destroy(ev);
}
......
......@@ -332,9 +332,58 @@ static void ice_send_stun_request(IceCandidatePair *pair, IceSession *ice_sessio
sendMessage(socket, buf, len, dest.addr, dest.port);
}
void ice_handle_stun_packet(IceCheckList *cl, RtpSession *session, mblk_t* m)
void ice_handle_stun_packet(IceCheckList *cl, RtpSession *session, OrtpEventData *evt_data)
{
//TODO
StunMessage msg;
char src6host[NI_MAXHOST];
mblk_t *mp = evt_data->packet;
struct sockaddr_in *udp_remote;
struct sockaddr_storage *aaddr;
int recvport;
bool_t res;
memset(&msg, 0, sizeof(msg));
res = stunParseMessage((char *) mp->b_rptr, mp->b_wptr - mp->b_rptr, &msg);
if (res == FALSE) {
ms_warning("ice_handle_stun_packet: Received invalid STUN packet");
return;
}
memset(src6host, 0, sizeof(src6host));
aaddr = (struct sockaddr_storage *)&evt_data->ep->addr;
switch (aaddr->ss_family) {
case AF_INET6:
recvport = ntohs(((struct sockaddr_in6 *)&evt_data->ep->addr)->sin6_port);
break;
case AF_INET:
udp_remote = (struct sockaddr_in*)&evt_data->ep->addr;
recvport = ntohs(udp_remote->sin_port);
break;
default:
ms_warning("ice: Wrong socket family");
return;
}
if (getnameinfo((struct sockaddr*)&evt_data->ep->addr, evt_data->ep->addrlen, src6host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) != 0) {
ms_error("ice: getnameinfo failed");
return;
}
if (STUN_IS_REQUEST(msg.msgHdr.msgType)) {
ms_message("ice: Received binding request [connectivity check] from %s:%d", src6host, recvport);
// TODO: Handle request and respond
}
else if (STUN_IS_SUCCESS_RESP(msg.msgHdr.msgType)) {
ms_message("ice: Received binding response from %s:%d", src6host, recvport);
// TODO: Handle response
}
else if (STUN_IS_ERR_RESP(msg.msgHdr.msgType)) {
ms_message("ice: Received error response from %s:%d", src6host, recvport);
// TODO: Handle error
}
else {
ms_warning("ice: STUN message type not handled");
}
}
......
......@@ -171,7 +171,7 @@ void video_stream_iterate(VideoStream *stream){
OrtpEventData *evd=ortp_event_get_data(ev);
video_steam_process_rtcp(stream,evd->packet);
}else if ((evt == ORTP_EVENT_STUN_PACKET_RECEIVED) && (stream->ice_check_list)) {
ice_handle_stun_packet(stream->ice_check_list,stream->session,ortp_event_get_data(ev)->packet);
ice_handle_stun_packet(stream->ice_check_list,stream->session,ortp_event_get_data(ev));
}
ortp_event_destroy(ev);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment