codeghar / Seagull

Seagull is a free, Open Source (GPL) multi-protocol traffic generator test tool. Forked from upstream on Sourceforge. Patched to build on recent versions of Ubuntu, CentOS, and openSUSE.
GNU General Public License v2.0
50 stars 48 forks source link

Fix issue #20 #21

Closed aikchar closed 6 years ago

aikchar commented 6 years ago

I searched for how to determine big vs little endianness in C++ and substituted the test with the first reasonable thing I found at https://stackoverflow.com/a/1001330.

    You can do it by setting an int and masking off bits, but probably the easiest way is just to use the built in network byte conversion ops (since network byte order is always big endian).

    if ( htonl(47) == 47 ) {
      // Big endian
    } else {
      // Little endian.
    }

    Bit fiddling could be faster, but this way is simple, straightforward and pretty impossible to mess up.