In SIP, why the Contact header field MUST be present in the Invite request

sip
Phoenix Luo picture Phoenix Luo · Feb 29, 2012 · Viewed 32.9k times · Source

Usually, the Contact header field in the Invite request is useless. For example, the UAC and the UAS are in different LANs. The Contact field may be:

INVITE sip:bob@sipprovider SIP/2.0
Contact: Alice<[email protected]>
.....

There is no use of the Contact field while we can still build a dialog. Then, why the Contact header field is mandatory?

Answer

Frank Shearar picture Frank Shearar · Mar 2, 2012

The Contact header says where you are (or rather, where your User Agent is), while the From header says who you are.

You might have several SIP devices all registered to the same Address of Record (the URI you put in the From header).

Further, REGISTER requests use Contact headers to maintain SIP's location service: they let a user agent update a registrar's location information.

(As an aside, if Alice calls Bob, the Contact header needs to be in a 2xx response so that Alice can route the 2xx's ACK to Bob. This points to DarkDust's comment about some SIP proxies mangling Contact headers: if it doesn't, you find yourself in the uncomfortable position of having a call that's only half established: Alice thinks the call's set up because she sent her ACK, but Bob never receives it. An alternative to a Contact-mangling Proxy is using a B2BUA as a network gateway; it wouldn't need to mangle the Contact header because the header would point to the B2BUA itself.)

In response to Phoenix Luo's comments, because of the shortcomings of using LAN IPs in a Contact header, RFC 5627 describes a solution - using globally routable user agent URIs (GRUUs) in the Contact header/s.