void handle_packet(u_char *args, const struct pcap_pkthdr *hdr, const u_char *pkt) { /* Here is the core of snarf; the packet handler. Whatever new modules/features should probably be added here, and implemented similarly to the ETHERTYPE_IP stmt below. As packets come in, deal with them according to whatever criteria you want, and make the calls here as much as possible, rather than within other calls (such as calling a DB or DNS routine from within the inspect_ip_header() function). This will help maintain modularity and extensibility. */ static int count = 1; char *ip_addr; if (DEBUG) fprintf(stdout, "\t====================\n"); u_int16_t eth_type = inspect_ethernet_header(args, hdr, pkt); if (eth_type == ETHERTYPE_IP && ETHERTYPE_IP != 0) { // parse ip and handle inspect_ip_header(args, hdr, pkt, &ip_addr); #ifdef WITH_HISTORY #ifdef DNS /* DNS lookup */ // NOTE: Think about way to limit excessive DNS lookups, ie to cache // results to avoid uncessary calls, like maintaining array of ips // that have already been resolved. This won't be super efficient, // but an array search will be much faster than send DNS requests // over the network (unless it's getting hits from the DNS cache...) char *domain_name = NULL; if (getHostnameByIP(ip_addr, &domain_name) != 0) fprintf(stderr, "DNS Lookup yielded no hostname!\n"); add_to_database(conn, ip_addr, domain_name); free(domain_name); #else // Domain name is NULL if no DNS add_to_database(conn, ip_addr, NULL); #endif //DNS #endif //WITH_HISTORY free(ip_addr); } #ifdef SIMPLE_DISPLAY fflush(stdout); fprintf(stdout, "\r"); fprintf(stdout, "%d", count); #endif count++; }
void actuate_move(struct database** head_ref, struct fact F){ struct fact newFact,oldFact; oldFact=search_in_database1((*head_ref), POSITION,F.robot_id); delete_from_database(head_ref, oldFact); //----movement actuation in robots------------- //ControlRobotgo2Position(F.x, F.y, 20/*float speed*/); //--------------------------------------------- newFact.code=POSITION; newFact.robot_id=F.robot_id; newFact.x=F.x; newFact.y=F.y; //printf("Moving robot %d from (%lf, %lf) to (%lf, %lf)\n", newFact.robot_id, oldFact.x, oldFact.y, newFact.x, newFact.y); add_to_database(head_ref, newFact); }
void vMeldTask( void *pvParameters ) { halt(1); //-------CREATE DATABASE----------------------------- struct database *databaseHead = NULL; //-------READ A LINE OF CODE----------------------- char line_of_code[100]="position(1,14.5,15.1)"; //-------REMOVE SPACES------------------------------- RemoveSpaces(line_of_code); //-------ADD TO DATABASE IF IT IS A RULE------------- if(type(line_of_code)==FACT){ struct fact Fact; Fact = getFact(line_of_code); //printf("It's a FACT\n"); add_to_database(&databaseHead,Fact); // print_database(databaseHead); } //------GET HEAD AND BODY IF IT IS A RULE------------ if(type(line_of_code)==RULE){ int i,state=0,headsize=0,bodysize=0; char head[50]={'\0'},body[50]={'\0'}; for(i=0;line_of_code[i]!='\0';i++){ if((line_of_code[i]=='-')&&(line_of_code[i+1]=='o')){ state=1; } if(state==0){ body[i]=line_of_code[i]; bodysize++; } else{ if(((line_of_code[i]=='-')&&(line_of_code[i+1]=='o')) || ((line_of_code[i-1]=='-')&&(line_of_code[i]=='o'))){ continue; } head[i-bodysize-2]=line_of_code[i]; headsize++; } } //printf("It's a RULE\nHead: %s\nBody: %s\n", head,body); struct fact Fact; Fact = getFact(body); // print_database(databaseHead); if(search_in_database(databaseHead, Fact)){ Fact=getFact(head); add_to_database(&databaseHead,Fact); // print_database(databaseHead); } } strcpy(line_of_code,"position(1,14,15) -o move(1,100,150)"); //-------REMOVE SPACES------------------------------- RemoveSpaces(line_of_code); //-------ADD TO DATABASE IF IT IS A RULE------------- if(type(line_of_code)==FACT){ struct fact Fact; Fact = getFact(line_of_code); //printf("It's a FACT\n"); add_to_database(&databaseHead,Fact); // print_database(databaseHead); } //------GET HEAD AND BODY IF IT IS A RULE------------ if(type(line_of_code)==RULE){ int i,state=0,headsize=0,bodysize=0; char head[50]={'\0'},body[50]={'\0'}; for(i=0;line_of_code[i]!='\0';i++){ if((line_of_code[i]=='-')&&(line_of_code[i+1]=='o')){ state=1; } if(state==0){ body[i]=line_of_code[i]; bodysize++; } else{ if(((line_of_code[i]=='-')&&(line_of_code[i+1]=='o')) || ((line_of_code[i-1]=='-')&&(line_of_code[i]=='o'))){ continue; } head[i-bodysize-2]=line_of_code[i]; headsize++; } } //printf("It's a RULE\nHead: %s\nBody: %s\n", head,body); struct fact Fact; Fact = getFact(body); // print_database(databaseHead); if(search_in_database(databaseHead, Fact)){ Fact=getFact(head); add_to_database(&databaseHead,Fact); // print_database(databaseHead); } } }