当前位置: 首页>>代码示例>>C++>>正文


C++ pcap_lookupdev函数代码示例

本文整理汇总了C++中pcap_lookupdev函数的典型用法代码示例。如果您正苦于以下问题:C++ pcap_lookupdev函数的具体用法?C++ pcap_lookupdev怎么用?C++ pcap_lookupdev使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pcap_lookupdev函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(){
    char *dev; 
    int ret; 
    char errbuf[PCAP_ERRBUF_SIZE];
    bpf_u_int32 netp; 
    bpf_u_int32 maskp;
    pcap_t* descr;

    dev = pcap_lookupdev(errbuf);
    if(dev == NULL){
        printf("%s\n",errbuf);
        exit(1);
    }
    
    ret = pcap_lookupnet(dev,&netp,&maskp,errbuf);
    if(ret == -1){
        printf("%s\n",errbuf);
        exit(1);
    }
    
    descr = pcap_open_live(dev,BUFSIZ,1,1,errbuf);
    if(descr == NULL){
	printf("%s\n",errbuf);
	exit(1);
    }
    pcap_loop(descr,-1,find,NULL);
    return 0;
}
开发者ID:okas832,项目名称:Packet_HW,代码行数:28,代码来源:pcap_main.c

示例2: main

int main(int argc, char *argv[])
{
	char *dev;
	char errbuf[PCAP_ERRBUF_SIZE];
	pcap_t *pd;
        
	if(!(dev = pcap_lookupdev(errbuf)))
	{
		perror(errbuf);
		exit(1);
	}
        
	if((pd = pcap_open_live(dev, PCAP_SNAPSHOT, 1, PCAP_TIMEOUT, errbuf)) == NULL) 
	{
		perror(errbuf);
		exit(1);
	}
        
	if(pcap_loop(pd, -1, packet_view, 0) < 0) 
	{
		perror(pcap_geterr(pd));
		exit(1);
	}
        
	pcap_close(pd);
        return 0;
}
开发者ID:gusals224,项目名称:network,代码行数:27,代码来源:packet.c

示例3: startSniffer

void startSniffer(char *filter)
{
	struct in_addr in;

	if (dev == NULL)
		if ((dev = pcap_lookupdev(errbuf)) == NULL) {
			fprintf(stderr, "startSniffer: couldn't find a device to sniff: %s\n", errbuf);
			exit(1);
		}

	printf("\n\n%s starting: listening on device: %s\n", VERSION, dev);

	if ((pd = pcap_open_live(dev, SNAPLEN, promisc, readtimeout, errbuf)) == NULL) {
		fprintf(stderr, "startSniffer: pcap_open_live failed: %s\n", errbuf);
		exit(1);
	}


	pcap_lookupnet(dev, &netp, &maskp, errbuf);
	in.s_addr = netp;
	printf("%s (%s/", dev, inet_ntoa(in));
	in.s_addr = maskp;
	printf("%s) opened successfully in %spromiscuous mode\n", inet_ntoa(in), (promisc ? "" : "non-"));

	if (filter != NULL) {
		pcap_compile(pd, &fprog, filter, 0, netp);
		if ((pcap_setfilter(pd, &fprog)) == -1) {
			fprintf(stderr, "startSniffer: pcap_setfilter: cannot set filter\n");
			exit(1);
		}
		pcap_freecode(&fprog);
	}
}
开发者ID:EnderUNIX,项目名称:Hafiye,代码行数:33,代码来源:Sniff.c

示例4: main

int main(void) {
  char *device=NULL;
  pcap_if_t *alldevsp;

  char errbuf[PCAP_ERRBUF_SIZE];


  device = pcap_lookupdev(errbuf);
  printf("device %s\n",device);




  if (pcap_findalldevs (&alldevsp, errbuf) < 0)   
    {
      fprintf (stderr, "Error %s", errbuf);
      exit (1);
    }

  while (alldevsp != NULL)
    {
      printf ("%s\n", alldevsp->name);
      alldevsp = alldevsp->next;
    }

  return 1;

}
开发者ID:iloveloveyou,项目名称:chirico,代码行数:28,代码来源:pcap0.c

示例5: main

int main(void)
{
	printf("I'm a sniffer, running...\n");

	pcap_t *sniffer_handle = NULL;
	char errbuf[PCAP_ERRBUF_SIZE], *device = NULL;
	int count = 0;
	memset(errbuf, 0, PCAP_ERRBUF_SIZE);

	device = pcap_lookupdev(errbuf);
	if (device == NULL)
		err_die(errbuf);
	printf("Opening device %s\n", device);

	sniffer_handle = pcap_open_live(device, 2048, 1, 512, errbuf);
	if (sniffer_handle == NULL)
		err_die(errbuf);

	if (pcap_datalink(sniffer_handle) != DLT_EN10MB)
	{
		printf("不支持Ethernet headers\n");
	}

	pcap_loop(sniffer_handle, -1, process_packet, (u_char *)&count);

	return 0;
}
开发者ID:2012-wangjiaqi,项目名称:network_sniffer,代码行数:27,代码来源:base_sniffer.c

