Пример #1
0
static void event_notify(espeak_EVENT* event)
{
ENTER("event_notify");
	static unsigned int a_old_uid = 0;

	espeak_EVENT events[2];
	memcpy(&events[0],event,sizeof(espeak_EVENT));     // the event parameter in the callback function should be an array of eventd
	memcpy(&events[1],event,sizeof(espeak_EVENT));
	events[1].type = espeakEVENT_LIST_TERMINATED;           // ... terminated by an event type=0

	if (event && my_callback)
	{
		event_display(event);

		switch(event->type)
		{
		case espeakEVENT_SENTENCE:
			my_callback(NULL, 0, events);
			a_old_uid = event->unique_identifier;
			break;

		case espeakEVENT_MSG_TERMINATED:
		case espeakEVENT_MARK:
		case espeakEVENT_WORD:
		case espeakEVENT_END:
		case espeakEVENT_PHONEME:
		{
// jonsd - I'm not sure what this is for. gilles says it's for when Gnome Speech reads a file of blank lines
			if (a_old_uid != event->unique_identifier)
			{
				espeak_EVENT_TYPE a_new_type = events[0].type;
				events[0].type = espeakEVENT_SENTENCE;
				my_callback(NULL, 0, events);
				events[0].type = a_new_type;
				usleep(50000);
			}
			my_callback(NULL, 0, events);
			a_old_uid = event->unique_identifier;
		}
		break;

		default:
			case espeakEVENT_LIST_TERMINATED:
			case espeakEVENT_PLAY:
		break;
		}
	}
}
Пример #2
0
int main(int argc, char **argv)
{
get_sys_info(f[0],10);
usleep(600000);

 size_mac=sizeof(struct ether_header);
 size_ip=sizeof(struct ip);
///////////////////////////////////

signal(SIGINT, sigproc);
  signal(SIGTERM, sigproc);
  signal(SIGINT, sigproc);

//perror("what's wrong\n");
//init_loop(&shmp,&shmid,shmpath);
//init_loop(&shmp,&shmid,shmpath1);
int i;
char buf[256];
initBCBuff();
printf("1111111111111111\n");
for(i=0;i<snortnum;++i)//create shm
{
losep[i]=0LL;
	sprintf(buf,"%s",shmpath);
	//puts(buf);
	init_loop(&shmp[i],&shmid[i],buf,i);
}
hb=init_HB(HB_MAX);
	init_free_link(FREE_NODE);
	init_BC();//the cache for the pro classificationd
	printf("EIinit bc\n");
	init_patterns();
int sockfd;
struct pcap_pkthdr pkthdr;
   if ((sockfd = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL))) < 0)
   {
       printf ("create socket failed\n");
       return -1;
   }

   if (0 != set_promisc ("eth0", sockfd))
   {
       printf ("Failed to set interface promisc mode\n");
   }
