Expanding IPv6 address using inet_pton

Discussion in 'C Programming' started by Roxy Natal, Dec 6, 2011.

  1. Roxy Natal

    Roxy Natal Guest

    hello every body,

    My name is roxy and i am from brazil.I want to expand IPv6 address
    using inet_pton().After
    that I increment the address by 1 using C code.If my address is -
    1234:12::ffff then after expand
    it will be 1234:0012:0000:0000:0000:0000:0000:ffff
    When I increment the address it will display -
    1234:0012:0000:0000:0000:0000:0001:0000
    Whenever it will reaches ffff it just put 0x0000 and increment the
    next value by 1.
    I already done some code part(not the increment part).Please help me
    in this matter.

    #include "stdafx.h"
    #include "string.h"
    #include "stdlib.h"
    #include "conio.h"
    #include "arpa/inet.h"
    #include "inet/ip6.h"



    int main(int argc, char argv[])
    {

    struct in6_addr {
    unsigned char s6_addr[16]; // IPv6 address
    };
    struct in6_addr ipv6;
    char str[]="abcd:1234::ffff";
    if(strcnt(str,":")>1)
    {


    if(inet_pton(AF_INET6,str,&ipv6.s6_addr))
    printf("%s is

    %0llu(IPv6)\n",str,ipv6.s6_addr);
    else
    printf("Error..");
    }

    getch();

    return 0;

    }
     
    Roxy Natal, Dec 6, 2011
    #1
    1. Advertising

  2. Roxy Natal <> writes:

    > My name is roxy and i am from brazil.I want to expand IPv6 address
    > using inet_pton().After
    > that I increment the address by 1 using C code.


    There have been a few similar questions posted here recently. Can you
    tell us how this problem came up? It is in some commonly used textbook?
    Some on-line tutorial?

    You make quite a few of the same mistakes as the other posters, so
    you could start by finding the previous threads a reading the replies
    given there.

    Rather the repeat lots of stuff, I'll make only one remark about your
    code:

    <snip>
    > struct in6_addr {
    > unsigned char s6_addr[16]; // IPv6 address
    > };
    > struct in6_addr ipv6;


    <snip>
    > printf("%s is
    >
    > %0llu(IPv6)\n",str,ipv6.s6_addr);


    Where did you get the idea of printing an array of 16 unsigned chars
    using the llu format?

    <snip>
    --
    Ben.
     
    Ben Bacarisse, Dec 6, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Skumar
    Replies:
    3
    Views:
    817
    Steve Zimmerman
    Aug 24, 2003
  2. Replies:
    8
    Views:
    5,437
    Jim Langston
    Feb 9, 2006
  3. Neha Jain

    inet_pton problem in C

    Neha Jain, Dec 2, 2011, in forum: C Programming
    Replies:
    2
    Views:
    394
  4. joao

    Question : inet_pton

    joao, Dec 7, 2011, in forum: C Programming
    Replies:
    3
    Views:
    362
    Ike Naar
    Dec 7, 2011
  5. Jesse van den Kieboom

    Ipv6 on a ipv4/ipv6 hostname

    Jesse van den Kieboom, Jun 5, 2005, in forum: Ruby
    Replies:
    1
    Views:
    364
    Dibya Prakash
    Jun 5, 2005
Loading...

Share This Page