I'm right now facing an issue. I was told to program a Network Traffic Analysis to keep track of all the traffic that is flowing within the Virtual Environment. The application now is running fine and able to track all the network traffic that is running across the virtual environment. I have a GUI(ASP.net). Now i have to actually design a GUI which has a start button. Before hitting the start button, there is 2 text box. One which specifies the Adapter that you wanna track, and the other is the ip address. All the traffic that is captured will be sent to the desired ip address of what you've entered. Of course the receiver side will have to also launch an application called a receiver to receive all the packets.
My objective now is to add in another textbox and allow user to enter which protocol they actually wanna filter in. let's say for example if they want to filter it according to TCP, only TCP packets should be sent over.
Main Program:
int main(int argc, char **argv)
{
// Interfaces
// pcap structures
int lRetVal = 0;
pcap_if_t *lAllDevs = NULL;
pcap_if_t *lDevice = NULL;
char lTemp[PCAP_ERRBUF_SIZE];
char lAdapter[MAX_BUF_SIZE + 1];
int lCounter = 1;
// int lIFCnum = 0;
pcap_t *lIFCHandle = NULL;
struct bpf_program lFCode;
unsigned int lNetMask = 0;
char filter_exp[] = ""; /* The filter expression */
bpf_u_int32 mask; /* The netmask of our sniffing device */
bpf_u_int32 net; /* The IP of our sniffing device */
char sth[255];
char desc[1000];
if ((lIFCHandle = pcap_open(lAdapter, // name of the device
65536, // portion of the packet to capture.
// 65536 grants that the whole packet will be captured on all the MACs
0, //PCAP_OPENFLAG_PROMISCUOUS (nonzeron promiscuous mode)
1000, // read timeout
NULL, // error buffer
lTemp)) == NULL)
{
fprintf(stderr,"\nUnable to open the adapter.\n");
lRetVal = 5;
goto END;
}
/*
* Compiling + setting the filter
*
*/
if (lDevice->addresses != NULL)
/* Retrieve the mask of the first address of the interface */
net=((struct sockaddr_in *)(lDevice->addresses->netmask))->sin_addr.S_un.S_addr;
else
/* If the interface is without an address we suppose to be in a C class network */
net=0xffffff;
char filter_exp[] = "what user enter in asp.net text box"; /* The filter expression */
bpf_u_int32 mask; /* The netmask of our sniffing device */
bpf_u_int32 net; /* The IP of our sniffing device */
/*
* Compiling + setting the filter
*
*/
if (lDevice->addresses != NULL)
/* Retrieve the mask of the first address of the interface */
net=((struct sockaddr_in *)(lDevice->addresses->netmask))->sin_addr.S_un.S_addr;
else
/* If the interface is without an address we suppose to be in a C class network */
net=0xffffff;