Chinaunix

标题: pcap_open_live函数报错 求高人指点 [打印本页]

作者: houhulou    时间: 2009-06-11 11:45
标题: pcap_open_live函数报错 求高人指点
以太网帧的监视小程序,基本书上COPY的 就修改了下
#include <pcap.h>
#include <stdio.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/sem.h>
#include<stdlib.h>
#include<math.h>
#include<errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <cf.h>
#include <sys/cfgodm.h>
#include <sys/cfgdb.h>
#define DEFAULT_SNAPLEN 68

void packet_print
(u_char* user, const struct pcap_pkthdr* h, const u_char* p)
{
          static int icount=1;
    printf("find %d packet\n", icount++);       
}


void   main()   
{   
  char   error_content[PCAP_ERRBUF_SIZE];   
  struct   in_addr   net_ip_address;   
  struct   in_addr   net_mask_address;   
  char   *net_interface;   
  char   *net_ip_string;   
  char   *net_mask_string;   
  bpf_u_int32   net_ip;   
  u_int32_t   net_mask;   
  /*net_interface   =   pcap_lookupdev(error_content);
  if ( net_interface == NULL)
  {
      fprintf(stderr, "pcap_lookupdev() error: %s\n", error_content);
              exit(-1);        
  }  */
  printf("网络接口:%s\n",   net_interface);   
  pcap_lookupnet("en0",   &net_ip,   &net_mask,   error_content);   
  net_ip_address.s_addr   =   net_ip;   
  net_ip_string   =   inet_ntoa(net_ip_address);   
  printf("网络地址:%s\n",   inet_ntoa(net_ip_address));   
  net_mask_address.s_addr   =   net_mask;   
  net_mask_string   =   inet_ntoa(net_mask_address);   
  printf("网络掩码:%s\n",   net_mask_string);   
  //
  pcap_t *pd;
  if ( genmajor("bpf") == -1 )
  {
      perror("genmajor");
      exit(-1);       
  }

  memset(error_content,0x00, sizeof(error_content));
  char tmpstr[]="en0";
  if ( (pd=pcap_open_live(tmpstr,DEFAULT_SNAPLEN, 0, 1000, error_content)) == NULL )
  {
            perror("pcap_open_live");
            fprintf(stderr, "%s\n", error_content);
              exit(-1);
  }
  memset(error_content,0x00, sizeof(error_content));
  if ( pcap_loop(pd, 10, packet_print, NULL) < 0 )
  {
      fprintf(stderr, "pcap_loop() error: %s\n", error_content);
              exit(-1);        
  }
  pcap_close(pd);
  exit(0);
}


//报错信息:
&Iacute;&oslash;&Acirc;&ccedil;&frac12;&Oacute;&iquest;&Uacute;:
&Iacute;&oslash;&Acirc;&ccedil;&micro;&Oslash;&Ouml;·:10.40.96.0
&Iacute;&oslash;&Acirc;&ccedil;&Ntilde;&Uacute;&Acirc;&euml;:255.255.255.0
genmajor: No such file or directory

红色 部分是我测试genmajor这个函数用的
如果删除去的话 在pcap_open_live报错
信息如下:
&Iacute;&oslash;&Acirc;&ccedil;&frac12;&Oacute;&iquest;&Uacute;:
&Iacute;&oslash;&Acirc;&ccedil;&micro;&Oslash;&Ouml;·:10.40.96.0
&Iacute;&oslash;&Acirc;&ccedil;&Ntilde;&Uacute;&Acirc;&euml;:255.255.255.0
pcap_open_live: Bad file number
bpf_load: genmajor failed: Error 0

我的系统是AIX
作者: houhulou    时间: 2009-06-11 11:56
顶一个
寻人启示
寻高人启示
作者: houhulou    时间: 2009-06-11 13:43
再顶
作者: 雨过白鹭洲    时间: 2009-06-11 14:18
虽然我不知道pcap_open_live是干什么用的,不过google一下一大把(仍然看不懂)

楼主何不自己解决?
作者: houhulou    时间: 2009-06-11 14:55
总算有点眉目了, 可能是权限不够 不过我现在没有管理员权限,不能试
作者: yikaikai    时间: 2009-06-11 16:19
没管理员权限那没办法了。
作者: mw3943    时间: 2009-07-06 21:04
提示: 作者被禁止或删除 内容自动屏蔽




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2