您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> VC/MFC >> winpcap中,为什么我的PacketGetAdapterNames函数得到的Adapter名称总为空?

winpcap中,为什么我的PacketGetAdapterNames函数得到的Adapter名称总为空?

来源:网络整理     时间:2016/8/8 22:32:41     关键词:

关于网友提出的“ winpcap中,为什么我的PacketGetAdapterNames函数得到的Adapter名称总为空?”问题疑问,本网通过在网上对“ winpcap中,为什么我的PacketGetAdapterNames函数得到的Adapter名称总为空?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: winpcap中,为什么我的PacketGetAdapterNames函数得到的Adapter名称总为空?
描述:

winxp系统.如下:
char      m_AdapterList[Max_Num_Adapter][1024]; //存放网卡名称
for(DWORD dw=0; dw<>
{
ZeroMemory(m_AdapterList[dw],sizeof(m_AdapterList[dw]));
}
DWORD m_dwAdaptCount=0;
char AdapterName[8192]; 
//WCHAR AdapterName[8192]; 
ULONG AdapterLength = sizeof(AdapterName);
ZeroMemory(AdapterName,sizeof(AdapterName));
AfxMessageBox("Get net card name");
if(PacketGetAdapterNames(AdapterName,&AdapterLength)==FALSE)
{
AfxMessageBox("取网卡名称错误\n");
return FALSE;
}
//AfxMessageBox(AdapterName);
//AfxMessageBox(AdapterName);
char *temp,*temp1;
temp=AdapterName;
temp1=AdapterName;
DWORD i=0;
AfxMessageBox("open the net card");
//AfxMessageBox(AdapterName);
while ((*temp!='\0')||(*(temp-1)!='\0'))
{
if (*temp=='\0') 
{
memcpy(m_AdapterList[i],temp1,temp-temp1);
temp1=temp+1;
i++;
}
temp++;
}
AfxMessageBox("open the net card");
  
m_dwAdaptCount = i;
for (i=0;i<>
TRACE("\n%d- %s\n",i+1,m_AdapterList[i]);
TRACE("\n");
AfxMessageBox("open the net card");


解决方案1:

BOOLEAN PacketGetAdapterNames  (  PTSTR  pStr,  
  PULONG  BufferSize 
 )   
 
   Retrieve the list of available network adapters and their description. 
Parameters:
 pStr  User allocated string that will be filled with the names of the adapters.  
 BufferSize  Length of the buffer pointed by pStr. If the function fails, this variable contains the number of bytes that are needed to contain the adapter list.  
Returns:
If the function succeeds, the return value is nonzero. If the return value is zero, BufferSize contains the number of bytes that are needed to contain the adapter list.
Usually, this is the first function that should be used to communicate with the driver. It returns the names of the adapters installed on the system and supported by WinPcap. After the names of the adapters, pStr contains a string that describes each of them.
After a call to PacketGetAdapterNames pStr contains, in succession:
a variable number of ASCII strings, each with the names of an adapter, separated by a "\0"
a double "\0"
a number of ASCII strings, each with the description of an adapter, separated by a "\0". The number of descriptions is the same of the one of names. The fisrt description corresponds to the first name, and so on.
a double "\0". 
Definition at line 2028 of file Packet32.c. 
 

解决方案2:

可能是因为我的本子是G级网卡的原因吧

解决方案3:

这个问题我也间遇见过,我曾经运行一个用pcap包开发的demo,居然连我的网卡都找不到


以上介绍了“ winpcap中,为什么我的PacketGetAdapterNames函数得到的Adapter名称总为空?”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3153127.html

相关图片

相关文章