SIP API Developer's Guide

Generating Call-ID, From and To tags, Branch-ID and Cseq

The library provides the sip_guid() function to generate unique identifiers for the Call-ID, From, and To tags. The stack generates the identifier by combining the upper 32 bits that are returned by the gethrtime() function with a 32–bit random number from the /dev/urandom pseudo-device. The stack randomly replaces numbers in the result with alphabetic characters. The applicatioon is responsible for freeing the string that is returned by the sip_guid() function.

The library provides the sip_branchid() function to generate Branch-ID fields. If the application invokes the sip_branchid() function without a SIP message, or if the SIP message does not have a VIA header, the stack forms a Branch-ID field by using the sip_guid() function. If the SIP message already has a VIA header, the stack generates the Branch-ID by using the MD5 hash of the following fields:

All branch identifiers begin with the string z9hG4bK. This behavior complies with RFC 3261. The application is responsible for freeing the string that is returned by the sip_branchid() function.

An application can use the sip_get_cseq() or sip_get_rseq() functions to obtain the initial sequence number. The sip_get_cseq() and sip_get_rseq() functions use the 31 most significant bits of the value that is returned by the time(2) function call.