示例6: pcap_lookupdev

/* Find and prepare ethernet device for capturing */
pcap_t *prepare_capture(char *interface, int promisc, char *capfilter) {
    char errbuf[PCAP_ERRBUF_SIZE];
    pcap_t *pcap_hnd;
    char *dev = NULL;
    bpf_u_int32 net, mask;
    struct bpf_program filter;


    /* Starting live capture, so find and open network device */
    if (!interface) {
        dev = pcap_lookupdev(errbuf);
        if (dev == NULL)
            LOG_DIE("Cannot find a valid capture device: %s", errbuf);
    } else {
        dev = interface;
    }

    if (pcap_lookupnet(dev, &net, &mask, errbuf) == -1) net = 0;

    pcap_hnd = pcap_open_live(dev, BUFSIZ, promisc, 0, errbuf);
    if (pcap_hnd == NULL)
        LOG_DIE("Cannot open live capture on '%s': %s", dev, errbuf);

    set_link_header_offset(pcap_datalink(pcap_hnd));

    /* Compile capture filter and apply to handle */
    if (pcap_compile(pcap_hnd, &filter, capfilter, 0, net) == -1)
        LOG_DIE("Cannot compile capture filter '%s': %s", capfilter, pcap_geterr(pcap_hnd));

    if (pcap_setfilter(pcap_hnd, &filter) == -1)
        LOG_DIE("Cannot apply capture filter: %s", pcap_geterr(pcap_hnd));

    pcap_freecode(&filter);
    return pcap_hnd;
}
开发者ID:kuaikuai,项目名称:httpcap,代码行数:36,代码来源:test_cap.c

示例7: main

int main()
{
    char *dev,errbuf[PCAP_ERRBUF_SIZE];
    pcap_t * handle;
    struct pcap_pkthdr header;
    const u_char *packet;

    struct bpf_program fp;
    char filter_exp[]="dst host www.google.com";
    bpf_u_int32 mask,net;

    dev=pcap_lookupdev(errbuf);

    pcap_lookupnet(dev,&net,&mask,errbuf);

    handle=pcap_open_live(dev,BUFSIZ,0,-1,errbuf);

    //pcap_compile(handle,&fp,filter_exp,0,net);

    //pcap_setfilter(handle,&fp);

    packet=pcap_next(handle,&header);
    printf("%d\n",header.len);

    pcap_loop(handle,-1,callback,NULL);
    pcap_close(handle);

    return 0;
}
开发者ID:war,项目名称:offlinetwitter,代码行数:29,代码来源:capture.c

示例8: pcap_lookupdev

/*
 * Class:     com_me_lodea_jcap_JCapSession
 * Method:    getDefaultInterface
 * Signature: ()Ljava/net/NetworkInterface;
 */
JNIEXPORT jobject JNICALL Java_com_me_lodea_jcap_JCapSession_getDefaultInterface
  (JNIEnv* const env, const jclass clazz)
{
    char errorbuf[PCAP_ERRBUF_SIZE];
    const char* dev;
    jclass ifaceClass;
    jmethodID factory;
    jstring ifaceName;
    
    dev = pcap_lookupdev(errorbuf);
    if (dev == NULL)
    {
        throwJCapException(env, errorbuf);
        return NULL;
    }
    ifaceClass = (*env)->FindClass(env, "java/net/NetworkInterface");
    if (ifaceClass == NULL)
    {
        return NULL;
    }
    factory = (*env)->GetStaticMethodID(env, ifaceClass,
        "getByName", "(Ljava/lang/String;)Ljava/net/NetworkInterface;");
    if (factory == NULL)
    {
        return NULL;
    }
    ifaceName = (*env)->NewStringUTF(env, dev);
    if (ifaceName == NULL)
    {
        return NULL;
    }
    return (*env)->CallStaticObjectMethod(env, ifaceClass, factory, ifaceName);
}
开发者ID:quelgar,项目名称:jcap,代码行数:38,代码来源:jcap.c

示例9: pcap_initialize

/*
 * PCap initialize
 */
