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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joan fruchtalle
    New Member
    • Jan 2011
    • 3

    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
  • hype261
    New Member
    • Apr 2010
    • 207

    #2
    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 );

    Comment

    • joan fruchtalle
      New Member
      • Jan 2011
      • 3

      #3
      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@13 0.237.250.244
      Content-Type: application/sdp
      Content-Length: 134
      CSeq: 1 INVITE
      From: "bob"<sip:127.0 .0.1>;tag=12778 715617702
      To: <sip:2@127.0.0. 1:5000>;tag=127 7871561770
      Via: SIP/2.0/UDP 127.0.0.1;rport ;branch=z9hG4bK 82edfaf40000001 7461e8e8a000055 8d00000001

      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

      Comment

      • hype261
        New Member
        • Apr 2010
        • 207

        #4
        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.

        Comment

        • joan fruchtalle
          New Member
          • Jan 2011
          • 3

          #5
          Hi Hype261,
          thanks for your reply that helped me!

          Joan

          Comment

          Working...