本文整理汇总了C++中pcap_freealldevs函数的典型用法代码示例。如果您正苦于以下问题:C++ pcap_freealldevs函数的具体用法?C++ pcap_freealldevs怎么用?C++ pcap_freealldevs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pcap_freealldevs函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: 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
示例2: get_adapter_index_from_addr
/** Get the index of an adapter by its network address
*
* @param netaddr network address of the adapter (e.g. 192.168.1.0)
* @return index of the adapter or negative on error
*/
static int
get_adapter_index_from_addr(struct in_addr *netaddr, char *guid, size_t guid_len)
{
pcap_if_t *alldevs;
pcap_if_t *d;
char errbuf[PCAP_ERRBUF_SIZE+1];
int index = 0;
memset(guid, 0, guid_len);
/* Retrieve the interfaces list */
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1) {
printf("Error in pcap_findalldevs: %s\n", errbuf);
return -1;
}
/* Scan the list printing every entry */
for (d = alldevs; d != NULL; d = d->next, index++) {
pcap_addr_t *a;
for(a = d->addresses; a != NULL; a = a->next) {
if (a->addr->sa_family == AF_INET) {
ULONG a_addr = ((struct sockaddr_in *)a->addr)->sin_addr.s_addr;
ULONG a_netmask = ((struct sockaddr_in *)a->netmask)->sin_addr.s_addr;
ULONG a_netaddr = a_addr & a_netmask;
ULONG addr = (*netaddr).s_addr;
if (a_netaddr == addr) {
int ret = -1;
char name[128];
char *start, *end;
size_t len = strlen(d->name);
if(len > 127) {
len = 127;
}
memcpy(name, d->name, len);
name[len] = 0;
start = strstr(name, "{");
if (start != NULL) {
end = strstr(start, "}");
if (end != NULL) {
size_t len = end - start + 1;
memcpy(guid, start, len);
ret = index;
}
}
pcap_freealldevs(alldevs);
return ret;
}
}
}
}
printf("Network address not found.\n");
pcap_freealldevs(alldevs);
return -1;
}
开发者ID:killvxk,项目名称:lwip-allnetworks,代码行数:59,代码来源:pcapif.c
示例3: main
int main(void)
{
pcap_if_t *iface, *devs;
int j, i;
char errbuf[PCAP_ERRBUF_SIZE + 1];
FILE *fp;
printf("Copyright (C) Ahmed Samy 2014 <[email protected]>\n\n");
printf("\t\t\tNetwork Traffic Analyzer\n");
if (pcap_findalldevs(&devs, errbuf) == -1 || !devs) {
fprintf(stderr, "No network devices are currently connected\n");
return 1;
}
printf("Enabled Network Devices:\n");
for (i = 1, iface = devs; iface; iface = iface->next)
printf("%d - %s\n", i++, iface->description);
prompt:
printf("Device Index> ");
scanf("%d", &j);
/* Find the interface pointer. */
for (i = 1, iface = devs; iface && i != j; iface = iface->next, ++i);
if (!iface) {
fprintf(stderr, "Invalid device index %d, please try again.", j);
goto prompt;
}
c = capture_new();
c->capture_fn = print_data;
if (!capture_set_iface(c, iface)) {
fprintf(stderr, "Internal error: could not set the interface to capture!\n");
pcap_freealldevs(devs);
return 1;
}
pcap_freealldevs(devs);
fp = fopen("last_bandwidth.txt", "r");
if (fp) {
fscanf(fp, "%lf", &c->cur_bw);
fclose(fp);
}
signal(SIGINT, handle_sig);
signal(SIGABRT, handle_sig);
signal(SIGTERM, handle_sig);
capture_start(c);
return 0;
}
开发者ID:DTSCode,项目名称:NetTraffic,代码行数:53,代码来源:main.c
示例4: fprintf
void pcaplistener::setFilter()
{
int res;
struct tm * ltime;
char timestr[16];
struct pcap_pkthdr *header;
const u_char *pkt_data;
time_t local_tv_sec;
if(pcap_compile(pcap, &filter, fexpr.c_str(), 1, mask) < 0)
{
fprintf(stderr,"\nUnable to compile the packet filter. Check the syntax.\n");
/* Free the device list */
pcap_freealldevs(allDevs);
exit(0);
}
if(pcap_setfilter(pcap, &filter) < 0)
{
fprintf(stderr,"\nError setting the filter.\n");
/* Free the device list */
pcap_freealldevs(allDevs);
exit(0);
}
printf("Filter is set for %s\n", fexpr.c_str());
printf("Filtering for packets...\n");
/* Retrieve the packets */
/* Using pcap_next_ex() instead of pcap_loop() */
while((res = pcap_next_ex(pcap, &header, &pkt_data)) >= 0)
{
if(res == 0)
/* Timeout elapsed */
continue;
/* convert the timestamp to readable format */
local_tv_sec = header->ts.tv_sec;
ltime = localtime(&local_tv_sec);
strftime( timestr, sizeof timestr, "%H:%M:%S", ltime);
printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);
}
if(res == -1) {
printf("Error reading the packets: %s\n", pcap_geterr(pcap));
exit(0);
}
return;
}
开发者ID:aclin,项目名称:winSlink,代码行数:51,代码来源:pcaplistener.cpp
示例5: sprintf
int net_interface_imp::set_capture_ether_type(uint16_t * ether_type, uint32_t count)
{
struct bpf_program fcode;
char ether_type_string[512];
char ether_type_single[64];
const unsigned char * ether_packet = NULL;
struct pcap_pkthdr pcap_header;
ether_type_string[0] = 0;
for (uint32_t index_i = 0; index_i < count; index_i++)
{
sprintf(ether_type_single, "ether proto 0x%04x", ether_type[index_i]);
strcat(ether_type_string, ether_type_single);
if ((index_i + 1) < count)
{
strcat(ether_type_string, " or ");
}
}
/******************************************************* Compile a filter ************************************************/
if (pcap_compile(pcap_interface, &fcode, ether_type_string, 1, 0) < 0)
{
log_imp_ref->post_log_msg(LOGGING_LEVEL_ERROR, "Unable to compile the packet filter.");
pcap_freealldevs(all_devs); // Free the device list
return -1;
}
/*************************************************** Set the filter *******************************************/
if (pcap_setfilter(pcap_interface, &fcode) < 0)
{
log_imp_ref->post_log_msg(LOGGING_LEVEL_ERROR, "Error setting the filter.");
pcap_freealldevs(all_devs); // Free the device list
return -1;
}
/*********** Flush any packets that might be present **********/
for (uint32_t index_j = 0; index_j < 1; index_j++)
{
ether_packet = pcap_next(pcap_interface, &pcap_header);
if (!ether_packet)
{
break;
}
}
return 0;
}
开发者ID:audioscience,项目名称:avdecc-lib,代码行数:49,代码来源:net_interface_imp.cpp
示例6: find_all_devices
inline std::vector<std::string> find_all_devices() {
pcap_if_t *all_devices = nullptr;
auto buf = error_buffer{};
const auto result = pcap_findalldevs(&all_devices, buf.data());
if (result != 0) {
pcap_freealldevs(all_devices);
throw error{"pcap_findalldevs error\n" + error_string(buf)};
}
std::vector<std::string> devices;
for (auto device = all_devices; device != nullptr; device = device->next) {
devices.emplace_back(device->name);
}
pcap_freealldevs(all_devices);
return devices;
}
开发者ID:jshrake,项目名称:pcapp,代码行数:15,代码来源:pcapp.hpp
示例7: GetAdapterName
int GetAdapterName(int AdapterNumber, char* AdapterName, int AdapterNameSize)
{
int i;
pcap_if_t *alldevs;
pcap_if_t *device;
char errbuf[PCAP_ERRBUF_SIZE + 1] = "";
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
printf("Error when getting the list of the installed adapters%s\n", errbuf );
return nbFAILURE;
}
// Get interface name
i= 1;
for (device=alldevs; device != NULL; device=device->next)
{
if (i == AdapterNumber)
{
strncpy(AdapterName, device->name, AdapterNameSize);
AdapterName[AdapterNameSize-1]= 0;
// Free the device list
pcap_freealldevs(alldevs);
return nbSUCCESS;
}
i++;
}
return nbFAILURE;
}
开发者ID:joestringer,项目名称:Netbee,代码行数:32,代码来源:configparams.cpp
示例8: list_devices
/* This function blatantly ripped from
http://www.winpcap.org/docs/docs31/html/group__wpcap__tut1.html */
void list_devices (void)
{
pcap_if_t *alldevs;
pcap_if_t *d;
int i=0;
char errbuf[PCAP_ERRBUF_SIZE];
/* Retrieve the device list from the local machine */
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
exit(1);
}
/* Print the list */
for(d= alldevs; d != NULL; 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;
}
/* We don't need any more the device list. Free it */
pcap_freealldevs(alldevs);
}
开发者ID:joninvski,项目名称:imsniff,代码行数:35,代码来源:imsniff.cpp
示例9: main
int main(int argc, char *argv[])
{
struct interface_list *itfc_list;
char iface[100];
pd = NULL;
gui_register_exit(&exit_fun);
gui_register_stop(&stop_fun);
itfc_list = get_interface_list();
gui_set_interface_list(itfc_list);
guipid = gui_pthread_start(&argc, &argv);
cappid = pthread_self();
signal(SIGUSR1, idle_sig);
while (gui_wait_capture(iface) == 0) {
start_capture(iface);
}
printf("exit\n");
pcap_freealldevs(if_list);
return 0;
}
开发者ID:ChenyuanHu,项目名称:nptool,代码行数:26,代码来源:main.c
示例10: pcap_ex_name
char *
pcap_ex_name(char *name)
{
#ifdef _WIN32
/*
* XXX - translate from libdnet logical interface name to
* WinPcap native interface name.
*/
static char pcap_name[256];
pcap_if_t *pifs, *pif;
char ebuf[128];
int idx, i = 0;
/* XXX - according to the WinPcap FAQ, no loopback support??? */
if (strncmp(name, "eth", 3) != 0 || sscanf(name+3, "%u", &idx) != 1 ||
_pcap_ex_findalldevs(&pifs, ebuf) == -1) {
return (name);
}
for (pif = pifs; pif != NULL; pif = pif->next) {
if (i++ == idx) {
strncpy(pcap_name, pif->name, sizeof(pcap_name)-1);
pcap_name[sizeof(pcap_name)-1] = '\0';
name = pcap_name;
break;
}
}
pcap_freealldevs(pifs);
return (name);
#else
return (name);
#endif
}
开发者ID:WilenceYao,项目名称:pypcap,代码行数:32,代码来源:pcap_ex.c
示例11: pcap_nameindex
struct if_nameindex * pcap_nameindex (void)
{
#if defined (WINPCAP) || defined (LIBPCAP)
char buffer [PCAP_ERRBUF_SIZE];
pcap_if_t * devices = (pcap_if_t *)(0);
pcap_if_t * device;
if (pcap_findalldevs (&devices, buffer) != -1)
{
struct if_nameindex * ifs;
struct if_nameindex * ifp;
unsigned count = 1;
for (device = devices; device; device = device->next)
{
count++;
}
ifp = ifs = (struct if_nameindex *)(malloc (count * sizeof (struct if_nameindex)));
if (ifs) for (device = devices; device; device = device->next)
{
ifp->if_index = device->index;
ifp->if_name = strdup (device->name);
ifp++;
}
memset (ifp, 0, sizeof (* ifp));
pcap_freealldevs (devices);
return (ifs);
}
#endif
return ((struct if_nameindex *)(0));
}
开发者ID:GSLyons,项目名称:open-plc-utils,代码行数:34,代码来源:pcap_nameindex.c
示例12: Call_Device
void Call_Device(char **C_dev)
{
pcap_if_t *alldevs;
pcap_if_t *d;
int i=0;
char Select_device[10];
char errbuf[PCAP_ERRBUF_SIZE];
/* Retrieve the device list */
if (pcap_findalldevs(&alldevs, errbuf) == -1)
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
/* Print the list */
for(d=alldevs;d;d=d->next)
printf("%d. %s \n", ++i, d->name);
if(i==0)
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
printf("\nSelect Device: ");
scanf("%s",&Select_device);
*C_dev=Select_device;
/* We don't need any more the device list. Free it */
pcap_freealldevs(alldevs);
}
开发者ID:JoongbuSPY,项目名称:TCP_sesstion,代码行数:30,代码来源:tcp.hpp
示例13: pcap_findalldevs
static char *match_dev_regex_or_die(const char *regstr) {
static char dev[1024];
int matches = 0, devlen = 0;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_if_t *interfaces, *cur;
int err;
err = pcap_findalldevs(&interfaces, errbuf);
if(err)
die(0, "pcap_findalldevs(): %s", errbuf);
for(cur = interfaces; cur; cur = cur->next)
if(regex_matches_or_is_null(regstr, cur->name))
devlen = snprintf(&dev[devlen], sizeof(dev) - devlen
, "%s%s"
, matches++ ? ", " : ""
, cur->name);
if(!matches)
die(0, "No device matching regex: %s", regstr);
else if(matches > 1)
die(0, "Ambiguous device regex: %s\nDid you mean one of these: %s", regstr, dev);
pcap_freealldevs(interfaces);
return dev;
}
开发者ID:protoben,项目名称:protodump,代码行数:26,代码来源:capture.c
示例14: SetupProcessImage
/**
********************************************************************************
\brief setup the process image
SetupProcessImage() sets up the process image used by the application.
\retval -1 if interface list couldn't be filled
\retval 0 if interface list was successfully filled
*******************************************************************************/
int InterfaceSelectDialog::fillList(void)
{
char sErr_Msg[PCAP_ERRBUF_SIZE];
pcap_if_t * alldevs;
pcap_if_t * seldev;
int numIntf = 0;
/* Retrieve the device list on the local machine */
if (pcap_findalldevs(&alldevs, sErr_Msg) == -1)
{
return -1;
}
/* Add the list to the listbox */
for (seldev = alldevs; seldev != NULL; seldev = seldev->next)
{
numIntf ++;
new QListWidgetItem(seldev->name, m_deviceListWidget);
}
pcap_freealldevs(alldevs);
if (numIntf > 0)
return 0;
else
return -1;
}
开发者ID:Lezval,项目名称:openPOWERLINK_systec,代码行数:35,代码来源:InterfaceSelectDialog.cpp
示例15: gen_eth_show_dev_list
/* Display Ethernet interfaces of the system */
int gen_eth_show_dev_list(void)
{
char pcap_errbuf[PCAP_ERRBUF_SIZE];
pcap_if_t *dev_list,*dev;
int res;
printf("Network device list:\n\n");
#ifndef CYGWIN
res = pcap_findalldevs(&dev_list,pcap_errbuf);
#else
res = pcap_findalldevs_ex(PCAP_SRC_IF_STRING,NULL,&dev_list,pcap_errbuf);
#endif
if (res < 0) {
fprintf(stderr,"PCAP: unable to find device list (%s)\n",pcap_errbuf);
return(-1);
}
for(dev=dev_list;dev;dev=dev->next) {
printf(" %s : %s\n",
dev->name,
dev->description ? dev->description : "no info provided");
}
printf("\n");
pcap_freealldevs(dev_list);
return(0);
}
开发者ID:GNS3,项目名称:dynamips,代码行数:31,代码来源:gen_eth.c
示例16: pcap_freealldevs
BOOL CDeviceDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在此添加额外的初始化
CCUGBLinkerDlg* pMainWnd=(CCUGBLinkerDlg*)theApp.m_pMainWnd;
CString curNicDes;
int curNicIndex=0;
pcap_if_t* alldevs=finddevs();
pcap_if_t* d=NULL;
int i=0;
for(d = alldevs; d != NULL; d = d->next,i++)
{
m_lstDev.AddString(CString(d->description));
if (CString(d->name)==m_curNIC)
{
curNicIndex=i;
}
}
if (alldevs)
{
pcap_freealldevs(alldevs);
}
m_lstDev.SetCurSel(curNicIndex);
OnLbnSelchangeListDevice();
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
开发者ID:peterix,项目名称:cugblinker,代码行数:28,代码来源:DeviceDlg.cpp
示例17: iface_find_or_exit
static void iface_find_or_exit(const char *wildcard)
{
pcap_if_t *alldevs, *dev;
char errbuf[PCAP_ERRBUF_SIZE];
if (-1 == pcap_findalldevs(&alldevs, errbuf)) {
fprintf(stderr, "Error building iface list: %s\n", errbuf);
exit(EXIT_FAILURE);
}
printf("Search for interface '%s'... ", wildcard);
for (dev = alldevs; dev; dev = dev->next) {
if ('\0' != wildcard[0] && NULL == strstr(dev->name, wildcard) && (NULL == dev->description || NULL == strstr(dev->description, wildcard)))
continue;
printf("OK.\n");
strlcpy(Dev_Str[Iface_Cnt++], dev->name, sizeof Dev_Str);
if (IFACE_MAX == Iface_Cnt) {
printf("Interface limit reached.\n");
break;
}
}
if (0 == Iface_Cnt) {
iface_list();
fprintf(stderr, "No interfaces matched '%s', quitting.\n", wildcard);
exit(EXIT_FAILURE);
}
pcap_freealldevs(alldevs);
}
开发者ID:rflynn,项目名称:lanassert,代码行数:26,代码来源:LANassert.c
示例18: selectNic
/*selectNum是从1开始*/
void selectNic(int selectNum)
{
pcap_if_t *d;
for (d=alldevs; selectNum>1; d=d->next,selectNum--);
strncpy(nic, d->name, sizeof(nic)-1);
pcap_freealldevs(alldevs);
}
开发者ID:yjcn,项目名称:gitxx,代码行数:8,代码来源:myconfig.c
示例19: qDebug
void DevSelectDlg::showallDev()
{
if(pcap_findalldevs(&alldevs, errbuf) == PCAP_ERROR)
{
qDebug() << "pcap_findalldevs() error : " << errbuf;
QMessageBox::information(NULL, "ERROR", "pcap_findalldevs() error");
close();
}
int i;
QListWidgetItem *qListWidgetItem;
for(devsTmp = alldevs, i = 1; NULL != devsTmp; devsTmp = devsTmp->next, i++)
{
if(i == 1 && devsTmp == NULL)
{
qDebug() << "Interface not found!";
QMessageBox::information(NULL, "ERROR", "Interface not found");
close();
}
qListWidgetItem = new QListWidgetItem(ui->listWidget);
qListWidgetItem->setText(devsTmp->name);
}
pcap_freealldevs(alldevs);
}
开发者ID:hojei1452,项目名称:da,代码行数:25,代码来源:devselectdlg.cpp
示例20: pcap_findalldevs
PcapLiveDeviceList::PcapLiveDeviceList()
{
pcap_if_t* interfaceList;
char errbuf[PCAP_ERRBUF_SIZE];
int err = pcap_findalldevs(&interfaceList, errbuf);
if (err < 0)
{
LOG_ERROR("Error searching for devices: %s", errbuf);
}
pcap_if_t* currInterface = interfaceList;
while (currInterface != NULL)
{
#ifdef WIN32
PcapLiveDevice* dev = new WinPcapLiveDevice(currInterface, true, true, true);
#else //LINUX, MAC_OSX
PcapLiveDevice* dev = new PcapLiveDevice(currInterface, true, true, true);
#endif
currInterface = currInterface->next;
m_LiveDeviceList.insert(m_LiveDeviceList.end(), dev);
}
setDnsServers();
LOG_DEBUG("Freeing live device data");
pcap_freealldevs(interfaceList);
}
开发者ID:HaochuanXJTU,项目名称:PcapPlusPlus,代码行数:27,代码来源:PcapLiveDeviceList.cpp
注:本文中的pcap_freealldevs函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论