// remove my previous mapping when port changes
removeSarosPortMapping();
} else if (currentlyMappedPort == 0) {
// first time mapping, lets check if mapped port is free
try {
PortMappingEntry portMapping = upnpAccess
.getSpecificPortMappingEntry(selectedGateway, port, "TCP");
if (portMapping != null) {
// There is already a port mapping!
// If it has Saros description then remove it else abort
String desc = portMapping.getPortMappingDescription();
if ((desc != null && desc.equals(MAPPINGDESC)))
selectedGateway.deletePortMapping(port, "TCP");
else {
log.debug("There is already a port mapping for the port ("
+ port + ") configured. Port mapping aborted.");
selectedGateway.deletePortMapping(port, "TCP");
discoveryRunningSemaphore.release();
return false;
}
}
} catch (Exception e) {
log.debug("Error performing port mapping:" + e.getMessage());
}
}
try {
InetAddress localAddress = selectedGateway.getLocalAddress();
PortMappingEntry portMapping = upnpAccess
.getSpecificPortMappingEntry(selectedGateway, port, "TCP");
if (portMapping == null) {
int errorcode = upnpAccess.addPortMapping(selectedGateway,