简体   繁体   中英

Hex representation of socket data(char) c++

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);
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM