0

Hi i'm coding a packet sniffer in C++. It's working now, but I'm receiving a char buffer and I want to show the packet data on the screen in a hex representation.

I've already researched of a char to hex conversion but I have a problem when the packet data has a char with an extended ascii code like a 'ê' character or another like this. When that occurs the 'ê' character is displayed as {0xA8, 0xBA} and sometimes like {0xBA} and not like the {0xC3, 0xAA} according to the the conversion in www.asciitohex.com.

int WINAPI send(SOCKET s, const char* buf, int len, int flags)
{
    //do the conversion of socket data here
    return pSend(s, buf, len, flags);
}
user207421
  • 305,947
  • 44
  • 307
  • 483
  • See if [this](https://stackoverflow.com/questions/19562103/uint8-t-cant-be-printed-with-cout/19562163#19562163) helps. – user0042 Dec 17 '17 at 17:51
  • Step 1) learn to convert hexadecimal to decimal and vice versa. So you actually know what's going on. It's not hard, it's just a different base number. – Jesper Juhl Dec 17 '17 at 17:52
  • Jesper Juhl when i try this the decimal code of a character is wrong too –  Dec 17 '17 at 17:53
  • i'm still stuck at this problem, anyone else? –  Dec 17 '17 at 18:12
  • How do you know what the character encoding of the text in the packet is (or even that it contains text)? – molbdnilo Dec 17 '17 at 19:27

1 Answers1

1

You don't have a "char with an extended ascii code like a 'ê' character". You just have a char. Your problem arises from converting binary to a string and then trying to convert that to hex. Just convert the data directly from the source byte array.

user207421
  • 305,947
  • 44
  • 307
  • 483