2015-05-29 3 views
1

Ниже приведен код для получения MAC-адресов от моего адаптера AirPcap. Но я сталкиваюсь с проблемами при выполнении программы: Пожалуйста, помогите мне в разрешении этой ошибки.Невозможно скомпилировать программу PCAP в Visual studio

#include <stdio.h> 
#include <conio.h> 
#include "packet32.h" 
#include <ntddndis.h> 
#include "StdAfx.h" 
#define Max_Num_Adapter 10 
char  AdapterList[Max_Num_Adapter][1024]; 

int main() 
{ 
    LPADAPTER lpAdapter = 0; 
    int   i; 
    DWORD  dwErrorCode; 
    WCHAR  AdapterName[8192]; 
    WCHAR  *temp,*temp1; 
    int   AdapterNum=0,Open; 
    ULONG  AdapterLength; 
    PPACKET_OID_DATA OidData; 
    BOOLEAN  Status; 

    // 
    // Obtain the name of the adapters installed on this machine 
    // 

    printf("Packet.dll test application. Library version:%s\n", PacketGetVersion()); 

    printf("Adapters installed:\n"); 
    i=0;  

    AdapterLength = sizeof(AdapterName); 

    if(PacketGetAdapterNames(AdapterName,&AdapterLength)==FALSE){ 
     printf("Unable to retrieve the list of the adapters!\n"); 
     return -1; 
    } 
    temp=AdapterName; 
    temp1=AdapterName; 

    while ((*temp!='\0')||(*(temp-1)!='\0')) 
    { 
     if (*temp=='\0') 
     { 
      memcpy(AdapterList[i],temp1,temp-temp1); 
      temp1=temp+1; 
      i++; 
     } 
     temp++; 
    } 

    AdapterNum=i; 
    for (i=0;i<AdapterNum;i++) 
     printf("\n%d- %s\n",i+1,AdapterList[i]); 
    printf("\n"); 


    do 
    { 
     printf("Select the number of the adapter to open : "); 
     scanf_s("%d",&Open); 
     if (Open>AdapterNum) printf("\nThe number must be smaller than %d",AdapterNum); 
    } while (Open>AdapterNum); 


    // 
    // Open the selected adapter 
    // 

    lpAdapter = PacketOpenAdapter(AdapterList[Open-1]); 

    if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE)) 
    { 
     dwErrorCode=GetLastError(); 
     printf("Unable to open the adapter, Error Code : %lx\n",dwErrorCode); 

     return -1; 
    } 

    // 
    // Allocate a buffer to get the MAC adress 
    // 

    OidData = (PPACKET_OID_DATA)malloc(6 + sizeof(PACKET_OID_DATA)); 
    if (OidData == NULL) 
    { 
     printf("error allocating memory!\n"); 
     PacketCloseAdapter(lpAdapter); 
     return -1; 
    } 

    // 
    // Retrieve the adapter MAC querying the NIC driver 
    // 

    OidData->Oid = OID_802_3_CURRENT_ADDRESS; 

    OidData->Length = 6; 
    ZeroMemory(OidData->Data, 6); 

    Status = PacketRequest(lpAdapter, FALSE, OidData); 
    if(Status) 
    { 
     printf("The MAC address of the adapter is %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", 
      (OidData->Data)[0], 
      (OidData->Data)[1], 
      (OidData->Data)[2], 
      (OidData->Data)[3], 
      (OidData->Data)[4], 
      (OidData->Data)[5]); 
    } 
    else 
    { 
     printf("error retrieving the MAC address of the adapter!\n"); 
    } 

    free(OidData); 
    PacketCloseAdapter(lpAdapter); 
    return (0); 
} 

Ниже приведены ошибки:

