使用sigaction和pthread进行嗅探

问题描述

我无法理解某些代码。我是信号处理pthread的新手。该代码用于获取ARP缓存等。提供的代码用于打开连接。

  1. 这是主要代码
 pthread_t tid;
  pthread_create(&tid,NULL,&allowAllConnections,NULL);
  struct sigaction action;
    memset(&action,sizeof(action));
    action.sa_handler = &sigint_handler;
    sigaction(SIGINT,&action,&old_action);
  1. 这是允许连接的代码
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;
}
  1. 这是sigint_handler
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);
}

问题

  1. 我无法具体理解这些内容。如何将action.sa_handler等同于sigint_handler
 pthread_create(&tid,NULL)
memset(&action,&old_action);
  1. 这两个命令的用途是什么 arp -d %s && arptables -P INPUT ACCEPT && arptables --flush && ip -s neighbour flush all && echo done arptables -P INPUT ACCEPT && arptables --flush && ip -s neighbour flush all

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)