mysql winpcap_Windows下配置使用WinPcap

//demo1.cpp : 定义控制台应用程序的入口点。//#include"stdafx.h"#include#include#include

//the macro HAVE_REMOTE must define before

#ifndef HAVE_REMOTE#define HAVE_REMOTE

#endif#include#include

#pragma comment(lib, "ws2_32.lib")

#pragma comment(lib, "packet.lib")

#pragma comment(lib, "wpcap.lib")

using namespacestd;/************************************************************************/

/*platfor win7 x64

* version of winpcap: 4.1.3

* version of developping tool: 4.1.2

* notes: The local/remote machine must install the Winpcap

and

Start the server(go to the install path and double click rpcapd.exe).

You must look out that the DEFAULT PORT is 2002.

If you use another port, the pcap_findalldevs_ex function return -1

and the erro information in errbuf is

[Is the server properly installed on XXX.XXX.XXX.XXX?

connect() failed: 由于目标计算机积极拒绝,无法连接。 (code 10061) ]

/************************************************************************/

int _tmain(int argc, _TCHAR*argv[])

{//char* pSource = "rpcap://";//localhost

char* pSource = "rpcap://XXX.XXX.XXX.XXX:2002"; //remote PC

struct pcap_rmtauth stAuth = {0};

stAuth.type=RPCAP_RMTAUTH_PWD;

stAuth.username= "xxxxx";

stAuth.password= "xxxxxxxxxxx";

pcap_if_t* pPcapIft =NULL;char chBuffer[PCAP_BUF_SIZE] = {0};int nCount = 0;if (0 == pcap_findalldevs_ex(pSource, &stAuth, &pPcapIft, chBuffer))

{for (pcap_if_t* pcap = pPcapIft; pcap != NULL; pcap = pcap->next)

{

cout<< endl << "----------- device"

<< nCount ++

<< "-------------" <

cout<< pcap->name<description<flags<

cout<< "-------- Output details below -----" <addresses;

pAddr!= NULL; pAddr = pAddr->next)

{struct sockaddr_in* psockAddr = (struct sockaddr_in*)(pAddr->addr);if (NULL !=psockAddr)

{

cout<< "IP is" << inet_ntoa(psockAddr->sin_addr) <

cout<< "Port is" << ntohs(psockAddr->sin_port) <

cout<< "Family is" << psockAddr->sin_family <

cout<< "-------" <

}

psockAddr= (struct sockaddr_in*)(pAddr->dstaddr);if (NULL !=psockAddr)

{

cout<< "Mask IP is" << inet_ntoa(psockAddr->sin_addr) <

cout<< "Mask Port is" << ntohs(psockAddr->sin_port) <

cout<< "Mask Family is" << psockAddr->sin_family <

cout<< "-------" <

}

psockAddr= (struct sockaddr_in*)(pAddr->broadaddr);if (NULL !=psockAddr)

{

cout<< "Broadcast IP is" << inet_ntoa(psockAddr->sin_addr) <

cout<< "Broadcast Port is" << ntohs(psockAddr->sin_port) <

cout<< "Broadcast Family is" << psockAddr->sin_family <

}

psockAddr= (struct sockaddr_in*)(pAddr->dstaddr);if (NULL !=psockAddr)

{

cout<< "P2P IP is" << inet_ntoa(psockAddr->sin_addr) <

cout<< "P2P Port is" << ntohs(psockAddr->sin_port) <

cout<< "P2P Family is" << psockAddr->sin_family <

}

cout<< "---------------------------------------" << endl << endl <

}//for

}//for

pcap_freealldevs(pPcapIft);

}//if

else{

cerr<< endl << "Last error is" << GetLastError() <

}

system("pause");return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值