/** * @todo Add command-line parameters for IPv4 network address and mask so we * can remove broadcast and multicast hosts from the result */ void IPForensics::load_hosts(std::string filename) { // open the filename char error[PCAP_ERRBUF_SIZE] {}; pcap_t* pcap = pcap_open_offline(filename.c_str(), error); if (pcap == NULL) { throw std::runtime_error(error); } // exit if the data link is not Ethernet if (pcap_datalink(pcap) != DLT_EN10MB) { pcap_close(pcap); throw std::runtime_error("Link-layer type not IEEE 802.3 Ethernet"); } // read the packets from the file const unsigned char * packet = NULL; struct pcap_pkthdr header; // if packet_count_ is set, read specified number of packets only if (packet_count_ > 0) { for (int i = 0; i < packet_count_; ++i) { packet = pcap_next(pcap, &header); if (packet != NULL) { packets_.push_back(Packet(packet)); } } } else { // if packet_count_ is not set, read all packets packet = pcap_next(pcap, &header); while (packet != NULL) { packets_.push_back(Packet(packet)); packet = pcap_next(pcap, &header); } } // close the packet capture pcap_close(pcap); // extract hosts from packets for (Packet p : packets_) { // add the source host std::set<Host>::iterator it = hosts_.find(static_cast<Host>(p.mac_src())); if (it == hosts_.end()) { add_host(p.mac_src(), p.ipv4_src(), p.ipv6_src()); } else { update_host(it, p.ipv4_src(), p.ipv6_src()); } // add the destination host it = hosts_.find(static_cast<Host>(p.mac_dst())); if (it == hosts_.end()) { add_host(p.mac_dst(), p.ipv4_dst(), p.ipv6_dst()); } else { update_host(it, p.ipv4_dst(), p.ipv6_dst()); } } // remove meaningless hosts clean_hosts(nullptr, nullptr); }
/** * @details Iterates through all the packets in the supplied Device and loads * the source host and destination host from each packet. If a host * detected from the packets already exists in the collection, the * host is updated with any new information from the packet (the IPv4 * or IPv6 address if not previously found). */ void IPForensics::load_hosts(Device device) { for (Packet packet : device.packets()) { // add the source host auto it = hosts_.find(static_cast<Host>(packet.mac_src())); if (it == hosts_.end()) { add_host(packet.mac_src(), packet.ipv4_src(), packet.ipv6_src()); } else { update_host(it, packet.ipv4_src(), packet.ipv6_src()); } // add the destination host it = hosts_.find(static_cast<Host>(packet.mac_dst())); if (it == hosts_.end()) { add_host(packet.mac_dst(), packet.ipv4_dst(), packet.ipv6_dst()); } else { update_host(it, packet.ipv4_dst(), packet.ipv6_dst()); } } // remove multicast and broadcast hosts IPv4Address net = device.net(), mask = device.mask(); clean_hosts(&net, &mask); }
void change_user_host(User * user, const char *host) { if (user->vhost) free(user->vhost); user->vhost = sstrdup(host); if (debug) alog("debug: %s changes its vhost to %s", user->nick, host); update_host(user); }
gfarm_error_t add_host(char *hostname, int port, char **hostaliases, char *architecture, int ncpu, int flags) { int nhostaliases = gfarm_strarray_length(hostaliases); gfarm_error_t e; e = check_hostname(hostname); if (e != GFARM_ERR_NO_ERROR) return (e); e = check_hostaliases(nhostaliases, hostaliases); if (e != GFARM_ERR_NO_ERROR) return (e); return (update_host(hostname, port, nhostaliases, hostaliases, architecture, ncpu, flags, gfm_client_host_info_set)); }
void viagra_set_umode(User * user, int ac, char **av) { int add = 1; /* 1 if adding modes, 0 if deleting */ char *modes = av[0]; ac--; if (debug) alog("debug: Changing mode for %s to %s", user->nick, modes); while (*modes) { /* This looks better, much better than "add ? (do_add) : (do_remove)". * At least this is readable without paying much attention :) -GD */ if (add) user->mode |= umodes[(int) *modes]; else user->mode &= ~umodes[(int) *modes]; switch (*modes++) { case '+': add = 1; break; case '-': add = 0; break; case 'd': if (ac == 0) { alog("user: umode +d with no parameter (?) for user %s", user->nick); break; } ac--; av++; user->svid = strtoul(*av, NULL, 0); break; case 'o': if (add) { opcnt++; if (WallOper) { xanadu_cmd_global(s_OperServ, "\2%s\2 is now an IRC operator.", user->nick); } display_news(user, NEWS_OPER); } else { opcnt--; } break; case 'r': if (add && !nick_identified(user)) { common_svsmode(user, "-r", NULL); user->mode &= ~UMODE_r; } break; case 'x': update_host(user); break; } } }
int main(int argc,char *argv[]) { int *becell; int *ecell; int *bound; int *bedge; int *edge; int *cell; float *x; float *q; float *qold; float *adt; float *res; int nnode; int ncell; int nedge; int nbedge; int niter; float rms; if (argc != 2) { printf("Usage: airfoil <grid>\n"); exit(1); } // read in grid printf("reading in grid \n"); char *grid = argv[1]; FILE *fp; if ((fp = fopen(grid,"r")) == 0L) { printf("can\'t open file %s\n",grid); exit((-1)); } if (fscanf(fp,"%d %d %d %d \n",&nnode,&ncell,&nedge,&nbedge) != 4) { printf("error reading from %s\n",grid); exit((-1)); } cell = ((int *)(malloc(((4 * ncell) * (sizeof(int )))))); edge = ((int *)(malloc(((2 * nedge) * (sizeof(int )))))); ecell = ((int *)(malloc(((2 * nedge) * (sizeof(int )))))); bedge = ((int *)(malloc(((2 * nbedge) * (sizeof(int )))))); becell = ((int *)(malloc((nbedge * (sizeof(int )))))); bound = ((int *)(malloc((nbedge * (sizeof(int )))))); x = ((float *)(malloc(((2 * nnode) * (sizeof(float )))))); q = ((float *)(malloc(((4 * ncell) * (sizeof(float )))))); qold = ((float *)(malloc(((4 * ncell) * (sizeof(float )))))); res = ((float *)(malloc(((4 * ncell) * (sizeof(float )))))); adt = ((float *)(malloc((ncell * (sizeof(float )))))); for (int n = 0; n < nnode; n++) { if (fscanf(fp,"%f %f \n",(x + (2 * n)),(x + ((2 * n) + 1))) != 2) { printf("error reading from new_grid.dat\n"); exit((-1)); } } for (int n = 0; n < ncell; n++) { if (fscanf(fp,"%d %d %d %d \n",(cell + (4 * n)),(cell + ((4 * n) + 1)),(cell + ((4 * n) + 2)),(cell + ((4 * n) + 3))) != 4) { printf("error reading from new_grid.dat\n"); exit((-1)); } } for (int n = 0; n < nedge; n++) { if (fscanf(fp,"%d %d %d %d \n",(edge + (2 * n)),(edge + ((2 * n) + 1)),(ecell + (2 * n)),(ecell + ((2 * n) + 1))) != 4) { printf("error reading from new_grid.dat\n"); exit((-1)); } } for (int n = 0; n < nbedge; n++) { if (fscanf(fp,"%d %d %d %d \n",(bedge + (2 * n)),(bedge + ((2 * n) + 1)),(becell + n),(bound + n)) != 4) { printf("error reading from new_grid.dat\n"); exit((-1)); } } fclose(fp); // set constants and initialise flow field and residual printf("initialising flow field \n"); gam = 1.4f; gm1 = (gam - 1.0f); cfl = 0.9f; eps = 0.05f; float mach = 0.4f; float alpha = ((3.0f * atan(1.0f)) / 45.0f); float p = 1.0f; float r = 1.0f; float u = (sqrt(((gam * p) / r)) * mach); float e = ((p / (r * gm1)) + ((0.5f * u) * u)); qinf[0] = r; qinf[1] = (r * u); qinf[2] = 0.0f; qinf[3] = (r * e); for (int n = 0; n < ncell; n++) { for (int m = 0; m < 4; m++) { q[(4 * n) + m] = qinf[m]; res[(4 * n) + m] = 0.0f; } } // OP initialisation op_init(argc,argv,2); // declare sets, pointers, datasets and global constants op_set nodes = op_decl_set(nnode,"nodes"); op_set edges = op_decl_set(nedge,"edges"); op_set bedges = op_decl_set(nbedge,"bedges"); op_set cells = op_decl_set(ncell,"cells"); op_map pedge = op_decl_map(edges,nodes,2,edge,"pedge"); op_map pecell = op_decl_map(edges,cells,2,ecell,"pecell"); op_map pbedge = op_decl_map(bedges,nodes,2,bedge,"pbedge"); op_map pbecell = op_decl_map(bedges,cells,1,becell,"pbecell"); op_map pcell = op_decl_map(cells,nodes,4,cell,"pcell"); op_dat p_bound = op_decl_dat(bedges,1,"int",bound,"p_bound"); op_dat p_x = op_decl_dat(nodes,2,"float",x,"p_x"); op_dat p_q = op_decl_dat(cells,4,"float",q,"p_q"); op_dat p_qold = op_decl_dat(cells,4,"float",qold,"p_qold"); op_dat p_adt = op_decl_dat(cells,1,"float",adt,"p_adt"); op_dat p_res = op_decl_dat(cells,4,"float",res,"p_res"); op_decl_const(1,"float",&gam); op_decl_const(1,"float",&gm1); op_decl_const(1,"float",&cfl); op_decl_const(1,"float",&eps); op_decl_const(1,"float",&mach); op_decl_const(1,"float",&alpha); op_decl_const(4,"float",qinf); op_diagnostic_output(); // main time-marching loop niter = 1000; for (int iter = 1; iter <= niter; iter++) { // save old flow solution save_soln_host("save_soln_modified",cells,op_arg_dat(p_q,(-1), OP_ID,4,"float",OP_READ),op_arg_dat(p_qold,(-1), OP_ID,4,"float",OP_WRITE)); // predictor/corrector update loop for (int k = 0; k < 2; k++) { // calculate area/timstep adt_calc_host("adt_calc_modified",cells,op_arg_dat(p_x,0,pcell,2,"float",OP_READ),op_arg_dat(p_x,1,pcell,2,"float",OP_READ),op_arg_dat(p_x,2,pcell,2,"float",OP_READ),op_arg_dat(p_x,3,pcell,2,"float",OP_READ),op_arg_dat(p_q,(-1), OP_ID,4,"float",OP_READ),op_arg_dat(p_adt,(-1), OP_ID,1,"float",OP_WRITE)); // calculate flux residual res_calc_host("res_calc_modified",edges,op_arg_dat(p_x,0,pedge,2,"float",OP_READ),op_arg_dat(p_x,1,pedge,2,"float",OP_READ),op_arg_dat(p_q,0,pecell,4,"float",OP_READ),op_arg_dat(p_q,1,pecell,4,"float",OP_READ),op_arg_dat(p_adt,0,pecell,1,"float",OP_READ),op_arg_dat(p_adt,1,pecell,1,"float",OP_READ),op_arg_dat(p_res,0,pecell,4,"float",OP_INC),op_arg_dat(p_res,1,pecell,4,"float",OP_INC)); bres_calc_host("bres_calc_modified",bedges,op_arg_dat(p_x,0,pbedge,2,"float",OP_READ),op_arg_dat(p_x,1,pbedge,2,"float",OP_READ),op_arg_dat(p_q,0,pbecell,4,"float",OP_READ),op_arg_dat(p_adt,0,pbecell,1,"float",OP_READ),op_arg_dat(p_res,0,pbecell,4,"float",OP_INC),op_arg_dat(p_bound,(-1), OP_ID,1,"int",OP_READ)); // update flow field rms = 0.0; update_host("update_modified",cells,op_arg_dat(p_qold,(-1), OP_ID,4,"float",OP_READ),op_arg_dat(p_q,(-1), OP_ID,4,"float",OP_WRITE),op_arg_dat(p_res,(-1), OP_ID,4,"float",OP_RW),op_arg_dat(p_adt,(-1), OP_ID,1,"float",OP_READ),op_arg_gbl(&rms,1,"float",OP_INC)); } // print iteration history rms = (sqrt((rms / ((float )ncell)))); if ((iter % 100) == 0) printf(" %d %10.5e \n",iter,rms); } /* for (int ll = 0; ll < (4 * ncell); ll++) printf("%lf\n",q[ll]);*/ op_timing_output(); return 0; }
gfarm_error_t gfarm_modify_host(const char *hostname, int port, char **hostaliases, char *architecture, int ncpu, int flags, int add_aliases) { gfarm_error_t e, e2; struct gfarm_host_info hi; int host_info_needs_free = 0; gfarm_stringlist aliases; if (port == 0 || *hostaliases == NULL || architecture == NULL || ncpu < 1 || flags == -1 || add_aliases) { e = gfm_client_host_info_get_by_names(gfarm_metadb_server, 1, &hostname, &e2, &hi); if (e != GFARM_ERR_NO_ERROR) return (e); if (e2 != GFARM_ERR_NO_ERROR) return (e2); host_info_needs_free = 1; if (!add_aliases) { /* XXX - do check_hostaliases() here, too. */ hostaliases = hostaliases; } else { e = check_hostaliases( gfarm_strarray_length(hostaliases), hostaliases); if (e != GFARM_ERR_NO_ERROR) goto free_host_info; e = gfarm_stringlist_init(&aliases); if (e != GFARM_ERR_NO_ERROR) goto free_host_info; if (hi.hostaliases != NULL) { e = gfarm_stringlist_cat(&aliases, hi.hostaliases); if (e != GFARM_ERR_NO_ERROR) goto free_aliases; } if (hostaliases != NULL) { e = gfarm_stringlist_cat(&aliases, hostaliases); if (e != GFARM_ERR_NO_ERROR) goto free_aliases; } e = gfarm_stringlist_add(&aliases, NULL); if (e != GFARM_ERR_NO_ERROR) goto free_aliases; hostaliases = GFARM_STRINGLIST_STRARRAY(aliases); } if (port == 0) port = hi.port; if (architecture == NULL) architecture = hi.architecture; if (ncpu < 1) ncpu = hi.ncpu; if (flags == -1) flags = hi.flags; } e = update_host(hostname, port, gfarm_strarray_length(hostaliases), hostaliases, architecture, ncpu, flags, gfm_client_host_info_modify); #if 0 /* XXX FIXME not yet in v2 */ if (e == GFARM_ERR_NO_ERROR && !add_aliases && *hostaliases == NULL) e = gfarm_host_info_remove_hostaliases(hostname); #endif free_aliases: if (add_aliases) gfarm_stringlist_free(&aliases); free_host_info: if (host_info_needs_free) gfarm_host_info_free(&hi); return (e); }