×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    16

    Local IP address (emulator/mobile phone)

    I have an application for a socket server. I use the following to find out what the local IP adddress is (to later make a call to bind to this same address).


    RSocket sock;
    sock.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp);

    iConnection.Open(iSocketServ));
    iConnection.GetIntSetting(_L("IAP\\Id"), iapId));

    TSoInetInterfaceInfo ifinfo;
    TPckg<TSoInetInterfaceInfo> ifinfopkg(ifinfo);

    TSoInetIfQuery ifquery;
    TPckg<TSoInetIfQuery> ifquerypkg(ifquery);

    sock.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);

    while(sock.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, ifinfopkg) == KErrNone) {
    ifquery.iName = ifinfo.iName;
    sock.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, ifquerypkg);

    if(ifquery.iZone[1] == iapId) {
    if(ifinfo.iAddress.Address() > 0) {
    aAddr = ifinfo.iAddress;
    sock.Close();
    return KErrNone;
    }
    }
    }
    sock.Close();



    On an emulator (S60_3rd_FP1_3), the above does not work. It goes twice through the loop, but the IAP-IDs and addresses it finds are always equal to 0. Why is this?
    On the mobile phone it returns an IP address of the form 169.x.x.x, which normally means that the adddress is non-valid (however, from another phone or the emulator I can actually connect to the socket using this IP address).

    On the other hand, the following code *does* find the local IP address on the emulator:


    // Get info about local IP address
    RHostResolver hostResolver;
    hostResolver.Open(iSocketServ, KAfInet, KProtocolInetTcp, iConnection);

    TBuf<255> hostName;
    hostResolver.GetHostName(hostName);

    TNameEntry nameEntry;
    hostResolver.GetByName(hostName, nameEntry);

    TNameRecord nameRec = nameEntry();
    TSockAddr sockAddr = nameRec.iAddr;

    GetInetAddressL(sockAddr, aInetAddr);


    Now, both on the emulator as on the mobile phone, I get an IP address of the form 192.x.x.x

    I would like to know why one code works and the other doesn´t, since I have found both types of code on the internet presented as valid solutions.

  2. #2
    Super Contributor
    Join Date
    Aug 2005
    Location
    india
    Posts
    2,078

    Re: Local IP address (emulator/mobile phone)

    hi,

    check this wiki example code might help you..

    http://wiki.forum.nokia.com/index.ph...eviceIpAddress

    Regards,
    Mateen Maldar
    "Whatever the mind can conceive and believe, the mind can achieve"

Similar Threads

  1. Local BT Address?
    By redfoodegm in forum Symbian
    Replies: 4
    Last Post: 2007-05-16, 22:12
  2. Local Device Address
    By squid1341 in forum Symbian Networking & Messaging (Closed)
    Replies: 15
    Last Post: 2006-07-03, 15:43
  3. I can't reinstall PC Suite Support into my phone
    By rulirahm in forum PC Suite API and PC Connectivity SDK
    Replies: 3
    Last Post: 2006-06-12, 08:49
  4. Use phone to receive SMS with port address
    By mattias.lindskog in forum General Messaging
    Replies: 1
    Last Post: 2004-01-26, 11:27
  5. query name by phone number from phone's address book
    By Wah in forum Mobile Java General
    Replies: 1
    Last Post: 2003-12-17, 07:09

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •