General discussion

gethostbyname() SOCKET PROGRAMMING ISSUE ON WINDOWS

Hi All

Discussion is locked
Follow
Reply to: gethostbyname() SOCKET PROGRAMMING ISSUE ON WINDOWS
PLEASE NOTE: Do not post advertisements, offensive materials, profanity, or personal attacks. Please remember to be considerate of other members. If you are new to the CNET Forums, please read our CNET Forums FAQ. All submitted content is subject to our Terms of Use.
Reporting: gethostbyname() SOCKET PROGRAMMING ISSUE ON WINDOWS
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Comments
- Collapse -
Re: ip address

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

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:

Deprecated but not gone. That function works fine.
Bob

- Collapse -
Perfect time to use the hosts file.

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

CNET Forums