I am trying a code for packet capturing for only SIP traffic however I'm capturing other traffic also inspite of having setup a filter. The system I am working on is connected to a linux bridge. Please have a look @ the code and tell me what I am doing wrong -
#include<pcap.h>
-
#include<stdlib.h>
-
#include<string.h>
-
#define MAXBYTES2CAPTURE 2074
-
-
void processPacket(u_char* arg,const struct pcap_pkthdr *pkthdr,const u_char *packet)
-
{
-
int i=0,*counter=(int*)arg;
-
printf("\nPacket count = %d",++(*counter));
-
printf("\nrecieved packet size = %d",pkthdr->len);
-
printf("\npayload\n");
-
for(i=0;i<pkthdr->len;i++)
-
{ if(isprint(packet[i]))
-
printf("%c",packet[i]);
-
else
-
printf(". ");
-
if(((i%16==0)&&(i!=0))||i==pkthdr->len-1)
-
printf("\n");
-
}
-
return;
-
}
-
int main()
-
{
-
int i=0,count=0;
-
pcap_t *desc=NULL;
-
char device[] = "my_bridge";
-
char filter_exp[] = "port 5060"; /* The filter expression */
-
bpf_u_int32 mask; /* The netmask of our sniffing device */
-
bpf_u_int32 net; /* The IP of our sniffing device */
-
char errbuf[PCAP_ERRBUF_SIZE];
-
struct bpf_program fp;
-
memset(errbuf,0,PCAP_ERRBUF_SIZE);
-
if (pcap_lookupnet(device, &net, &mask, errbuf) == -1) {
-
fprintf(stderr, "Can't get netmask for device %s\n", device);
-
net = 0;
-
mask = 0;
-
}
-
printf("\nAfter looknet");
-
printf("\nopening device %s",device);
-
printf("\nnetmaskv
-
",mask);
-
printf("\nnet
-
",net);
-
desc=pcap_open_live(device,MAXBYTES2CAPTURE,1,512,errbuf);
-
if (pcap_compile(desc, &fp, filter_exp, 1, net) == -1) {
-
fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(desc));
-
return(2);
-
}
-
else
-
printf("\ncompile OK");
-
if (pcap_setfilter(desc, &fp) == -1) {
-
fprintf(stderr, "Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(desc));
-
return(2);
-
}
-
else printf("\nfilter ok");
-
pcap_loop(desc,-1,processPacket,(u_char*)&count);
-
return 0;
-
}
0 1488 Sign in to post your reply or Sign up for a free account.
Similar topics
by: SirPoonga |
last post by:
Is it possible that when having a user using Filter By Form in a form
that no matter what the user enters in for a value that "LIKE *Value*"
gets automatically replaced? Would I have to do...
|
by: steve |
last post by:
Hi
Can anyone help me with how I can capture binary data that is being sent to a com port 1 from an app that is sitting on the same machine
Thanks heap
Steve
|
by: HL |
last post by:
How can I watched the outgoing packets. for exampled,
when I send an email, how can I catch the whole outgoing packets?
I've looked for some snifer-like tools, most of them "just" watch
the...
|
by: David |
last post by:
Hi, I use DataView to filter my record.
But when I use:
ls_filter += " and DATEPART(hh, CA103)=" + i ;
mydv.RowFilter = ls_filter;
I got error.
How should I filter by hour using...
|
by: Fraser Dickson |
last post by:
I am building a web based system using ASP.NET and VB.NET
which has to interact with a web service which uses XML
WDDX packets.
I have been given the XML Packet Specification by the Web
Service...
|
by: Qajussi |
last post by:
Hi!
I am trying to create data entry forms like MS access forms using asp.net.
I am talking about a form like MS access forms which let you enter a new
record, edit, navigate to previous and next...
|
by: sck10 |
last post by:
Hello,
I want to allow all users on our company intranet (domain\handle) to enter
our website. However, I would like to capture the handle of the person
entering my website. I was told that if...
|
by: mostafijur |
last post by:
Hi,
I need Source code in C/C++ to capture packets from a LAN using Linux (Mandriva) OS.Packets are like TCP,UDP,HTTP.
Thanks
|
by: jaco.versfeld |
last post by:
Hi There,
I have a basic TCP client and TCP server in C++. The TCP client
connects to the server, and after a setup phase starts to transmit a
file to the TCP server using multiple packets...
|
by: ghost1980 |
last post by:
hi there,
i need your help for a solution and code (if neccessary), to help me to filter a datasheet using a COMBO BOX.
i have a query, which contain the following example:
NAME | AGE |...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |