SIP: From ,Contact, Via 和 Record-Route/Route head

本文详细介绍了SIP协议中的关键头域的作用与使用方式,包括Contact、Record-Route/Route、Via等,阐述了它们如何指导呼叫的建立与响应路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

From: 如果一个SIP消息中没有Contact或者Record-Route头域,那么callee就会根据From头域产生后续的Request。比如:如果Alice打一个电话给Bob,From头域的内容是 From:Alice<sip:alice@example.org>。那么Bob打给Alice时就会使用 sip:alice@example.org作为To头域和Request-URI头域的内容。

Contact: 后续Request将根据Contact头域的内容决定目的地的地址,同时将Contact头域的内容放到Request-URI中。它还可以用来指示没有在Record-Route头域中记录的Proxies的地址。同时它还可以被用在Redirect servers和REGISTER requests 和responses。

Record-Route/Route: Record-Route头域一般是被proxies插入到request中的,这样后续的Request如何有着和前面一样的call-id就会被路由到这些proxies。它也会被User Agent作为发送后续request的依据。这套机制很像source-route,Record-Route头域的信息被复制到Route头域中。并且Request-URI头域会被设置为第一个Route头域的内容。


Via:
Via头域是被服务器插入request中,用来检查路由环的,并且可以使response根据via找到返回的路。它不会对未来的request 或者是response造成影响。

