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); //释放掉内存资源
    
    }
    
  • 相关阅读:
    Android流畅度测试
    linux常用操作指令
    SQL语句
    客户端专项测试谈
    我的面经(ing)
    整理面试题
    百度质量部测试开发面试题
    UIResponder响应链
    NSURLSession进行网络请求
    命令行工具打包
  • 原文地址:https://www.cnblogs.com/UnGeek/p/2731613.html
Copyright © 2011-2022 走看看