Windows 용 WinPcap 4.1.1 라이브러리를 실험하고 있지만 라이브러리와 함께 제공되는 예제 소스를 컴파일 할 수 없습니다.Winpcap MinGW 컴파일 오류
나는 이러한 오류를 받고 있어요 :
'PCAP_OPENFLAG_PROMISCUOUS'선언되지 않은 (이 기능에서 처음 사용)
'PCAP_SRC_IF_STRING'
그리고 무리를 (먼저이 기능에 사용) 선언되지 않은 경고 :
암시 적으로 'localtime_s'함수 선언
기능의 mplicit 선언 'pcap_findalldevs_ex'기능 'pcap_open'기능의
암시 적 선언의
암시 적 선언 'scanf_s'
나는 비트를 봤 내가 줄 #define HAVE_REMOTE
을 추가해야합니다 발견 (나는 어떤이 없습니다 단서는 할)하지만이 같은 더 많은 오류를 초래하는 일 :
정의되지 않은 참조 'pcap_findalldevs_ex'
UNDEFINE에 'pcap_open'
정의되지 않은 참조에 d 'localtime_s'에 대한 참조
"pcap.h"
이 포함되어있는 것 같습니다 (eclipse는 오류를 포함하여보고하지 않습니다). * .lib 파일을 MinGW/lib 디렉터리로 복사하고 Path and Symbols->Library Paths
(이클립스 프로젝트 속성)에이 경로를 설정하십시오.
다음에 시도 할 내용이 없습니다. 어떤 아이디어라도 환영합니다.
#include "pcap.h"
/* prototype of the packet handler */
void packet_handler(u_char *param, const struct pcap_pkthdr *header,
const u_char *pkt_data);
int main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i=0;
pcap_t *adhandle;
char errbuf[PCAP_ERRBUF_SIZE];
/* Retrieve the device list on the local machine */
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
exit(1);
}
/* Print the list */
for(d=alldevs; d; d=d->next)
{
printf("%d. %s", ++i, d->name);
if (d->description)
printf(" (%s)\n", d->description);
else
printf(" (No description available)\n");
}
if(i==0)
{
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
return -1;
}
printf("Enter the interface number (1-%d):",i);
scanf_s("%d", &inum);
if(inum < 1 || inum > i)
{
printf("\nInterface number out of range.\n");
/* Free the device list */
pcap_freealldevs(alldevs);
return -1;
}
/* Jump to the selected adapter */
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
/* Open the device */
if ((adhandle= pcap_open(d->name, // name of the device
65536, // portion of the packet to capture
// 65536 guarantees that the whole packet will be captured
on all the link layers
PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
1000, // read timeout
NULL, // authentication on the remote machine
errbuf // error buffer
)) == NULL)
{
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by
WinPcap\n", d->name);
/* Free the device list */
pcap_freealldevs(alldevs);
return -1;
}
printf("\nlistening on %s...\n", d->description);
/* At this point, we don't need any more the device list. Free it */
pcap_freealldevs(alldevs);
/* start the capture */
pcap_loop(adhandle, 0, packet_handler, NULL);
return 0;
}
/* Callback function invoked by libpcap for every incoming packet */
void packet_handler(u_char *param, const struct pcap_pkthdr *header,
const u_char *pkt_data)
{
struct tm ltime;
char timestr[16];
time_t local_tv_sec;
/*
* unused variables
*/
(VOID)(param);
(VOID)(pkt_data);
/* convert the timestamp to readable format */
local_tv_sec = header->ts.tv_sec;
localtime_s(<ime, &local_tv_sec);
strftime(timestr, sizeof timestr, "%H:%M:%S", <ime);
printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);
}
"정의되지 않은 참조"메시지는 당신이'libpcap'과 링크하지 않는다는 것을 의미합니다. 'pcap-config --libs'는 링크에 필요한 플래그를줍니다. http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man1/pcap-config.1.html –
@Alok 당신이 옳다고 생각합니다. 저는 라이브러리를 연결하는 대신 라이브러리 디렉토리를 설정했습니다. . 'wpcap.lib'와'Packet.lib'을 링크 한 후에는'localtime_s'와'scanf_s' 함수에 대해서 정의되지 않은 참조 에러가 2 개 밖에 없습니다. 이 기능들은 어디에 위치해 있습니까? –