总的来说,如果有Route,request就应该根据Route发送,如果没有就根据Contact头域发送,如果连Contact都没有,就根据From头域发送。
freeswitch@localhost.localdomain> recv 1026 bytes from udp/[183.227.181.232]:1864 at 09:19:10.523919: ------------------------------------------------------------------------ INVITE sip:18996228654@27.25.152.174:5080 SIP/2.0 Via: SIP/2.0/UDP 10.168.1.102:59028;branch=z9hG4bK-d87543-b7678846ac1d547d-1--d87543-;rport Max-Forwards: 70 Contact: <sip:03512332064@183.227.181.232:1864> To: "18996228654"<sip:18996228654@27.25.152.174:5080> From: "03512332064"<sip:03512332064@27.25.152.174:5080>;tag=842b1e78 Call-ID: M2ZiZDEzZTk3ZTZmMDBmNDFkYTg1NDNhM2I5MDk4NWI. CSeq: 1 INVITE Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO Content-Type: application/sdp User-Agent: eyeBeam release 1011d stamp 40820 Content-Length: 435 v=0 o=- 8 2 IN IP4 10.168.1.102 s=CounterPath eyeBeam 1.5 c=IN IP4 10.168.1.102 t=0 0 m=audio 15344 RTP/AVP 0 8 18 101 a=alt:1 3 : 0E+mq1nU hFt+pKdF 172.28.16.1 15344 a=alt:2 2 : 65/yrvXK tFeCv5wr 172.17.144.1 15344 a=alt:3 1 : dKt7HfUt 78IDBaMu 10.168.1.102 15344 a=fmtp:18 annexb=no a=fmtp:101 0-15 a=rtpmap:18 G729/8000 a=rtpmap:101 telephone-event/8000 a=sendrecv a=x-rtp-session-id:02EC42FF7A2C4B7B91C41D4000CC93D6 2025-07-19 09:19:10.517138 100.00% [NOTICE] switch_channel.c:1142 New Channel sofia/external/03512332064@27.25.152.174:5080 [4bd59857-2eb6-4470-987d-446b63d19f14] 2025-07-19 09:19:10.517138 100.00% [INFO] sofia.c:10460 sofia/external/03512332064@27.25.152.174:5080 receiving invite from 183.227.181.232:1864 version: 1.10.12-release git a88d069 2024-08-02 21:02:27Z 64bit call-id: M2ZiZDEzZTk3ZTZmMDBmNDFkYTg1NDNhM2I5MDk4NWI. 2025-07-19 09:19:10.517138 100.00% [INFO] mod_dialplan_xml.c:639 Processing 03512332064 <03512332064>->18996228654 in context public send 448 bytes to udp/[183.227.181.232]:1864 at 09:19:10.526257: ------------------------------------------------------------------------ SIP/2.0 100 Trying Via: SIP/2.0/UDP 10.168.1.102:59028;branch=z9hG4bK-d87543-b7678846ac1d547d-1--d87543-;rport=1864;received=183.227.181.232 From: "03512332064"<sip:03512332064@27.25.152.174:5080>;tag=842b1e78 To: "18996228654"<sip:18996228654@27.25.152.174:5080> Call-ID: M2ZiZDEzZTk3ZTZmMDBmNDFkYTg1NDNhM2I5MDk4NWI. CSeq: 1 INVITE User-Agent: FreeSWITCH-mod_sofia/1.10.12-release+git~20240802T210227Z~a88d069d6f~64bit Content-Length: 0 EXECUTE [depth=0] sofia/external/03512332064@27.25.152.174:5080 set(outside_call=true) EXECUTE [depth=0] sofia/external/03512332064@27.25.152.174:5080 export(RFC2822_DATE=Sat, 19 Jul 2025 09:19:10 +0800) EXECUTE [depth=0] sofia/external/03512332064@27.25.152.174:5080 log(INFO Calling outbound number: 18996228654) 2025-07-19 09:19:10.517138 100.00% [INFO] mod_dptools.c:1865 Calling outbound number: 18996228654 EXECUTE [depth=0] sofia/external/03512332064@27.25.152.174:5080 bridge(sofia/gateway/121_40_149_63_6086/18996228654) 2025-07-19 09:19:10.517138 100.00% [NOTICE] switch_channel.c:1142 New Channel sofia/external/18996228654 [35bf0415-4fe3-4206-8d41-eda1d8e43604] 2025-07-19 09:19:10.517138 100.00% [INFO] sofia_glue.c:1659 sofia/external/18996228654 sending invite call-id: (null) send 1145 bytes to udp/[121.40.149.63]:6086 at 09:19:10.529992: ------------------------------------------------------------------------ INVITE sip:18996228654@121.40.149.63:6086 SIP/2.0 Via: SIP/2.0/UDP 27.25.152.174:5080;rport;branch=z9hG4bKF27pv3mFS6p9g Max-Forwards: 69 From: "03512332064" <sip:03512332064@27.25.152.174>;tag=pa6eaSDe6Xyej To: <sip:18996228654@121.40.149.63:6086> Call-ID: 3718d4b7-dee1-123e-558e-246e963b2e1c CSeq: 101890183 INVITE Contact: <sip:gw+121_40_149_63_6086@27.25.152.174:5080;transport=udp;gw=121_40_149_63_6086> User-Agent: FreeSWITCH-mod_sofia/1.10.12-release+git~20240802T210227Z~a88d069d6f~64bit Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY Supported: timer, path, replaces Allow-Events: talk, hold, conference, refer Content-Type: application/sdp Content-Disposition: session Content-Length: 246 X-FS-Support: update_display,send_info Remote-Party-ID: "03512332064" <sip:03512332064@27.25.152.174>;party=calling;screen=yes;privacy=off v=0 o=FreeSWITCH 1752856774 1752856775 IN IP4 27.25.152.174 s=FreeSWITCH c=IN IP4 27.25.152.174 t=0 0 m=audio 31176 RTP/AVP 0 8 101 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15 a=ptime:20 send 1145 bytes to udp/[121.40.149.63]:6086 at 09:19:11.530080: ------------------------------------------------------------------------ INVITE sip:18996228654@121.40.149.63:6086 SIP/2.0 Via: SIP/2.0/UDP 27.25.152.174:5080;rport;branch=z9hG4bKF27pv3mFS6p9g Max-Forwards: 69 From: "03512332064" <sip:03512332064@27.25.152.174>;tag=pa6eaSDe6Xyej To: <sip:18996228654@121.40.149.63:6086> Call-ID: 3718d4b7-dee1-123e-558e-246e963b2e1c CSeq: 101890183 INVITE Contact: <sip:gw+121_40_149_63_6086@27.25.152.174:5080;transport=udp;gw=121_40_149_63_6086> User-Agent: FreeSWITCH-mod_sofia/1.10.12-release+git~20240802T210227Z~a88d069d6f~64bit Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY Supported: timer, path, replaces Allow-Events: talk, hold, conference, refer Content-Type: application/sdp Content-Disposition: session Content-Length: 246 X-FS-Support: update_display,send_info Remote-Party-ID: "03512332064" <sip:03512332064@27.25.152.174>;party=calling;screen=yes;privacy=off v=0 o=FreeSWITCH 1752856774 1752856775 IN IP4 27.25.152.174 s=FreeSWITCH c=IN IP4 27.25.152.174 t=0 0 m=audio 31176 RTP/AVP 0 8 101 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15 a=ptime:20 send 1145 bytes to udp/[121.40.149.63]:6086 at 09:19:13.530314: ------------------------------------------------------------------------ INVITE sip:18996228654@121.40.149.63:6086 SIP/2.0 Via: SIP/2.0/UDP 27.25.152.174:5080;rport;branch=z9hG4bKF27pv3mFS6p9g Max-Forwards: 69 From: "03512332064" <sip:03512332064@27.25.152.174>;tag=pa6eaSDe6Xyej To: <sip:18996228654@121.40.149.63:6086> Call-ID: 3718d4b7-dee1-123e-558e-246e963b2e1c CSeq: 101890183 INVITE Contact: <sip:gw+121_40_149_63_6086@27.25.152.174:5080;transport=udp;gw=121_40_149_63_6086> User-Agent: FreeSWITCH-mod_sofia/1.10.12-release+git~20240802T210227Z~a88d069d6f~64bit Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY Supported: timer, path, replaces Allow-Events: talk, hold, conference, refer Content-Type: application/sdp Content-Disposition: session Content-Length: 246 X-FS-Support: update_display,send_info Remote-Party-ID: "03512332064" <sip:03512332064@27.25.152.174>;party=calling;screen=yes;privacy=off v=0 o=FreeSWITCH 1752856774 1752856775 IN IP4 27.25.152.174 s=FreeSWITCH c=IN IP4 27.25.152.174 t=0 0 m=audio 31176 RTP/AVP 0 8 101 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15 a=ptime:20 send 1145 bytes to udp/[121.40.149.63]:6086 at 09:19:17.530507: ------------------------------------------------------------------------ INVITE sip:18996228654@121.40.149.63:6086 SIP/2.0 Via: SIP/2.0/UDP 27.25.152.174:5080;rport;branch=z9hG4bKF27pv3mFS6p9g Max-Forwards: 69 From: "03512332064" <sip:03512332064@27.25.152.174>;tag=pa6eaSDe6Xyej To: <sip:18996228654@121.40.149.63:6086> Call-ID: 3718d4b7-dee1-123e-558e-246e963b2e1c CSeq: 101890183 INVITE Contact: <sip:gw+121_40_149_63_6086@27.25.152.174:5080;transport=udp;gw=121_40_149_63_6086> User-Agent: FreeSWITCH-mod_sofia/1.10.12-release+git~20240802T210227Z~a88d069d6f~64bit Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY Supported: timer, path, replaces Allow-Events: talk, hold, conference, refer Content-Type: application/sdp Content-Disposition: session Content-Length: 246 X-FS-Support: update_display,send_info Remote-Party-ID: "03512332064" <sip:03512332064@27.25.152.174>;party=calling;screen=yes;privacy=off v=0 o=FreeSWITCH 1752856774 1752856775 IN IP4 27.25.152.174 s=FreeSWITCH c=IN IP4 27.25.152.174 t=0 0 m=audio 31176 RTP/AVP 0 8 101 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15 a=ptime:20 send 1145 bytes to udp/[121.40.149.63]:6086 at 09:19:25.531945: ------------------------------------------------------------------------ INVITE sip:18996228654@121.40.149.63:6086 SIP/2.0 Via: SIP/2.0/UDP 27.25.152.174:5080;rport;branch=z9hG4bKF27pv3mFS6p9g Max-Forwards: 69 From: "03512332064" <sip:03512332064@27.25.152.174>;tag=pa6eaSDe6Xyej To: <sip:18996228654@121.40.149.63:6086> Call-ID: 3718d4b7-dee1-123e-558e-246e963b2e1c CSeq: 101890183 INVITE Contact: <sip:gw+121_40_149_63_6086@27.25.152.174:5080;transport=udp;gw=121_40_149_63_6086> User-Agent: FreeSWITCH-mod_sofia/1.10.12-release+git~20240802T210227Z~a88d069d6f~64bit Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY Supported: timer, path, replaces Allow-Events: talk, hold, conference, refer Content-Type: application/sdp Content-Disposition: session Content-Length: 246 X-FS-Support: update_display,send_info Remote-Party-ID: "03512332064" <sip:03512332064@27.25.152.174>;party=calling;screen=yes;privacy=off v=0 o=FreeSWITCH 1752856774 1752856775 IN IP4 27.25.152.174 s=FreeSWITCH c=IN IP4 27.25.152.174 t=0 0 m=audio 31176 RTP/AVP 0 8 101 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15 a=ptime:20 send 1145 bytes to udp/[121.40.149.63]:6086 at 09:19:41.532767: ------------------------------------------------------------------------ INVITE sip:18996228654@121.40.149.63:6086 SIP/2.0 Via: SIP/2.0/UDP 27.25.152.174:5080;rport;branch=z9hG4bKF27pv3mFS6p9g Max-Forwards: 69 From: "03512332064" <sip:03512332064@27.25.152.174>;tag=pa6eaSDe6Xyej To: <sip:18996228654@121.40.149.63:6086> Call-ID: 3718d4b7-dee1-123e-558e-246e963b2e1c CSeq: 101890183 INVITE Contact: <sip:gw+121_40_149_63_6086@27.25.152.174:5080;transport=udp;gw=121_40_149_63_6086> User-Agent: FreeSWITCH-mod_sofia/1.10.12-release+git~20240802T210227Z~a88d069d6f~64bit Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY Supported: timer, path, replaces Allow-Events: talk, hold, conference, refer Content-Type: application/sdp Content-Disposition: session Content-Length: 246 X-FS-Support: update_display,send_info Remote-Party-ID: "03512332064" <sip:03512332064@27.25.152.174>;party=calling;screen=yes;privacy=off v=0 o=FreeSWITCH 1752856774 1752856775 IN IP4 27.25.152.174 s=FreeSWITCH c=IN IP4 27.25.152.174 t=0 0 m=audio 31176 RTP/AVP 0 8 101 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15 a=ptime:20 2025-07-19 09:19:42.517142 100.00% [NOTICE] sofia.c:8736 Hangup sofia/external/18996228654 [CS_CONSUME_MEDIA] [RECOVERY_ON_TIMER_EXPIRE] 2025-07-19 09:19:42.537141 100.00% [NOTICE] switch_core_session.c:1762 Session 6 (sofia/external/18996228654) Ended 2025-07-19 09:19:42.537141 100.00% [NOTICE] switch_core_session.c:1766 Close Channel sofia/external/18996228654 [CS_DESTROY] 2025-07-19 09:19:42.537141 100.00% [INFO] mod_dptools.c:3635 Originate Failed. Cause: RECOVERY_ON_TIMER_EXPIRE 2025-07-19 09:19:42.537141 100.00% [NOTICE] switch_channel.c:5012 Hangup sofia/external/03512332064@27.25.152.174:5080 [CS_EXECUTE] [RECOVERY_ON_TIMER_EXPIRE] send 845 bytes to udp/[183.227.181.232]:1864 at 09:19:42.544835: ------------------------------------------------------------------------ SIP/2.0 408 Request Timeout Via: SIP/2.0/UDP 10.168.1.102:59028;branch=z9hG4bK-d87543-b7678846ac1d547d-1--d87543-;rport=1864;received=183.227.181.232 Max-Forwards: 70 From: "03512332064"<sip:03512332064@27.25.152.174:5080>;tag=842b1e78 To: "18996228654" <sip:18996228654@27.25.152.174:5080>;tag=N1cp8Xva9m8Up Call-ID: M2ZiZDEzZTk3ZTZmMDBmNDFkYTg1NDNhM2I5MDk4NWI. CSeq: 1 INVITE User-Agent: FreeSWITCH-mod_sofia/1.10.12-release+git~20240802T210227Z~a88d069d6f~64bit Accept: application/sdp Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY Supported: timer, path, replaces Allow-Events: talk, hold, conference, refer Reason: Q.850;cause=102;text="RECOVERY_ON_TIMER_EXPIRE" Content-Length: 0 Remote-Party-ID: "18996228654" <sip:18996228654@27.25.152.174>;party=calling;privacy=off;screen=no 2025-07-19 09:19:42.537141 100.00% [NOTICE] switch_core_session.c:1762 Session 5 (sofia/external/03512332064@27.25.152.174:5080) Ended 2025-07-19 09:19:42.537141 100.00% [NOTICE] switch_core_session.c:1766 Close Channel sofia/external/03512332064@27.25.152.174:5080 [CS_DESTROY] recv 374 bytes from udp/[183.227.181.232]:1864 at 09:19:42.577655: ------------------------------------------------------------------------ ACK sip:18996228654@27.25.152.174:5080 SIP/2.0 Via: SIP/2.0/UDP 10.168.1.102:59028;branch=z9hG4bK-d87543-b7678846ac1d547d-1--d87543-;rport To: "18996228654" <sip:18996228654@27.25.152.174:5080>;tag=N1cp8Xva9m8Up From: "03512332064"<sip:03512332064@27.25.152.174:5080>;tag=842b1e78 Call-ID: M2ZiZDEzZTk3ZTZmMDBmNDFkYTg1NDNhM2I5MDk4NWI. CSeq: 1 ACK Content-Length: 0
最新发布
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值