user2711681
user2711681

Reputation: 275

Conversion from hex into normal char and doing string manipulation?

We have a packet capture programming where the whole packet is represented by the this input const u_char *p into the function. We have managed to convert it from hex into readable characters. My challenge now how to store into another array where I need further string processing on it? I am trying to use this method but not sure is this correct way to go ? But this seems not too be dynamic either.

char all[1500];

    for(i = 0; i < h->caplen; i++)
    {
          printf("%02X ", p[i]);
          printf("\n");
          sprintf(all,"%02X ",p[i]);
    }

For part of the packet in hex is this 474554202f6d61696c2f20485454502f312e310d0a but when we view is this in normal characters is this GET /mail/ HTTP/1.1\r\n. My challenge is to pick the url where I need to check if there get or post and end with http/1.1 or http/1.0 ?

Syntax for extraction

 char *getPointer = strstr (all, "GET"); 
 char *httpPointer = strstr (all, "HTTP/1.");

Upvotes: 1

Views: 175

Answers (1)

Fiddling Bits
Fiddling Bits

Reputation: 8861

Convert string (char *) to binary (hex). Hex array will 1/2 the length of char array. Use strstr () to parse hex array for tokens (e.g. "GET"). You're method, so far, is the way to go.

Upvotes: 1

Related Questions