zoukankan      html  css  js  c++  java
  • Wincap获取设备

    // hello.cpp : 定义控制台应用程序的入口点。
    //
    #define  WPCAP
    #define HAVE_REMOTE
    #include "stdafx.h"
    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <vector>
    /*
    * we do not want the warnings about the old deprecated and unsecure CRT functions
    * since these examples can be compiled under *nix as well
    */
    
    #include "pcap.h"
    
    void  main()
    
    {
    
    	pcap_if_t *alldevs,*d;
    
    	int i=0;
    
    	char errbuf[PCAP_ERRBUF_SIZE];
    
    	/* PCAP_ERRBUF_SIZE =256,在pcap.h中定义*/            
    	if (pcap_findalldevs(&alldevs, errbuf) == -1) /* 这个API用来获得网卡的列表*/
    
    	{	
    		fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
    
    		//errbuf参数当有异常情况发生时这个参数会被填充为某个特定的错误字串
    
    		return;
    
    	} 
    	/* 显示列表的响应字段的内容*/
    
    	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;
    
    	}
    
    
    
    	/*We don't need any more the device list. Free it */
    
    	pcap_freealldevs(alldevs); //释放掉内存资源
    
    }
    
  • 相关阅读:
    Jasper 常用知识点总结
    Linux
    搭建spring项目,无法创建RequestMappingHandlerMapping异常
    pom.xml文件设置
    MySQL的常用JSON函数
    SQL中的条件判断语句(case when zhen if,ifnull)用法
    sql查询原理
    sql积累
    Linux常用命令大全
    mysql中group by 的用法解析
  • 原文地址:https://www.cnblogs.com/UnGeek/p/2731613.html
Copyright © 2011-2022 走看看