int pcap_initialize(char *pcap_errbuf, u_int32_t *net, u_int32_t *mask)
{
    char *dev;

    // find a device if not specified
    if(!progopt.device_set()) {
        dev = pcap_lookupdev(pcap_errbuf);
        if (dev == NULL) {
            return 0;
        }
    }
    else {
        dev = progopt.device;
    }

    // get network number and mask associated with capture device
    if(pcap_lookupnet(dev, net, mask, pcap_errbuf) == -1) {
        return 0;
    }

    // open capture device
    handle = pcap_open_live(dev, PKT_LEN, 1, progopt.time, pcap_errbuf);
    if (handle == NULL) {
        return 0;
    }

    return 1;
}
开发者ID:olemoudi,项目名称:toolbox,代码行数:31,代码来源:inject.cpp

示例10: capture_package

void capture_package( char * dst_ip_str )
{
	pcap_t* pcap_handle;
	char error_content[PCAP_ERRBUF_SIZE];
	char *net_interface;
	struct bpf_program bpf_filter;
	/* "" indicates capture all packet*/
	char bpf_filter_string[] = "tcp";
	bpf_u_int32 net_mask;
	bpf_u_int32 net_ip;

	/* get network interface */
	net_interface = pcap_lookupdev( error_content );
	if(net_interface == NULL){
		fprintf(stderr, "Couldn't find default device: %s\n",
           error_content);
		exit(1);
	}
	printf("Device: %s\n", net_interface);

	/* get network addr, mask */
	if( pcap_lookupnet( net_interface, &net_ip,
                     &net_mask, error_content ) == -1){
		fprintf(stderr, "Couldn't get netmask for device %s\n",
            net_interface);
		exit(1);
	}

	/* open network interface */
	pcap_handle = pcap_open_live( net_interface, BUFSIZ,
                               1, 0, error_content );
	if(pcap_handle == NULL){
		fprintf(stderr, "Couldn't open device %s: %s\n",
           net_interface, error_content);
		exit(1);
	}

	//sprintf(bpf_filter_string, "src %s and dst %s tcp", net_ip, dst_ip_str);
	/* compile the filter */
	if( pcap_compile( pcap_handle, &bpf_filter,
                   bpf_filter_string, 0, net_ip ) == -1){
		fprintf(stderr, "couldn't parse filter: %s: %s\n",
           bpf_filter_string, pcap_geterr(pcap_handle));
		exit(1);
	}
	/* set the filter */
	if( pcap_setfilter( pcap_handle, &bpf_filter ) == -1 ){
		fprintf(stderr, "couldn't install filter: %s: %s\n",
          bpf_filter_string, pcap_geterr(pcap_handle));
		exit(1);
	}

	//if( pcap_datalink( pcap_handle ) != DLT_EN10MB ) //return link layer type
	//	return;
	/* register the call back function, capture the packet in loop
	   then, callback function analysis the packet */
	pcap_loop( pcap_handle, -1, tcp_protocol_packet_callback, NULL );
	pcap_close( pcap_handle );

}
开发者ID:WangLin2011,项目名称:simple_port_scanner,代码行数:60,代码来源:captpacket.c

示例11: main

int main() {
	struct pcap_pkthdr header;
	const u_char *packet;
	char errbuf[PCAP_ERRBUF_SIZE];
	char *device;
	pcap_t *pcap_handle;
	int i;

	device = pcap_lookupdev(errbuf);
	if(device == NULL)
		pcap_fatal("pcap_lookupdev", errbuf);

	printf("Sniffing on device %s\n", device);
	
	pcap_handle = pcap_open_live(device, 4096, 1, 0, errbuf);
	if(pcap_handle == NULL)
		pcap_fatal("pcap_open_live", errbuf);
	
	for(i=0; i < 3; i++) {
		packet = pcap_next(pcap_handle, &header);
		printf("Got a %d byte packet\n", header.len);
		dump(packet, header.len);
	}

	pcap_close(pcap_handle);
}
开发者ID:17twenty,项目名称:hackingSkel,代码行数:26,代码来源:pcap_sniff.c

示例12: main

int main(int argc,char *argv[]){  
	char *dev, errbuf[PCAP_ERRBUF_SIZE];  
	int i  =  0;
	struct bpf_program filter;
	char filter_app[]  =  "src host  192.168.8.144 && arp ";
	bpf_u_int32 mask;
	bpf_u_int32 net;
	pcap_t *handle  =  NULL;
	pcap_dumper_t *pcap_dumper  =  NULL;
	dev = pcap_lookupdev(errbuf);  
	if(dev == NULL){  
		fprintf(stderr,"couldn't find default device: %s\n",errbuf);  
		return(2);  
	}  
	prjntf("Device: %s\n",dev);  
	pcap_lookupnet(dev,&net,&mask,errbuf);
	handle  =  pcap_open_ljve(dev,BUFSIZ,1,0,errbuf);
	pcap_compjle(handle,&filter,filter_app,0,net);
	pcap_setfjlter(handle,&filter);
	pcap_dumper  =  pcap_dump_open(handle,"ljbcaptest1.pcap");
	prjntf("%d*******\n",i);
	j  =  pcap_loop(handle,10,pcap_dump,(u_char *)pcap_dumper);
	pcap_dump_flush(pcap_dumper);
	pcap_dump_close(pcap_dumper);

	prjntf("%d*******\n",i);
	pcap_close(handle);
	return(0);  
}
开发者ID:sugarguo,项目名称:work,代码行数:29,代码来源:vimtest.c

示例13: curses_bridged_sniff

/*
 * display the interface selection for bridged sniffing
 */
static void curses_bridged_sniff(void)
{
   wdg_t *in;
   char err[PCAP_ERRBUF_SIZE];
   
   DEBUG_MSG("curses_bridged_sniff");
   
   /* if the user has not specified an interface, get the first one */
   if (GBL_OPTIONS->iface == NULL) {
      SAFE_CALLOC(GBL_OPTIONS->iface, IFACE_LEN, sizeof(char));
      strncpy(GBL_OPTIONS->iface, pcap_lookupdev(err), IFACE_LEN - 1);
   }
   
   SAFE_CALLOC(GBL_OPTIONS->iface_bridge, IFACE_LEN, sizeof(char));

   wdg_create_object(&in, WDG_INPUT, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL);
   wdg_set_color(in, WDG_COLOR_SCREEN, EC_COLOR);
   wdg_set_color(in, WDG_COLOR_WINDOW, EC_COLOR);
   wdg_set_color(in, WDG_COLOR_FOCUS, EC_COLOR_FOCUS);
   wdg_set_color(in, WDG_COLOR_TITLE, EC_COLOR_MENU);
   wdg_input_size(in, strlen("Second network interface :") + IFACE_LEN, 4);
   wdg_input_add(in, 1, 1, "First network interface  :", GBL_OPTIONS->iface, IFACE_LEN, 1);
   wdg_input_add(in, 1, 2, "Second network interface :", GBL_OPTIONS->iface_bridge, IFACE_LEN, 1);
   wdg_input_set_callback(in, bridged_sniff);
   
   wdg_draw_object(in);
      
   wdg_set_focus(in);
}
开发者ID:devlicious,项目名称:ettercap,代码行数:32,代码来源:ec_curses.c

示例14: capture

void capture(char *dev) {
  pcap_t *pcap;
  char errbuf[PCAP_ERRBUF_SIZE];
  struct pcap_pkthdr header;	/* The header that pcap gives us */
  const u_char *packet;		/* The actual packet */

  if(NULL == dev) {
    dev = pcap_lookupdev(errbuf);
    if (dev == NULL) {
      fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
      exit(1);
    }
  }

  pcap = pcap_create(dev, errbuf);
  pcap_set_rfmon(pcap, 1);
  pcap_set_promisc(pcap, 1);
  pcap_set_buffer_size(pcap, 1 * 1024 * 1024);
  pcap_set_timeout(pcap, 1);
  pcap_set_snaplen(pcap, 16384);
  pcap_activate(pcap);    
  if(DLT_IEEE802_11_RADIO == pcap_datalink(pcap)) {
    pcap_loop(pcap, 0, got_packet, 0);
  } else {
    fprintf(stderr, "Could not initialize a IEEE802_11_RADIO packet capture for interface %s\n", dev);
  }
}
开发者ID:ayourtch,项目名称:beacondump,代码行数:27,代码来源:beacondump.c

示例15: main

/* main(): Main function. Opens network interface and calls pcap_loop() */
int main(int argc, char *argv[] ){ 

    int i=0, count=0; 
    pcap_t *descr = NULL; 
    char errbuf[PCAP_ERRBUF_SIZE], *device=NULL; 
    memset(errbuf,0,PCAP_ERRBUF_SIZE); 

    if( argc > 1){  /* If user supplied interface name, use it. */
        device = argv[1];
    }
    else{  /* Get the name of the first device suitable for capture */ 

        if ( (device = pcap_lookupdev(errbuf)) == NULL){
            fprintf(stderr, "ERROR: %s\n", errbuf);
            exit(1);
        }
    }

    printf("Opening device %s\n", device); 

    /* Open device in promiscuous mode */ 
    if ( (descr = pcap_open_live(device, MAXBYTES2CAPTURE, 1,  512, errbuf)) == NULL){
        fprintf(stderr, "ERROR: %s\n", errbuf);
        exit(1);
    }

    /* Loop forever & call processPacket() for every received packet*/ 
    if ( pcap_loop(descr, -1, processPacket, (u_char *)&count) == -1){
        fprintf(stderr, "ERROR: %s\n", pcap_geterr(descr) );
        exit(1);
    }

    return 0; 

} 
开发者ID:HSpear,项目名称:cliqq,代码行数:36,代码来源:sniffer.cpp


注:本文中的pcap_lookupdev函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。