Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 574457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:49:58+00:00 2026-05-13T13:49:58+00:00

I have a packet capture code that writes http payload into a file. Now

  • 0

I have a packet capture code that writes http payload into a file. Now i want to extract the URL information from these dumps.
For each packet , the payload begins like this.

GET /intl/en_com/images/logo_plain.png
HTTP/1.1..Host:
http://www.google.co.in..User-Agent:
Mozilla/5.0

I would like to extract :

  1. the string between “GET” and “HTTP/1.1”
  2. the string between “Host:” and “User-Agent”

How to do this in C ? Are there any inbuilt string functions ? Or Regular expressions ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:49:59+00:00Added an answer on May 13, 2026 at 1:49 pm

    C doesn’t have built-in regular expressions, though libraries are available: http://www.arglist.com/regex/, http://www.pcre.org/ are the two I see most often.

    For a task this simple, you can easily get away without using regexes though. Provided the lines are all less than some maximum length MAXLEN, just process them one line at a time:

    char buf[MAXLEN];
    char url[MAXLEN];
    char host[MAXLEN];
    int state = 0;      /* 0: Haven't seen GET yet; 1: haven't seen Host yet */
    FILE *f = fopen("my_input_file", "rb");
    
    if (!f) {
        report_error_somehow();
    }
    
    while (fgets(buf, sizeof buf, f)) {
        /* Strip trailing \r and \n */
        int len = strlen(buf);
        if (len >= 2 && buf[len - 1] == '\n' && buf[len - 2] == '\r') {
            buf[len - 2] = 0;
        } else {
            if (feof(f)) {
                /* Last line was not \r\n-terminated: probably OK to ignore */
            } else {
                /* Either the line was too long, or ends with \n but not \r\n. */
                report_error_somehow();
            }
        }
    
        if (state == 0 && !memcmp(buf, "GET ", 4)) {
            strcpy(url, buf + 4);    /* We know url[] is big enough */
            ++state;
        } else if (state == 1 && !memcmp(buf, "Host: ", 6)) {
            strcpy(host, buf + 6);   /* We know host[] is big enough */
            break;
        }
    }
    
    fclose(f);
    

    This solution doesn’t require buffering the entire file in memory as KennyTM’s answer does (though that is fine by the way if you know the files are small). Notice that we use fgets() instead of the unsafe gets(), which is prone to overflow buffers on long lines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 383k
  • Answers 383k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think the best way to think (!) is to… May 14, 2026 at 10:53 pm
  • Editorial Team
    Editorial Team added an answer I always prefer Dash Commerce dashCommerce is an ASP.NET Open… May 14, 2026 at 10:53 pm
  • Editorial Team
    Editorial Team added an answer Why not just target the ones you want (demo)? $('form').find('input[type=text],textarea,select').filter(':visible:first');… May 14, 2026 at 10:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.