From 8677479486ad9d441764651f8c2f6a0ebbec7a92 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Tue, 6 Dec 2022 17:12:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E6=BB=9Avia=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/gb28181/utils/SipUtils.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java index 5c31f904..56fdb5b6 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java @@ -13,6 +13,7 @@ import javax.sip.SipFactory; import javax.sip.header.FromHeader; import javax.sip.header.Header; import javax.sip.header.UserAgentHeader; +import javax.sip.header.ViaHeader; import javax.sip.message.Request; import java.text.ParseException; import java.util.ArrayList; @@ -121,6 +122,12 @@ public class SipUtils { return builder.toString(); } + /** + * 从请求中获取设备ip地址和端口号 + * @param request 请求 + * @param sipUseSourceIpAsRemoteAddress false 从via中获取地址, true 直接获取远程地址 + * @return 地址信息 + */ public static RemoteAddressInfo getRemoteAddressFromRequest(SIPRequest request, boolean sipUseSourceIpAsRemoteAddress) { String remoteAddress; @@ -131,12 +138,13 @@ public class SipUtils { }else { // 判断RPort是否改变,改变则说明路由nat信息变化,修改设备信息 // 获取到通信地址等信息 - remoteAddress = request.getTopmostViaHeader().getReceived(); - remotePort = request.getTopmostViaHeader().getPort(); + ViaHeader viaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME); + remoteAddress = viaHeader.getReceived(); + remotePort = viaHeader.getRPort(); // 解析本地地址替代 if (ObjectUtils.isEmpty(remoteAddress) || remotePort == -1) { - remoteAddress = request.getViaHost(); - remotePort = request.getViaPort(); + remoteAddress = viaHeader.getHost(); + remotePort = viaHeader.getPort(); } }