Esempio n. 1
0
int main(int argc, char *argv[])
{
  int ret;
  TCPClientSocket *sk=NULL;
  PingClient *client =NULL;

  if( argc!= 3){
    fprintf(stderr, "Usage: %s ip port\n", argv[0]);
    return -1;
  }
  const char *ip = argv[1];
  uint16_t port = (uint16_t)atoi(argv[2]);

  loop = init_loop();
  if(!loop){
    goto error;
  }
  sk = create_client_socket(loop);
  if(!sk)
    goto sk_error;

  client = new PingClient(sk, ip, port);
  
  loop->run();

  delete client;
  return 0;
  
 sk_error:
  delete loop;
 error:
  return -1;
}
Esempio n. 2
0
/*	int main()
	{
		
		int n;
		int shmid;
		shmid=CreateShm("/home",4,sizeof(UC_ShmMemory));
		p=(UC_ShmMemory*)AttachShm(shmid);
			printf("ccccccccccc\n");
		my_lock_init(p,NULL);
		printf("aaaaaaaaaaaa\n");
		//printf("input:");
	//	scanf("%d",&n);
		//p->CurFileNum=n;
	//	printf("%d\n",p->CurFileNum);
		//sleep(10);
	//	scanf("%d",&n);
	
	while(p->CurFileNum==0)
	my_lock_wait(p);
	//my_lock_wait(p);
	printf("nnnnnnnnnnnn\n");
	printf("%d\n",p->CurFileNum);
		DetachShm(p);
		//DeleteShm(shmid);
		
	}*/
		int main()
	{
		
		UC_ShmMemory *p=NULL;
		int n;
	int shmid;
	//	shmid=CreateShm("/home",4,sizeof(UC_ShmMemory));
	//	p=(UC_ShmMemory*)AttachShm(shmid);
	//	my_lock_init(p,NULL);
	//	printf("input:");
	printf("%d\n",sizeof(UC_ShmMemory));
	init_loop(&p,&shmid,"/home/zhao",26);
printf("%d\n",shmid);
	//	scanf("%d",&n);

		if(!p)
			printf("pppppppppp\n");
//	p->head=n;
	//while(p->head==0)
	//my_lock_wait(p);
	while(1)
	{
	
	my_lock_wait(p);
		printf("%d\n",p->head);
		//	my_lock_release(p);
	if(p->head==-1)
		break;
}		
		destroy_loop(p);
	//	DeleteShm(shmid);

	return 1;
		
	}
