Is there any flag within the compiler to precompile IPV6 only
I have written t开发者_运维技巧he code for IPv6 implementation using a flag setting. The flag needs to be set in the header file before the compilation process if I need to enable IPv6 part. Is there any flag provided with the compiler itself so that I just need to use the statement #ifdef COMPILER_FLAG_FOR_IPV6 to enable IPv6 part of code. If not then IPv4 part is compiled. I dont want to manually define a flag here rather use a inbuilt flag for IPV6.
IPv6 compatibility is not dependent upon compiler support, rather OS-specific header files. There is no standard way of testing this as such. (As was pointed out you'd probably want CMake/AutoConf/Some other build system to detect this).
You can also achieve what you seem to be looking for more directly, on Linux for example you can probably do:
#include <sys/socket.h>
#ifdef AF_INET6
....
#endif
I'm not sure I'd want to bet on how portable/reliable this is though, I'd guess it would work with any implementation of sys/socket.h
and a quick look through winsock2.h
seems to have a similar #define
of AF_INET6
too.
精彩评论