Here is the sequence needed to parse a given buffer containing a sip request or response. Because the SIP message can contains binary data in its body part, the length of the buffer must be given to the API.

Here is the sequence needed to convert the message into a printable string. Note that in this sequence, dest is allocated dynamically and must be released at the end of the call sequence to avoid memory leaks.

When converting SIP message, the final length of the allocated buffer will be returned in the third argument. You then have the knowledge of the length of the data received.

It is important to understand that the libosip2 parser will not check completely if the message is compliant and well formed. The application layer is still responsible for this. The following string shows a request-URI containing a strange port number!