winxp系统.如下: char      m_AdapterList[Max_Num_Adapter][1024]; //存放网卡名称 for(DWORD dw=0; dw<Max_Num_Adapter; 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<m_dwAdaptCount;i++)
TRACE("\n%d- %s\n",i+1,m_AdapterList[i]);
TRACE("\n");
AfxMessageBox("open the net card");

解决方案 »

  1.   

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

  2.   

    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.  
      

  3.   

    这是我的测试程序:#pragma comment(lib,"Packet.lib")#include <Packet32.h>
    #include <windows.h>
    #include <stdio.h>int main()
    {
    char AdapterName[8192]; 
    ULONG AdapterLength = sizeof(AdapterName); ZeroMemory(AdapterName,sizeof(AdapterName));
    printf("Get net card name:\n");
    if(PacketGetAdapterNames(AdapterName,&AdapterLength)==FALSE)
    {
    printf("取网卡名称错误\n");
    return -1;
    }
    printf("%s\n",AdapterName);
    return 0;
    }
    -------------------
    结果:
    Get net card name:
    \Device\NPF_GenericNdisWanAdapter
      

  4.   

    重装WinPcap,注意版本,我用的是WinPcap_3_0,高版本好象在我的机子上也有问题,注意版本和Packet32.h匹配