本文整理汇总了C++中pcap_next_ex函数的典型用法代码示例。如果您正苦于以下问题:C++ pcap_next_ex函数的具体用法?C++ pcap_next_ex怎么用?C++ pcap_next_ex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pcap_next_ex函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
char errbuf[PCAP_ERRBUF_SIZE];
struct pcap_pkthdr *pkthdr;
const u_char *pkt_data;
Options options;
parse_args(argc, argv, &options);
if(options.list_devices) {
show_devices();
exit(0);
}
// Create Handles for in and out
pcap_t *in_handle = pcap_create(argv[1], errbuf);
pcap_t *out_handle = pcap_create(argv[1], errbuf);
if(!in_handle | !out_handle )
exit_error(errbuf, -1);
int result = 0;
// Set timeout
result = pcap_set_timeout(in_handle, 1); // Header size up to window size
result = pcap_set_timeout(out_handle, 1); // Header size up to window size
handle_pcap_errors(in_handle, result, "set_timeout");
handle_pcap_errors(out_handle, result, "set_timeout");
// Activate!
result = pcap_activate(out_handle);
result = pcap_activate(in_handle);
handle_pcap_errors(out_handle, result, "pcap_activate");
handle_pcap_errors(in_handle, result, "pcap_activate");
// Set Filter
filter_on_port(out_handle, "src port ", options.port_str);
filter_on_port(in_handle, "dst port ", options.port_str);
// Count packet lenghts on port
int out_byte_count = 0;
int in_byte_count = 0;
for(int i = 0; i < 100; i++) {
pcap_next_ex(out_handle, &pkthdr, &pkt_data);
out_byte_count += pkthdr->len;
pcap_next_ex(in_handle, &pkthdr, &pkt_data);
in_byte_count += pkthdr->len;
}
printf("In Bytes: %d\n", in_byte_count);
printf("Out Bytes: %d\n", out_byte_count);
return 0;
}
开发者ID:cwgreene,项目名称:pcap-tests,代码行数:58,代码来源:filter_on.cpp
示例2: _recv_frame
Hushort _recv_frame( Hubyte *frame )
{
int res;
const Hubyte *packet;
struct pcap_pkthdr *hdr;
struct ether_header *eptr;
short len;
res = pcap_next_ex( eth_cap, &hdr, &packet );
while( res != 1 ) res = pcap_next_ex( eth_cap, &hdr, &packet );
len = hdr->len;
while( --len >= 0 ) frame[len] = packet[len];
return hdr->len;
}
开发者ID:mafzzz,项目名称:heterogeneous_hthreads,代码行数:16,代码来源:ethernet.c
示例3: copy_capture
/* Copy the whole capture into the shared memory */
void copy_capture(struct shmstruct *ptr)
{
u_int32_t cap_len;
int r;
struct pcap_pkthdr *pkthdr;
const u_char *packet;
pkt_handle *hndl;
uint counter= 0;
while ((r = pcap_next_ex (ConfigParams.in_descr, &pkthdr, &packet)) == 1)
{
if (counter >= QUEUE_SIZE)
{
error("Too many packet for queue");
exit(-2);
}
hndl = &ptr->queues[counter];
cap_len = pkthdr->caplen;
hndl->cap_len = cap_len;
memcpy(hndl->pkt_data, packet, cap_len);
counter++;
}
/* insert a fake trailing packet to signal workers that capture is over */
log("Inserting last packet into queue");
hndl = &ptr->queues[counter];
hndl->cap_len = 0;
}
开发者ID:AshleyPeterson,项目名称:netbee-lite,代码行数:32,代码来源:multicore.c
示例4: Ethernet_receivePacket
int
Ethernet_receivePacket(EthernetSocket self, uint8_t* buffer, int bufferSize)
{
struct pcap_pkthdr* header;
uint8_t* packetData;
int pcapCode = pcap_next_ex(self->rawSocket, &header, (const unsigned char**) &packetData);
if (pcapCode > 0) {
int packetSize = header->caplen;
if (packetSize > bufferSize)
packetSize = bufferSize;
memcpy(buffer, packetData, packetSize);
return packetSize;
}
else {
if (pcapCode < 0)
printf("winpcap error\n");
return 0;
}
}
开发者ID:feuvan,项目名称:libiec61850,代码行数:25,代码来源:ethernet_win32.c
示例5: client_event_read
client_event * client_event_read(pcap_t * handle) {
while (1) {
struct pcap_pkthdr * header;
const u_char * buffer;
int ret = pcap_next_ex(handle, &header, &buffer);
if (ret < 0) {
return NULL;
}
if (ret != 1 || header->caplen < 4) {
continue;
}
size_t radiotapLen = (size_t)((uint16_t *)buffer)[1];
if (header->caplen < radiotapLen) {
continue;
}
const u_char * macPacket = buffer + radiotapLen;
size_t macPacketLen = (size_t)header->caplen - radiotapLen;
if (!is_data_packet(macPacket, macPacketLen)) {
continue;
}
client_event * res = read_mac_info(macPacket, macPacketLen);
res->data_size = macPacketLen;
res->timestamp = header->ts;
res->rssi = radiotap_rssi(buffer);
res->request_info = http_req_in_packet(macPacket, macPacketLen);
res->response_info = http_resp_in_packet(macPacket, macPacketLen);
return res;
}
}
开发者ID:unixpickle,项目名称:net-dump,代码行数:32,代码来源:events.c
示例6: epcap_loop
void
epcap_loop(EPCAP_STATE *ep)
{
pcap_t *p = ep->p;
struct pcap_pkthdr *hdr = NULL;
const u_char *pkt = NULL;
int read_packet = 1;
int datalink = pcap_datalink(p);
while (read_packet) {
switch (pcap_next_ex(p, &hdr, &pkt)) {
case 0: /* timeout */
VERBOSE(1, "timeout reading packet");
break;
case 1: /* got packet */
epcap_response(hdr, pkt, datalink);
break;
case -2: /* eof */
VERBOSE(1, "end of file");
epcap_ctrl("eof");
read_packet = 0;
break;
case -1: /* error reading packet */
VERBOSE(1, "error reading packet");
/* fall through */
default:
read_packet = 0;
}
}
}
开发者ID:kvakvs,项目名称:epcap,代码行数:31,代码来源:epcap.c
示例7: filte_success
/*
* 过滤得到登录成功包
* @return: 0: 成功获取
* -1: 超时
* -2: 服务器中止登录,密码错误吧
*/
static int filte_success(pcap_t *skfd)
{
int stime = time((time_t*)NULL);
struct pcap_pkthdr *pkt_hd;
const uchar *recvbuff;
int timeout;
for (; time((time_t*)NULL)-stime <= TIMEOUT;) {
timeout = pcap_next_ex(skfd, &pkt_hd, &recvbuff);
if (0 >= timeout) return -1;
FORMAT_RECVPKT(recvbuff);
if (recvethii->type == htons(ETHII_8021X)
&& mac_equal(recvethii->dst_mac, client_mac)
&& recveapol->type == EAPOL_PACKET ) {
if (recveap->id == sendeap->id
&& recveap->code == EAP_CODE_SUCS) {
_D("id: %d login success.\n", sendeap->id);
return 0;
} else if (recveap->id == sendeap->id
&& recveap->code == EAP_CODE_FAIL) {
_D("id: %d fail.\n", sendeap->id);
return -2;
}
}
}
return -1;
}
开发者ID:leetking,项目名称:cwnu-drcom,代码行数:32,代码来源:eapol_win.c
示例8: read_rtp_nb
int read_rtp_nb(const char *fpcap, int dport)
{
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
struct pcap_pkthdr *header;
const u_char *pkt_data;
int res, pkt_count = 0;
ip_header *ih;
udp_header *uh;
u_int ip_len;
fp = pcap_open_offline(fpcap, errbuf);
/* Retrieve the packets from the file */
while((res = pcap_next_ex(fp, &header, &pkt_data)) >= 0) {
/* retireve the position of the ip header */
ih = (ip_header *) (pkt_data + 14); //length of ethernet header
/* retireve the position of the udp header */
ip_len = (ih->ver_ihl & 0xf) * 4;
uh = (udp_header *) ((u_char*)ih + ip_len);
if( ntohs(uh->dport) == dport) {
pkt_count++;
}
}
pcap_close(fp);
return pkt_count;
}
开发者ID:Jelassi,项目名称:QoEComm,代码行数:35,代码来源:rtp.cpp
示例9: us_rawnet_recv
ssize_t us_rawnet_recv(
us_rawnet_context_t *self, uint8_t src_mac[6], uint8_t dest_mac[6], void *payload_buf, ssize_t payload_buf_max_size )
{
ssize_t r = -1;
pcap_t *m_pcap = (pcap_t *)self->m_pcap;
if ( m_pcap )
{
const uint8_t *data;
struct pcap_pkthdr *header;
int e = pcap_next_ex( m_pcap, &header, &data );
if ( e == 1 && ( (ssize_t)header->caplen - 14 ) <= payload_buf_max_size )
{
r = header->caplen - 14;
memcpy( payload_buf, &data[14], r );
if ( src_mac )
{
memcpy( src_mac, &data[6], 6 );
}
if ( dest_mac )
{
memcpy( dest_mac, &data[0], 6 );
}
}
}
return r;
}
开发者ID:AVB-YJ,项目名称:microsupport,代码行数:28,代码来源:us_rawnet.c
示例10: qDebug
void my_sniffer::run(){
//qDebug("[[[");
qDebug("start a thread to get data");
int packet_id=0;
while(!stopped)
{
int temp;
// pkthdr=new struct pcap_pkthdr();
// packet=new const u_char();
temp=pcap_next_ex(dev_haddle,&pkthdr,&packet);
if(temp!=1)
{
;// qDebug("error in the pcap_next_ex and the temp is %d",temp);
}
else if(temp==1)
{
packet_id++;
qDebug("in the run");
// const u_char *packet=mydata[row];// get the packet been selected
//struct pcap_pkthdr *pkthdr=mypkthdr[row];
emit send_capture_pcaket(pkthdr,packet,packet_id);
// emit send_capture_packettomydeal(pkthdr,packet);
}
// stopped=false;
}
qDebug("sniffer thread is running");
if(dev_haddle)
{
qDebug("close dev_handle");
pcap_close(dev_haddle);
}
}
开发者ID:lovevv,项目名称:sniffer,代码行数:34,代码来源:my_sniffer.cpp
示例11: while
void ReceivePacketThread::recvTCPSYNACKPortScanPacket()
{
pcap_t *adhandle = this->handle;
int res;
struct pcap_pkthdr * pktHeader;
const u_char * pktData;
while (!scanIsFinished) {
if ((res = pcap_next_ex(adhandle, &pktHeader, &pktData)) >= 0) {
etherpacket->setData(pktData);
if ((etherpacket->getEtherNetType() == my_htons(IP_TYPE))){
ipheaderpacket->setData(pktData);
if((ipheaderpacket->getProtocolType() == "TCP")){
tcppacket->setData(pktData);
if((ipheaderpacket->getDestIpAddStr() == QString(hostInfo->ip)) &&
(ipheaderpacket->getSourceIpAddStr() == scanIp)){
// 端口开放
if(tcppacket->getFlag() == (TCP_SYN_ACK)){
//qDebug() << my_htons(tcppacket->getSrcPort()) << " 端口已开放";
QString service = portServiceMap->getService(my_htons(tcppacket->getSrcPort()));
QString msg = QString("端口:%1 协议:tcp 服务:%2").arg(QString::number(my_htons(tcppacket->getSrcPort())),service);
//qDebug()<< msg;
emit portScanRecvUpdataSig(msg);
}
// 端口未开放
else if(tcppacket->getFlag() == (TCP_RST_ACK)){
//qDebug() << my_htons(tcppacket->getSrcPort()) << " 端口未开放";
}
}
}
}
}
}
}
开发者ID:FreeApe,项目名称:SnifferToolServer,代码行数:34,代码来源:receivepacketthread.cpp
示例12: pcap_loop
int pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
struct pcap_pkthdr *header = NULL;
const u_char *pktdata = NULL;
int ret = 0;
if (initFinished == 0)
{
return DPDKPCAP_FAILURE;
}
for (;;)
{
ret = pcap_next_ex(p, &header, &pktdata);
if (ret == 1)
{
callback(user, header, pktdata);
}
if (!PACKET_COUNT_IS_UNLIMITED(cnt))
{
cnt -= ret;
if (cnt <= 0)
return DPDKPCAP_OK;
}
}
return DPDKPCAP_FAILURE;
}
开发者ID:garyachy,项目名称:SwitchEmu,代码行数:29,代码来源:dpdkpcap.c
示例13: while
UINT CNILayer::ReadingThread(LPVOID pParam)
{
struct pcap_pkthdr *header;
const u_char *pkt_data;
int result;
CNILayer *pNI = (CNILayer *)pParam;
while(pNI->m_thrdSwitch) // 패킷 체크
{
// 패킷 읽어오기
result = pcap_next_ex(pNI->m_AdapterObject,&header,&pkt_data);
if(result==0){
// AfxMessageBox("패킷 없음");
}
else if(result==1){
// AfxMessageBox("패킷 있음");
pNI->Receive((u_char *)pkt_data);
}
else if(result<0){
// AfxMessageBox("패킷 오류");
}
}
return 0;
}
开发者ID:ohheebin,项目名称:ARP,代码行数:27,代码来源:NILayer.cpp
示例14: rs_got_packet
static void rs_got_packet(UNUSED fr_event_list_t *el, int fd, void *ctx)
{
static uint64_t count = 0; /* Packets seen */
rs_event_t *event = ctx;
pcap_t *handle = event->in->handle;
int i;
int ret;
const uint8_t *data;
struct pcap_pkthdr *header;
for (i = 0; (event->in->type == PCAP_FILE_IN) || (i < RS_FORCE_YIELD); i++) {
ret = pcap_next_ex(handle, &header, &data);
if (ret == 0) {
/* No more packets available at this time */
return;
}
if (ret == -2 && (event->in->type == PCAP_FILE_IN)) {
INFO("Done reading packets (%s)", event->in->name);
fr_event_fd_delete(events, 0, fd);
return;
}
if (ret < 0) {
ERROR("Error requesting next packet, got (%i): %s", ret, pcap_geterr(handle));
return;
}
count++;
rs_packet_process(count, event, header, data);
}
}
开发者ID:OsvaldoTCF,项目名称:freeradius-server,代码行数:31,代码来源:radsniff.c
示例15: forward_to_hijacker
/**
* Forward data to hijacker
*
*/
static ssize_t forward_to_hijacker ( int fd, struct hijack *hijack ) {
struct pcap_pkthdr *pkt_header;
const unsigned char *pkt_data;
ssize_t len;
/* Receive packet from network */
if ( pcap_next_ex ( hijack->pcap, &pkt_header, &pkt_data ) < 0 ) {
logmsg ( LOG_ERR, "read from hijacked port failed: %s\n",
pcap_geterr ( hijack->pcap ) );
return -1;
}
if ( pkt_header->caplen != pkt_header->len ) {
logmsg ( LOG_ERR, "read partial packet (%d of %d bytes)\n",
pkt_header->caplen, pkt_header->len );
return -1;
}
if ( pkt_header->caplen == 0 )
return 0;
len = pkt_header->caplen;
/* Write packet to hijacker */
if ( write ( fd, pkt_data, len ) != len ) {
logmsg ( LOG_ERR, "write to hijacker failed: %s\n",
strerror ( errno ) );
return -1;
}
hijack->rx_count++;
return len;
};
开发者ID:B-Rich,项目名称:serialice,代码行数:34,代码来源:hijack.c
示例16: Cappacketlivethread
UINT Cappacketlivethread(LPVOID pParam)//抓包线程函数
{
//CMainFrame *p_frame=(CMainFrame*)AfxGetMainWnd();
//int m_exsn=p_frame->m_myprosheet.m_page2.m_thread_num;
//int m_stoptime=p_frame->m_myprosheet.m_page2.m_stoptime;
//int m_thread_index=0;
for(int i=0;i<m_mystruct.m_packetlimit;i++)//线程数目
{
if (::WaitForSingleObject(m_stoptimeup,0)==WAIT_OBJECT_0)
{
//m_thread_index=i;
m_mystruct.m_count=i;
break;
}
pcap_next_ex(m_mystruct.pcap_handle,&m_mystruct.protocol_header,&m_mystruct.pkt_data);//句柄,协议头,数据包
if ((m_mystruct.protocol_header->len)>m_mystruct.m_pl)//判断是否在规定长度以内
{
i--;
continue;
}
pcap_dump((u_char*)m_mystruct.dumpfile,m_mystruct.protocol_header,m_mystruct.pkt_data);
m_mystruct.m_count=i;
}
m_eventEnd.SetEvent();
return 0;
}
开发者ID:murdercdh,项目名称:mysniffer,代码行数:26,代码来源:MyOwnView.cpp
示例17: lpcap_next
static int lpcap_next(lua_State* L)
{
pcap_t* cap = checkpcap(L);
struct pcap_pkthdr* pkt_header = NULL;
const u_char* pkt_data = NULL;
int e = pcap_next_ex(cap, &pkt_header, &pkt_data);
/* Note: return values don't have names, they are documented numerically
in the man page. */
switch(e) {
case 1: /* success */
return pushpkt(L, pkt_header, pkt_data);
case 0: /* read live, and timeout occurred */
lua_pushnil(L);
lua_pushstring(L, "timeout");
return 2;
case -2: /* read from a savefile, and no more packets */
lua_pushnil(L);
lua_pushstring(L, "closed");
return 2;
case -1: /* an error occurred */
return pusherr(L, cap);
}
return luaL_error(L, "unreachable");
}
开发者ID:mikegarts,项目名称:pcap-lua,代码行数:25,代码来源:pcap.c
示例18: NETVM_ASSERT
u_int32_t nbNetVmPortLocalAdapter::SrcPollingFunctionWinPcap(void * ptr, nvmExchangeBufferState *buffer, int *dummy)
{
struct pcap_pkthdr *header;
u_char *pkt_data;
int res;
nbNetVmPortLocalAdapter *ClassHandler = (nbNetVmPortLocalAdapter *) ptr;
NETVM_ASSERT(ClassHandler->m_WinPcapDevice != NULL, __FUNCTION__ " - WinPcapDevice not opened, this is weird");
do
{
res = pcap_next_ex( (pcap_t*)ClassHandler->m_WinPcapDevice, &header, (const u_char**)&pkt_data);
NETVM_ASSERT(res >= 0, __FUNCTION__ " - I don't know what to do, the next_ex failed... GV");
if (res == 1)
{
buffer->timestamp_sec = header->ts.tv_sec;
buffer->timestamp_usec = header->ts.tv_usec;
buffer->pkt_pointer=pkt_data;
buffer->pktlen=header->len;
buffer->infolen=0;
return nbSUCCESS;
}
}
while (res == 0);
return nbFAILURE;
}
开发者ID:AshleyPeterson,项目名称:netbee-lite,代码行数:29,代码来源:netvmportlocaladapter.cpp
示例19: pcap2Daemon
/*******************************************************************************
* The pcap2Daemon function is spawned as a thread.
* It takes packets from winPCap and relays them to the coLinux Daemon.
*/
DWORD WINAPI
pcap2Daemon(LPVOID lpParam)
{
int pcap_status;
co_rc_t rc;
while (1) {
// Attempt to receive packet from WPcap.
pcap_status = pcap_next_ex(pcap_packet.adhandle,
&pcap_packet.pkt_header,
&pcap_packet.buffer);
switch (pcap_status) {
case 1: /* Packet read */
rc = co_win32_pcap_read_received(&pcap_packet);
if (!CO_OK(rc))
return 0;
break;
case 0: /* Timeout */
break;
default:
/* Error or EOF(offline capture only) */
co_debug("Unexpected error reading from winPCap.\n");
ExitProcess(0);
return 0;
break;
}
}
// We should never get to here.
co_debug("Unexpected exit of winPCap read loop.\n");
ExitProcess(0);
return 0;
}
开发者ID:matt81093,项目名称:Original-Colinux,代码行数:39,代码来源:main.c
示例20: pcap_next_ex
U8 *pcapRawsockGetRxFrame(void *pvRawsock, U32 timeout, unsigned int *offset, unsigned int *len)
{
pcap_rawsock_t *rawsock = (pcap_rawsock_t*)pvRawsock;
rawsock->rxHeader = 0;
const u_char *packet = 0;
int ret;
if (rawsock) {
ret = pcap_next_ex(rawsock->handle, &rawsock->rxHeader, &packet);
switch(ret) {
case 1:
*offset = 0;
*len = rawsock->rxHeader->caplen;
return (U8*)packet;
case -1:
AVB_LOGF_ERROR("pcap_next_ex failed: %s", pcap_geterr(rawsock->handle));
break;
case 0:
// timeout;
break;
case -2:
// no packets to be read from savefile
// this should not happened
break;
default:
break;
}
}
return NULL;
}
开发者ID:AVnu,项目名称:Open-AVB,代码行数:32,代码来源:pcap_rawsock.c
注:本文中的pcap_next_ex函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论