是不是出现很多undefined的错误?这个程序里面有些函数是unix系统提供的API.在Windows下没有这样的函数。你要找出这些函数,分析它们的功能,用相似的Windows Api来代替,或者自己写这些函数。

解决方案 »

  1.   

    它有个ioctl(sock, SIOCSIFFLAGS, &ifr)函数-----来 set the flags on the interface。
    //把网卡置于混杂模式
    我查了一下以为在 "afxsock.h"中现在再看看好象不是它(同名不同功能)。
    我不知道在vc中是什么。来达到同样的功能。
      

  2.   

    //
    #include "winsock2.h"
    #include "stdio.h"
    #include "header.h"
    #include "string.h"
    #pragma comment (lib , "ws2_32.lib")//1. 把网卡置于混杂模式
    //2. 捕获数据包
    //3. 分析数据包
    #define INTERFACE "eth0"
    int Open_Raw_Socker();
    int Set_Promisc(char *my_interface,int sock);int main()
    {
       int sock, bytes_recieved, fromlen;
       char buffer[65535];
       struct sockaddr_in from;
       struct ip *ip;
       struct tcp *tcp;
       sock =Open_Raw_Socker();
       Set_Promisc(INTERFACE, sock);
       while(1)
       {
         fromlen = sizeof from;
         bytes_recieved = recvfrom(sock, buffer, sizeof buffer, 0, (struct sockaddr *)&from, &fromlen);
         printf("\nBytes received ::: %5d\n",bytes_recieved);
         printf("Source address ::: %s\n",inet_ntoa(from.sin_addr));
         ip = (struct ip *)buffer;
         /*See if this is a TCP packet*/
         if(ip->ip_protocol == 6)
     {
           printf("IP header length ::: %d\n",ip->ip_length);
           printf("Protocol ::: %d\n",ip->ip_protocol);
           tcp = (struct tcp *)(buffer + (4*ip->ip_length));
           printf("Source port ::: %d\n",ntohs(tcp->tcp_source_port));
           printf("Dest port ::: %d\n",ntohs(tcp->tcp_dest_port));
     }
       }
       return 1;
    }int Open_Raw_Socket()
    {
     int sock;
         if((sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP)) < 0) 
     {
          /*Then the socket was not created properly and must die*/
           perror("The raw socket was not created");
           exit(0);
     };
         return(sock);
    }int Set_Promisc(char *my_interface, int sock )
    {
      struct ifreq ifr;
      strncpy(ifr.ifr_name,my_interface,strlen(my_interface)+1);
      if((ioctl(sock, SIOCGIFFLAGS, &ifr) == -1))
      {
      /*Could not retrieve flags for the interface*/
      perror("Could not retrive flags for the interface");
      exit(0);
      }
      printf("THE interface is ::: %s \n",my_interface);
      perror("Retrieved flags from interface successfully");
      ifr.ifr_flags |= IFF_PROMISC;
      if (ioctl(sock, SIOCSIFFLAGS, &ifr) == -1 ) //ioctl我不知道怎么改
      {
       /*Could not set the flags on the interface */
        perror("Could not set the PROMISC flag:"); 
        exit(0);
      }
      printf(" Setting interface :::%s ::: to promisc",my_interface);
      return(0);

      

  3.   


    我在编com的服务端。加以下语句,他编译不通过。(exectuable)
     #include"winsock2.h"
     char FAR *hname=NULL;
     int h=gethostname((char FAR *)hname,sizeof(hname));
      

  4.   

    从unix到win32
    使用DeviceIOControl代替ioctl。
    祝你好运。
      

  5.   

    musicdancer(饭盆)  :
            我在网上找了NT 下的SNIFF ,同样谢谢你等会儿给你分。
    我还想问 我是照CSDN上的开发文挡中的 实战COM(04)----创建一个DCOM应用.htm
    1.
     我在编com的服务端。加以下语句,他编译不通过。(exectuable)不加可以。
      #include"winsock2.h"
      char FAR *hname=NULL;
      int h=gethostname((char FAR *)hname,sizeof(hname));
    2.我编的com在自己的机子上能连到服务端返回我想要的(原来),
      但是当我把服务端拷到其他的机子上, 我自己机子上的服务端也配置(dcomcnfg)好了,
      执行时create com failed。我这里是(NT 4。0)
      然后,我自己机子上的服务端恢复成默认,连原来可以的现在也不行了。
      

  6.   

    我想可能是我没有配置好。谁能说一下,服务端,和客户端分别怎么配DCOM。nt4.0