示例#1
0
int 
print_nstat_msg (void *msg, int size)
{
  nstat_msg_hdr *ns = (nstat_msg_hdr *) msg;
  
  switch (ns->type)
	{

	   case  10001: // NSTAT_MSG_TYPE_SRC_ADDED               = 10001
         {
	  	nstat_msg_src_added *nmsa = (nstat_msg_src_added *) (ns);
		
	     // printf("Src Added - %ld\n", sizeof(nstat_msg_src_added));
	//	printf ("PRovider: %d, SrcRef: %d\n", nmsa->provider, nmsa->srcref);
		
		return (10001);
		
		}
	      break;
	   case 10002: //NSTAT_MSG_TYPE_SRC_REMOVED             = 10002

		// remove this descriptor
	      return (10002);
		//remove_descriptor(...)

	    break;
	   case 10003: // ,NSTAT_MSG_TYPE_SRC_DESC                = 10003
	     {
	      nstat_msg_src_description *nmsd = (nstat_msg_src_description *) (ns );
		if (nmsd->provider == 2)
		descriptors[nmsd->srcref]  =print_tcp_descriptor((char *)nmsd->data, nmsd->provider,nmsd->srcref);
		else if (nmsd->provider == 3)
		 {descriptors[nmsd->srcref] = print_udp_descriptor((char *) nmsd->data, nmsd->provider, nmsd->srcref);
			}
  		descriptorsModded[nmsd->srcref] = 10;

		}
	      break;

           case 10004: //NSTAT_MSG_TYPE_SRC_COUNTS              = 10004
		{
		nstat_msg_src_counts *nmsc = (nstat_msg_src_counts *) (ns );
	//	printf ("RX: %d TX:%d\n", nmsc->counts.nstat_rxpackets , nmsc->counts.nstat_txpackets );

	
		} break;
	
	    case 1: 
		{
			if (ns->context < MAX_DESC && !descriptors[ns->context]) break;
			printf ("ERROR for context %lld - should be available\n", ns->context); break; 
		}
	    case 0: // printf("Success\n"); break;
		break;
	   default:
		printf("Type : %d\n", ns->type);
	}
	fflush(NULL);
return (ns->type) ;
}
示例#2
0
文件: lsock.c 项目: davidrhodus/misc
int process_nstat_msg (void *msg, int size)
{

  nstat_msg_hdr *ns = (nstat_msg_hdr *) msg;
  
  nstat_msg_get_src_description gsdreq;
  int rc = 0;
  switch (ns->type)
	{


	case NSTAT_MSG_TYPE_SRC_ADDED : // 10001:
	  {
  	   nstat_msg_src_added *nmsa = (nstat_msg_src_added *) (ns);
		// Initialize counts for a new source
		memset(&descriptorCounts[nmsa->srcref], '\0', sizeof(nstat_counts));

	   descriptors[nmsa->srcref] = "reading";
	   gsdreq.hdr.type= 1005; //NSTAT_MSG_TYPE_GET_SRC_DESC
	   gsdreq.srcref=nmsa->srcref;
	   gsdreq.hdr.context = 1005; // This way I can tell if errors get returned for dead sources
	   rc = write (fd, &gsdreq, sizeof(gsdreq));
	   break;
	  }
	case NSTAT_MSG_TYPE_SRC_REMOVED: //             = 10002
	  {
		//struct nstat_msg_src_removed *rem;

  	   nstat_msg_src_removed *nmsr = (nstat_msg_src_removed *) (ns);
	   if (descriptors[nmsr->srcref]) 
		{

		 // force a refresh
		 if (wantCurses)
			{
			  print_descriptors();
			}
		}
	
	   descriptors[nmsr->srcref] = NULL; // @TODO:  free..

	   
	   break;
	  }


           case NSTAT_MSG_TYPE_SRC_COUNTS: //              = 10004
		{
		nstat_msg_src_counts *nmsc = (nstat_msg_src_counts *) (ns );
		memcpy (&(descriptorCounts[nmsc->srcref]), &(nmsc->counts), sizeof (nstat_counts));
		update_provider_statistics (nmsc->srcref);
		} 

		break;

	   case NSTAT_MSG_TYPE_SRC_DESC: //                = 10003
	     {
	        nstat_msg_src_description *nmsd = (nstat_msg_src_description *) (ns );
		
		switch (nmsd->provider)
		{
			case NSTAT_PROVIDER_TCP:
				descriptors[nmsd->srcref]  = print_tcp_descriptor((char *)nmsd->data, nmsd->provider,nmsd->srcref);
				break;
			case NSTAT_PROVIDER_UDP:
         			descriptors[nmsd->srcref] = print_udp_descriptor((char *) nmsd->data, nmsd->provider, nmsd->srcref);
				break;
		}


	     }
	      break;

	
	    case 1: 
		{
			if (ns->context < MAX_DESC && !descriptors[ns->context]) break;
			printf ("ERROR for context %lld - should be available\n", ns->context); break; 
		}
	    case 0: // printf("Success\n"); break;
		break;
	   default:
		printf("Type : %d\n", ns->type);
	}
	fflush(NULL);
return (ns->type) ;
}