Satchmo Brown
Satchmo Brown

Reputation: 1437

Cross platform version of ntohl()? - C++

I am writing a cross platform client and in the archives that are extracted for use, it uses an IEEE 802.3 Ethernet CRC-32 checksum for each file. I run this check against all of the files like so:

if(s3d_meta_block.crc != 0x61580AC9)
{
    errorLog.writeError("File %i is not a valid file/ or is the directory", i);
}

It ends up failing on every one of the files and I have found it written elsewhere in similar clients with ntohl(0x61580AC9).

I am writing this on 64-bit Windows and would ideally like this to run on every platform without having to include "Winsock2.h" and the other libraries involved in reversing the endianess.

Thanks!

Upvotes: 1

Views: 1067

Answers (1)

Adrian Cornish
Adrian Cornish

Reputation: 23906

ntohl() is included on many platforms and will/will not swap the bits as needed by your processors alignment. The only thing you may need in you code is #def's to include the right header files for this function (I've never seen an OS without it)

Upvotes: 1

Related Questions