perlperl
asked on
converting ip address
I have a character array that stores both and IPv6 and IPv4 address that is inside IPv6
example)
A real ipv6 address char client[64] = "fe80::252:39cc:fe45:1234"
An IPv4 address inside IPv6 char client[64] = "::ffff:172.17.30.3"
Is there a way I can convert the the second address to real IPv4 address?
One way is to copy to string and use substring
but can this be done using the standard inet_ntop or inet_pton or something else.
example)
A real ipv6 address char client[64] = "fe80::252:39cc:fe45:1234"
An IPv4 address inside IPv6 char client[64] = "::ffff:172.17.30.3"
Is there a way I can convert the the second address to real IPv4 address?
One way is to copy to string and use substring
but can this be done using the standard inet_ntop or inet_pton or something else.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well, the line of interest is actually
Howevre, printing that does not really make sense since it's quite unreadable. Yet it will contain the IP address you want. You could try 'inet_ntop()' (http://man7.org/linux/man-pages/man3/inet_ntop.3.html) to convert and output ist,
s = inet_pton(domain, argv[2], buf);
Howevre, printing that does not really make sense since it's quite unreadable. Yet it will contain the IP address you want. You could try 'inet_ntop()' (http://man7.org/linux/man-pages/man3/inet_ntop.3.html) to convert and output ist,
ASKER
## ./test i6 ::ffff:172.4.4.4
::ffff:172.4.4.4
## ./test i4 ::ffff:172.4.4.4
Not in presentation format (I was expecting this to be printed as 172.4.4.4)