Previous code :
struct Inet_address{
char v4[4];
};
extern "C" Inet_address Inet_loopback =
{
{127,0,0,1}
};
After modifying:
I have made Inet_address a union
Here Inet address is a union
union Inet_address{
char v4[4];
char v6[16];
};
Now I want to do the same operation on extern “C” Inet_address Inet_loopback
Say,
extern "C" Inet_address Inet_loopback =
{
if(some condition)
{127,0,0,1} //It should be Inet_address.v4
else
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } //This should be Inet_address.v6
};
Please suggest a correct way to acheive this as I am getting error here.
You shouldn’t use char arrays for this – make a union out of
in_addrandin6_addr:To set an ipv4 loopback address:
For IPv6: