void ProgramRegistry::deletePid(ProcessId pid) { boost::lock_guard<boost::recursive_mutex> lk(_mutex); if (!isPidRegistered(pid)) { int port = portForPid(pid); if (port < 0) return; deletePort(port); return; } close(_pids.find(pid)->second); _pids.erase(pid); }
void PortScanner::deleteAllHosts() { host_element *h; int done = 0; while (!done) { h = pcurrent_host_element; if (h) { // deletePort will return 1 when all ports have been deleted. // it updates h->pcurrent_port after each deletion // it deletes h when all ports have been removed while (! deletePort(h, h->pcurrent_port)) {} } else { done = 1; } } }
PortScanner::~PortScanner() { if (debug > 2) printf("PortScanner::~PortScanner: Called\n"); host_element *h; int done = 0; while (!done) { h = pcurrent_host_element; if (h) { // deletePort will return 1 when all ports have been deleted. // it updates h->pcurrent_port after each deletion // it deletes h when all ports have been removed while (! deletePort(h, h->pcurrent_port)) {} } else { done = 1; } // deleteHost will return 1 when all hosts have been deleted. // it updates pcurrent_host_element after each deletion // if (deleteHost(h)) { // done = 1; // } } }
void TcpScanner::noMoreRetries(in_addr ip, unsigned short int port) { if (debug > 2) printf("noMoreRetries: Searching for %s:%d. Just sent to ", inet_ntoa(ip), port); if (debug > 2) printf("%s:%d. \n", inet_ntoa(pcurrent_host_element->ip), pcurrent_host_element->pcurrent_port->port); // dumpPortList(); struct host_element *h; int more_hosts = 1; int found_port = 0; int ports_tried = 0; // if pcurrent_host_element is null, we're nearing the end of // our scan and there are no port elements left in the list to // remove. Our work is done. Just return. if (!pcurrent_host_element) { return; } h = pcurrent_host_element; // search for ip in hostlist while (more_hosts and !found_port) { // if (debug > 3) printf("comparing candidate %s with target ip %s\n", inet_ntoa(*(in_addr *)(&h->ip.s_addr)), inet_ntoa(ip)); // // TODO why are the IPs always the same on the XX line??!?!?! #ifdef DEBUG if (debug > 3) printf("host cmp: %x vs %x\n", h->ip.s_addr, ip.s_addr); if (debug > 3) printf("XX comparing candidate %s with target ip %s\n", inet_ntoa(h->ip), inet_ntoa(ip)); #endif // if this is the right host if (h->ip.s_addr == ip.s_addr) { if (debug > 3) printf("Found host\n"); struct port_element *p; int more_ports = 1; p = h->pcurrent_port; // search for port in hostlist of this port while (more_ports and !found_port) { ports_tried++; if (debug > 3) printf("\tcomparing candidate port %d with target port %d\n", p->port, port); // if this is the right port if (p->port == port) { if (debug > 3) printf("Found port\n"); found_port = 1; // deletePort might free() it's first arg // so set h to a value that won't get clobbered // TODO what if we've only got 1 host and pprev = pnext? h = h->pprev; deletePort(h->pnext, p); // TODO does this work? } else { p = p->pprev; if (p == h->pcurrent_port) { if (debug > 3) printf("STRANGE: have searched all the ports on this host\n"); more_ports = 0; } } } } // increment host pointer if (pcurrent_host_element and more_hosts) { // check incase we just deleted the last host // only increment host if we haven't already // Is this the last host we need to check? if (h == pcurrent_host_element->pnext) { more_hosts = 0; } else { h = h->pprev; } } } if (debug > 2) printf("Search took %d steps\n", ports_tried); if (!found_port and verbose) { printf("STRANGE: Couldn't find %s:%d in my port list!\n", inet_ntoa(ip), port); } }