Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用sigaction和pthreads进行嗅探_Linux_Pthreads_Pcap_Sigaction - Fatal编程技术网

Linux 使用sigaction和pthreads进行嗅探

Linux 使用sigaction和pthreads进行嗅探,linux,pthreads,pcap,sigaction,Linux,Pthreads,Pcap,Sigaction,我无法理解一些代码。我不熟悉信号处理pthreads。该代码用于获取ARP缓存等。提供的代码用于打开连接 这是主代码 这是允许连接的代码 这是sigint_handler 问题 我无法具体理解这些台词。action.sa_处理程序如何与sigint_处理程序等同 这两个命令的用途是什么 arp-d%s&&arptables-P输入接受&&arptables--flush&&ip-s邻居刷新所有和回显完成 arptables-P输入接受和&arptables-flush和&ip-s邻居flush

我无法理解一些代码。我不熟悉信号处理pthreads。该代码用于获取ARP缓存等。提供的代码用于打开连接

  • 这是主代码
  • 这是允许连接的代码
  • 这是sigint_handler
  • 问题

  • 我无法具体理解这些台词。action.sa_处理程序如何与sigint_处理程序等同
  • 这两个命令的用途是什么
    arp-d%s&&arptables-P输入接受&&arptables--flush&&ip-s邻居刷新所有和回显完成
    arptables-P输入接受和&arptables-flush和&ip-s邻居flush all

  • 阅读相关手册页。读一读这本书。它告诉您,
    sa_handler
    是一个函数指针。所以给它分配一个函数地址是非常有意义的。对于2,请阅读和手册页。
     pthread_t tid;
      pthread_create(&tid, NULL, &allowAllConnections, NULL);
      struct sigaction action;
        memset(&action, 0, sizeof(action));
        action.sa_handler = &sigint_handler;
        sigaction(SIGINT, &action, &old_action);
    
    void *allowAllConnections(void *arg)
    {
      FILE *fp;
      char path[1035];
      int exists = 0;
        while(1)
        {
            sleep(300);
            fp = popen("arptables -P INPUT ACCEPT && arptables --flush && ip -s neighbour flush all", "r");
            if (fp == NULL) {
              printf("Failed to run command\n" );
              exit(1);
            }
            printf("ARP Refresh: Allowing all connections!\n");
        }
        return 0;
    }
    
    void sigint_handler(int sig_no){
      FILE *fp;
      char path[1035];
      int exists = 0;
      char j[1024] = "";
      snprintf(j, sizeof(j), "arp -d %s && arptables -P INPUT ACCEPT && arptables --flush && ip -s neighbour flush all && echo done", gateway_ip);
    
      fp = popen(j, "r");
      if (fp == NULL) {
        printf("Failed to run command\n" );
        exit(1);
      }
    
      while (fgets(path, sizeof(path)-1, fp) != NULL) {
        printf("%s", path);
      }
    
      printf("Successfully exited. Flushed ARP table and enabled all ARP connections!\n");
      exit(0);
    }
    
     pthread_create(&tid, NULL, &allowAllConnections, NULL)
    memset(&action, 0, sizeof(action));
        action.sa_handler = &sigint_handler;
        sigaction(SIGINT, &action, &old_action);