2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* This stuff is actually C */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern C */
|
|
|
|
#endif
|
|
|
|
/* This stuff is actually C */
|
|
|
|
|
|
|
|
#include "upnp/upnphandler.h"
|
|
|
|
|
2008-02-11 11:27:55 -05:00
|
|
|
#include "util/rsnet.h"
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
bool upnphandler::initUPnPState()
|
|
|
|
{
|
2009-10-29 20:33:40 -04:00
|
|
|
std::cerr << "upnphandler::initUPnPState" << std::endl;
|
|
|
|
cUPnPControlPoint = new CUPnPControlPoint(2000);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
bool IGWDetected = cUPnPControlPoint->GetIGWDeviceDetected();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-06-13 19:22:20 -04:00
|
|
|
/* MODIFY STATE */
|
|
|
|
dataMtx.lock(); /* LOCK MUTEX */
|
2009-10-29 20:33:40 -04:00
|
|
|
std::cerr << "upnphandler::initUPnPState cUPnPControlPoint internal ip adress : ";
|
|
|
|
std::cerr << cUPnPControlPoint->getInternalIpAddress() << std::endl;
|
2008-06-13 19:22:20 -04:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
//const char ipaddr = cUPnPControlPoint->getInternalIpAddress().c_str();
|
|
|
|
inet_aton(cUPnPControlPoint->getInternalIpAddress(), &(upnp_iaddr.sin_addr));
|
|
|
|
upnp_iaddr.sin_port = htons(iport);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
if (IGWDetected) {
|
|
|
|
upnpState = RS_UPNP_S_READY;
|
|
|
|
} else {
|
|
|
|
upnpState = RS_UPNP_S_UNAVAILABLE;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
dataMtx.unlock(); /* UNLOCK MUTEX */
|
2008-02-27 10:43:02 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
/* done, NOT AVAILABLE YET */
|
2008-02-27 10:43:02 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
if (upnpState == RS_UPNP_S_READY) {
|
|
|
|
std::cerr << "upnphandler::initUPnPState READY" << std::endl;
|
|
|
|
} else {
|
|
|
|
std::cerr << "upnphandler::initUPnPState UNAVAILABLE" << std::endl;
|
2008-02-27 10:43:02 -05:00
|
|
|
}
|
2009-10-29 20:33:40 -04:00
|
|
|
return 0;
|
2008-02-27 10:43:02 -05:00
|
|
|
}
|
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
class upnpThreadData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
upnphandler *handler;
|
|
|
|
bool start;
|
|
|
|
bool stop;
|
|
|
|
};
|
2008-02-27 10:43:02 -05:00
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
/* Thread routines */
|
|
|
|
extern "C" void* doSetupUPnP(void* p)
|
|
|
|
{
|
2009-10-29 20:35:12 -04:00
|
|
|
std::cerr << "doSetupUPnP Creating upnp thread." << std::endl;
|
2008-04-09 08:54:15 -04:00
|
|
|
upnpThreadData *data = (upnpThreadData *) p;
|
|
|
|
if ((!data) || (!data->handler))
|
|
|
|
{
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* publish it! */
|
|
|
|
if (data -> stop)
|
|
|
|
{
|
|
|
|
data->handler->shutdown_upnp();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data -> start)
|
|
|
|
{
|
|
|
|
data->handler->initUPnPState();
|
|
|
|
data->handler->start_upnp();
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
delete data;
|
|
|
|
pthread_exit(NULL);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool upnphandler::background_setup_upnp(bool start, bool stop)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-04-09 08:54:15 -04:00
|
|
|
pthread_t tid;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
/* launch thread */
|
2009-10-29 20:35:12 -04:00
|
|
|
std::cerr << "background_setup_upnp Creating upnp thread." << std::endl;
|
2008-04-09 08:54:15 -04:00
|
|
|
upnpThreadData *data = new upnpThreadData();
|
|
|
|
data->handler = this;
|
|
|
|
data->start = start;
|
|
|
|
data->stop = stop;
|
|
|
|
|
|
|
|
pthread_create(&tid, 0, &doSetupUPnP, (void *) data);
|
|
|
|
pthread_detach(tid); /* so memory is reclaimed in linux */
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool upnphandler::start_upnp()
|
|
|
|
{
|
2008-04-22 07:45:28 -04:00
|
|
|
RsStackMutex stack(dataMtx); /* LOCK STACK MUTEX */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
if (!(upnpState >= RS_UPNP_S_READY))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-10-29 20:33:40 -04:00
|
|
|
std::cerr << "upnphandler::start_upnp() Not Ready" << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char eprot1[] = "TCP";
|
|
|
|
char eprot2[] = "UDP";
|
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
/* if we're to load -> load */
|
|
|
|
/* select external ports */
|
|
|
|
eport_curr = eport;
|
|
|
|
if (!eport_curr)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-04-09 08:54:15 -04:00
|
|
|
/* use local port if eport is zero */
|
|
|
|
eport_curr = iport;
|
|
|
|
std::cerr << "Using LocalPort for extPort!";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
if (!eport_curr)
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid eport ... ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
/* our port */
|
|
|
|
char in_addr[256];
|
|
|
|
char in_port1[256];
|
|
|
|
char eport1[256];
|
|
|
|
|
|
|
|
upnp_iaddr.sin_port = htons(iport);
|
|
|
|
struct sockaddr_in localAddr = upnp_iaddr;
|
|
|
|
uint32_t linaddr = ntohl(localAddr.sin_addr.s_addr);
|
|
|
|
|
|
|
|
snprintf(in_port1, 256, "%d", ntohs(localAddr.sin_port));
|
|
|
|
snprintf(in_addr, 256, "%d.%d.%d.%d",
|
|
|
|
((linaddr >> 24) & 0xff),
|
|
|
|
((linaddr >> 16) & 0xff),
|
|
|
|
((linaddr >> 8) & 0xff),
|
|
|
|
((linaddr >> 0) & 0xff));
|
|
|
|
|
|
|
|
snprintf(eport1, 256, "%d", eport_curr);
|
|
|
|
|
|
|
|
std::cerr << "Attempting Redirection: InAddr: " << in_addr;
|
|
|
|
std::cerr << " InPort: " << in_port1;
|
|
|
|
std::cerr << " ePort: " << eport1;
|
|
|
|
std::cerr << " eProt: " << eprot1;
|
|
|
|
std::cerr << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
//build port mapping config
|
|
|
|
std::vector<CUPnPPortMapping> upnpPortMapping1;
|
|
|
|
CUPnPPortMapping cUPnPPortMapping1 = CUPnPPortMapping(eport_curr, ntohs(localAddr.sin_port), "TCP", true, "tcp retroshare redirection");
|
|
|
|
upnpPortMapping1.push_back(cUPnPPortMapping1);
|
|
|
|
bool res = cUPnPControlPoint->AddPortMappings(upnpPortMapping1);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
upnpState = RS_UPNP_S_ACTIVE;
|
|
|
|
} else {
|
|
|
|
upnpState = RS_UPNP_S_TCP_FAILED;
|
|
|
|
std::vector<CUPnPPortMapping> upnpPortMapping2;
|
|
|
|
CUPnPPortMapping cUPnPPortMapping2 = CUPnPPortMapping(eport_curr, ntohs(localAddr.sin_port), "UDP", true, "udp retroshare redirection");
|
|
|
|
upnpPortMapping2.push_back(cUPnPPortMapping2);
|
|
|
|
bool res2 = cUPnPControlPoint->AddPortMappings(upnpPortMapping2);
|
2009-10-29 20:34:51 -04:00
|
|
|
if (res2) {
|
2008-04-09 08:54:15 -04:00
|
|
|
upnpState = RS_UPNP_S_ACTIVE;
|
2009-10-29 20:33:40 -04:00
|
|
|
} else {
|
2009-10-29 20:34:51 -04:00
|
|
|
//upnpState = RS_UPNP_S_ACTIVE;
|
2009-10-29 20:33:40 -04:00
|
|
|
upnpState = RS_UPNP_S_UDP_FAILED;
|
|
|
|
}
|
2008-04-09 08:54:15 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
/* now store the external address */
|
2009-10-29 20:33:40 -04:00
|
|
|
std::string externalAdress = cUPnPControlPoint->getExternalAddress();
|
2008-04-09 08:54:15 -04:00
|
|
|
sockaddr_clear(&upnp_eaddr);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
if(!externalAdress.empty())
|
2008-04-09 08:54:15 -04:00
|
|
|
{
|
2009-10-29 20:33:40 -04:00
|
|
|
const char* externalIPAddress = externalAdress.c_str();
|
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
std::cerr << "Stored External address: " << externalIPAddress;
|
|
|
|
std::cerr << ":" << eport_curr;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
inet_aton(externalIPAddress, &(upnp_eaddr.sin_addr));
|
|
|
|
upnp_eaddr.sin_family = AF_INET;
|
|
|
|
upnp_eaddr.sin_port = htons(eport_curr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "FAILED To get external Address";
|
|
|
|
std::cerr << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
toStart = false;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-29 20:34:51 -04:00
|
|
|
return (upnpState == RS_UPNP_S_ACTIVE);
|
2008-04-09 08:54:15 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool upnphandler::shutdown_upnp()
|
|
|
|
{
|
2008-04-22 07:45:28 -04:00
|
|
|
RsStackMutex stack(dataMtx); /* LOCK STACK MUTEX */
|
2008-04-09 08:54:15 -04:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
if (!(upnpState >= RS_UPNP_S_READY))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-04-09 08:54:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
char eprot1[] = "TCP";
|
|
|
|
char eprot2[] = "UDP";
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
/* always attempt this (unless no port number) */
|
|
|
|
if (eport_curr > 0)
|
|
|
|
{
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
char eport1[256];
|
|
|
|
char eport2[256];
|
|
|
|
|
|
|
|
snprintf(eport1, 256, "%d", eport_curr);
|
2008-02-11 11:27:55 -05:00
|
|
|
snprintf(eport2, 256, "%d", eport_curr);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
std::cerr << "Attempting To Remove Redirection: port: " << eport1;
|
|
|
|
std::cerr << " Prot: " << eprot1;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
std::vector<CUPnPPortMapping> upnpPortMapping1;
|
2009-10-29 20:34:51 -04:00
|
|
|
CUPnPPortMapping cUPnPPortMapping1 = CUPnPPortMapping(eport_curr, 0, eprot1, true, "tcp redirection");
|
|
|
|
upnpPortMapping1.push_back(cUPnPPortMapping1);
|
2009-10-29 20:33:40 -04:00
|
|
|
cUPnPControlPoint->DeletePortMappings(upnpPortMapping1);
|
2008-02-11 11:27:55 -05:00
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
std::cerr << "Attempting To Remove Redirection: port: " << eport2;
|
|
|
|
std::cerr << " Prot: " << eprot2;
|
|
|
|
std::cerr << std::endl;
|
2008-02-11 11:27:55 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
std::vector<CUPnPPortMapping> upnpPortMapping2;
|
2009-10-29 20:34:51 -04:00
|
|
|
CUPnPPortMapping cUPnPPortMapping2 = CUPnPPortMapping(eport_curr, 0, eprot2, true, "udp redirection");
|
|
|
|
upnpPortMapping2.push_back(cUPnPPortMapping2);
|
2009-10-29 20:33:40 -04:00
|
|
|
cUPnPControlPoint->DeletePortMappings(upnpPortMapping2);
|
2008-02-11 11:27:55 -05:00
|
|
|
|
2009-10-29 20:33:40 -04:00
|
|
|
//destroy the upnp object
|
|
|
|
cUPnPControlPoint->~CUPnPControlPoint();
|
|
|
|
upnpState = RS_UPNP_S_UNINITIALISED;
|
2009-10-29 20:35:12 -04:00
|
|
|
|
|
|
|
//stopping os ok, set starting to true for next net reset
|
2008-04-09 08:54:15 -04:00
|
|
|
toStop = false;
|
2009-10-29 20:35:12 -04:00
|
|
|
toStart = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-01-25 02:25:05 -05:00
|
|
|
/************************ External Interface *****************************
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
upnphandler::upnphandler()
|
2008-04-09 08:54:15 -04:00
|
|
|
:toEnable(false), toStart(false), toStop(false),
|
2009-10-29 20:33:40 -04:00
|
|
|
eport(0), eport_curr(0)
|
2008-01-25 02:25:05 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
upnphandler::~upnphandler()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RsIface */
|
2008-08-16 11:02:24 -04:00
|
|
|
void upnphandler::enable(bool active)
|
2008-01-25 02:25:05 -05:00
|
|
|
{
|
2009-10-29 20:35:12 -04:00
|
|
|
std::cerr << "upnphandler::enable called with argument active : " << active << std::endl;
|
|
|
|
std::cerr << "toEnable : " << toEnable << std::endl;
|
|
|
|
std::cerr << "toStart : " << toStart << std::endl;
|
2008-01-25 02:25:05 -05:00
|
|
|
dataMtx.lock(); /*** LOCK MUTEX ***/
|
|
|
|
|
|
|
|
if (active != toEnable)
|
|
|
|
{
|
|
|
|
if (active)
|
|
|
|
{
|
|
|
|
toStart = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
toStop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
toEnable = active;
|
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
bool start = toStart;
|
|
|
|
|
2008-01-25 02:25:05 -05:00
|
|
|
dataMtx.unlock(); /*** UNLOCK MUTEX ***/
|
2008-04-09 08:54:15 -04:00
|
|
|
|
|
|
|
if (start)
|
|
|
|
{
|
|
|
|
/* make background thread to startup UPnP */
|
|
|
|
background_setup_upnp(true, false);
|
|
|
|
}
|
2008-01-25 02:25:05 -05:00
|
|
|
}
|
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
|
2008-08-16 11:02:24 -04:00
|
|
|
void upnphandler::shutdown()
|
2008-01-25 02:25:05 -05:00
|
|
|
{
|
2008-04-09 08:54:15 -04:00
|
|
|
/* blocking call to shutdown upnp */
|
|
|
|
|
|
|
|
shutdown_upnp();
|
|
|
|
}
|
2008-01-25 02:25:05 -05:00
|
|
|
|
|
|
|
|
2008-08-16 11:02:24 -04:00
|
|
|
void upnphandler::restart()
|
2008-04-09 08:54:15 -04:00
|
|
|
{
|
|
|
|
/* non-blocking call to shutdown upnp, and startup again. */
|
2009-10-29 20:34:51 -04:00
|
|
|
std::cerr << "upnphandler::restart() called." << std::endl;
|
2008-04-09 08:54:15 -04:00
|
|
|
background_setup_upnp(true, true);
|
2008-01-25 02:25:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
|
2008-08-16 11:02:24 -04:00
|
|
|
bool upnphandler::getEnabled()
|
2008-01-25 02:25:05 -05:00
|
|
|
{
|
|
|
|
dataMtx.lock(); /*** LOCK MUTEX ***/
|
|
|
|
|
|
|
|
bool on = toEnable;
|
|
|
|
|
|
|
|
dataMtx.unlock(); /*** UNLOCK MUTEX ***/
|
|
|
|
|
|
|
|
return on;
|
|
|
|
}
|
|
|
|
|
2008-08-16 11:02:24 -04:00
|
|
|
bool upnphandler::getActive()
|
2008-01-25 02:25:05 -05:00
|
|
|
{
|
|
|
|
dataMtx.lock(); /*** LOCK MUTEX ***/
|
|
|
|
|
2009-10-29 20:34:51 -04:00
|
|
|
std::cerr <<"GetActive Called result : " << (upnpState == RS_UPNP_S_ACTIVE) << std::endl;
|
|
|
|
|
2008-01-25 02:25:05 -05:00
|
|
|
bool on = (upnpState == RS_UPNP_S_ACTIVE);
|
|
|
|
|
|
|
|
dataMtx.unlock(); /*** UNLOCK MUTEX ***/
|
|
|
|
|
|
|
|
return on;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the address that the listening port is on */
|
|
|
|
void upnphandler::setInternalPort(unsigned short iport_in)
|
|
|
|
{
|
2009-10-29 20:33:40 -04:00
|
|
|
std::cerr << "UPnPHandler::setInternalAddress() pre Lock!" << std::endl;
|
2008-01-25 02:25:05 -05:00
|
|
|
dataMtx.lock(); /*** LOCK MUTEX ***/
|
2009-10-29 20:33:40 -04:00
|
|
|
std::cerr << "UPnPHandler::setInternalAddress() postLock!" << std::endl;
|
2008-01-25 02:25:05 -05:00
|
|
|
|
2008-02-11 11:27:55 -05:00
|
|
|
std::cerr << "UPnPHandler::setInternalPort(" << iport_in << ") current port: ";
|
|
|
|
std::cerr << iport << std::endl;
|
|
|
|
|
2008-01-25 02:25:05 -05:00
|
|
|
if (iport != iport_in)
|
|
|
|
{
|
|
|
|
iport = iport_in;
|
|
|
|
if ((toEnable) &&
|
|
|
|
(upnpState == RS_UPNP_S_ACTIVE))
|
|
|
|
{
|
|
|
|
toStop = true;
|
|
|
|
toStart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dataMtx.unlock(); /*** UNLOCK MUTEX ***/
|
|
|
|
}
|
|
|
|
|
|
|
|
void upnphandler::setExternalPort(unsigned short eport_in)
|
|
|
|
{
|
2009-10-29 20:33:40 -04:00
|
|
|
std::cerr << "UPnPHandler::setExternalPort() pre Lock!" << std::endl;
|
2008-01-25 02:25:05 -05:00
|
|
|
dataMtx.lock(); /*** LOCK MUTEX ***/
|
2009-10-29 20:33:40 -04:00
|
|
|
std::cerr << "UPnPHandler::setExternalPort() postLock!" << std::endl;
|
2008-01-25 02:25:05 -05:00
|
|
|
|
2008-02-11 11:27:55 -05:00
|
|
|
std::cerr << "UPnPHandler::setExternalPort(" << eport_in << ") current port: ";
|
|
|
|
std::cerr << eport << std::endl;
|
|
|
|
|
2008-01-25 02:25:05 -05:00
|
|
|
/* flag both shutdown/start -> for restart */
|
|
|
|
if (eport != eport_in)
|
|
|
|
{
|
|
|
|
eport = eport_in;
|
|
|
|
if ((toEnable) &&
|
|
|
|
(upnpState == RS_UPNP_S_ACTIVE))
|
|
|
|
{
|
|
|
|
toStop = true;
|
|
|
|
toStart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dataMtx.unlock(); /*** UNLOCK MUTEX ***/
|
|
|
|
}
|
|
|
|
|
|
|
|
/* as determined by uPnP */
|
|
|
|
bool upnphandler::getInternalAddress(struct sockaddr_in &addr)
|
|
|
|
{
|
|
|
|
// std::cerr << "UPnPHandler::getInternalAddress() pre Lock!" << std::endl;
|
|
|
|
dataMtx.lock(); /*** LOCK MUTEX ***/
|
|
|
|
// std::cerr << "UPnPHandler::getInternalAddress() postLock!" << std::endl;
|
|
|
|
|
2008-02-11 11:27:55 -05:00
|
|
|
std::cerr << "UPnPHandler::getInternalAddress()" << std::endl;
|
|
|
|
|
2008-01-25 02:25:05 -05:00
|
|
|
addr = upnp_iaddr;
|
2008-02-11 11:27:55 -05:00
|
|
|
bool valid = (upnpState >= RS_UPNP_S_ACTIVE);
|
2008-01-25 02:25:05 -05:00
|
|
|
|
|
|
|
dataMtx.unlock(); /*** UNLOCK MUTEX ***/
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool upnphandler::getExternalAddress(struct sockaddr_in &addr)
|
|
|
|
{
|
|
|
|
// std::cerr << "UPnPHandler::getExternalAddress() pre Lock!" << std::endl;
|
|
|
|
dataMtx.lock(); /*** LOCK MUTEX ***/
|
|
|
|
// std::cerr << "UPnPHandler::getExternalAddress() postLock!" << std::endl;
|
|
|
|
|
2008-02-11 11:27:55 -05:00
|
|
|
std::cerr << "UPnPHandler::getExternalAddress()" << std::endl;
|
2008-01-25 02:25:05 -05:00
|
|
|
addr = upnp_eaddr;
|
2008-02-11 11:27:55 -05:00
|
|
|
bool valid = (upnpState == RS_UPNP_S_ACTIVE);
|
2008-01-25 02:25:05 -05:00
|
|
|
|
|
|
|
dataMtx.unlock(); /*** UNLOCK MUTEX ***/
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|