IPv4, IPv6, inet_ntoa(), inet_aton(), inet_pton(), inet_ntop():Hexadecimal to Decimal

This is a discussion on IPv4, IPv6, inet_ntoa(), inet_aton(), inet_pton(), inet_ntop():Hexadecimal to Decimal within the C Programming forums, part of the General Programming Boards category; I need to write a C program to convert an IP address, in IPv6 format, (that is in hexadecimal) to ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    21

    Lightbulb IPv4, IPv6, inet_ntoa(), inet_aton(), inet_pton(), inet_ntop():Hexadecimal to Decimal

    I need to write a C program to convert an IP address, in IPv6 format, (that is in hexadecimal)
    to the standard IP address format (that is 255.255.255.255).

    Example:
    a1b2:c3d4 after conversion : 161.178.195.212

    I found a way to do that using the strtol() function but I know there are functions that can manipulate IPv4 or IPv6 addresses
    such as inet_ntoa(), inet_aton(), inet_pton(), inet_ntop()

    I would like to know if there is a way to make such conversion using one of these functions.

    any idea ?

    thanks for your help

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    21
    thanks for the valuable info but the use of gethostbyaddr() to get the IP address is out of question , since it is sort of hard coded :

    char * IPv4_address; /* IPv4 address i.e. a1b2:c3d4 */

    And now all I need to do is convert a1b2:c3d4 to 161.178.195.212

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. geting ipv4 and ipv6 interfaces with ioclt
    By wwwnuwan in forum Networking/Device Communication
    Replies: 0
    Last Post: 04-21-2009, 12:38 AM
  2. Sockets: IPv4 vs IPv6
    By ninboy in forum Networking/Device Communication
    Replies: 1
    Last Post: 10-15-2008, 01:02 AM
  3. IPv6 multicast example code
    By Sang-drax in forum Networking/Device Communication
    Replies: 7
    Last Post: 07-25-2005, 09:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21