1

I am looking for a library or class in c# that can parse sip packets. I need functions that will help me get the Call-ID field from the packet, types of requests, and basically breakdown the sip packet to its fields.

Does anybody know something that can help me? Thanks, ofek

Ofek Agmon
  • 5,040
  • 14
  • 57
  • 101

1 Answers1

5

This class from my sipsorcery project can do it for you.

Update: If you have a string that contains a full SIP packet you can parse the full thing by using:

var req = SIPSorcery.SIP.SIPRequest.ParseSIPRequest(reqStr); 
var headers = req.Header;

var resp = SIPSorcery.SIP.SIPResponse.ParseSIPResponse(respStr);  
var headers = resp.Header;

If you don't know whether the SIP packet is a request or a response you can use the SIPMessage class:

var mess = SIPSorcery.SIP.SIPMessage.ParseSIPMessage(messStr, null, null);
var headers = SIPSorcery.SIP.SIPHeader.ParseSIPHeaders(mess.SIPHeaders);        

Update 2:

Given you're using pcap.net to capture the SIP packets you are probably ending up with a block of bytes rather than a string. You can use the SIPMessage class to parse the SIP packet from a UDP payload:

var mess = SIPSorcery.SIP.SIPMessage.ParseSIPMessage(packet.Ethernet.IPv4datagram.Udp.Payload, null, null);
var headers = SIPSorcery.SIP.SIPHeader.ParseSIPHeaders(mess.SIPHeaders);
sipsorcery
  • 30,273
  • 24
  • 104
  • 155
  • Thnaks you, but the problem is that I dont know what is the string that I should put in the function. As I said, I am using pcap.net to capture the packets, so I have the "Packet" class. should I send the whole packet? or just the packet.Ethernet.IPv4datagram.Udp.Payload.ToString()??? Thanks a lot! – Ofek Agmon Oct 16 '13 at 12:55
  • The SIP portion of your capture packet will be the UDP payload so Udp.Payload would seem to be the correct property. See further update. – sipsorcery Oct 16 '13 at 21:08
  • One more thing if you can help me.. I need to get the source number and the destination number ( not IP, number). Thanks! – Ofek Agmon Oct 17 '13 at 12:50
  • For destination number you probably mean the request URI (req.URI.User) and for source number take a look at the "From" header. – sipsorcery Oct 17 '13 at 21:12
  • Hey again :) is there a way to get the SDP info from the SIP packets? I am trying to get the media port from the SIP packets in order to know which RTP packets belong to which SIP Packets – Ofek Agmon Oct 28 '13 at 07:17