Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Reading/Writing raw data  (Read 6168 times)

0 Members and 1 Guest are viewing this topic.

e_barroga

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Reading/Writing raw data
« 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;
    }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Reading/Writing raw data
« Reply #1 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?
Laurent Gomila - SFML developer

e_barroga

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Reading/Writing raw data
« Reply #2 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Reading/Writing raw data
« Reply #3 on: August 13, 2010, 10:28:27 pm »
Indeed, if you want to see numbers instead of characters, you have to cast to int ;)
Laurent Gomila - SFML developer

e_barroga

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Reading/Writing raw data
« Reply #4 on: August 31, 2010, 09:32:05 am »
Why char? Why not unsigned char?

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Reading/Writing raw data
« Reply #5 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 :)
Mindiell
----

e_barroga

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Reading/Writing raw data
« Reply #6 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Reading/Writing raw data
« Reply #7 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.
Laurent Gomila - SFML developer

e_barroga

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Reading/Writing raw data
« Reply #8 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.

 

anything