473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

I would like to filter and capture only SIP Packets using libpcap

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
Expand|Select|Wrap|Line Numbers
  1. #include<pcap.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #define MAXBYTES2CAPTURE 2074
  5.  
  6. void processPacket(u_char* arg,const struct pcap_pkthdr *pkthdr,const u_char *packet)
  7. {
  8.     int i=0,*counter=(int*)arg;
  9.     printf("\nPacket count = %d",++(*counter));
  10.     printf("\nrecieved packet size = %d",pkthdr->len);
  11.     printf("\npayload\n");
  12.     for(i=0;i<pkthdr->len;i++)
  13.     {    if(isprint(packet[i]))
  14.         printf("%c",packet[i]);
  15.         else
  16.         printf(". ");
  17.         if(((i%16==0)&&(i!=0))||i==pkthdr->len-1)
  18.         printf("\n");
  19.     }
  20.     return;
  21. }
  22. int main()
  23. {
  24.     int i=0,count=0;
  25.     pcap_t *desc=NULL;
  26.     char device[] = "my_bridge";
  27.     char filter_exp[] = "port 5060";    /* The filter expression */
  28.      bpf_u_int32 mask;        /* The netmask of our sniffing device */
  29.      bpf_u_int32 net;        /* The IP of our sniffing device */
  30.     char errbuf[PCAP_ERRBUF_SIZE];
  31.     struct bpf_program fp;
  32.     memset(errbuf,0,PCAP_ERRBUF_SIZE);
  33.     if (pcap_lookupnet(device, &net, &mask, errbuf) == -1) {
  34.          fprintf(stderr, "Can't get netmask for device %s\n", device);
  35.          net = 0;
  36.          mask = 0;
  37.      }    
  38.     printf("\nAfter looknet");
  39.     printf("\nopening device %s",device);
  40.     printf("\nnetmaskv 
  41. ",mask);
  42.     printf("\nnet 
  43. ",net);
  44.     desc=pcap_open_live(device,MAXBYTES2CAPTURE,1,512,errbuf);
  45.     if (pcap_compile(desc, &fp, filter_exp, 1, net) == -1) {
  46.          fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(desc));
  47.          return(2);
  48.      }
  49.     else
  50.     printf("\ncompile OK");
  51.      if (pcap_setfilter(desc, &fp) == -1) {
  52.          fprintf(stderr, "Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(desc));
  53.          return(2);
  54.      }
  55.     else printf("\nfilter ok");
  56.     pcap_loop(desc,-1,processPacket,(u_char*)&count);
  57.     return 0;
  58. }
Feb 18 '11 #1
0 1488

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
0
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
1
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...
2
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...
0
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...
0
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...
4
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...
3
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
5
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...
4
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 |...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.