pcap_lookupdev example

#include<stdio.h>
#include<pcap.h>
#define ERROR_BUFFER_SIZE 20
int main(int argc,char *argv[])
{


/*
First thing we have to do here is know the  network interface which we have to listen. If we already know the interface which
Ww have to listen then we can directly specify it or we can ask libpcap give us the interface with the function char* pcap_lookupdev(char *errbuf).This function returns the pointer to the string specifying the interface which is suitable for packet capturing
*/

char *interface,error[PCAP_ERRBUF_SIZE];
interface=pcap_lookupdev(error);
if(interface == NULL){

printf("no interface exist on which we can listen");
return -1;
}
printf("\n the interface on which we can listen is %s",interface);
return 0;


}


My Previous posts has how to install pcap library if you have not installed yet

Use the following command to generate the binary

gcc -o test test.c -lpcap

and run it by using root permissions: sudo ./test

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto