Parsing a string to get the ip address

This is a discussion on Parsing a string to get the ip address within the C++ Programming forums, part of the General Programming Boards category; Hello g++ (GCC) 4.6.2 I have a string that I need parse. The string is sdp information. I am trying ...

  1. #1
    UK2
    Join Date
    Sep 2003
    Posts
    112

    Parsing a string to get the ip address

    Hello

    g++ (GCC) 4.6.2

    I have a string that I need parse. The string is sdp information. I am trying to seperate each of the elements into seperate strings.

    Basically the string would contain some thing like this:
    Code:
    v=0 o=sip_user IN 10230 22472 IP4 NET.CAT.NTBC s=SIP_CALL c=IN IP4 10.10.10.44 m=audio 49152 RTP/AVP 0 8 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000
    What is the best method to get the ip address?

    I was trying something like this:

    Code:
    char *ip_addr = NULL  
    str_v = strstr(sdp_string, "c=");
    
    if(ip_addr != NULL) {
        printf("found line: [ %s ]", ip_addr);
    }
    Many thanks for any suggestions,
    Last edited by steve1_rm; 12-08-2011 at 08:57 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Well if the c= is unique, and the IP address is always a fixed number of chars following on from there, then you can do things like

    ip_addr = str_v + 10;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    UK2
    Join Date
    Sep 2003
    Posts
    112
    Hello

    'c=' will always be unique. But the IP will always be different.

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parsing a string
    By bhdavis1978 in forum C Programming
    Replies: 3
    Last Post: 11-04-2010, 02:51 PM
  2. String parsing
    By broli86 in forum C Programming
    Replies: 3
    Last Post: 07-03-2008, 05:06 PM
  3. String parsing(parsing comments out of HTML file)
    By slcjoey in forum C# Programming
    Replies: 0
    Last Post: 07-29-2006, 08:28 PM
  4. Parsing a string
    By robin171 in forum C Programming
    Replies: 22
    Last Post: 10-20-2005, 10:44 AM
  5. String parsing
    By Cbuild in forum C Programming
    Replies: 5
    Last Post: 05-03-2004, 05:15 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21