I’m porting some Windows code to the Mac. I’ve come across some code using the type in_addr and found the documentation for the Windows implementation here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms738571%28v=vs.85%29.aspx
Specifically the problem I am having is that the code tries to access the S_un property of in_addr, which the compiler (CLang) complains doesn’t exist. Looking at the definition for the Mac implementation I get this (in usr/include/netinet/in.h):
struct in_addr {
in_addr_t s_addr;
};
…and in_addr_t is defined as follows (in usr/include/sys/types.h):
typedef __uint32_t in_addr_t;
Does anyone know of a good workaround for this, or if there is a representation of IPv4 addresses on the Mac that is more closely tied to the Windows implementation?
See my comment. But also … you can just implement the windows declaration in your code (just do not call it in_addr to avoid conflicts). You could do something like:
Note however that this is not portable and will only work as intended on little endian CPUs.