locked
How to retrieve Ip address of my windows mobile 6.1 using c and win32 RRS feed

  • Question

  • Hi all,
                I have a problem in finding out the ip address of my windowsmobile 6 device...i use GetAdaptersadress() api and while debugging i could find 3 structure ptrs...i get firstunicast address and firstanycastadress and multicastaddress.........but to get the ip i am going to unicast address->ipsockaddr...
    here the value is in hexadecimal.......how can i convert it to standard ip address.......
       thanks in advance...
    Avinash

    Whenever I find the key to success, someone changes the lock.
    Thursday, October 1, 2009 1:12 PM

Answers

  • Hi guys.....
                     The above Link provided could not help me much and its to complicated one..but i cld find out another and simple way of finding local ip address of windows mobile......and i am sharing my function......

    // Name       :       MyGetIpaddress
    //Description:    Finds the Ip address of a mobile..(NOT 127.0.0.1)
    //author       :    Avinash
    //date          :     5.10.09
     

    int MyGetIpAdress()
    {
        WSADATA wsa_Data;
        WCHAR pWideCharStr[80];
        int wsa_ReturnCode = WSAStartup(0x202,&wsa_Data);
        char szHostName[255];
        gethostname(szHostName, 255);
        struct hostent *host_entry;
        host_entry=gethostbyname(szHostName);
        char * szLocalIP;
        szLocalIP = inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list);
        MultiByteToWideChar(CP_ACP, 0,szLocalIP , -1,pWideCharStr , sizeof(pWideCharStr) / sizeof(wchar_t));

        //MultiByteToWideChar(CP_UTF8, MB_COMPOSITE,szLocalIP , 32, pWideCharStr,32);
        MessageBox(NULL,pWideCharStr, TEXT("IP address"), MB_OK|MB_ICONERROR);

        WSACleanup();
        return SUCCESS;
    }



    ..................If my Code was useful..plz mark this as answer and mark as Helpful.......And encourage me for future enhancements......


    Regards
    Avinash
    Whenever I find the key to success, someone changes the lock.
    Monday, October 5, 2009 6:52 AM

All replies

  • HI,

    Maybe this answered question could help you.

    Cheers,

    José Miguel Torres
    Thursday, October 1, 2009 2:09 PM
  • hi ,

    but that particular thing is not working for me..it is producing a junk value....



    thanks in advance
    Avinash
    Whenever I find the key to success, someone changes the lock.
    Thursday, October 1, 2009 3:20 PM
  • Hi guys.....
                     The above Link provided could not help me much and its to complicated one..but i cld find out another and simple way of finding local ip address of windows mobile......and i am sharing my function......

    // Name       :       MyGetIpaddress
    //Description:    Finds the Ip address of a mobile..(NOT 127.0.0.1)
    //author       :    Avinash
    //date          :     5.10.09
     

    int MyGetIpAdress()
    {
        WSADATA wsa_Data;
        WCHAR pWideCharStr[80];
        int wsa_ReturnCode = WSAStartup(0x202,&wsa_Data);
        char szHostName[255];
        gethostname(szHostName, 255);
        struct hostent *host_entry;
        host_entry=gethostbyname(szHostName);
        char * szLocalIP;
        szLocalIP = inet_ntoa (*(struct in_addr *)*host_entry->h_addr_list);
        MultiByteToWideChar(CP_ACP, 0,szLocalIP , -1,pWideCharStr , sizeof(pWideCharStr) / sizeof(wchar_t));

        //MultiByteToWideChar(CP_UTF8, MB_COMPOSITE,szLocalIP , 32, pWideCharStr,32);
        MessageBox(NULL,pWideCharStr, TEXT("IP address"), MB_OK|MB_ICONERROR);

        WSACleanup();
        return SUCCESS;
    }



    ..................If my Code was useful..plz mark this as answer and mark as Helpful.......And encourage me for future enhancements......


    Regards
    Avinash
    Whenever I find the key to success, someone changes the lock.
    Monday, October 5, 2009 6:52 AM
  • Hi Avinash,

    Please refer to following sample:
    http://www.codeproject.com/KB/IP/IpXconfig.aspx
    http://69.10.233.10/KB/IP/Net_Adapter_Info_in_C_.aspx?fid=365556&df=90&mpp=25&noise=3&sort=Position&view=Quick



    Alghough it is c# code, we can study how to get data via using GetAdaptersadresses API.


    Best regards,
    Guang-Ming Bian - MSFT
    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Monday, October 5, 2009 7:44 AM