Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

gethostbyname() SOCKET PROGRAMMING ISSUE ON WINDOWS

May 31, 2011 8:05PM PDT

Hi All

Discussion is locked

- Collapse -
Re: ip address
May 31, 2011 8:15PM PDT

That's what they invented the hosts file for. It could very well be that the gethostbyname() function uses that internally.

Otherwise, you have to write your own code to replace the gethostbyname() function in your development environment. That's how we overcome these limitations.

For example. You write a custom function mygethostbyname(). If it "sees" it's in the development environment it returns the right value. if it's in the productionenvironment if calls gethostbyname().

Kees

- Collapse -
gethostbyname() SOCKET PROGRAMMING ISSUE ON WINDOWS
Jun 1, 2011 8:34PM PDT

Hi...

I added my target board host name and ip address into windows hosts file. and as expected it started working...thanks to you Happy

But as you know this function gethostbyname is depreciated so i used the getaddrinfo funtion.

I have given the arguments of getaddrinfo function are

getaddrinfo ( "hostname", portnumber, &hints, &result)

say my host name is aaauc
i am using the port number 5001
hints structure i am filling before calling getaddrinfo function and result will come in result variable

I want to send/recv some raw data between client and server but with above arguments my getaddr function is failing So i checked the error code and error cod is Specified class is not found that mean my 2nd argument is wrong...

So i am confuse what variable i have to give in 2nd parametre

since 2nd argument is service so i checked service fiile also but there are a lot of entries are there...So do i need to use the existing service...i tried by using the existing "ftp" / "ftp-data" service in 2nd argument but then my server does't connect to client and sendind data from client to server is failing...

So please advice my what to do....??

Thanks and best Regards
Sandeep gulati

- Collapse -
Hint:
Jun 2, 2011 3:53AM PDT

Deprecated but not gone. That function works fine.
Bob

- Collapse -
Perfect time to use the hosts file.
Jun 1, 2011 6:40AM PDT

Noted as a solution by Kees and "runed" may need to be "ran".
Bob