LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-19-2006, 10:36 AM   #1
phugoid
LQ Newbie
 
Registered: Mar 2006
Location: Dubai, United Arab Emirates
Distribution: Suse 10.0
Posts: 14

Rep: Reputation: 0
Generic approach to reading/writing packets?


I'm starting work on a peer-to-peer application that needs to understand a number of protocols including SIP, RTCP, RTP, etc. I don't want to write a parser for each of these. Is there a generic approach/library for parsing a packet and exposing its fields to the rest of your application?

For example you get an SIP packet:
Code:
SIP/2.0 200 OK
Via: SIP/2.0/UDP site4.server2.com;branch=z9hG4bKnashds8;received=192.0.2.3
Via: SIP/2.0/UDP site3.server1.com;branch=z9hG4bK77ef4c2312983.1;received=192.0.2.2
Via: SIP/2.0/UDP pc33.server1.com;branch=z9hG4bK776asdhds;received=192.0.2.1
To: user2 ;tag=a6c85cf
From: user1 ;tag=1928301774
Call-ID: a84b4c76e66710@pc33.server1.com
CSeq: 314159 INVITE
Contact:
Content-Type: application/sdp
Content-Length: 131
I have not yet found decent libraries (C, C++, Python) that will take this packet, and
  1. Recognize the protocol type.
  2. Parse the fields and fill up a data structure. It should be a collection or associative array so that you can access the fields by name. (To, From, CSeq, etc.)
  3. Call an appropriate handler based on protocol type, and hand it the data structure.

To make this approach useful as possible, it should also provide a generic means to define the protocols using simple text (field names, field data types and the parsing rules). That way you could feed various protocol definitions to your parser, without adding extra code for each one.

Am I running in the wrong direction here? If it doesn't exist, could such a library/object be useful?
 
Old 03-19-2006, 11:24 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
To me, it sounds like you are trying to write a subset of a network packet analyzer. So, one approach might be to start out with a complete packet analyzer such as ethereal, and take out the parts you don't want. I don't know of any generic library that provides the services you are looking for. If one exists, I'd be interested in knowing about it.

--- rod.
 
Old 03-19-2006, 11:59 AM   #3
gr33ndata
Member
 
Registered: Aug 2003
Location: DMZ
Distribution: Ubuntu
Posts: 144

Rep: Reputation: 15
Actually if you are going to write a p2p *application*, then it is sockets that you are going to use not packet capturing, the socket will handle the lower layers - till transpor - and you will have to find a library to handle the application layer parsing, for example there is libosip for parsing SIP.
 
Old 03-20-2006, 02:12 AM   #4
phugoid
LQ Newbie
 
Registered: Mar 2006
Location: Dubai, United Arab Emirates
Distribution: Suse 10.0
Posts: 14

Original Poster
Rep: Reputation: 0
I agree that packet capturing is not on the agenda. It's the application layer that I'm interested in.

SIP might have been a poor example, because there's a lot more going on than parsing: you need to conduct several transactions to make thing happen, something a protocol-specific library can do for you. But specifically for things like RTP, RTCP and SDP, it seems to me that parsing the packet fields is a repetitive task that should be made generic across protocols.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help writing and reading shared memory djgannon Linux - Newbie 0 02-23-2006 08:51 PM
writing and reading from a file! sahel Programming 1 12-27-2005 01:33 PM
Binary reading/writing in cpp kornerr Programming 1 11-27-2005 07:09 PM
C File reading and writing AbhishekSamuel Programming 3 05-03-2005 03:59 PM
Help reading and writing to file xiste Programming 1 04-15-2005 12:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration