equivalent function to inet_addr()
equivalent function to inet_addr()
Is there any equivalent functions in wxWidgets for inet_addr(), inet_aton(),ntohl() like calls ?
-
- Super wx Problem Solver
- Posts: 396
- Joined: Wed Oct 05, 2005 1:19 am
you have to set the Hostname to your wxIPV4address before getting the IPaddressRaghu wrote:IPAddress() returns 0.0.0.0 but not the actual IPAddress of the machine.
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