I have a project that should be built on Windows, Linux, and VxWorks. The project is built on Linux and Windows, but compiled for VxWorks. To handle endianness on multiple platforms, it uses ntoh.h. The Linux machine is a little oriented, but ntohl does not change its program.
I wrote a test program that directly includes in.h. It matches accordingly. I wrote another test program that only includes ntoh.h. It matches accordingly. Both test programs reference lib64 / libc.so.6.
However, when I compile my project, ntohl does not swap. I cannot break ntohl using the gdb "break ntohl" command. When creating, I see a LITTLE ENDIAN warning (see below) and don’t see the "FOLLOW HERE" error .
Please, help. I do not understand why this problem occurs.
Below ntoh.h:
#ifndef __ntoh__
#define __ntoh__
#include "basic_types.h"
#ifdef WIN32
#include <winsock2.h>
#elif LINUX
#include <netinet/in.h>
#if __BYTE_ORDER == __BIG_ENDIAN
#warning BIG ENDIAN BYTE ORDER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN
#warning YAY LITTLE ENDIAN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#endif
#else
#error SHOULDNT BE HERE
#define ntohl(x) (x)
#define ntohs(x) (x)
#define htonl(x) (x)
#define htons(x) (x)
#endif
#endif
Part of my compilation command:
g++ -DDAU_PARSER -DNO_MT -DTEST_CLOCK -DLINUX -g -Irelease/include -Irelease/include/Record_Data/ -Irelease/include/Utility -o dauParser DAU_Support_Tools/src/dau_parser.cpp DAU_Support_Tools/src/dau_parser_write_data_to_file.cpp Utility/src/Messaging/Communications/Message.cpp Utility/src/time_type.cpp Utility/src/collectable.cpp Utility/src/clist.cpp Utility/src/clock.cpp Utility/src/test_clock.cpp Utility/src/mutex.cpp Utility/src/ntoh.cpp ...
The error is generated by the following lines:
int deadbeef = 0xDEADBEEF;
printf("TESTING DEADBEEF %x %x\n", deadbeef, ntohl(deadbeef) );
Exiting these two lines produces the same output. DEADBEEF TEST deadbeef deadbeef
source
share