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

  • SEARCH
  • Home
  • 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 6692005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:49:03+00:00 2026-05-26T05:49:03+00:00

…. finalize(char *hdrs, sendip_data *headers[], int index, sendip_data *data, sendip_data *pack) { …….. For

  • 0
 ....
 finalize(char *hdrs, sendip_data *headers[], int index,
                    sendip_data *data, sendip_data *pack)
 {

 ........

For debugging purposes I want a hex dump of the data and pack structures, which are of type sendip_data, a really complex structure. Actually they contain some binary information so I am not sure whether output of my project is correct or not. So for debugging purposes, I want to write the data into a file so that I can use hexdump as follows –

$hexdump -C file.txt

Also as this is a run time generation of a n/w packet so I am also not sure about the length of data and pack structure which I think fread / fwrite will require ..So please suggest me something.

  • 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-26T05:49:04+00:00Added an answer on May 26, 2026 at 5:49 am

    The following code will give you a hex dump of arbitrary memory from within your code.

    #include <stdio.h>
    
    // Usage:
    //     hexDump(desc, addr, len, perLine);
    //         desc:    if non-NULL, printed as a description before hex dump.
    //         addr:    the address to start dumping from.
    //         len:     the number of bytes to dump.
    //         perLine: number of bytes on each output line.
    
    void hexDump (
        const char * desc,
        const void * addr,
        const int len,
        int perLine
    ) {
        // Silently ignore silly per-line values.
    
        if (perLine < 4 || perLine > 64) perLine = 16;
    
        int i;
        unsigned char buff[perLine+1];
        const unsigned char * pc = (const unsigned char *)addr;
    
        // Output description if given.
    
        if (desc != NULL) printf ("%s:\n", desc);
    
        // Length checks.
    
        if (len == 0) {
            printf("  ZERO LENGTH\n");
            return;
        }
        if (len < 0) {
            printf("  NEGATIVE LENGTH: %d\n", len);
            return;
        }
    
        // Process every byte in the data.
    
        for (i = 0; i < len; i++) {
            // Multiple of perLine means new or first line (with line offset).
    
            if ((i % perLine) == 0) {
                // Only print previous-line ASCII buffer for lines beyond first.
    
                if (i != 0) printf ("  %s\n", buff);
    
                // Output the offset of current line.
    
                printf ("  %04x ", i);
            }
    
            // Now the hex code for the specific character.
    
            printf (" %02x", pc[i]);
    
            // And buffer a printable ASCII character for later.
    
            if ((pc[i] < 0x20) || (pc[i] > 0x7e)) // isprint() may be better.
                buff[i % perLine] = '.';
            else
                buff[i % perLine] = pc[i];
            buff[(i % perLine) + 1] = '\0';
        }
    
        // Pad out last line if not exactly perLine characters.
    
        while ((i % perLine) != 0) {
            printf ("   ");
            i++;
        }
    
        // And print the final ASCII buffer.
    
        printf ("  %s\n", buff);
    }
    
    // Very simple test harness.
    
    int main (int argc, char *argv[]) {
        char my_str[] = "a char string greater than 16 chars";
        hexDump ("my_str", &my_str, sizeof (my_str), 16);
        return 0;
    }
    

    You pass into hexDump a description, memory address, length, and how many bytes you want on each line.

    It will output a hex dump (including character data) for examination. When you run it with the included main, the output is:

    my_str:
      0000  61 20 63 68 61 72 20 73 74 72 69 6e 67 20 67 72  a char string gr
      0010  65 61 74 65 72 20 74 68 61 6e 20 31 36 20 63 68  eater than 16 ch
      0020  61 72 73 00                                      ars.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
what about this one: I want to format the currentTime displayed by a videoPlayer
I want to run this <!-- This will remove the tag --> <xsl:template name=remove-html>
I want to open a popup window of an Image on More Info link
See below matrix data: A B C D E F G 1 89 92
English is not my native language. I need a software to spellcheck and correct
I have been making a wordpress template. i got stuck at some place... the
I see that some rss on xml have strange strings. For example, ... is

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.