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
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);
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!
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.
One more thing if you can help me.. I need to get the source number and the destination number ( not IP, number). Thanks!
For destination number you probably mean the request URI (req.URI.User) and for source number take a look at the "From" header.
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