/*---------------------------------------------------------------------- | PLT_SsdpAnnounceInterfaceIterator class +---------------------------------------------------------------------*/ NPT_Result PLT_SsdpAnnounceInterfaceIterator::operator()(NPT_NetworkInterface*& net_if) const { // don't use this interface address if it's not broadcast capable if (m_Broadcast && !(net_if->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_BROADCAST)) { return NPT_FAILURE; } NPT_List<NPT_NetworkInterfaceAddress>::Iterator niaddr = net_if->GetAddresses().GetFirstItem(); if (!niaddr) return NPT_FAILURE; // Remove disconnected interfaces NPT_IpAddress addr = (*niaddr).GetPrimaryAddress(); if (!addr.ToString().Compare("0.0.0.0")) return NPT_FAILURE; if (!m_Broadcast && !(net_if->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_MULTICAST) && !(net_if->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_LOOPBACK)) { NPT_LOG_INFO_2("Not a valid interface: %s (flags: %d)", (const char*)addr.ToString(), net_if->GetFlags()); return NPT_FAILURE; } NPT_HttpUrl url; NPT_UdpMulticastSocket multicast_socket; NPT_UdpSocket broadcast_socket; NPT_UdpSocket* socket; if (m_Broadcast) { url = NPT_HttpUrl((*niaddr).GetBroadcastAddress().ToString(), 1900, "*"); socket = &broadcast_socket; } else { url = NPT_HttpUrl("239.255.255.250", 1900, "*"); NPT_CHECK_SEVERE(multicast_socket.SetInterface(addr)); socket = &multicast_socket; multicast_socket.SetTimeToLive(PLT_Constants::GetInstance().GetAnnounceMulticastTimeToLive()); } NPT_HttpRequest req(url, "NOTIFY", NPT_HTTP_PROTOCOL_1_1); PLT_HttpHelper::SetHost(req, "239.255.255.250:1900"); // Location header valid only for ssdp:alive or ssdp:update messages if (m_Type != PLT_ANNOUNCETYPE_BYEBYE) { PLT_UPnPMessageHelper::SetLocation(req, m_Device->GetDescriptionUrl(addr.ToString())); } NPT_CHECK_SEVERE(m_Device->Announce(req, *socket, m_Type)); #if defined(PLATINUM_UPNP_SPECS_STRICT) // delay alive only as we don't want to delay when stopping if (m_Type != PLT_ANNOUNCETYPE_BYEBYE) { NPT_System::Sleep(NPT_TimeInterval(PLT_DLNA_SSDP_DELAY_GROUP)); } NPT_CHECK_SEVERE(m_Device->Announce(req, *socket, m_Type)); #endif return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | PLT_SsdpAnnounceInterfaceIterator class +---------------------------------------------------------------------*/ NPT_Result PLT_SsdpAnnounceInterfaceIterator::operator()(NPT_NetworkInterface*& net_if) const { // don't use this interface address if it's not broadcast capable if (m_Broadcast && !(net_if->GetFlags() & NPT_NETWORK_INTERFACE_FLAG_BROADCAST)) { return NPT_FAILURE; } NPT_List<NPT_NetworkInterfaceAddress>::Iterator niaddr = net_if->GetAddresses().GetFirstItem(); if (!niaddr) return NPT_FAILURE; // Remove disconnected interfaces NPT_IpAddress addr = (*niaddr).GetPrimaryAddress(); if (!addr.ToString().Compare("0.0.0.0")) return NPT_FAILURE; NPT_HttpUrl url; NPT_UdpMulticastSocket multicast_socket; NPT_UdpSocket broadcast_socket; NPT_UdpSocket* socket; if (m_Broadcast) { //url = NPT_HttpUrl("255.255.255.255", 1900, "*"); url = NPT_HttpUrl((*niaddr).GetBroadcastAddress().ToString(), 1900, "*"); socket = &broadcast_socket; } else { url = NPT_HttpUrl("239.255.255.250", 1900, "*"); socket = &multicast_socket; NPT_CHECK_SEVERE(((NPT_UdpMulticastSocket*)socket)->SetInterface(addr)); } NPT_HttpRequest req(url, "NOTIFY", NPT_HTTP_PROTOCOL_1_1); PLT_HttpHelper::SetHost(req, "239.255.255.250:1900"); // put a location only if alive message if (m_IsByeBye == false) { PLT_UPnPMessageHelper::SetLocation(req, m_Device->GetDescriptionUrl(addr.ToString())); } NPT_CHECK_SEVERE(m_Device->Announce(req, *socket, m_IsByeBye)); NPT_CHECK_SEVERE(m_Device->Announce(req, *socket, m_IsByeBye)); return NPT_SUCCESS; }
virtual void Run() { while (!NeedToStop) { NPT_IpAddress addr; m_Result = addr.ResolveName(m_Name); if (NPT_FAILED(m_Result)) { NPT_Console::OutputF("ERROR: ResolveName failed (%d)\n", m_Result); return; } if (!(addr == m_Addr)) { m_Result = NPT_FAILURE; NPT_Console::OutputF("ERROR: wrong IP address (%s instead of %s for %s)\n", addr.ToString().GetChars(), m_Addr.ToString().GetChars(), m_Name.GetChars()); return; } } }