Esempio n. 1
0
File: UPnP.cpp Progetto: D504/i2pd
    void UPnP::Discover ()
    {
        int nerror = 0;
#if MINIUPNPC_API_VERSION >= 14
        m_Devlist = upnpDiscoverFunc (2000, m_MulticastIf, m_Minissdpdpath, 0, 0, 2, &nerror);
#else
        m_Devlist = upnpDiscoverFunc (2000, m_MulticastIf, m_Minissdpdpath, 0, 0, &nerror);
#endif

        int r;
        r = UPNP_GetValidIGDFunc (m_Devlist, &m_upnpUrls, &m_upnpData, m_NetworkAddr, sizeof (m_NetworkAddr));
        if (r == 1)
        {
            r = UPNP_GetExternalIPAddressFunc (m_upnpUrls.controlURL, m_upnpData.first.servicetype, m_externalIPAddress);
            if(r != UPNPCOMMAND_SUCCESS)
            {
                LogPrint (eLogError, "UPnP: UPNP_GetExternalIPAddress () returned ", r);
                return;
            }
            else
            {
                if (m_externalIPAddress[0])
                {
                    LogPrint (eLogInfo, "UPnP: ExternalIPAddress = ", m_externalIPAddress);
                    i2p::context.UpdateAddress (boost::asio::ip::address::from_string (m_externalIPAddress));
                    return;
                }
                else
                {
                    LogPrint (eLogError, "UPnP: GetExternalIPAddress failed.");
                    return;
                }
            }
        }
    }
Esempio n. 2
0
File: UPnP.cpp Progetto: apprb/i2pd
    void UPnP::Discover ()
    {
#ifndef UPNPDISCOVER_SUCCESS
        /* miniupnpc 1.5 */
        m_Devlist = upnpDiscoverFunc (2000, m_MulticastIf, m_Minissdpdpath, 0);
#else
        /* miniupnpc 1.6 */
        int nerror = 0;
        m_Devlist = upnpDiscoverFunc (2000, m_MulticastIf, m_Minissdpdpath, 0, 0, &nerror);
#endif

        int r;
        r = UPNP_GetValidIGDFunc (m_Devlist, &m_upnpUrls, &m_upnpData, m_NetworkAddr, sizeof (m_NetworkAddr));
        if (r == 1)
        {
            r = UPNP_GetExternalIPAddressFunc (m_upnpUrls.controlURL, m_upnpData.first.servicetype, m_externalIPAddress);
            if(r != UPNPCOMMAND_SUCCESS)
            {
                LogPrint ("UPnP: UPNP_GetExternalIPAddress () returned ", r);
                return;
            }
            else
            {
                if (m_externalIPAddress[0])
                {
                    LogPrint ("UPnP: ExternalIPAddress = ", m_externalIPAddress);
                    i2p::context.UpdateAddress (boost::asio::ip::address::from_string (m_externalIPAddress));
                    return;
                }
                else
                {
                    LogPrint ("UPnP: GetExternalIPAddress failed.");
                    return;
                }
            }
        }
    }