?
Solved

getaddrinfo() problem

Posted on 2004-09-05
5
Medium Priority
?
1,639 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

770 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