media: rtp: Refactoring address containers

This commit is contained in:
Kaian 2016-01-27 20:29:36 +01:00
parent 79a54ce2a5
commit d0a01de0f4
10 changed files with 94 additions and 140 deletions

View File

@ -214,8 +214,6 @@ parse_packet(u_char *info, const struct pcap_pkthdr *header, const u_char *packe
{
// Capture info
capture_info_t *capinfo = (capture_info_t *) info;
// Source and Destination Ports
uint16_t sport, dport;
// UDP header data
struct udphdr *udp;
// UDP header size
@ -261,8 +259,8 @@ parse_packet(u_char *info, const struct pcap_pkthdr *header, const u_char *packe
udp_off = sizeof(struct udphdr);
// Set packet ports
sport = htons(udp->uh_sport);
dport = htons(udp->uh_dport);
pkt->src.port = htons(udp->uh_sport);
pkt->dst.port = htons(udp->uh_dport);
// Remove UDP Header from payload
size_payload -= udp_off;
@ -274,7 +272,6 @@ parse_packet(u_char *info, const struct pcap_pkthdr *header, const u_char *packe
payload = (u_char *) (udp) + udp_off;
// Complete packet with Transport information
packet_set_transport_data(pkt, sport, dport);
packet_set_type(pkt, PACKET_SIP_UDP);
packet_set_payload(pkt, payload, size_payload);
@ -284,8 +281,8 @@ parse_packet(u_char *info, const struct pcap_pkthdr *header, const u_char *packe
tcp_off = (tcp->th_off * 4);
// Set packet ports
sport = htons(tcp->th_sport);
dport = htons(tcp->th_dport);
pkt->src.port = htons(tcp->th_sport);
pkt->dst.port = htons(tcp->th_dport);
// Get actual payload size
size_payload -= tcp_off;
@ -297,7 +294,6 @@ parse_packet(u_char *info, const struct pcap_pkthdr *header, const u_char *packe
payload = (u_char *)(tcp) + tcp_off;
// Complete packet with Transport information
packet_set_transport_data(pkt, sport, dport);
packet_set_type(pkt, PACKET_SIP_TCP);
packet_set_payload(pkt, payload, size_payload);

View File

@ -213,8 +213,8 @@ capture_eep_send_v2(packet_t *pkt)
hdr.hp_v = 2;
hdr.hp_f = pkt->ip_version == 4 ? AF_INET : AF_INET6;
hdr.hp_p = pkt->proto;
hdr.hp_sport = htons(pkt->sport);
hdr.hp_dport = htons(pkt->dport);
hdr.hp_sport = htons(pkt->src.port);
hdr.hp_dport = htons(pkt->dst.port);
/* Timestamp */
hep_time.tv_sec = frame->header->ts.tv_sec;
@ -357,13 +357,13 @@ capture_eep_send_v3(packet_t *pkt)
/* SRC PORT */
hg->src_port.chunk.vendor_id = htons(0x0000);
hg->src_port.chunk.type_id = htons(0x0007);
hg->src_port.data = htons(pkt->sport);
hg->src_port.data = htons(pkt->src.port);
hg->src_port.chunk.length = htons(sizeof(hg->src_port));
/* DST PORT */
hg->dst_port.chunk.vendor_id = htons(0x0000);
hg->dst_port.chunk.type_id = htons(0x0008);
hg->dst_port.data = htons(pkt->dport);
hg->dst_port.data = htons(pkt->dst.port);
hg->dst_port.chunk.length = htons(sizeof(hg->dst_port));
/* TIMESTAMP SEC */
@ -567,7 +567,7 @@ capture_eep_receive_v2()
// Create a new packet
pkt = packet_create((family == AF_INET) ? 4 : 6, proto, src, dst, 0);
packet_add_frame(pkt, &header, payload);
packet_set_transport_data(pkt, sport, dport);
packet_set_transport_data(pkt, src.port, dst.port);
packet_set_type(pkt, PACKET_SIP_UDP);
packet_set_payload(pkt, payload, header.caplen);
@ -595,13 +595,10 @@ capture_eep_receive_v3()
uint32_t len, pos;
char buffer[MAX_CAPTURE_LEN] ;
//! Source and Destination Address
char ip_src[ADDRESSLEN], ip_dst[ADDRESSLEN];
address_t src, dst;
//! EEP client data
struct sockaddr eep_client;
socklen_t eep_client_len;
//! Source and Destination Port
uint16_t sport, dport;
//! Packet header
struct pcap_pkthdr header;
//! New created packet pointer
@ -630,12 +627,12 @@ capture_eep_receive_v3()
if (family == AF_INET) {
/* SRC IP */
memcpy(&src_ip4, (void*) buffer + pos, sizeof(struct hep_chunk_ip4));
inet_ntop(AF_INET, &src_ip4.data, ip_src, sizeof(ip_src));
inet_ntop(AF_INET, &src_ip4.data, src.ip, sizeof(src.ip));
pos += sizeof(struct hep_chunk_ip4);
/* DST IP */
memcpy(&dst_ip4, (void*) buffer + pos, sizeof(struct hep_chunk_ip4));
inet_ntop(AF_INET, &dst_ip4.data, ip_dst, sizeof(ip_dst));
inet_ntop(AF_INET, &dst_ip4.data, dst.ip, sizeof(src.ip));
pos += sizeof(struct hep_chunk_ip4);
}
#ifdef USE_IPV6
@ -654,9 +651,9 @@ capture_eep_receive_v3()
#endif
/* SRC PORT */
sport = ntohs(hg.src_port.data);
src.port = ntohs(hg.src_port.data);
/* DST PORT */
dport = ntohs(hg.dst_port.data);
dst.port = ntohs(hg.dst_port.data);
/* TIMESTAMP*/
header.ts.tv_sec = ntohl(hg.time_sec.data);
header.ts.tv_usec = ntohl(hg.time_usec.data);
@ -689,10 +686,9 @@ capture_eep_receive_v3()
memcpy(payload, (void*) buffer + pos, header.caplen);
// Create a new packet
pkt = packet_create((family == AF_INET)?4:6, proto, ip_src, ip_dst, 0);
pkt = packet_create((family == AF_INET)?4:6, proto, src, dst, 0);
packet_add_frame(pkt, &header, payload);
packet_set_transport_data(pkt, sport, dport);
capture_packeet_set_type(pkt, PACKET_SIP_UDP);
packet_set_type(pkt, PACKET_SIP_UDP);
packet_set_payload(pkt, payload, header.caplen);
/* FREE */

View File

@ -261,8 +261,8 @@ tls_process_segment(packet_t *packet, struct tcphdr *tcp)
uint32_t outl = packet->payload_len;
out = sng_malloc(outl);
struct in_addr ip_src, ip_dst;
uint16_t sport = packet->sport;
uint16_t dport = packet->dport;
uint16_t sport = packet->src.port;
uint16_t dport = packet->dst.port;
// Convert addresses
inet_pton(AF_INET, packet->src.ip, &ip_src);

View File

@ -234,8 +234,8 @@ tls_process_segment(packet_t *packet, struct tcphdr *tcp)
uint32_t outl = packet->payload_len;
out = sng_malloc(outl);
struct in_addr ip_src, ip_dst;
uint16_t sport = packet->sport;
uint16_t dport = packet->dport;
uint16_t sport = packet->src.port;
uint16_t dport = packet->dst.port;
// Convert addresses
inet_pton(AF_INET, packet->src.ip, &ip_src);

View File

@ -314,8 +314,8 @@ call_flow_draw_columns(PANEL *panel)
streams = vector_iterator(call->streams);
while ((stream = vector_iterator_next(&streams))) {
if (stream_get_count(stream)) {
call_flow_column_add(panel, NULL, stream->ip_src);
call_flow_column_add(panel, NULL, stream->ip_dst);
call_flow_column_add(panel, NULL, stream->src.ip);
call_flow_column_add(panel, NULL, stream->dst.ip);
}
}
}
@ -586,22 +586,22 @@ call_flow_draw_rtp_stream(PANEL *panel, call_flow_arrow_t *arrow, int cline)
// Get origin column for this stream.
// If we share the same Address from its setup SIP packet, use that column instead.
if (!strcmp(stream->ip_src, msg_src)) {
if (!strcmp(stream->src.ip, msg_src)) {
column1 = call_flow_column_get(panel, callid, msg_src);
} else if (!strcmp(stream->ip_src, msg_dst)) {
} else if (!strcmp(stream->src.ip, msg_dst)) {
column1 = call_flow_column_get(panel, callid, msg_dst);
} else {
column1 = call_flow_column_get(panel, 0, stream->ip_src);
column1 = call_flow_column_get(panel, 0, stream->src.ip);
}
// Get destination column for this stream.
// If we share the same Address from its setup SIP packet, use that column instead.
if (!strcmp(stream->ip_dst, msg_dst)) {
if (!strcmp(stream->dst.ip, msg_dst)) {
column2 = call_flow_column_get(panel, callid, msg_dst);
} else if (!strcmp(stream->ip_dst, msg_src)) {
} else if (!strcmp(stream->dst.ip, msg_src)) {
column2 = call_flow_column_get(panel, callid, msg_src);
} else {
column2 = call_flow_column_get(panel, 0, stream->ip_dst);
column2 = call_flow_column_get(panel, 0, stream->dst.ip);
}
call_flow_column_t *tmp;
@ -651,8 +651,8 @@ call_flow_draw_rtp_stream(PANEL *panel, call_flow_arrow_t *arrow, int cline)
// Write the arrow at the end of the message (two arrows if this is a retrans)
if (arrow_dir == 0 /* right */) {
if (!setting_has_value(SETTING_CF_SDP_INFO, "compressed")) {
mvwprintw(win, cline, startpos - 4, "%d", stream->sport);
mvwprintw(win, cline, endpos, "%d", stream->dport);
mvwprintw(win, cline, startpos - 4, "%d", stream->src.port);
mvwprintw(win, cline, endpos, "%d", stream->dst.port);
}
mvwaddch(win, cline, endpos - 2, '>');
if (arrow->rtp_count != stream_get_count(stream)) {
@ -662,8 +662,8 @@ call_flow_draw_rtp_stream(PANEL *panel, call_flow_arrow_t *arrow, int cline)
}
} else {
if (!setting_has_value(SETTING_CF_SDP_INFO, "compressed")) {
mvwprintw(win, cline, endpos, "%d", stream->sport);
mvwprintw(win, cline, startpos - 4, "%d", stream->dport);
mvwprintw(win, cline, endpos, "%d", stream->src.port);
mvwprintw(win, cline, startpos - 4, "%d", stream->dst.port);
}
mvwaddch(win, cline, startpos + 2, '<');
if (arrow->rtp_count != stream_get_count(stream)) {
@ -729,22 +729,22 @@ call_flow_draw_rtcp_stream(PANEL *panel, call_flow_arrow_t *arrow, int cline)
// Get origin column for this stream.
// If we share the same Address from its setup SIP packet, use that column instead.
if (!strcmp(stream->ip_src, msg_src)) {
if (!strcmp(stream->src.ip, msg_src)) {
column1 = call_flow_column_get(panel, callid, msg_src);
} else if (!strcmp(stream->ip_src, msg_dst)) {
} else if (!strcmp(stream->src.ip, msg_dst)) {
column1 = call_flow_column_get(panel, callid, msg_dst);
} else {
column1 = call_flow_column_get(panel, 0, stream->ip_src);
column1 = call_flow_column_get(panel, 0, stream->src.ip);
}
// Get destination column for this stream.
// If we share the same Address from its setup SIP packet, use that column instead.
if (!strcmp(stream->ip_dst, msg_dst)) {
if (!strcmp(stream->dst.ip, msg_dst)) {
column2 = call_flow_column_get(panel, callid, msg_dst);
} else if (!strcmp(stream->ip_dst, msg_src)) {
} else if (!strcmp(stream->dst.ip, msg_src)) {
column2 = call_flow_column_get(panel, callid, msg_src);
} else {
column2 = call_flow_column_get(panel, 0, stream->ip_dst);
column2 = call_flow_column_get(panel, 0, stream->dst.ip);
}
call_flow_column_t *tmp;
@ -793,8 +793,8 @@ call_flow_draw_rtcp_stream(PANEL *panel, call_flow_arrow_t *arrow, int cline)
// Write the arrow at the end of the message (two arrows if this is a retrans)
if (arrow_dir == 0 /* right */) {
if (!setting_has_value(SETTING_CF_SDP_INFO, "compressed")) {
mvwprintw(win, cline, startpos - 4, "%d", stream->sport);
mvwprintw(win, cline, endpos, "%d", stream->dport);
mvwprintw(win, cline, startpos - 4, "%d", stream->src.port);
mvwprintw(win, cline, endpos, "%d", stream->dst.port);
}
mvwaddch(win, cline, endpos - 2, '>');
if (arrow->rtp_count != stream_get_count(stream)) {
@ -804,8 +804,8 @@ call_flow_draw_rtcp_stream(PANEL *panel, call_flow_arrow_t *arrow, int cline)
}
} else {
if (!setting_has_value(SETTING_CF_SDP_INFO, "compressed")) {
mvwprintw(win, cline, endpos, "%d", stream->sport);
mvwprintw(win, cline, startpos - 4, "%d", stream->dport);
mvwprintw(win, cline, endpos, "%d", stream->src.port);
mvwprintw(win, cline, startpos - 4, "%d", stream->dst.port);
}
mvwaddch(win, cline, startpos + 2, '<');
if (arrow->rtp_count != stream_get_count(stream)) {

View File

@ -59,12 +59,6 @@ media_destroyer(void *item)
sng_free(media);
}
void
media_set_port(sdp_media_t *media, uint16_t port)
{
media->port = port;
}
void
media_set_type(sdp_media_t *media, const char *type)
{
@ -72,9 +66,9 @@ media_set_type(sdp_media_t *media, const char *type)
}
void
media_set_address(sdp_media_t *media, const char *address)
media_set_address(sdp_media_t *media, address_t addr)
{
strcpy(media->address, address);
media->address = addr;
}
void
@ -99,13 +93,13 @@ media_add_format(sdp_media_t *media, uint32_t code, const char *format)
const char *
media_get_address(sdp_media_t *media)
{
return media->address;
return media->address.ip;
}
uint16_t
media_get_port(sdp_media_t *media)
{
return media->port;
return media->address.port;
}
const char *

View File

@ -50,8 +50,7 @@ struct sdp_media_fmt {
struct sdp_media {
//! SDP Addresses information
char address[ADDRESSLEN];
uint16_t port;
address_t address;
char type[10];
uint32_t fmtcode;
//! List of described formats in this media
@ -77,14 +76,11 @@ media_create(struct sip_msg *msg);
void
media_destroyer(void *item);
void
media_set_port(sdp_media_t *media, uint16_t port);
void
media_set_type(sdp_media_t *media, const char *type);
void
media_set_address(sdp_media_t *media, const char *address);
media_set_address(sdp_media_t *media, address_t addr);
void
media_set_prefered_format(sdp_media_t *media, uint32_t code);

View File

@ -65,10 +65,12 @@ rtp_encoding_t encodings[] = {
};
rtp_stream_t *
stream_create(sdp_media_t *media, const char *dst, uint16_t dport, int type)
stream_create(sdp_media_t *media, address_t dst, int type)
{
rtp_stream_t *stream;
fprintf(stderr, "Waiting for packets on %s:%u\n", dst.ip, dst.port);
// Allocate memory for this stream structure
if (!(stream = sng_malloc(sizeof(rtp_stream_t))))
return NULL;
@ -76,17 +78,15 @@ stream_create(sdp_media_t *media, const char *dst, uint16_t dport, int type)
// Initialize all fields
stream->type = type;
stream->media = media;
strcpy(stream->ip_dst, dst);
stream->dport = dport;
stream->dst = dst;
return stream;
}
rtp_stream_t *
stream_complete(rtp_stream_t *stream, const char *src, uint16_t sport)
stream_complete(rtp_stream_t *stream, address_t src)
{
strcpy(stream->ip_src, src);
stream->sport = sport;
stream->src = src;
return stream;
}
@ -157,8 +157,7 @@ rtp_get_standard_format(uint32_t code)
rtp_stream_t *
rtp_check_packet(packet_t *packet)
{
const char *src, *dst;
uint16_t sport, dport;
address_t src, dst;
rtp_stream_t *stream;
rtp_stream_t *reverse;
u_char format = 0;
@ -176,10 +175,8 @@ rtp_check_packet(packet_t *packet)
size = packet_payloadlen(packet);
// Get Addresses from packet
src = packet->src.ip;
dst = packet->dst.ip;
sport = packet->src.port;
dport = packet->dst.port;
src = packet->src;
dst = packet->dst;
// Check if we have at least RTP type
if ((int32_t) size < 2)
@ -196,7 +193,7 @@ rtp_check_packet(packet_t *packet)
format = RTP_PAYLOAD_TYPE(*(payload + 1));
// Find the matching stream
stream = rtp_find_stream(src, sport, dst, dport, format);
stream = rtp_find_stream(src, dst, format);
// Check if a valid stream has been found
if (!stream)
@ -205,20 +202,20 @@ rtp_check_packet(packet_t *packet)
// We have found a stream, but with different format
if (stream_is_complete(stream) && stream->rtpinfo.fmtcode != format) {
// Create a new stream for this new format
stream = stream_create(stream->media, dst, dport, PACKET_RTP);
stream_complete(stream, src, sport);
stream = stream_create(stream->media, dst, PACKET_RTP);
stream_complete(stream, src);
stream_set_format(stream, format);
call_add_stream(msg_get_call(stream->media->msg), stream);
}
// First packet for this stream, set source data
if (!(stream_is_complete(stream))) {
stream_complete(stream, src, sport);
stream_complete(stream, src);
stream_set_format(stream, format);
// Check if an stream in the opposite direction exists
if (!(reverse = rtp_find_call_stream(stream->media->msg->call, stream->ip_dst, stream->dport, stream->ip_src, stream->sport))) {
reverse = stream_create(stream->media, stream->ip_src, stream->sport, PACKET_RTP);
stream_complete(reverse, stream->ip_dst, stream->dport);
if (!(reverse = rtp_find_call_stream(stream->media->msg->call, stream->dst, stream->src))) {
reverse = stream_create(stream->media, stream->src, PACKET_RTP);
stream_complete(reverse, stream->dst);
stream_set_format(reverse, format);
call_add_stream(msg_get_call(stream->media->msg), reverse);
}
@ -228,7 +225,7 @@ rtp_check_packet(packet_t *packet)
stream_add_packet(stream, packet);
} else {
// Find the matching stream
if ((stream = rtp_find_stream(src, sport, dst, dport, format))) {
if ((stream = rtp_find_stream(src, dst, format))) {
// Parse all packet payload headers
while ((int32_t) size > 0) {
@ -296,7 +293,7 @@ rtp_check_packet(packet_t *packet)
}
// Add packet to stream
stream_complete(stream, src, sport);
stream_complete(stream, src);
stream_add_packet(stream, packet);
}
}
@ -305,7 +302,7 @@ rtp_check_packet(packet_t *packet)
}
rtp_stream_t *
rtp_find_stream(const char *src, uint16_t sport, const char *dst, uint16_t dport, uint32_t format)
rtp_find_stream(address_t src, address_t dst, uint32_t format)
{
// Structure for RTP packet streams
rtp_stream_t *stream;
@ -320,7 +317,7 @@ rtp_find_stream(const char *src, uint16_t sport, const char *dst, uint16_t dport
while ((call = vector_iterator_next(&calls))) {
// Check if this call has an RTP stream for current packet data
if ((stream = rtp_find_call_stream(call, src, sport, dst, dport))) {
if ((stream = rtp_find_call_stream(call, src, dst))) {
return stream;
}
}
@ -329,7 +326,7 @@ rtp_find_stream(const char *src, uint16_t sport, const char *dst, uint16_t dport
}
rtp_stream_t *
rtp_find_call_stream(struct sip_call *call, const char *ip_src, uint16_t sport, const char *ip_dst, uint16_t dport)
rtp_find_call_stream(struct sip_call *call, address_t src, address_t dst)
{
rtp_stream_t *stream;
vector_iter_t it;
@ -340,8 +337,8 @@ rtp_find_call_stream(struct sip_call *call, const char *ip_src, uint16_t sport,
// Look for an incomplete stream with this destination
vector_iterator_set_last(&it);
while ((stream = vector_iterator_prev(&it))) {
if (!strcmp(ip_dst, stream->ip_dst) && dport == stream->dport) {
if (!ip_src && !sport) {
if (address_equals(dst, stream->dst)) {
if (!src.port) {
return stream;
} else {
if (!stream->pktcnt) {
@ -352,11 +349,11 @@ rtp_find_call_stream(struct sip_call *call, const char *ip_src, uint16_t sport,
}
// Try to look for an incomplete stream with this destination
if (ip_src && sport) {
if (src.port) {
vector_iterator_set_last(&it);
while ((stream = vector_iterator_prev(&it))) {
if (!strcmp(ip_src, stream->ip_src) && sport == stream->sport &&
!strcmp(ip_dst, stream->ip_dst) && dport == stream->dport) {
if (address_equals(src, stream->src) &&
address_equals(dst, stream->dst)) {
return stream;
}
}

View File

@ -92,12 +92,10 @@ struct rtp_encoding {
struct rtp_stream {
//! Determine stream type
uint32_t type;
//! Source address and port
char ip_src[ADDRESSLEN];
uint16_t sport;
//! Destination address and port
char ip_dst[ADDRESSLEN];
uint16_t dport;
//! Source address
address_t src;
//! Destination address
address_t dst;
//! SDP media that setup this stream
sdp_media_t *media;
//! Packet count for this stream
@ -265,10 +263,10 @@ struct rtcp_blk_xr_voip
};
rtp_stream_t *
stream_create(sdp_media_t *media, const char *dst, uint16_t dport, int type);
stream_create(sdp_media_t *media, address_t dst, int type);
rtp_stream_t *
stream_complete(rtp_stream_t *stream, const char *src, uint16_t sport);
stream_complete(rtp_stream_t *stream, address_t src);
void
stream_set_format(rtp_stream_t *stream, uint32_t format);
@ -292,10 +290,10 @@ rtp_stream_t *
rtp_check_packet(packet_t *packet);
rtp_stream_t *
rtp_find_stream(const char *ip_src, uint16_t sport, const char *ip_dst, uint16_t dport, uint32_t format);
rtp_find_stream(address_t src, address_t dst, uint32_t format);
rtp_stream_t *
rtp_find_call_stream(struct sip_call *call, const char *ip_src, uint16_t sport, const char *ip_dst, uint16_t dport);
rtp_find_call_stream(struct sip_call *call, address_t src, address_t dst);
/**
* @brief Check if a message is older than other

View File

@ -222,8 +222,6 @@ sip_check_packet(packet_t *packet)
sip_call_t *call;
char callid[1024], xcallid[1024];
address_t src, dst;
char msg_src[ADDRESSLEN];
char msg_dst[ADDRESSLEN];
u_char payload[MAX_SIP_PAYLOAD];
// Max SIP payload allowed
@ -237,8 +235,6 @@ sip_check_packet(packet_t *packet)
// Initialize local variables
memset(callid, 0, sizeof(callid));
memset(xcallid, 0, sizeof(xcallid));
memset(msg_src, 0, sizeof(msg_src));
memset(msg_dst, 0, sizeof(msg_dst));
// Get payload from packet(s)
memset(payload, 0, MAX_SIP_PAYLOAD);
@ -294,20 +290,6 @@ sip_check_packet(packet_t *packet)
call->index = vector_count(calls.list);
}
// Store sorce address. Prefix too long IPv6 addresses with two dots
if (strlen(src.ip) > 15) {
sprintf(msg_src, "..%s", src.ip + strlen(src.ip) - 13);
} else {
strcpy(msg_src, src.ip);
}
// Store destination address. Prefix too long IPv6 addresses with two dots
if (strlen(dst.ip) > 15) {
sprintf(msg_dst, "..%s", dst.ip + strlen(dst.ip) - 13);
} else {
strcpy(msg_dst, dst.ip);
}
// At this point we know we're handling an interesting SIP Packet
msg->packet = packet;
@ -512,31 +494,25 @@ sip_parse_msg_payload(sip_msg_t *msg, const u_char *payload)
void
sip_parse_msg_media(sip_msg_t *msg, const u_char *payload)
{
char address[ADDRESSLEN];
char media_address[ADDRESSLEN] = { };
address_t dst, src;
char media_type[15] = { };
char media_format[30] = { };
int media_port;
uint32_t media_fmt_pref;
uint32_t media_fmt_code;
sdp_media_t *media = NULL;
char *payload2, *tofree, *line;
sip_call_t *call = msg_get_call(msg);
// Initialize variables
memset(address, 0, sizeof(address));
// Parse each line of payload looking for sdp information
tofree = payload2 = strdup((char*)payload);
while ((line = strsep(&payload2, "\r\n")) != NULL) {
// Check if we have a media string
if (!strncmp(line, "m=", 2)) {
if (sscanf(line, "m=%s %d RTP/%*s %u", media_type, &media_port, &media_fmt_pref) == 3) {
if (sscanf(line, "m=%s %hu RTP/%*s %u", media_type, &dst.port, &media_fmt_pref) == 3) {
// Create a new media structure for this message
if ((media = media_create(msg))) {
media_set_type(media, media_type);
media_set_port(media, media_port);
media_set_address(media, media_address);
media_set_address(media, dst);
media_set_prefered_format(media, media_fmt_pref);
msg_add_media(msg, media);
@ -547,11 +523,12 @@ sip_parse_msg_media(sip_msg_t *msg, const u_char *payload)
*/
// Create a new stream with this destination address:port
if (!call_msg_is_retrans(msg)) {
if (!rtp_find_call_stream(call, 0, 0, media_address, media_port)) {
if (!rtp_find_call_stream(call, src, dst)) {
// Create RTP stream
call_add_stream(call, stream_create(media, media_address, media_port, PACKET_RTP));
call_add_stream(call, stream_create(media, dst, PACKET_RTP));
// Create early RTCP stream
call_add_stream(call, stream_create(media, media_address, media_port + 1, PACKET_RTCP));
dst.port++;
call_add_stream(call, stream_create(media, dst, PACKET_RTCP));
}
}
}
@ -560,8 +537,8 @@ sip_parse_msg_media(sip_msg_t *msg, const u_char *payload)
// Check if we have a connection string
if (!strncmp(line, "c=", 2)) {
if (sscanf(line, "c=IN IP4 %s", media_address) && media) {
media_set_address(media, media_address);
if (sscanf(line, "c=IN IP4 %s", dst.ip) && media) {
media_set_address(media, dst);
}
}
@ -574,10 +551,10 @@ sip_parse_msg_media(sip_msg_t *msg, const u_char *payload)
// Check if we have attribute format RTCP port
if (!strncmp(line, "a=rtcp:", 7)) {
if (media && sscanf(line, "a=rtcp:%u", &media_port)) {
if (media && sscanf(line, "a=rtcp:%hu", &dst.port)) {
// Create early RTCP stream
if (!rtp_find_call_stream(call, 0, 0, media_address, media_port)) {
call_add_stream(call, stream_create(media, media_address, media_port, PACKET_RTCP));
if (!rtp_find_call_stream(call, src, dst)) {
call_add_stream(call, stream_create(media, dst, PACKET_RTCP));
}
}
}