本文整理汇总了C++中pcap_open函数的典型用法代码示例。如果您正苦于以下问题:C++ pcap_open函数的具体用法?C++ pcap_open怎么用?C++ pcap_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pcap_open函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main (void)
{
int fd;
/* Create PCAP file */
assert((fd = pcap_create(test_path, LINKTYPE_EN10MB)) > 0);
/* Write payload */
assert(test_pcap_write(fd, icmp_dns, sizeof(icmp_dns)) == 0);
assert(pcap_close(fd) == 0);
assert((fd = pcap_open(test_path, O_RDONLY)) > 0);
assert(pcap_has_packets(fd));
assert(pcap_close(fd) == 0);
assert((fd = pcap_open(test_path, O_RDWR | O_APPEND)) > 0);
/* Write payload */
assert(test_pcap_write(fd, icmp_dns, sizeof(icmp_dns)) == 0);
assert(pcap_close(fd) == 0);
pcap_destroy(fd, test_path);
return (EXIT_SUCCESS);
}
开发者ID:eroullit,项目名称:net-toolbox,代码行数:29,代码来源:test_pcap.c
示例2: test_pcap
void test_pcap(void)
{
rdpPcap* pcap;
pcap_record record;
test_packet packets[3];
packets[0].data = test_packet_1;
packets[0].length = sizeof(test_packet_1);
packets[1].data = test_packet_2;
packets[1].length = sizeof(test_packet_2);
packets[2].data = test_packet_3;
packets[2].length = sizeof(test_packet_3);
pcap = pcap_open("/tmp/test.pcap", true);
pcap_add_record(pcap, test_packet_1, sizeof(test_packet_1));
pcap_flush(pcap);
pcap_add_record(pcap, test_packet_2, sizeof(test_packet_2));
pcap_flush(pcap);
pcap_add_record(pcap, test_packet_3, sizeof(test_packet_3));
pcap_close(pcap);
pcap = pcap_open("/tmp/test.pcap", false);
int i = 0;
while (pcap_has_next_record(pcap))
{
pcap_get_next_record(pcap, &record);
CU_ASSERT(record.length == packets[i].length)
i++;
}
CU_ASSERT(i == 3);
pcap_close(pcap);
}
开发者ID:ArthurGodoy,项目名称:FreeRDP,代码行数:35,代码来源:test_pcap.c
示例3: freerdp_connect
boolean freerdp_connect(freerdp* instance)
{
rdpRdp* rdp;
boolean status;
rdp = instance->context->rdp;
IFCALL(instance->PreConnect, instance);
status = rdp_client_connect(rdp);
if (status)
{
if (instance->settings->dump_rfx)
{
instance->update->pcap_rfx = pcap_open(instance->settings->dump_rfx_file, True);
if (instance->update->pcap_rfx)
instance->update->dump_rfx = True;
}
IFCALL(instance->PostConnect, instance);
if (instance->settings->play_rfx)
{
STREAM* s;
rdpUpdate* update;
pcap_record record;
s = stream_new(1024);
instance->update->pcap_rfx = pcap_open(instance->settings->play_rfx_file, False);
if (instance->update->pcap_rfx)
instance->update->play_rfx = True;
update = instance->update;
while (instance->update->play_rfx && pcap_has_next_record(update->pcap_rfx))
{
pcap_get_next_record_header(update->pcap_rfx, &record);
s->data = xrealloc(s->data, record.length);
record.data = s->data;
s->size = record.length;
pcap_get_next_record_content(update->pcap_rfx, &record);
stream_set_pos(s, 0);
update->BeginPaint(update);
update_recv_surfcmds(update, s->size, s);
update->EndPaint(update);
}
xfree(s->data);
return True;
}
}
return status;
}
开发者ID:zzzhou,项目名称:FreeRDP,代码行数:57,代码来源:freerdp.c
示例4: openpcapfile
int openpcapfile(pcap_t **pcapout, char *filename) {
pcap_t *pcap;
char errbuf[PCAP_ERRBUF_SIZE];
char source[PCAP_BUF_SIZE];
/* Create the source string according to the new WinPcap syntax */
if ( pcap_createsrcstr( source, // variable that will keep the source string
PCAP_SRC_FILE, // we want to open a file
NULL, // remote host
NULL, // port on the remote host
filename, // name of the file we want to open
errbuf // error buffer
) != 0)
{
fprintf(stderr,"\nError creating a source string\n");
return -1;
}
/* Open the capture file */
if ( (pcap = pcap_open(source, // 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 %s: %s\n", filename, errbuf);
return -1;
}
*pcapout = pcap;
return 0;
}
开发者ID:cajun-rat,项目名称:analysepcap,代码行数:35,代码来源:Analyse.c
示例5: prvOpenInterface
static void prvOpenInterface( const char *pucName )
{
static char pucInterfaceName[ 256 ];
if( pucName != NULL )
{
strncpy( pucInterfaceName, pucName, sizeof( pucInterfaceName ) );
}
pxOpenedInterfaceHandle = pcap_open( pucInterfaceName, /* The name of the selected interface. */
ipTOTAL_ETHERNET_FRAME_SIZE, /* The size of the packet to capture. */
PCAP_OPENFLAG_PROMISCUOUS, /* Open in promiscuous mode as the MAC and
IP address is going to be "simulated", and
not be the real MAC and IP address. This allows
traffic to the simulated IP address to be routed
to uIP, and traffic to the real IP address to be
routed to the Windows TCP/IP stack. */
100,
NULL, /* No authentication is required as this is
not a remote capture session. */
cErrorBuffer
);
if ( pxOpenedInterfaceHandle == NULL )
{
printf( "\n%s is not supported by WinPcap and cannot be opened\n", pucInterfaceName );
}
else
{
/* Configure the capture filter to allow blocking reads, and to filter
out packets that are not of interest to this demo. */
prvConfigureCaptureBehaviour();
}
}
开发者ID:unnamet,项目名称:Repo,代码行数:34,代码来源:NetworkInterface.c
示例6: log
/**
@brief
This will sniff incoming packets for an ICMP ECHO reply
libpcap version
*/
bool turbotrace::start_sniffer()
{
log("Sniffer initialising...\n");
char errbuf[1000];
//Open the device
adapter = pcap_open(adapter_info.name , 65536 , PCAP_OPENFLAG_PROMISCUOUS , 20 , NULL ,errbuf);
if (adapter == NULL)
{
log(_("pcap_open_live failed") + wxString(errbuf , wxConvUTF8));
return false;
}
log(_("pcap_open successful"));
sniffer_ready = true;
//Send the syn packets
send_syn();
//Put the device in sniff loop
pcap_loop(adapter , -1 , process_packet2 , (u_char*)this);
return true;
}
开发者ID:silv3rm00n,项目名称:Turbotrace,代码行数:31,代码来源:turbotrace.cpp
示例7: main
void main(int argc, char **argv)
{
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
struct timeval st_ts;
u_int netmask;
struct bpf_program fcode;
/* Check the validity of the command line */
if (argc != 2)
{
usage();
return;
}
/* Open the output adapter */
if ( (fp= pcap_open(argv[1], 100, PCAP_OPENFLAG_PROMISCUOUS, 1000, NULL, errbuf) ) == NULL)
{
fprintf(stderr,"\nUnable to open adapter %s.\n", errbuf);
return;
}
/* Don't care about netmask, it won't be used for this filter */
netmask=0xffffff;
//compile the filter
if (pcap_compile(fp, &fcode, "tcp", 1, netmask) <0 )
{
fprintf(stderr,"\nUnable to compile the packet filter. Check the syntax.\n");
/* Free the device list */
return;
}
//set the filter
if (pcap_setfilter(fp, &fcode)<0)
{
fprintf(stderr,"\nError setting the filter.\n");
pcap_close(fp);
/* Free the device list */
return;
}
/* Put the interface in statstics mode */
if (pcap_setmode(fp, MODE_STAT)<0)
{
fprintf(stderr,"\nError setting the mode.\n");
pcap_close(fp);
/* Free the device list */
return;
}
printf("TCP traffic summary:\n");
/* Start the main loop */
pcap_loop(fp, 0, dispatcher_handler, (PUCHAR)&st_ts);
pcap_close(fp);
return;
}
开发者ID:3xp10it,项目名称:sulley-win-installer,代码行数:60,代码来源:tcptop.c
示例8: return
/*
* Tries to open the given interface on promiscuous
* Parameters:
* none
* Returns: true if the interface is open, false otherwise
*/
bool Interface::open() {
#ifdef _WIN32
return (handle = pcap_open(dev, BUFSIZ, PCAP_OPENFLAG_PROMISCUOUS | PCAP_OPENFLAG_NOCAPTURE_LOCAL | PCAP_OPENFLAG_MAX_RESPONSIVENESS, 500, NULL, errbuf)) != NULL;
#else
return (handle = pcap_open_live(dev, BUFSIZ, 1, 500, errbuf)) != NULL;
#endif
}
开发者ID:codestation,项目名称:usbridge,代码行数:13,代码来源:Interface.cpp
示例9: main
int main(int argc, char **argv)
{
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
struct timeval st_ts;
u_int netmask;
struct bpf_program fcode;
/* 检查命令行参数的合法性 */
if (argc != 2)
{
usage();
return -1;
}
/* 打开输出适配器 */
if ( (fp= pcap_open(argv[1], 100, PCAP_OPENFLAG_PROMISCUOUS, 1000, NULL, errbuf) ) == NULL)
{
fprintf(stderr,"\nUnable to open adapter %s.\n", errbuf);
return -1;
}
/* 不用关心掩码,在这个过滤器中,它不会被使用 */
netmask=0xffffff;
// 编译过滤器
if (pcap_compile(fp, &fcode, "tcp", 1, netmask) <0 )
{
fprintf(stderr,"\nUnable to compile the packet filter. Check the syntax.\n");
/* 释放设备列表 */
return -1;
}
//设置过滤器
if (pcap_setfilter(fp, &fcode)<0)
{
fprintf(stderr,"\nError setting the filter.\n");
pcap_close(fp);
/* 释放设备列表 */
return -1;
}
/* 将接口设置为统计模式 */
if (pcap_setmode(fp, MODE_STAT)<0)
{
fprintf(stderr,"\nError setting the mode.\n");
pcap_close(fp);
/* 释放设备列表 */
return -1;
}
printf("TCP traffic summary:\n");
/* 开始主循环 */
pcap_loop(fp, 0, dispatcher_handler, (PUCHAR)&st_ts);
pcap_close(fp);
return 0;
}
开发者ID:Ryan--Yang,项目名称:winpcap,代码行数:60,代码来源:main.c
示例10: fprintf
pcap_t *nr_open_current_device_adapter(int snaplen, pcap_addr_t ** sockaddr) {
pcap_if_t *devices;
pcap_if_t *device;
char errbuf[PCAP_ERRBUF_SIZE];
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &devices, errbuf) == -1) {
fprintf(stderr, "Error in pcap_findalldevs_ex: %s\n", errbuf);
return 0;
}
// Return first interface with an address
for (device = devices; device; device = device->next) {
if (device->description) {
pcap_addr_t *addr;
for (addr = device->addresses; addr; addr = addr->next) {
if (addr->addr->sa_family == AF_INET) { // IPv4 addr
if (addr->addr) {
(*sockaddr) = nr_get_device_ip_interface(device);
pcap_t *handle;
handle = pcap_open(device->name, snaplen, PCAP_OPENFLAG_PROMISCUOUS, 1000, NULL, errbuf);
return handle;
}
}
}
}
}
return 0;
}
开发者ID:nullruto,项目名称:CPacketSniffer,代码行数:28,代码来源:nr_packet_interface.c
示例11: pcap_setdirection
/* Open an Ethernet interface using PCAP */
static pcap_t *nio_ethernet_open(char *device)
{
char pcap_errbuf[PCAP_ERRBUF_SIZE];
pcap_t *p;
#ifndef CYGWIN
/* Timeout is 10ms */
if (!(p = pcap_open_live(device, 65535, TRUE, 10, pcap_errbuf)))
goto pcap_error;
pcap_setdirection(p, PCAP_D_INOUT);
#ifdef BIOCFEEDBACK
{
int on = 1;
ioctl(pcap_fileno(p), BIOCFEEDBACK, &on);
}
#endif
#else
p = pcap_open(device, 65535,
PCAP_OPENFLAG_PROMISCUOUS |
PCAP_OPENFLAG_NOCAPTURE_LOCAL |
PCAP_OPENFLAG_MAX_RESPONSIVENESS |
PCAP_OPENFLAG_NOCAPTURE_RPCAP,
10, NULL, pcap_errbuf);
if (!p)
goto pcap_error;
#endif
return p;
pcap_error:
fprintf(stderr, "nio_ethernet_open: unable to open device '%s' ""with PCAP (%s)\n", device, pcap_errbuf);
return NULL;
}
开发者ID:gcetusic,项目名称:ubridge,代码行数:36,代码来源:nio_ethernet.c
示例12: add_stream_from_pcap
int add_stream_from_pcap(char *file_path)
{
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
char source[PCAP_BUF_SIZE];
struct pcap_pkthdr *header;
const u_char *pkt_data;
t_stream t_stream_tmp;
/* Create the source string according to the new WinPcap syntax */
if ( pcap_createsrcstr( source, // variable that will keep the source string
PCAP_SRC_FILE, // we want to open a file
NULL, // remote host
NULL, // port on the remote host
file_path, // name of the file we want to open
errbuf // error buffer
) != 0)
{
WinPrintf(hwnd_frame, "Error creating a source string");
return -1;
}
/* Open the capture file */
if ( (fp= pcap_open(source, // 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)
{
WinPrintf(hwnd_frame, "打开文件失败:\n%s\n可能是抓包存档文件损坏或格式不支持", source);
return -1;
}
while (pcap_next_ex(fp, &header, &pkt_data)>0)
{
if (nr_cur_stream>=MAX_STREAM_NUM)
{
err_msg_box("已达最大流数目 %d", MAX_STREAM_NUM);
break;
}
init_stream(&t_stream_tmp);
t_stream_tmp.len=header->caplen;
memcpy(t_stream_tmp.data, pkt_data, t_stream_tmp.len);
t_stream_tmp.err_flags = build_err_flags((void *)(t_stream_tmp.data), t_stream_tmp.len);
add_stream(&t_stream_tmp);
}
pcap_close(fp);
re_populate_items();
return 0;
}
开发者ID:yedan2010,项目名称:xb-ether-tester,代码行数:58,代码来源:right_window.c
示例13: eapol_init
/*
* 初始化缓存区,生成接口句柄
* skfd: 被初始化的接口句柄
* @return: 0: 成功
* -1: 初始化接口句柄失败
*/
static int eapol_init(pcap_t **skfd)
{
pcap_if_t *alldevs, *d;
char errbuf[PCAP_ERRBUF_SIZE];
char ifbuff[8+IFNAMSIZ] = "rpcap://";
sendethii = (ethII_t*)sendbuff;
sendeapol = (eapol_t*)((uchar*)sendethii+sizeof(ethII_t));
sendeap = (eap_t*)((uchar*)sendeapol+sizeof(eapol_t));
sendeapbody = (eapbody_t*)((uchar*)sendeap+sizeof(eap_t));
if (-1 == pcap_findalldevs(&alldevs, errbuf)) {
_M("Get interface: %s\n", errbuf);
return -1;
}
for (d = alldevs; NULL != d; d = d->next)
if (0 == strcmp(ifname, d->name))
break;
if (NULL == d) return -1;
/* 获取mac */
LPADAPTER lpAdapter = PacketOpenAdapter(d->name);
if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE))
return -1;
PPACKET_OID_DATA oidData = malloc(ETH_ALEN + sizeof(PACKET_OID_DATA));
if (NULL == oidData) {
PacketCloseAdapter(lpAdapter);
return -1;
}
oidData->Oid = OID_802_3_CURRENT_ADDRESS;
oidData->Length = ETH_ALEN;
memset(oidData->Data, 0, ETH_ALEN);
if (0 == PacketRequest(lpAdapter, FALSE, oidData)) {
free(oidData);
return -1;
}
memcpy(client_mac, oidData->Data, ETH_ALEN);
PacketCloseAdapter(lpAdapter);
_D("%s's MAC: %02X-%02X-%02X-%02X-%02X-%02X\n", ifname,
client_mac[0],client_mac[1],client_mac[2],
client_mac[3],client_mac[4],client_mac[5]);
/* 获取网络接口句柄 */
strncat(ifbuff, ifname, IFNAMSIZ);
if (NULL == (*skfd = pcap_open(d->name, MTU_MAX,
PCAP_OPENFLAG_PROMISCUOUS, TIMEOUT*1000, NULL, errbuf))) {
_M("Get interface handler:%s\n", errbuf);
pcap_freealldevs(alldevs);
return -1;
}
pcap_freealldevs(alldevs);
return 0;
}
开发者ID:leetking,项目名称:cwnu-drcom,代码行数:61,代码来源:eapol_win.c
示例14: pcap_port_open
/* Opens a port with the given name and uid. */
struct pcap_port * MALLOC_ATTR
pcap_port_open(struct pcap_drv *pcap_drv, size_t id, const char *name) {
struct linux_port *linux_port;
HASH_FIND_STR(pcap_drv->linux_ports_map, name, linux_port);
if(linux_port == NULL) {
logger_log(pcap_drv->logger, LOG_ERR, "Unable to get interface flags");
logger_log(pcap_drv->logger, LOG_ERR, "There is no linux port for %s", name);
return NULL;
}
struct linux_port_flags *flags = &linux_port->flags;
if (flags == NULL) {
logger_log(pcap_drv->logger, LOG_ERR, "Unable to get interface flags %s", name);
return NULL;
}
struct pcap_port *pcap_port = malloc(sizeof(struct pcap_port));
pcap_port->drv = pcap_drv;
pcap_port->id = id;
pcap_port->name = strdup(name);
pcap_port->logger = logger_mgr_get(LOGGER_NAME_PORT_DRV_PCAP_PORT, id);
pcap_port->dp_uid = 0; // invalidity marked by port_no
pcap_port->dp_port_no = OF_NO_PORT;
pcap_port->pkt_mbox = NULL;
pcap_port->rwlock = malloc(sizeof(pthread_rwlock_t));
pthread_rwlock_init(pcap_port->rwlock, NULL);
pcap_port->of_port = malloc(sizeof(struct ofl_port));
memset(pcap_port->of_port, '\0', sizeof(struct ofl_port));
pcap_port->of_stats = malloc(sizeof(struct ofl_port_stats));
memset(pcap_port->of_stats, '\0', sizeof(struct ofl_port_stats));
pcap_port->of_port->name = strdup(name);
pcap_port->stats_mutex = malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(pcap_port->stats_mutex, NULL);
if(flags->UP && flags->RUNNING) {
return pcap_open(pcap_port);
} else {
pcap_port->pcap = NULL;
pcap_port->fd = -1;
pcap_port->watcher = NULL;
}
return pcap_port;
}
开发者ID:elekjani,项目名称:ofss,代码行数:51,代码来源:pcap_port.c
示例15: Releaseinfo
int CapturePacketThread::RunCapture()
{
Releaseinfo("RunCapture input");
pcap_t *adhandle;
char errbuf[PCAP_ERRBUF_SIZE];
u_int netmask=0xffffff;
struct bpf_program fp;
if((adhandle= pcap_open(devname.c_str(), // 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)
{
Releaseinfo("pcap_open fails");
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", devname.c_str());
return -1;
}
string filter("");
string host_str("");
host_str = AppConfig::SharedInstance()->GetHostIp();
filter+="host ";
filter+=ipstr;
filter+=" and (tcp or udp) and (not host ";
filter+=host_str;
filter+=")";
//char test_filter[100]={0};
//strcpy(test_filter,filter.c_str());
//Releaseinfo(test_filter);
if(pcap_compile(adhandle, &fp, filter.c_str(), 0, netmask) == -1) {
Releaseinfo("pcap_compile fails");
fprintf(stderr, "Error calling pcap_compile\n");
return -1;
}
if(pcap_setfilter(adhandle, &fp) == -1) {
Releaseinfo("pcap_setfilter fails");
fprintf(stderr, "Error setting filter\n");
return -1;
}
char user_ip[20]={0};
strcpy(user_ip,ipstr.c_str());
pcap_loop(adhandle, 0, PacketHandler, (u_char*)user_ip);
return 0;
}
开发者ID:Yight,项目名称:InfoSecurity,代码行数:48,代码来源:CapturePacketThread.cpp
示例16: OpenDevice
//打开设备
int Device::OpenDevice(pcap_if_t *d)
{
if ((adhandle = pcap_open(d->name, // 设备名
65536, // 65535保证能捕获到不同数据链路层上的每个数据包的全部内容
PCAP_OPENFLAG_PROMISCUOUS, // 混杂模式,以保证抓到ARP包
1, /*读取超时时间,单位为毫秒,捕捉数据包的时候,延迟一定的时间,然后再调用内核中的程序,
这样效率较高。0表示没有延迟,没有包到达的时候永不返回。-1表示立即返回。*/
NULL, // 远程机器验证
errbuf // 错误缓冲池
)) == NULL)
{
pcap_freealldevs(alldevs);//释放设备列表
return -1;
}
else return 0;
}
开发者ID:Wilhelmshaven,项目名称:Port-Scanner,代码行数:17,代码来源:Device.cpp
示例17: tf_peer_dump_rfx
BOOL tf_peer_dump_rfx(freerdp_peer* client)
{
wStream* s;
UINT32 prev_seconds;
UINT32 prev_useconds;
rdpUpdate* update;
rdpPcap* pcap_rfx;
pcap_record record;
s = Stream_New(NULL, 512);
if (!s)
return FALSE;
update = client->update;
if (!(pcap_rfx = pcap_open(test_pcap_file, FALSE)))
return FALSE;
prev_seconds = prev_useconds = 0;
while (pcap_has_next_record(pcap_rfx))
{
if (!pcap_get_next_record_header(pcap_rfx, &record))
break;
if (!Stream_EnsureCapacity(s, record.length))
break;
record.data = Stream_Buffer(s);
pcap_get_next_record_content(pcap_rfx, &record);
Stream_SetPointer(s, Stream_Buffer(s) + Stream_Capacity(s));
if (test_dump_rfx_realtime
&& test_sleep_tsdiff(&prev_seconds, &prev_useconds, record.header.ts_sec,
record.header.ts_usec) == FALSE)
break;
update->SurfaceCommand(update->context, s);
if (client->CheckFileDescriptor(client) != TRUE)
break;
}
Stream_Free(s, TRUE);
pcap_close(pcap_rfx);
return TRUE;
}
开发者ID:kevans91,项目名称:FreeRDP,代码行数:47,代码来源:sfreerdp.c
示例18: openDevice
///////////////////////////////////////////////////////////////////////////////////////
//
// Body
//
///////////////////////////////////////////////////////////////////////////////////////
//=====================================================================================
//
// * Function : openDevice()
// * Description
// 해당 모듈은 사용자가 선택한 디바이스를 열고 해당 핸들을 datas.cpp에 선언된
// adhandle에 저장한다.
//
//=====================================================================================
int openDevice(int index){
char errbuf[PCAP_ERRBUF_SIZE];
int counter;
char logmsg[LOG_MSG_SIZE];
unsigned int lNetMask = 0;
struct bpf_program lFCode;
for(d=alldevs, counter=0; d; d=d->next, counter++){
if(counter==index){
strncpy(deviceName,d->name,1024);
break;
}
}
/* 디바이스 열기 */
if((adhandle = pcap_open(deviceName, 65536, PCAP_OPENFLAG_PROMISCUOUS, 1000, NULL, errbuf)) == NULL){
sprintf(logmsg,"[Error] Unable to open the adapter. not supported by WinPcap\n");
log(logmsg);
SendMessage(hC1, WM_SPOOF, SM_NODEVICE, NULL);
pcap_freealldevs(alldevs);
return -1;
}
if (d->addresses != NULL)
lNetMask = ((struct sockaddr_in *)(d->addresses->netmask))->sin_addr.S_un.S_addr;
else
lNetMask = 0xffffff;
ZeroMemory(&lFCode, sizeof(lFCode));
if(pcap_compile(adhandle, &lFCode, "", 1, lNetMask) < 0 ) {
log("[Error] Unable to compile the packet filter. \n");
exit(1);
}
if(pcap_setfilter(adhandle, &lFCode) < 0 ) {
log("[Error] Error setting the filter.\n");
}
/* 로그기록 */
sprintf(logmsg, "[Info] %s Device Opened\n\r", d->description);
log(logmsg);
/* 네트워크 디바이스 목록 해제 */
pcap_freealldevs(alldevs);
return 0;
}
开发者ID:JeoKim224,项目名称:ziARP,代码行数:59,代码来源:openDevice.cpp
示例19: main
int main(int argc, char **argv)
{
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
char source[PCAP_BUF_SIZE];
if(argc != 2){
printf("usage: %s filename", argv[0]);
return -1;
}
/* Create the source string according to the new WinPcap syntax */
if ( pcap_createsrcstr( source, // variable that will keep the source string
PCAP_SRC_FILE, // we want to open a file
NULL, // remote host
NULL, // port on the remote host
argv[1], // name of the file we want to open
errbuf // error buffer
) != 0)
{
fprintf(stderr,"\nError creating a source string\n");
return -1;
}
/* Open the capture file */
if ( (fp= pcap_open(source, // 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 file %s.\n", source);
return -1;
}
// read and dispatch packets until EOF is reached
pcap_loop(fp, 0, dispatcher_handler, NULL);
return 0;
}
开发者ID:52M,项目名称:npcap,代码行数:45,代码来源:readfile.c
示例20: pcap_open
int nbNetVmPortLocalAdapter::OpenAsDataSrc()
{
int IsPromiscuous;
char errbuf[PCAP_ERRBUF_SIZE];
if (nbFLAG_ISSET(Flags, nbNETDEVICE_PROMISCUOUS))
IsPromiscuous = PCAP_OPENFLAG_PROMISCUOUS;
else
IsPromiscuous = 0;
m_WinPcapDevice = pcap_open(Name,65535,IsPromiscuous,1000,NULL,errbuf);
if (m_WinPcapDevice == NULL)
return nbFAILURE;
return nbSUCCESS;
}
开发者ID:AshleyPeterson,项目名称:netbee-lite,代码行数:18,代码来源:netvmportlocaladapter.cpp
注:本文中的pcap_open函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论