bool PortMapper::addPortMapping(Device& igd, PortMapping& pm) { bool rval = false; // get wan IP connection service from device ControlPoint cp; Service wipcs = cp.getWanIpConnectionService(igd); if(!wipcs.isNull()) { // add port mapping rval = cp.addPortMapping(pm, wipcs); } return rval; }
int PortMapper::discoverGateways(uint32_t timeout) { int rval = -1; mCacheLock.lockExclusive(); { // clear cache mGatewayCache->clear(); // search for 1 internet gateway device DeviceDiscoverer dd; rval = dd.discover(mGatewayCache, UPNP_DEVICE_TYPE_IGD, timeout, 1); if(rval) { // default to error case rval = -1; // get device description Device igd = mGatewayCache.first(); ControlPoint cp; if(cp.getDeviceDescription(igd)) { // get wan IP connection service from device Service wipcs = cp.getWanIpConnectionService(igd); if(!wipcs.isNull()) { // get service description if(cp.getServiceDescription(wipcs)) { // useful device found rval = 1; } } } } } mCacheLock.unlockExclusive(); return rval; }
bool PortMapper::removePortMapping(Device& igd, PortMapping& pm, bool ignoreDne) { bool rval = false; // get wan IP connection service from device ControlPoint cp; Service wipcs = cp.getWanIpConnectionService(igd); if(!wipcs.isNull()) { // remove port mapping bool dne = false; rval = cp.removePortMapping(pm, wipcs, &dne); // ignore does not exist errors if requested if(!rval && ignoreDne && dne) { Exception::clear(); rval = true; } } return rval; }