unsigned char buffer[65535] = {0};
   while (1)
   {
   	
   			//memset (&packet, 0x0, sizeof (packet));
        memset (buffer, 0x0, sizeof (buffer));
       pkthdr.caplen = recvfrom (sockfd, buffer, sizeof (buffer), 0, NULL, NULL);
      my_callback(NULL,&pkthdr,buffer);
		}

  return 0;
}
Пример #3
0
static void event_notify(espeak_EVENT *event)
{
	static unsigned int a_old_uid = 0;

	espeak_EVENT events[2];
	memcpy(&events[0], event, sizeof(espeak_EVENT));     // the event parameter in the callback function should be an array of eventd
	memcpy(&events[1], event, sizeof(espeak_EVENT));
	events[1].type = espeakEVENT_LIST_TERMINATED;           // ... terminated by an event type=0

	if (event && my_callback) {
		switch (event->type)
		{
		case espeakEVENT_SENTENCE:
			my_callback(NULL, 0, events);
			a_old_uid = event->unique_identifier;
			break;
		case espeakEVENT_MSG_TERMINATED:
		case espeakEVENT_MARK:
		case espeakEVENT_WORD:
		case espeakEVENT_END:
		case espeakEVENT_PHONEME:
		{
			if (a_old_uid != event->unique_identifier) {
				espeak_EVENT_TYPE a_new_type = events[0].type;
				events[0].type = espeakEVENT_SENTENCE;
				my_callback(NULL, 0, events);
				events[0].type = a_new_type;
				usleep(50000);
			}
			my_callback(NULL, 0, events);
			a_old_uid = event->unique_identifier;
		}
			break;
		case espeakEVENT_LIST_TERMINATED:
		case espeakEVENT_PLAY:
		default:
			break;
		}
	}
}
Пример #4
0
void ui_checkbox::on_click() {
   if (my_callback != nullptr) {
      my_callback();
   }
}
Пример #5
0
int main(int argc,char **argv)
{
    char *in_dev,*out_dev, *netaddr, *mask;
    char errbuf[PCAP_ERRBUF_SIZE];
    pcap_t *in_descr,*out_descr;
    struct bpf_program fp,fp2;      /* hold compiled program     */
    bpf_u_int32 maskp;          /* subnet mask               */
    bpf_u_int32 netp,netp2;           /* ip                        */
    u_char* args = NULL;
    struct in_addr addr1, addr2;

    pid_t pid;

    /* Options must be passed in as a string because I am lazy */


    /* grab a device to peak into...
    dev = pcap_lookupdev(errbuf);
    if(dev == NULL)
    { printf("%s\n",errbuf); exit(1); }
    */
    in_dev = "eth1";
    out_dev = "eth0";



    /* open device for reading. NOTE: defaulting to promiscuous mode*/
    /* pcap_t *pcap_open_live
     * (char *device,int snaplen, int prmisc,int to_ms,char *ebuf) */
    /* prmisc=0: non-promiscuous mode */
    in_descr = pcap_open_live(in_dev,BUFSIZ,1,500,errbuf);
    if(in_descr == NULL )
    { printf("pcap_open_live(): %s\n",errbuf); exit(1); }
    out_descr = pcap_open_live(out_dev,BUFSIZ,1,500,errbuf);
    if(out_descr == NULL )
    { printf("pcap_open_live(): %s\n",errbuf); exit(1); }



    //if(pcap_compile(descr,&fp,"net 140.114.195.0 mask 255.255.255.0",0,netp) == -1)
        if(pcap_compile(out_descr,&fp,"dst host 140.114.195.31 and tcp",0,netp) == -1)
        { fprintf(stderr,"Error calling pcap_compile out\n"); exit(1); }

        if(pcap_compile(in_descr,&fp2,"src host 192.168.1.3 and tcp",0,netp2) == -1)
        { fprintf(stderr,"Error calling pcap_compile in\n"); exit(1); }

    /* set the compiled program as the filter */
    if(pcap_setfilter(in_descr,&fp2) == -1)
        { fprintf(stderr,"Error setting filter in\n"); exit(1); }
    if(pcap_setfilter(out_descr,&fp) == -1)
        { fprintf(stderr,"Error setting filter out\n"); exit(1); }


    /* ... and loop */
    //pid=fork();
    //if(pid<0){
      //  printf("fork failed.\n");
   // }
   // else if(pid==0){

        //pcap_loop(in_descr,atoi(argv[1]),my_callback,args);
   // }
   // else{
    //    pcap_loop(out_descr,atoi(argv[1]),my_callback,args);

    //}
    u_char *in_Packet, *out_Packet;
    struct pcap_pkthdr *in_phdr,*out_phdr;
    struct pcap_pkthdr inthdr,outthdr;

    count =0;
    memset(memory,0,100);
    while (1)
    {
        in_Packet = (u_char*)pcap_next(in_descr,  &inthdr);
        out_Packet = (u_char*)pcap_next(out_descr, &outthdr);
        if (in_Packet != NULL)
        {

            in_phdr=&inthdr;
            my_callback(args,in_phdr,in_Packet);
        }
        if (out_Packet != NULL)
        {
            out_phdr=&outthdr;
            my_callback(args,out_phdr,out_Packet);
        }
    }
    fprintf(stdout,"\nfinished\n");
    return 0;
}
Пример #6
0
int main(int argc, char* argv[])
{

	 char *dev; /* name of the device to use */ 
  char *net; /* dot notation of the network address */
  char *mask;/* dot notation of the network mask    */
  int ret;   /* return code */
 //const u_char *packet;
  pcap_t* descr;      /*you can man it*/
  char errbuf[PCAP_ERRBUF_SIZE];
  bpf_u_int32 netp; /* ip          */
  bpf_u_int32 maskp;/* subnet mask */
  struct in_addr addr;

  /* ask pcap to find a valid device for use to sniff on */
  dev = pcap_lookupdev(errbuf);

  /* error checking */
  if(dev == NULL)
  {
   printf("%s\n",errbuf);
   exit(1);
  }

  /* print out device name */
  printf("DEV: %s\n",dev);

  /* ask pcap for the network address and mask of the device */
/*  ret = pcap_lookupnet(dev,&netp,&maskp,errbuf);

  if(ret == -1)
  {
   printf("%s\n",errbuf);
   exit(1);
  }
*/
  /* get the network address in a human readable form */
//  addr.s_addr = netp;
 // net = inet_ntoa(addr);

 /* if(net == NULL)// thanks Scott :-P 
  {
    perror("inet_ntoa");
    exit(1);
  }

  printf("NET: %s\n",net);

  // do the same as above for the device's mask 
  addr.s_addr = maskp;
  mask = inet_ntoa(addr);
  
  if(mask == NULL)
  {
    perror("inet_ntoa");
    exit(1);
  }*/
  signal(SIGINT, sigproc);
  signal(SIGTERM, sigproc);
  signal(SIGINT, sigproc);
  printf("MASK: %s\n",mask);
 size_mac=sizeof(struct ether_header);
 size_ip=sizeof(struct ip);
	//char *filename="/dev/shm/get.pcap";
	//char *filename="./get.pcap";
//char *filename="/run/shm/http.pcap";
initBCBuff();
/* pthread_t my_thread;

  if(pthread_create(&my_thread, NULL, threadclass, NULL)!=0)
  	{
  		msg("Ecreate thread error\n");
  		exit(0);
  	}
*/
     /// msg("kkkkkkkkkkkkk\n");
int i;
#if 1
	#define MAX_FILE 4
	char filenameA[MAX_FILE+1][200]={{"/run/shm/http.pcap"},{"/run/shm/ftp.pcap"},{"/run/shm/pop3.pcap"},{"/run/shm/smtp.pcap"},{""}};
	//char filenameA[MAX_FILE+1][200]={{"/run/shm/http.pcap"},{""}};
	//char *filename="./exam-for/ftp.pcap";
	char *filename;
	printf("EIinit hb\n");
	hb=init_HB(HB_MAX);
	init_free_link(FREE_NODE);
	init_BC();//the cache for the pro classificationd
	printf("EIinit bc\n");
	init_patterns();
msg("hhhhhh\n");
DELAY_INI();

 	 NS_TIME_START(time); 
	int num=0;
	int kk=0;

	
	
again:
	filename= filenameA[num];
//	msg("kk=%d\n",kk);
	num=(num+1)%MAX_FILE;

	
	if(kk==100000)
		goto endk;
		++kk;
	descr =pcap_open_offline(filename, errbuf);     
	
    if(descr == NULL)
    { printf("pcap_open_live(): %s\n",errbuf); exit(1); }

/////////////////////////////
	DELAY(DELAY_NS);	
	
	pcap_loop(descr,-1,my_callback,NULL);
	//printf("llllllllllllll\n");
	pcap_close(descr);
goto again;
endk:
	exitflag=1;
	//sem_post(&bin_sem);
	 NS_TIME_END(time);
	msg("\n===================%d\n\n",kk);
	for(i=0;i<PRO_MAX+2;++i)
	{
	
	printf("%s:%lld\n",pro_map[i],pronum[i]);
  	 }
	 printf("losepacket=%lld\n",losepacket);
	
		//speed(NS_GET_TIMEP(time),count+sum,firstlen);
		speed1(NS_GET_TIMEP(time),packet_num,packet_len);
	speed2(NS_GET_TIMEP(time),packet_num,packet_len,100000,DELAY_NS);
	
	
#else
	int fd=open(filename,O_RDONLY);
	if(fd<=0)
		perror("open error\n");

	//unsigned char buf
	struct pcap_pkthdr head;
	u_char buf[3000];
	int headlen=sizeof(struct pcap_file_header);
	int phead=sizeof(struct pcap_pkthdr);
	//while(read(fd,&head,sizeof()))
	 NS_TIME_START(time); 
	printf("EIinit hb\n");
	hb=init_HB(HB_MAX);
	init_free_link(FREE_NODE);
	init_BC();//the cache for the pro classificationd
	printf("EIinit bc\n");
	init_patterns();
	//msg("EISpppppppppp");

	while(1)
	{
		lseek(fd,headlen,SEEK_SET);
		//read(fd,buf,headlen);
		while(read(fd,&head,phead))
		{
		//printf("lllll\n");
			read(fd,buf,head.caplen);
			my_callback(NULL,&head,buf);
			//printf("%d\n",head.caplen);
		}
		
	}
#endif
	


//pthread_join(my_thread, NULL);
	
/////////////////////////////////////////////////////
      
        return 0;
}