Exemplo n.º 1
0
bool CMgmtCmd::SendCmd(CMgmtPMessage& p_rMsg)
{
    unsigned char ipv6[16];
    int targetType = 0;
    bool isInfo = false;

    if (!m_rEPDBMngt.GetDevShortInf(m_rDBReq.targetID, isInfo, ipv6, targetType) || !isInfo)
    {   NLOG_ERR("[CMgmtCmd::SendCmd]: no info for devID = %s!", BuffToHEXStr(m_rDBReq.targetID, 8).c_str());
        return false;
    }

    CNetAddressExt addr;
    addr.SetIP((unsigned char*) ipv6);
    addr.SetPort(m_rDBReq.targetPort);

    p_rMsg.m_oNetAddr = addr;
    p_rMsg.m_Header.m_u8SourceType        = MgmtProtocol::MOD_EP;
    p_rMsg.m_Header.m_u8DestinationType   = targetType;
    p_rMsg.m_Header.m_u32SeqNo            = m_rPersistMsgId->GetNextMsgId();

    m_rMsgQueue->Push(CMgmtPMessage::Ptr(new CMgmtPMessage(p_rMsg)));

    if (m_rDBCmdTrackList->Insert(p_rMsg.m_Header.m_u32SeqNo, TrackItem(m_rDBReq.trackingNo)) == false)
    {   NLOG_ERR("[CMgmtCmd::SendCmd]: already seqNo=%ud in tracking list", p_rMsg.m_Header.m_u32SeqNo);
    }

    return true;
}
Exemplo n.º 2
0
int CConfig::GetNetAddressExt( const char * p_pszNetAddrExt, CNetAddressExt& p_roNetAddrExt)
{
	char szAddr[64];
	unsigned short usPort;
	char iface[100] = {0,0};
	
	if (sscanf(p_pszNetAddrExt, "%[^, ] %*[,] %hu%*[%%]%s", szAddr, &usPort, iface) < 2)
	{
		NLOG_ERR("CConfig::GetNetAddressExt: invalid NetAddressExt %s", p_pszNetAddrExt);
		return 0;
	}
	if (*iface) p_roNetAddrExt.SetIfName (iface);
	p_roNetAddrExt.SetPort(usPort);

	union
	{
		unsigned int	unIPv4;
		unsigned char	szIPv6[INET6_ADDRSTRLEN];
	};

	if (inet_pton(AF_INET, szAddr, &unIPv4))
	{
		p_roNetAddrExt.SetIP(unIPv4);
		return 1;
	}

	if (inet_pton(AF_INET6, szAddr, szIPv6))
	{
		p_roNetAddrExt.SetIP(szIPv6);
		return 1;
	}

	NLOG_ERR("CConfig::GetVarAsExtAddr: invalid NetAddressExt %s", p_pszNetAddrExt);

	return 0;
}