Esempio n. 3
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;
}
Esempio n. 4
0
int			pipe_inf(t_plist *plist, t_cmd *cmd, int n, char **env)
{
  int			pid;
  int			status;

  plist->pipe = 1;
  if ((pid = fork()) == 0)
    init_loop(plist, cmd, n, env);
  else
    waitpid(pid, &status, 0);
  plist->pipe = 0;
  if (WIFEXITED(status) == 1)
    if (WEXITSTATUS(status))
      return (plist->exit_value = 1);
  return (0);
}
Esempio n. 5
0
int main(int argc, char** argv)
{ if (no_terminal(stdin)) redirected_input=true;
  cur_in=stdin; cur_out=stdout; /* these cannot be initialised statically */

  
  { int nr=1;  argc--; infofil[0]='\0';
    if (argc > 0)
    {
        strcpy(initfil,argv[nr++]);
        argc--;
    }
    if (argc > 0)
    {
        strcpy(infofil,argv[nr++]);
        strcat(infofil,"/");
        argc--;
    }
    if (argc!=0)
    {
        printf("Illegal number of arguments.\n");
        exit(1);
    }
  }
  init();

    ignore_intr();
    (void) signal(SIGINT, handle);
    (void) setjmp(envbuf);

 /* Finished  signal handling and environment set  */

    while (init_loop(),init_loop_gettype(),yyparse(),!stop)
    {	if (feof(cur_in))
	  stop=exit_input_file(false); /* close file when fully read */
	if (runtime) print_runtime();
    }
    if (!redirected_input) Printf("end program\n");
    return 0;
}
int	main(int argc, char** argv)
{
  struct sigaction	action;
  int			ch, i, count = 0;
  int			ret, passed = 0;
  addr_t		addr;

  memset(&tracee, 0, sizeof(tracee_t));

  /*
  ** Catch sigint & sigquit
  */
  action.sa_handler = quit_ftrace;
  action.sa_flags = SA_RESTART;
  if (sigaction(SIGQUIT, &action, NULL))
    errexit("ftrace: sigaction(SIGQUIT), %s", ftrace_strerror(errno));
  if (sigaction(SIGINT, &action, NULL))
    errexit("ftrace: sigaction(SIGKILL), %s", ftrace_strerror(errno));

  /*
  ** Count Args Before -p, -e or -c Option
  */
  for (i = 0; i < argc; i++)
    {
      if (!strcmp(argv[i], "-p") ||
	  !strcmp(argv[i], "-e") ||
	  !strcmp(argv[i], "-c")
	  )
	{
	  if (i != argc - 1)
	    argc = i + 2;
	  break;
	}
    }

  if (atexit(clean_ftrace) == -1)
    errexit("ftrace: atexit:, %s", ftrace_strerror(errno));

  for (count = 0; (ch = getopt(argc, argv,"hv:b:p:e:c:")) != -1; count++)
    {
      switch ((char) ch)
	{
	case 'b':
	  /*
	  ** Add Breakpoint
	  */
	  tracee.brkps_toset = list_add(tracee.brkps_toset, optarg);
	  if (tracee.brkps_toset == NULL)
	    errexit("ftrace: list_add:, %s", ftrace_strerror(errno));
	  break;
	case 'p':
	  passed = 1;
	  /*
	  ** Attach To Pid
	  */
	  tracee.proc = proc_new();
	  if (tracee.proc == NULL)
	    errexit("ftrace: proc_new:, %s", ftrace_strerror(errno));
	  if (proc_attach(tracee.proc, atoi(optarg)) == -1)
	    errexit("ftrace: proc_attach:, %s", ftrace_strerror(errno));
	  if (*(argv + i + 2))
	    tracee.proc->path = *(argv + i + 2);
	  else
	    tracee.proc->path = proc_get_bin_path(tracee.proc);
	  break;
	case 'e':
	  passed = 1;
	  /*
	  ** Exec Process
	  */
	  tracee.proc = proc_new();
	  if (tracee.proc == NULL)
	    errexit("ftrace: proc_new:, %s", ftrace_strerror(errno));
	  if (proc_create(tracee.proc, optarg, argv + i + 1) == -1)
	    errexit("ftrace: proc_create:, %s", ftrace_strerror(errno));
	  break;
	case 'c':
	  passed = 1;
	  /*
	  ** Backtrace Core
	  */
	  core_trace(optarg, *(argv + i + 2));
	  return (0);
	  break;
	case 'v':
	  verbose = atoi(optarg);
	  if (verbose > 0 && verbose < 5)
	    break;
	case 'h':
	default:
	  errexit(USAGE);
	  break;
	}
      if (passed == 1)
	break;
    }

  if (!passed)
    errexit(USAGE);

  /*
  ** Tracee Ready !
  */
  ret = init_loop(&tracee, &addr);
  if (tracer_quit)
    return (0);
  switch (ret)
    {
    case TRACEE_OK:
      if (tracing_loop(&tracee, addr) == -1)
	errexit("ftrace: tracing_loop:, %s", ftrace_strerror(errno));
      break;
    case TRACEE_EXIT:
      return (0);
    default:
      errexit("ftrace: init_loop:, %s", ftrace_strerror(errno));
    }

  return (0);
}
Esempio n. 7
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;
  initBCBuff();

  /* 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);
  }
  
  printf("MASK: %s\n",mask);

 //descr = pcap_open_live(dev,65536,1 ,0,errbuf);
	descr = pcap_open_live(dev,MAX_BUFFER_FOR_PACKET,1 ,0,errbuf);
  // descr = pcap_open_live(NULL,BUFSIZ,1 ,0,errbuf);
    if(descr == NULL)
    { printf("pcap_open_live(): %s\n",errbuf); exit(1); }

//printf("pcap:%d\n",descr->bufsize);

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];
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);
}
//////////////
//compile ac dfa
///////////////
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");



pcap_loop(descr,-1,my_callback,NULL);


/////////////////////////////////////
//pthread_join(threadid,NULL);
 
printf("aaaaaaa\n");
  return 0;
}