Hostname() problem in linux

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

Hostname() problem in linux

Post by Raghu » Wed Mar 01, 2006 1:44 pm

I had written a function to get Host Ip address.

wxString BasicFrame::GetMyIp()
{
wxIPV4address MyIp;
wxString MyHostName = MyIp.Hostname(); /* Get my hostname */
wxString sMyIp;
bool bRet;
bRet = MyIp.Hostname(MyHostName); /* Set MyIp to my Hostname */
if (bRet == true)
{
sMyIp = MyIp.IPAddress(); /* Get Ip address of my Hostname */
}
else
{
sMyIp = "0.0.0.0";
}
return sMyIp;
}

The code works perfectly for Windows. But I have a problem in linux. It gives a warning "Trying to solve NULL hostname:Giving up" and returns 0.0.0.0 .When I debuged the program I found out that MyIp.Hostname() is returning false.

Thanks and regards

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

Post by Raghu » Wed Mar 01, 2006 2:16 pm

I am running in super user mode

Post Reply