Reputation:
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);
}
Upvotes: 0
Views: 259
Reputation: 311008
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.
Upvotes: 1