Solved

getaddrinfo() problem

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now