int w_parse_rtcp_to_json(msg_t *_m) { int json_len; char *json_rtcp_buffer; _m->mfree = 0; json_rtcp_buffer = malloc(JSON_BUFFER_LEN); json_rtcp_buffer[0] = '\0'; if((json_len = capt_parse_rtcp((char *)_m->data, _m->len, json_rtcp_buffer, JSON_BUFFER_LEN)) > 0) { _m->rcinfo.proto_type = rtcp_proto_type; _m->data = json_rtcp_buffer; _m->len = json_len; _m->mfree = 1; } else { LDEBUG("GOODBYE or APP MESSAGE. Ignore!\n"); if(json_rtcp_buffer) free(json_rtcp_buffer); if(_m->corrdata) { free(_m->corrdata); _m->corrdata = NULL; } return -1; } LDEBUG("JSON RTCP %s\n", json_rtcp_buffer); return 1; }
int dump_rtp_packet(struct pcap_pkthdr *pkthdr, u_char *packet, uint8_t proto, unsigned char *data, uint32_t len, const char *ip_src, const char *ip_dst, uint16_t sport, uint16_t dport, uint8_t flags, uint16_t hdr_offset, uint8_t frag, uint16_t frag_offset, uint32_t frag_id, uint32_t ip_ver) { struct timeval tv; time_t curtime; char timebuffer[30]; rc_info_t *rcinfo = NULL; unsigned char *senddata; int json_len; gettimeofday(&tv,NULL); sendPacketsCount++; curtime = tv.tv_sec; strftime(timebuffer,30,"%m-%d-%Y %T.",localtime(&curtime)); if(len < 5) { LERR("rtcp the message is too small: %d\n", len); return -1; } LDEBUG("GOT RTCP %s:%d -> %s:%d. LEN: %d\n", ip_src, sport, ip_dst, dport, len); if(find_and_update(sip_callid, ip_src, sport, ip_dst, dport) == 0) { return 0; } if(rtcp_as_json) { json_rtcp_buffer[0] = '\0'; if((json_len = capt_parse_rtcp((char *)data, len, json_rtcp_buffer, sizeof(json_rtcp_buffer))) > 0) { senddata = json_rtcp_buffer; len = strlen(json_rtcp_buffer); } else { LDEBUG("GOODBYE or APP MESSAGE. Ignore!\n"); return 0; } LDEBUG("JSON RTCP %s\n", json_rtcp_buffer); } else senddata = data; rcinfo = malloc(sizeof(rc_info_t)); memset(rcinfo, 0, sizeof(rc_info_t)); LDEBUG("CALLID RTCP %s\n", sip_callid); rcinfo->src_port = sport; rcinfo->dst_port = dport; rcinfo->src_ip = ip_src; rcinfo->dst_ip = ip_dst; rcinfo->ip_family = ip_ver = 4 ? AF_INET : AF_INET6 ; rcinfo->ip_proto = proto; rcinfo->time_sec = pkthdr->ts.tv_sec; rcinfo->time_usec = pkthdr->ts.tv_usec; rcinfo->proto_type = rtcp_proto_type; /* correlation stuff */ rcinfo->correlation_id.len = strlen(sip_callid); rcinfo->correlation_id.s = &sip_callid; if(debug_proto_rtcp_enable) LDEBUG("SENDING PACKET: Len: [%d]\n", len); /* Duplcate */ if(!send_message(rcinfo, senddata, (unsigned int) len)) { LERR("Not duplicated\n"); } if(rcinfo) free(rcinfo); return 1; }