473,385 Members | 1,593 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,385 software developers and data experts.

How to parse the Port Number from SDP using C language?

Hi,
I am working on a VoIP project, in that there is a small task of extracting Port Number from the incoming SDP which is stored in a Buffer.


Let me say it in another way, I have a text which is stored in a Buffer (lets say 'string21[]' ) and from that I need to extract a Port Number and assign it to an Integer variable (lets say 'audio_port' ).

For example the text which is coming from the Server is "m = audio 17764 RTP/AVP 0 8" [this is just a part of the Text, the whole Text is very big.......], in this case "17764" should be extracted.

One more point in "m = audio 17764 RTP/AVP 0 8" , m = audio RTP/AVP 0 8 are constant, only the port number will be changing randomly, so that each time my code the port number will be changed and therefore I need this to be extracted each time.

Any idea of how I can do it, I can only use Header Files and Functions from C not from C++(no C++ libraries).

Regards,
Joan
Jan 12 '11 #1
4 2939
hype261
207 100+
I would look into using the strstr function in string.h

char * strstr ( const char *, const char * );

I would also look at the atoi function in stdlib.h

int atoi ( const char * str );
Jan 12 '11 #2
my problem is the I need to search this port number which is not constant and keeps on changing every time I run it new and also it should be extracted from a whole bunch of text which looks something like this.......

SIP/2.0 200 OK
Call-ID: 058E40CC-5AD9-40C7-A919-07758E503BA0@130.237.250.244
Content-Type: application/sdp
Content-Length: 134
CSeq: 1 INVITE
From: "bob"<sip:127.0.0.1>;tag=12778715617702
To: <sip:2@127.0.0.1:5000>;tag=1277871561770
Via: SIP/2.0/UDP 127.0.0.1;rport;branch=z9hG4bK82edfaf400000017461e 8e8a0000558d00000001

v=0
o=bob 3385396490 3385396490 IN IP4 130.237.250.244
s=SJphone
c=IN IP4 130.237.250.244
t=0 0
m=audio 3456 RTP/AVP 0 8
a=rtpmap: 0 PCMU/8000

so out of this I need to extract the port number(which is not a constant) and you can find it in this line "m=audio 3456 RTP/AVP 0 8"

I hope somebody got my point what I am intend to do.

Regards,
Joan
Jan 13 '11 #3
hype261
207 100+
Okay so you have all this text and I am assuming that you can get this text into a char *. So first I would use the strstr to find the string "m=audio". The strstr function will return a pointer to the first occurance of "m=audio" or NULL if "m=audio" doesn't exist. I would then advance the return pointer 7 to get it past "m=audio" and at the beginning of the port number. I would then pass this pointer to the atoi function to convert the string into an integer.

There are some degenerate conditions that I haven't mentioned here that you will need to account for. Hopefully this gets you started.
Jan 13 '11 #4
Hi Hype261,
thanks for your reply that helped me!

Joan
Jan 14 '11 #5

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

Similar topics

2
by: nik | last post by:
Hi all I'm struggling to find an answer to this one! We've configured our SQL boxes to run under a different port number, e.g. from 1433 to 4533. This works fine under our Citrix enviornmnet...
2
by: Seal | last post by:
Hi, May I know how to change the default port number to other number (default is 80) when I start an asp.net web application using VS.net? Thanks. Regards, Seal
1
by: wobbles | last post by:
Hi Everyone, I have a server which reads information from a "server.exe.config" file and a client that also reads from its "client.exe.config" file. If the server location or the port number...
2
by: Bozo | last post by:
Hi, Does anyone know how to run a .Net exe using a particualr port number to connect to a web service? How do you do this programmatically. Thanks
0
by: Sanjay Patil | last post by:
Hi , I am using IBuySpay Portal modified code. Public page of the web site uses nonssl port. Once user is logged in I am transferring to page which uses ssl port. During this process I am using...
0
by: Nick | last post by:
Is there a way to avoid using a specific TCP port number, on the client side, when using HttpWebRequest? I've written an HTTP server and client that can't communicate with each other when the...
0
by: narayanansun | last post by:
hi, i need to the get the com port number of the connected usb device. pls help me to find out the com port number using win32 api in C#. i have device path and handle with me and want to find out...
9
by: xparrot1 | last post by:
I know that I can get the SERVER port number like this: HttpContext.Current.Request.ServerVariables My question is how do I get the remote CLIENT port number? Thanks Derek
1
by: anneaunimme | last post by:
I have a program which allow my computer to communicate to another device using an ethernet Cable. The thing is that this program is set so that it can only work through a specific IP address and a...
0
by: rotaryfreak | last post by:
Hello, Im building a client-server application and the user needs to input the hostName and the portNumber the client application and needs to send the portnumber to the server application. I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.