返回首页

我做VB6的Winsock程序客户端 - 服务器。我想发送数据包WINPCAP没有连接的服务器和客户端服务器连接。我建立从WinPcap的客户VB6,但服务器VB6相同的数据包的数据包不能接收从WinPcap的包

回答

评论会员:安德鲁布鲁克 时间:2012/02/06
服务器是如何成立?我怀疑这是一个TCP连接。

一个典型的客户机/服务器系统将使用传输控制协议(TCP)。这就要求客户端发送一个连接请求(如SYN),服务器接受连接(确认)和客户承认公认的连接(称为一个SYN的ACK)答辩。只有这样,你的程序看到数据。这也应该是干净关机(这是不absolutly需要的协议,但应编码)。 TCP连接时允许错误处理数据包丢失,这使得它一个很好的选择。

另一种方法是用户数据报协议(UDP)这是一个无状态的连接。您可以将数据发送到服务器的IP地址和端口和服务器程序接收这个数据。 UDP没有任何连接状态,因此并不能保证成功交付的数据,这是留给你,如果你不在乎。这通常是使用像Skype,你不希望有一个包等待被怨恨,因为这会增加延迟到您的聊天的东西,视频只是跳过位,而不是

PCAP(或Windows WINPCAP)发送原始数据包时,它仅发送单一的数据包,而不是一个连接设置。这是一个UDP程序会做什么。

你可以先建立一个连接,然后从PCAP发送数据(必须使用相同的源IP和端口以及同一目的地的IP和端口这工作)。如果它是一个真正的客户机/服务器的情况,我会强烈建议反对使用UDP,如果你真的需要,它是可能的伪造SYN,SYN ACK数据包PCAP

如果你是陌生与网络也许得到Wireshark的副本,并嗅出一些数据。它不会工作在环回地址芹苴,它只会看到发送到其他计算机上的数据
评论会员:te2531 时间:2012/02/06
TCP需要连接之前发送数据
可以发送无法连接?
#define HAVE_REMOTE

#include <pcap.h>

int main()

{

    pcap_if_t      * allAdapters;

    pcap_if_t       * adapter;

    pcap_t       * adapterHandle;

    u_char         packet[ 58 ];

    char             errorBuffer[ PCAP_ERRBUF_SIZE ];

 

    // retrieve the adapters from the computer

    if( pcap_findalldevs_ex( PCAP_SRC_IF_STRING, NULL, 

                &allAdapters, errorBuffer ) == -1 )

    {

        fprintf( stderr, "Error in pcap_findalldevs_ex function: %s\n", 

                 errorBuffer );

        return -1;

    }

 

    // if there are no adapters, print an error

    if( allAdapters == NULL )

    {

    printf( "\nNo adapters found! Make sure WinPcap is installed.\n" );

        return 0;

    }

 

    // print the list of adapters along with basic information about an adapter

    int crtAdapter = 0;

    for( adapter = allAdapters; adapter != NULL; adapter = adapter->next)

    {

    printf( "\n%d.%s ", ++crtAdapter, adapter->name );

    printf( "-- %s\n", adapter->description );

    }

 

    printf( "\n" );

 

    int adapterNumber;

 

    printf( "Enter the adapter number between 1 and %d:", crtAdapter );

    scanf( "%d", &adapterNumber );

    

    if( adapterNumber < 1 || adapterNumber > crtAdapter )

    {

        printf( "\nAdapter number out of range.\n" );

 

        // Free the adapter list

        pcap_freealldevs( allAdapters );

 

        return -1;

    }

    

    // parse the list until we reach the desired adapter

    adapter = allAdapters;

    for( crtAdapter = 0; crtAdapter < adapterNumber - 1; crtAdapter++ )

        adapter = adapter->next;

 

    // open the adapter

    adapterHandle = pcap_open( adapter->name, // name of the adapter

                               65536,         // portion of the packet to capture

                                              // 65536 guarantees that the whole 

                                              // packet will be captured

                               PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode

                               1000,             // read timeout - 1 millisecond

                               NULL,          // authentication on the remote machine

                               errorBuffer    // error buffer

                              );

 

    if( adapterHandle == NULL )

    {

        fprintf( stderr, "\nUnable to open the adapter\n", adapter->name );

 

        // Free the adapter list

        pcap_freealldevs( allAdapters );

 

        return -1;

    }

    

    // free the adapter list

    pcap_freealldevs( allAdapters );

 



    // this is the most important part of the application

    // here we send the packet



    // first we create the packet



    // set mac destination address to 01 : 01 : 01 : 01 : 01 : 01

    packet[0] = 0x00;

    packet[1] = 0x23;

    packet[2] = 0x5a;

    packet[3] = 0x99;

    packet[4] = 0x4f;

    packet[5] = 0xe2;

    

    // set mac source address to 02 : 02 : 02 : 02 : 02 : 02

    packet[6]  = 0x00;

    packet[7]  = 0x13;

    packet[8]  = 0x8f;

    packet[9]  = 0x83;

    packet[10] = 0xa9;

    packet[11] = 0xb3;

    

    // set the rest of the packet



    packet[12]  = 0x08;

    packet[13]  = 0x00;

    

    packet[14]  = 0x45;

    packet[15]  = 0x00;

    packet[16]  = 0x00;

    packet[17]  = 0x2c;

    

    packet[18]  = 0x00;

    packet[19]  = 0xfb;

    

    packet[20]  = 0x40;

    packet[21]  = 0x00;

    packet[22]  = 0x40;

    packet[23]  = 0x06;

    

    packet[24]  = 0xb6;

    packet[25]  = 0x7d;

    

    packet[26]  = 0xc0;

    packet[27]  = 0xa8;

    packet[28]  = 0x01;

    packet[29]  = 0x01;

    packet[30]  = 0xc0;

    packet[31]  = 0xa8;

    packet[32]  = 0x01;

    packet[33]  = 0x02;

    

    packet[34]  = 0x04;

    packet[35]  = 0x15;

    packet[36]  = 0x00;

    packet[37]  = 0xa6;

    

    packet[38]  = 0x4d;

    packet[39]  = 0x62;

    packet[40]  = 0xfe;

    packet[41]  = 0x09;

    

    packet[42]  = 0x17;

    packet[43]  = 0x46;

    packet[44]  = 0x60;

    packet[45]  = 0x5c;

    

    packet[46]  = 0x50;

    packet[47]  = 0x18;

    packet[48]  = 0xff;

    packet[49]  = 0xff;

    packet[50]  = 0x7d;

    packet[51]  = 0x15;

    packet[52]  = 0x00;

    packet[53]  = 0x00;

    

    packet[54]  = 0x74;

    packet[55]  = 0x65;

    packet[56]  = 0x73;

    packet[57]  = 0x74;

    

    // send the packet

    if( pcap_sendpacket( adapterHandle, // the adapter handle

             packet, // the packet

             58 // the length of the packet

               ) != 0 )

    {

        fprintf( stderr,"\nError sending the packet: \n", pcap_geterr( adapterHandle ) );

        return -1;

    }

 



    system( "PAUSE" );

    return 0;

 

}