Resip获取本机IPV4地址

在语音对讲注册时,需要绑定本机ip及端口,甚至于如果在手机端连接本机wifi,进行呼叫时,需要进行IPV4获取: 

bool checkIPAddress(resip::Data& ipAddessCanUsed, const resip::Data& ipUserInputAddress)
{
	LOG_JNI_E("Insert checkIPAddress, ipUserInputAddress= %s!", ipUserInputAddress.c_str());
	std::list<std::pair<resip::Data, resip::Data> > interfaces = resip::DnsUtil::getInterfaces();
	LOG_JNI_E("Insert getInterfaces!");
	if (!ipUserInputAddress.empty())
	{
		LOG_JNI_E("ipUserInputAddress is not empty!ipUserInputAddress is :%s", ipUserInputAddress.c_str());
		CompareIPAddress compare(ipUserInputAddress);
		if (std::find_if(interfaces.begin(), interfaces.end(), compare) != interfaces.end()) //find
		{
			ipAddessCanUsed = ipUserInputAddress;
			return resip::DnsUtil::isIpV4Address(ipUserInputAddress);
		}
	}
	//ip address invailed
	LOG_JNI_E("ipUserInputAddress is empty!");
	std::list<std::pair<resip::Data, resip::Data> >::iterator iter = interfaces.begin();
	for (; iter != interfaces.end(); iter++)
	{
		if (resip::DnsUtil::isIpV4Address(iter->second))
		{
			ipAddessCanUsed = iter->second;
			LOG_JNI_E("ipAddessCanUsed:%s", ipAddessCanUsed.c_str());
			break;
		}
	}
	return !ipAddessCanUsed.empty();
}

 

转载于:https://www.cnblogs.com/SunkingYang/p/11049109.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值