LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 662|回复: 0

请问这个网络程序哪里的错?!!!

[复制链接]
发表于 2006-11-24 09:35:25 | 显示全部楼层 |阅读模式
主函数里调用test_tcp()
void
test_tcp()
{
    .......
    tcp_read(ipt);    //ipt是全局struct ip 型指针
  ........;
}

void tcp_read(struct ip        *ipx)
{
        int                                        len;
        char                                *ptr,buf[255];
        struct ether_header        *eptr;
        struct tcphdr                *tcphead;
        struct my_sql                mysql;
        struct ip                *tcp_check(char *,int);
                int        i=0;
        for ( ; ; ) {
        ptr = next_pcap(&len);    //返回下一个捕获数据包的地址       
        printf("ptr=%p\n",ptr);
        pcap_close(pd);
                switch (datalink) {
        case DLT_NULL:        /* loopback header = 4 bytes */
                     tcp_check(ptr+4,len-4);break;
        case DLT_EN10MB:
                      eptr = (struct ether_header *) ptr;
                      if (ntohs(eptr->ether_type) != ETHERTYPE_IP){
                       perror("Ethernet type:");
                        exit }
                      int  i;
                      char *hwadd=eptr->ether_shost;

                      for(i=0;i<5;++i)
                          printf("%2x:",hwadd);
                           printf("%2x\n",hwadd);

                  ipx=tcp_check(ptr+14,len-14); //校验ip头部
                               printf("ipx%p\n",ipx);
                           inet_ntop(AF_INET,&(ipx->ip_src),buf,sizeof(buf));
                        printf("ip_src: %s\n",buf);
                           inet_ntop(AF_INET,&(ipx->ip_dst),buf,sizeof(buf));
                                                printf("dst: %s\n",buf);
                  tcphead=(struct tcphdr *)(ptr+4*ipx->ip_hl);
                  printf("tcphead%p\n",tcphead);
                   printf("srcport%d\n",ntohs(tcphead->source));
                   printf("dstport%d\n",ntohs(tcphead->dest));
                   goto lable;
               default:
                        perror("unsupported datalink:");
                        exit(1);
                }
        }
      lable:
        printf("lable\n");
}


调用tcp_read()返回有段错误,怎么回事??
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表