void process_file (char *filename) { TARGET_LIST targets; struct in_addr target; FILE *infile; char buffer[BUFFER_MAX_LEN], *cp, *tok_store; int line = 0; if (strcasecmp(filename, "-") == 0) { if ((infile = fdopen(0, "r")) == NULL) err(EX_IOERR, "fdopen() failed"); } else { if ((infile = fopen(filename, "r")) == NULL) err(EX_IOERR, "fopen(%s) failed", filename); } while (fgets(buffer, BUFFER_MAX_LEN-1, infile)) { line++; cp = strtok_r(buffer, " \t\r\n", &tok_store); while (cp != NULL && cp[0] != '#') { if (init_target_list(&targets, cp)) { while (next_target(&targets, &target)) { printf("%s\n", inet_ntoa(target)); count++; } } else errx(EX_USAGE, "Bad target specification on line %d: %s", line, target_list_err()); cp = strtok_r(NULL, " \t\r\n", &tok_store); } continue; } if (fclose(infile) != 0) warn("fclose(%s) failed", filename); }
int main (int argc, char *argv[]) { int i, method = M_NMAP; TARGET_LIST targets; struct in_addr target; u_int32_t start, end; while ((i = getopt(argc, argv, "hri:")) != -1) { switch (i) { case 'h': usage(argv[0]); exit(EX_OK); /* NOTREACHED */ case 'r': method = M_IPRANGE; break; case 'i': process_file(optarg); break; default: exit(EX_USAGE); } } argc -= optind; argv += optind; if (method == M_IPRANGE) { if (argc != 2) errx(EX_USAGE, "Not enought targets for range specified!"); if (!inet_aton(argv[0], &target)) errx(EX_USAGE, "Invalid IP address!"); start = ntohl(target.s_addr); if (!inet_aton(argv[1], &target)) errx(EX_USAGE, "Invalid IP address!"); end = ntohl(target.s_addr); for (i = start; i <= end; i++) { target.s_addr = htonl(i); printf("%s\n", inet_ntoa(target)); count++; } } else { for (i = 0; i < argc; i++) { if (init_target_list(&targets, argv[i])) { while (next_target(&targets, &target)) { printf("%s\n", inet_ntoa(target)); count++; } } else errx(EX_USAGE, "Bad target specification on line: %s", target_list_err()); } } if (count == 0) errx(EX_USAGE, "No targets specified!"); return(EX_OK); }
static void query_names(FILE *ofp, SOCKET sockfd) { short seq = 1000; int npending = 0; struct in_addr next_addr; int have_next_addr = FALSE; char errbuf[256]; assert( ofp != 0 ); assert( SOCKET_IS_VALID(sockfd) ); /*---------------------------------------------------------------- * Figure out our starting and ending addresses to be scanning. * These are treated as simple long integers that are incremented * on each loop, and we must have at least one loop to be valid. */ while ( have_next_addr || ((have_next_addr = next_target(&next_addr)) != 0) || (npending > 0) ) { fd_set rfds, /* list of read descriptors */ wfds, /* list of write descriptors */ *pwfds = 0; int n; struct timeval tv; /*-------------------------------------------------------- * Our select is just a bit tricky. We always are waiting * on the read channel, but we only want to wait on the * write channel if there are any more addresses in our * list to process. After we've sent all the packets to * the other end, we stop writing and do only reading. */ FD_ZERO(&rfds); FD_SET(sockfd, &rfds); timeval_set_secs(&tv, timeout_secs); if ( have_next_addr ) { wfds = rfds; pwfds = &wfds; } if ( (n = select(sockfd+1, &rfds, pwfds, 0, &tv)) == 0 ) { fprintf(stderr, "*timeout (normal end of scan)\n"); fflush(ofp); break; } else if ( n < 0) { printf("ERROR [%s]\n", strerror(errno)); break; } /*-------------------------------------------------------- * Has the read descriptor fired? */ if ( n > 0 && FD_ISSET(sockfd, &rfds) ) { int paklen; struct sockaddr_in src; struct NMBpacket pak; struct NMB_query_response rsp; memset(&src, 0, sizeof src); memset(&rsp, 0, sizeof rsp); paklen = (int)recvpacket(sockfd, &pak, sizeof pak,&src); if ( verbose ) { if ( paklen < 0 ) { fprintf(ofp, "Error on read: %s\n", strerror(errno)); } else { fprintf(ofp, "Got %d bytes from %s\n", paklen, inet_ntoa(src.sin_addr) ); if ( verbose > 1 ) dump_nbtpacket(&pak, paklen, stdout); } } /*------------------------------------------------ * If we actually got something from the other end, * parse the response, plug in the remote's IP addr, * and display it. */ if ( paklen <= 0 ) continue; npending--; if ( parse_nbtstat(&pak, paklen, &rsp, errbuf) ) { rsp.remote = src; if ( target_responded(&rsp.remote.sin_addr) ) { #ifdef ENABLE_PERL if ( gen_Perl ) generate_perl(ofp, &rsp); else #endif display_nbtstat(ofp,&rsp,full_nbtstat); } } else { fprintf(ofp, "ERROR: no parse for %s -- %s\n", inet_ntoa(src.sin_addr), errbuf); } } /*-------------------------------------------------------- * If we have room to write one packet, do so here. Note * that we make not notice whether the write succeeds or * not: we don't care. */ if ( n > 0 && pwfds && FD_ISSET(sockfd, pwfds) ) { struct sockaddr_in dst; struct NMBpacket pak; int sendlen; memset(&dst, 0, sizeof dst); dst.sin_family = AF_INET; dst.sin_addr.s_addr = next_addr.s_addr; dst.sin_port = htons(dest_portno); have_next_addr = FALSE; fill_namerequest(&pak, &sendlen, seq++); if ( verbose ) { fprintf(ofp, "sending to %s\n", inet_ntoa(dst.sin_addr)); } /* yes, ignore response! */ (void) sendpacket(sockfd, &pak, sendlen, &dst); if ( write_sleep_msecs > 0 ) sleep_msecs(write_sleep_msecs); npending++; continue; } } }
void goto_inlinet::expand_function_call( goto_programt &dest, goto_programt::targett &target, const exprt &lhs, const exprt &function, const exprt::operandst &arguments, const exprt &constrain, bool full) { // look it up if(function.id()!="symbol") { err_location(function); throw "function_call expects symbol as function operand, " "but got `"+function.id_string()+"'"; } const irep_idt &identifier=function.identifier(); // see if we are already expanding it if(recursion_set.find(identifier)!=recursion_set.end()) { if(!full) { target++; return; // simply ignore, we don't do full inlining, it's ok } // it's really recursive. Uh. Buh. Give up. err_location(function); warning("recursion is ignored"); target->make_skip(); target++; return; } goto_functionst::function_mapt::iterator m_it= goto_functions.function_map.find(identifier); if(m_it==goto_functions.function_map.end()) { err_location(function); str << "failed to find function `" << identifier << "'"; throw 0; } goto_functiont &f=m_it->second; // see if we need to inline this if(!full) { if(!f.body_available || (!f.is_inlined() && f.body.instructions.size() > smallfunc_limit)) { target++; return; } } if(f.body_available) { inlined_funcs.insert(identifier.as_string()); for (std::set<std::string>::const_iterator it2 = f.inlined_funcs.begin(); it2 != f.inlined_funcs.end(); it2++) { inlined_funcs.insert(*it2); } recursion_sett::iterator recursion_it= recursion_set.insert(identifier).first; goto_programt tmp2; tmp2.copy_from(f.body); assert(tmp2.instructions.back().is_end_function()); tmp2.instructions.back().type=LOCATION; replace_return(tmp2, lhs, constrain); goto_programt tmp; parameter_assignments(tmp2.instructions.front().location, f.type, arguments, tmp); tmp.destructive_append(tmp2); // set local variables Forall_goto_program_instructions(it, tmp) it->local_variables.insert(target->local_variables.begin(), target->local_variables.end()); if(f.type.hide()) { const locationt &new_location=function.find_location(); Forall_goto_program_instructions(it, tmp) { if(new_location.is_not_nil()) { // can't just copy, e.g., due to comments field it->location.id(""); // not NIL it->location.set_file(new_location.get_file()); it->location.set_line(new_location.get_line()); it->location.set_column(new_location.get_column()); it->location.set_function(new_location.get_function()); } } } // do this recursively goto_inline_rec(tmp, full); // set up location instruction for function call target->type=LOCATION; target->code = expr2tc(); goto_programt::targett next_target(target); next_target++; dest.instructions.splice(next_target, tmp.instructions); target=next_target; recursion_set.erase(recursion_it); }