# Kqueue - Kevent



## dursino (May 24, 2012)

Hi,
I am Italian student, so sorry for my bad english.

I would understand some things about functions in the title.

I have to check if some ICMP Packets are arrived, so


```
int kqueue_descr = kqueue();   /* Descriptor */
				 if( kqueue_descr == -1)
				 {
	 			      perror("Error in Kqueue: ");
	  			      abort_multi_ping();
	   			  
				  }
				     /* we need to set some parameters of kqueue */
				 for( i= 0; i< how_many_targets; i++)
	     			            EV_SET(&events_list[i],targets[i].sockets, EVFILT_READ,EV_ADD | EV_ENABLE|
```
Now I am ready to use Kevent function


```
/* Now we are waiting for a ready descriptor  */
				            nev = kevent( kqueue_descr, events_list, how_many_targets, 
                                                  events_trig, how_many_targets,
                                                  &tmout);
					/* Here kevent has returned, we need understand why ... */ 


					/* ... so we are checking for some errors ...   */
 				          for ( index = 0; index < nev; index++) 
					  {
            					if ( events_trig [index].flags & EV_ERROR) 
						{            
               					     fprintf(stderr, "EV_ERROR: %s\n", strerror(events_trig[index].data));
               				             abort_multi_ping();
            					}               
					   }
					/* ... No errors, so we have to understand what descriptor are ready ... */
					
					  gettimeofday(&now, NULL);  /* TimeStamp   */
					  printf("\n NEV: %d",nev);
	       			          for( index = 0 ; index < nev; index++)
				          {    
		   			       for( who = 0; who < how_many_targets; who ++)
		     	  		            if( targets[who].sockets == events_trig[index].ident)
			      			        break;
						if( how_many_targets == who )
						    abort_multi_ping();
```
I can be sure that Nev when is >0 is equal to ready decriptors and that these are placed in events_trig?

At last, if I send a Pkt to a IP that is down the descriptor in kqueue never returns?

Bye

Sorry for bad english

Good Evening


----------



## dursino (May 25, 2012)

If something is not clear please post it. I didn't even find an answer to my question on the net!


----------



## acheron (May 25, 2012)

You should probably post your question on freebsd-hackers@


----------



## dursino (May 25, 2012)

Hi,

What's that? A mailing list?


----------



## DutchDaemon (May 25, 2012)

http://lists.freebsd.org/mailman/listinfo/freebsd-hackers


----------

