SFML community forums

Help => Network => Topic started by: e_barroga on August 13, 2010, 04:31:13 pm

Title: Reading/Writing raw data
Post by: e_barroga on August 13, 2010, 04:31:13 pm
I need to read and write raw data. By raw data I mean reading/writing bytes as you would see them using a packet sniffer like http://wpepro.net/

To do this I understand that SFML reads/writes a character array/char*

However, when I try to receive a packet I do not think it is being read correctly because when I print it to the console I see gibberish.

This is what a piece of my code looks like:
Code: [Select]
if ( _authServer.Connect( _authIP, _authPort, 10.0f ) == sf::Socket::Done )
    {
        std::cout << "[SYSTEM] - CONNECTED TO AUTHENTICATION SERVER.\n";

        char loginPacket[8] = { 0 };
        std::size_t received;
        _authServer.Receive( loginPacket, sizeof( loginPacket ), received );

        _crypt.Decrypt( (unsigned char*)loginPacket, 8 );
       
        for ( int i = 0; i < sizeof( loginPacket ); i++ )
        {
            std::cout << std::hex << loginPacket[i] << "\t";
        }
        std::cout << std::endl;
    }
Title: Reading/Writing raw data
Post by: Laurent on August 13, 2010, 04:50:43 pm
What do you see exactly, and what do you expect to see?

Have you tried without calling your Decrypt function?
Title: Reading/Writing raw data
Post by: e_barroga on August 13, 2010, 05:14:50 pm
I see special characters instead of numbers.

edit:
Just realized I forgot to perform a cast when printing to the console. Not in a position right now to check it out but would you agree this solves the problem?
Title: Reading/Writing raw data
Post by: Laurent on August 13, 2010, 10:28:27 pm
Indeed, if you want to see numbers instead of characters, you have to cast to int ;)
Title: Reading/Writing raw data
Post by: e_barroga on August 31, 2010, 09:32:05 am
Why char? Why not unsigned char?
Title: Reading/Writing raw data
Post by: Mindiell on September 02, 2010, 11:24:03 am
neither char nor unisgned char, you'll have to cast to an int in order to see the byte value. a char (unsigned or not) will be showed on the console as a character (using the ASCII table).

So "8" will be a backspace for example.

I had the same problem while doing my Telnet class :)
Title: Reading/Writing raw data
Post by: e_barroga on September 06, 2010, 01:54:51 am
Quote from: "Mindiell"
neither char nor unisgned char, you'll have to cast to an int in order to see the byte value. a char (unsigned or not) will be showed on the console as a character (using the ASCII table).

So "8" will be a backspace for example.

I had the same problem while doing my Telnet class :)

I am talking about why SFML takes char instead of unsigned char. o.0
Title: Reading/Writing raw data
Post by: Laurent on September 06, 2010, 08:30:57 am
Quote
I am talking about why SFML takes char instead of unsigned char. o.0

What would it change? The type doesn't really matter anyway, it could be char*, unsigned char*, or void* as well.
Title: Reading/Writing raw data
Post by: e_barroga on September 23, 2010, 06:03:37 pm
Quote from: "Laurent"
Quote
I am talking about why SFML takes char instead of unsigned char. o.0

What would it change? The type doesn't really matter anyway, it could be char*, unsigned char*, or void* as well.

Generally raw data comes with encryption and it is a good idea to be using unsigned.

But you are right, the type doesn't really matter you can just cast.