回滚via获取地址的方式

pull/706/head
648540858 2022-12-06 17:12:12 +08:00
parent 5606bce885
commit 1516991372
1 changed files with 12 additions and 4 deletions

View File

@ -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();
}
}