微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用sigaction和pthread进行嗅探

如何解决使用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 举报,一经查实,本站将立刻删除。