Solved

getaddrinfo() problem

Posted on 2004-09-05
5
1,574 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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
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.

837 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