I am using jNetPcap to decode rtp from tcpdumps. Currently I use the SIP Invite Message and the source IP (and also checking via source ips..) to detect the directions (forward, reverse) from the call.. this is working but not really how it is intended to work from rfc standard and to work-around all possible behaviours.
Is there any way to determine from SSRC in which direction the source works for a sip call? As far as I can see the ssrc identifiers first appear on the rtp stream from which I can not say which call flow direction it is.
And I don't want to save both directions and have the user decide which direction it is.
I did dirty parsing but it seems that jnetpcap has no better way to do that:
private class JPacketHandlerSSRCs implements JPacketHandler<String> {
@Override
public void nextPacket(JPacket packet, String user) {
// TODO Auto-generated method stub
Udp udp = new Udp();
Rtp rtp = new Rtp();
Sdp sdp = new Sdp();
Sip sip = new Sip();
// get the source ip of the caller from the invite message.
// seems to be a tricky and dirty workaround, poor jnetpcap framework!
if(packet.hasHeader(sip) && packet.hasHeader(sdp)) {
if( (sip.getUTF8String(0, '@')).startsWith("INVITE ") ) {
String sdptext = sdp.text();
int pos = sdptext.indexOf("m=audio ") + 8;
int end = pos;
if(pos != -1)
while(sdptext.charAt(end) != ' ') end++;
rtp_forward_channel_port = Integer.parseInt(sdptext.substring(pos, end));
}
}
if(packet.hasHeader(udp))
if(rtp_forward_channel_port == udp.source() && packet.hasHeader(rtp)) {
try {
dos = getOutputStream(rtp.ssrc());
dos.write(rtp.getPayload());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}