1>------ Build started: Project: qqq, Configuration: Release Win32 ------ 
1>Build started 5/29/2015 3:10:00 PM. 
1>InitializeBuildStatus: 
1> Touching "Release\qqq.unsuccessfulbuild". 
1>ClCompile: 
1> All outputs are up-to-date. 
1> ppp.cpp 
1>ppp.cpp(35): warning C4627: '#include <conio.h>': skipped when looking for precompiled header use 
1>   Add directive to 'StdAfx.h' or rebuild precompiled header 
1>ppp.cpp(36): warning C4627: '#include "packet32.h"': skipped when looking for precompiled header use 
1>   Add directive to 'StdAfx.h' or rebuild precompiled header 
1>ppp.cpp(37): warning C4627: '#include <ntddndis.h>': skipped when looking for precompiled header use 
1>   Add directive to 'StdAfx.h' or rebuild precompiled header 
1>ppp.cpp(44): error C2065: 'LPADAPTER' : undeclared identifier 
1>ppp.cpp(44): error C2146: syntax error : missing ';' before identifier 'lpAdapter' 
1>ppp.cpp(44): error C2065: 'lpAdapter' : undeclared identifier 
1>ppp.cpp(46): error C2065: 'DWORD' : undeclared identifier 
1>ppp.cpp(46): error C2146: syntax error : missing ';' before identifier 'dwErrorCode' 
1>ppp.cpp(46): error C2065: 'dwErrorCode' : undeclared identifier 
1>ppp.cpp(47): error C2065: 'WCHAR' : undeclared identifier 
1>ppp.cpp(47): error C2146: syntax error : missing ';' before identifier 'AdapterName' 
1>ppp.cpp(47): error C2065: 'AdapterName' : undeclared identifier 
1>ppp.cpp(48): error C2065: 'WCHAR' : undeclared identifier 
1>ppp.cpp(48): error C2065: 'temp' : undeclared identifier 
1>ppp.cpp(48): error C2065: 'temp1' : undeclared identifier 
1>ppp.cpp(50): error C2065: 'ULONG' : undeclared identifier 
1>ppp.cpp(50): error C2146: syntax error : missing ';' before identifier 'AdapterLength' 
1>ppp.cpp(50): error C2065: 'AdapterLength' : undeclared identifier 
1>ppp.cpp(51): error C2065: 'PPACKET_OID_DATA' : undeclared identifier 
1>ppp.cpp(51): error C2146: syntax error : missing ';' before identifier 'OidData' 
1>ppp.cpp(51): error C2065: 'OidData' : undeclared identifier 
1>ppp.cpp(52): error C2065: 'BOOLEAN' : undeclared identifier 
1>ppp.cpp(52): error C2146: syntax error : missing ';' before identifier 'Status' 
1>ppp.cpp(52): error C2065: 'Status' : undeclared identifier 
1>ppp.cpp(58): error C3861: 'PacketGetVersion': identifier not found 
1>ppp.cpp(63): error C2065: 'AdapterLength' : undeclared identifier 
1>ppp.cpp(63): error C2065: 'AdapterName' : undeclared identifier 
1>ppp.cpp(63): error C2070: ''unknown-type'': illegal sizeof operand 
1>ppp.cpp(65): error C2065: 'AdapterName' : undeclared identifier 
1>ppp.cpp(65): error C2065: 'AdapterLength' : undeclared identifier 
1>ppp.cpp(65): error C2065: 'FALSE' : undeclared identifier 
1>ppp.cpp(65): error C3861: 'PacketGetAdapterNames': identifier not found 
1>ppp.cpp(69): error C2065: 'temp' : undeclared identifier 
1>ppp.cpp(69): error C2065: 'AdapterName' : undeclared identifier 
1>ppp.cpp(70): error C2065: 'temp1' : undeclared identifier 
1>ppp.cpp(70): error C2065: 'AdapterName' : undeclared identifier 
1>ppp.cpp(72): error C2065: 'temp' : undeclared identifier 
1>ppp.cpp(72): error C2065: 'temp' : undeclared identifier 
1>ppp.cpp(72): fatal error C1903: unable to recover from previous error(s); stopping compilation 
1> qqq.cpp 
1>qqq.cpp(36): warning C4627: '#include <conio.h>': skipped when looking for precompiled header use 
1>   Add directive to 'StdAfx.h' or rebuild precompiled header 
1>qqq.cpp(155): error C3861: '_kbhit': identifier not found 
1>qqq.cpp(197): error C2440: '=' : cannot convert from 'PVOID' to 'char *' 
1>   Conversion from 'void*' to pointer to non-'void' requires an explicit cast 
1>qqq.cpp(202): error C3861: '_kbhit': identifier not found 
1> 
1>Build FAILED. 
1> 
1>Time Elapsed 00:00:00.33 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

Я облицовочная необъявленный вопрос Identifier. Пожалуйста, помогите мне в решении этой проблемы.

+1

Ясный случай RTFM: LNK2001? https://msdn.microsoft.com/it-it/library/f6xx1b1z.aspx – Luca

+0

Ваше изменение изменило ваше сообщение на совершенно другой вопрос. Я вернул редактирование, если у вас есть новая проблема, отправьте вопрос _new_. –

ответ

0

stdafx.h должен быть включен перед всеми другими заголовками. Это требование компилятора VC++. Если stdafx.h включен после других файлов заголовков, эти файлы заголовков будут пропущены компилятором. В этом случае он не может разрешить символы, объявленные в этих заголовках.

+0

Это сработало. Спасибо. Но новые ошибки заполнились. Не могли бы вы мне помочь. Устаревшие ошибки. – sai

Смежные вопросы