equivalent function to inet_addr()

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Raghu
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Oct 19, 2005 11:33 am

equivalent function to inet_addr()

Post by Raghu » Tue Feb 21, 2006 1:20 pm

Is there any equivalent functions in wxWidgets for inet_addr(), inet_aton(),ntohl() like calls ?

sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post by sethjackson » Tue Feb 21, 2006 3:57 pm


Raghu
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Oct 19, 2005 11:33 am

Post by Raghu » Wed Feb 22, 2006 5:13 am

IPAddress() returns 0.0.0.0 but not the actual IPAddress of the machine.

tiwag
Earned some good credits
Earned some good credits
Posts: 123
Joined: Tue Dec 21, 2004 8:51 pm
Location: Austria

Post by tiwag » Wed Feb 22, 2006 10:19 am

Raghu wrote:IPAddress() returns 0.0.0.0 but not the actual IPAddress of the machine.
you have to set the Hostname to your wxIPV4address before getting the IPaddress

then it works

Code: Select all

void MyFrame::OnMyIP(wxCommandEvent& event)
{
    wxIPV4address addr;
    wxString myhn = addr.Hostname();    // get my Hostname
    wxString addr2hn;
    bool res;
    res = addr.Hostname(myhn);          // set addr to my Hostname
    addr2hn = (res)? _T("true")         // check result of assignment
                   : _T("false");
    wxString myip = addr.IPAddress();   // get IP-address of my Hostname

    wxString othn = _T("google.com");   // get another Hostname
    res = addr.Hostname(othn);          // set addr to other Hostname
    wxString otip;
    otip = (res)? addr.IPAddress()      // get IP-address of other Hostname
                : _T("Host not found");

    wxString msg = _T("\n");
    msg += _T("get my Hostname         \t myhn    \t = ") + myhn    + _T("\t\n");
    msg += _T("set addr to my Hostname \t addr2hn \t = ") + addr2hn + _T("\t\n");
    msg += _T("get my IP address       \t myip    \t = ") + myip    + _T("\t\n");
    msg += _T("get other Hostname      \t othn    \t = ") + othn    + _T("\t\n");
    msg += _T("get other IP address    \t otip    \t = ") + otip    + _T("\t\n");

    wxMessageBox(msg);
}
-tiwag

Raghu
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Oct 19, 2005 11:33 am

Post by Raghu » Wed Feb 22, 2006 12:52 pm

Thanks a lot. That helped me a lot.

Post Reply