Getting the system ipv6 address RRS feed

  • Question

  • Hi,
    Can any one help me to get the system ipv6 address by api cals.

        struct addrinfo *ai;
        struct addrinfo hints;
        memset (&hints, '\0', sizeof (hints));
        hints.ai_family = PF_INET6;
        hints.ai_socktype = SOCK_STREAM;
        hints.ai_flags = AI_PASSIVE;
        char                serv[6];
        sprintf(serv,"%d", 1234);
        char v6addrstr[64];
        int e = getaddrinfo (name, serv, &hints, &ai);
        MessageBox(NULL,"Remote","IPV6   1",0);
        //for (; ai; ai = ai->ai_next)
        DWORD addressSize = sizeof(v6addrstr);

        getnameinfo(ai->ai_addr, ai->ai_addrlen,
          v6addrstr, sizeof(v6addrstr),  NULL, 0, NI_NUMERICHOST);

    Now i am using this code but in vista its giving error(IE is restarting the function call getnameinfo())
    Wether i did any mistake or any settings i need to change in vista?

    If any other better way is there?
    Ur reply is appriciated..........


    Monday, November 10, 2008 4:51 PM


  • Hi a142,

    To get the IPv6 address in vista, perhaps you can take a look at the following WMI code snippet.


    strComputer = "hostname"

    Set objWMIService = GetObject( _

        "winmgmts:\\" & strComputer & "\root\cimv2")

    Set colNics = objWMIService.ExecQuery _

        ("Select * From Win32_NetworkAdapter " _

            & "Where NetConnectionID = " & _

            "'Local Area Connection'")


    For Each objNic in colNics

        Set colNicConfigs = objWMIService.ExecQuery _

          ("ASSOCIATORS OF " _

              & "{Win32_NetworkAdapter.DeviceID='" & _

          objNic.DeviceID & "'}" & _

          " WHERE AssocClass=Win32_NetworkAdapterSetting")

        For Each objNicConfig In colNicConfigs

            For Each strIPAddress in objNicConfig.IPAddress

                Wscript.Echo "IP Address: " &  strIPAddress





    And in to consume the WMI in visual C++, please refer  to WMI C++ Application Examples



    Please remember to mark the replies as answers if they help and unmark them if they provide no help. http://forums.msdn.microsoft.com/en-US/csharpide/thread/8e9ed0d7-11ff-402a-8489-9b5f05eeb706
    • Marked as answer by jack 321 Monday, November 17, 2008 9:16 AM
    Thursday, November 13, 2008 8:24 AM