[SIP01]SIP Header Fields里面各字段用途


INVITE sip:bob@biloxi.com SIP/2.0
      Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds
      Max-Forwards: 70
      To: Bob <sip:bob@biloxi.com>
      From: Alice <sip:alice@atlanta.com>;tag=1928301774
      Call-ID: a84b4c76e66710@pc33.atlanta.com
      CSeq: 314159 INVITE
      Contact: <sip:alice@pc33.atlanta.com>
      Content-Type: application/sdp
      Content-Length: 142

      (Alice’s SDP not shown)

1. Via

Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds

1.1 用來標識Responeses消息的返回路徑(todo:各router的區別),包含SIP版本,通過的路徑,branch;每個Request-Line(請求消息)路過代理Server時都會記錄,然后原路返回;

1.2 用來檢查路由環,因為每經過server都會把他放在via里面,每都一個Server里先檢查via頭里面有沒有這個server如果有,出現了路由環Spiral:Alice calls Bob@example.com ,example.com 把信息傳給Bob的PC,返回時又轉給了Joe@example.com,這樣又回到了example.com proxy上,所以這不是一個死循環【PS: 和loop不一樣】;

1.3 Branch是一個事務ID(Transaction ID),用於區分同一個Client所發起的不同Transaction,它不會對未來的request 或者是response造成影響,對於遵循RFC3261規范的實現,這個branch參數的值必須用magic cookie”z9hG4bK”打頭. 其它部分是對“To, From, Call-ID頭域和Request-URI”按一定的算法加密后得到;

1.4 與CallID的區別:CallID是用來在session層,branch用在transation層

Call-ID contains a globally unique identifier for this call,generated by the combination of a random string and the softphone's host name or IP address. The combination of the To tag, From tag,and Call-ID completely defines a peer-to-peer SIP relationship between Alice and Bob and is referred to as a dialog.

2.Max-Forwards

Max-Forwards: 70

serves to limit the number of hops a request can make on the way to its destination. It consists of an integer that is decremented by one at each hop.

2.1 用於表示這個包最多可以傳送多少跳,當Max-Forwards==0&&沒到達目的地時,系統會返回483(Too many hops);一般會在有Request的包里面;

2.2 默認為70;

2.3 原理:每經過一跳時【Todo:一個代理?】都會減一向下一跳傳去.

 

3. To

To: Bob <sip:bob@biloxi.com>

3.1 目的地的絕對地址,包含補叫的display name 和被 叫URL,&前面帶的是設備號或被叫號碼,&后帶的是Proxy地址;

3.2 這個地址用於給Proxy們找路由的,一般會經過Proxy一步步定位到最精確的位置【改為其它精確地址】.

4. From

From: Alice <sip:alice@atlanta.com>;tag=1928301774

4.1 格式與To一樣,表示Caller的絕對地址,但是會加一個Tag標簽;

4.2 Tag 他是一個隨機碼【Todo:可不可變?】用於 identification purposes.

5. Call-ID

Call-ID: a84b4c76e66710@pc33.atlanta.com

5.1 Call-ID由本地設備(Client)生成,全局唯一,每次呼叫這個值唯一不變,與其它的session是不同的;

5.2 對於用戶發出Invite消息,本地會生成From Tag 和Call-ID全局唯一碼,被叫方代理生成 To tag全局唯一碼,這三個隨機碼做為整個對話中對話標識(dialog indentifier).

6. Cseq

CSeq: 314159 INVITE

6.1 又叫Command Seqence(命令隊列),每發一個新的請求,這個數就會+1,最大2*31;

6.2 用來標識命令和命令順序,整數部用於同一session(CallID決定)中不同的請求排序,它會與將請求和應答想匹配:比如:Alice 發1 Invite 沒返回--->再發 2 Invite--->沒返回--->再發3 Invite--->這時返回了2 Invite就知道是第2個請求得到了響應(這個數是一直遞增1的); 【因為在同一個transtation里面,所以invite其它消息都沒有變化的,就用cseq來區別了】
- Ack的CSeq:這個是與Invite里面的一樣的,這使代理為非成功最終應答產生Ack時不用再建立新的CSeq,保證唯一性,只用client代理創建哦;
- Cancel的CSeq:這個也是與Invite里面的一樣的,這也是為什么CSeq里面要加Method的原因,如果不加,client就不知道這個是cancel還是invite的應答了;

以上幾個字段是所有 SIP 消息體所必須的,其它頭字段有些是可選的,有些在特定請求也是必須

 

7. Contact

Contact: <sip:alice@pc33.atlanta.com>

Contact contains a SIP or SIPS URI that represents a direct route to contact Alice, usually composed of a username at a fully qualified domain name (FQDN). While an FQDN is preferred, many end systems do not have registered domain names, so IP addresses are permitted. While the Via header field tells other elements where to send the response, the Contact header field tells other elements where to send future requests.

7.1 包含源的URI信息,用來給響應消息直接和源建立連接用;

7.2 注意和From的差別:這個是可以讓被叫方Bob直接找到呼叫方的絕對地址。

8. Content-Type,Content-Length

Content-Type: application/sdp %%指明消息體的類型為SDP【Todo: SDP會話描述協議】

Content-Length: 142 %%指明消息體的字節大小


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM