Solved

getaddrinfo() problem

Posted on 2004-09-05
5
1,564 Views
Last Modified: 2007-12-19
Here is my code:

      addrhints.ai_family = AF_INET;
      addrhints.ai_socktype = SOCK_STREAM;
      addrhints.ai_protocol = IPPROTO_TCP;
      pres = 0;
      retVal = getaddrinfo(szHost,"80",&addrhints,&pres);

szHost is equal to "bithub.com".  getaddrinfo() is returning 11003 which is WSANO_RECOVERY.  Does anyone know what I'm doing wrong that is causing the error?
Thanks.
0
Comment
Question by:lwinkenb
  • 2
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 11985421
The error code is described as "Nonrecoverable failure in name resolution" (API Ref.: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp). Have you tried to provide an IP address instead of a host name?
0
 
LVL 5

Author Comment

by:lwinkenb
ID: 11986169
no I havent.  Im using this method to get the ip address.  I usually use gethostbyname(), but in msdn, it says that gethostbyname() is depreciated and to use getaddrinfo() instead.
0
 
LVL 7

Accepted Solution

by:
aib_42 earned 250 total points
ID: 11986172
Try doing a ZeroMemory(&addrhints, sizeof(addrhints)); before setting up ai_family et cetera.
0
 
LVL 5

Author Comment

by:lwinkenb
ID: 11986233
Clearing the memory made it so the function returned successfully.  Yhanks :)
0
 
LVL 7

Expert Comment

by:aib_42
ID: 11993305
For the record, the problem was that the seemingly-unused fields in the struct contained garbage whereas the MSDN documentation states, quote:

ai_addrlen must be zero or a NULL pointer
ai_canonname must be zero or a NULL pointer
ai_addr must be zero or a NULL pointer
ai_next must be zero or a NULL pointer
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question