Questions tagged [getaddrinfo]

`getaddrinfo(3)` provides network address and service translation.

From the man page:

Name

getaddrinfo, freeaddrinfo, gai_strerror - network address and service translation

Synopsis

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

int getaddrinfo(const char *node, const char *service,
                const struct addrinfo *hints,
                struct addrinfo **res);

void freeaddrinfo(struct addrinfo *res);

const char *gai_strerror(int errcode);

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

getaddrinfo(), freeaddrinfo(), gai_strerror():
    _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE 

Description

Given node and service, which identify an Internet host and a service, getaddrinfo() returns one or more addrinfo structures, each of which contains an Internet address that can be specified in a call to bind(2) or connect(2). The getaddrinfo() function combines the functionality provided by the getservbyname(3) and getservbyport(3) functions into a single interface, but unlike the latter functions, getaddrinfo() is reentrant and allows programs to eliminate IPv4-versus-IPv6 dependencies.

252 questions
2
votes
2 answers

C - getaddrinfo()

Can someone help me to get the IPs of google.com? I can't find any good resource on this. Most tutorials on C network programming create a client socket and a server socket on the same computer. (I don't know in which situation that would make…
RaspberMan
  • 31
  • 1
  • 1
  • 4
2
votes
2 answers

IPv6 address to domain name

I'm searching for a function that take an IPv6 address as argument and returns the domain name. To make it clear, 2a00:1450:8006::68 returns ipv6.google.com. (The aim is to give this domain name to the getaddrinfo function.) Thanks :-) edit1 : I've…
lilawood
  • 333
  • 2
  • 4
  • 10
2
votes
2 answers

getaddrinfo error: ai_socktype not supported

struct addrinfo *myAddrinfo, *curMyAddrinfo, hint; memset(&hint, 0, sizeof(struct addrinfo)); hint.ai_family = AF_INET; hint.ai_protocol = AI_PASSIVE; hint.ai_socktype = SOCK_STREAM; const int code = getaddrinfo(NULL, SERVER_PORT, &hint,…
Nissan911
  • 293
  • 1
  • 7
  • 17
2
votes
1 answer

WinSock getaddrinfo to get IP from hostname fails until ipconfig /flushdns is called

Getting an IP address from a hostname is normally done by calling getaddrinfo (which is really just an alias for WspiapiGetAddrInfo). We see cases where this fails. At that same time as the failure: ping {hostname} is able to resolve the hostname…
DougN
  • 4,407
  • 11
  • 56
  • 81
2
votes
1 answer

gai_cancel() takes a really long time to succeed

I am trying to look up domain asynchronously in c++. The reason is I want to be able to effectively add a time out period in case the system can't look up the domain. I came across the getaddrinfo_a() command so I decided to give it a try. However…
ktb92677
  • 407
  • 4
  • 16
2
votes
1 answer

How can I fix `getaddrinfo` definitions not being found?

I get the following errors when I try to compile my code: main.c:13:40: note: each undeclared identifier is reported only once for each function it appears in main.c:17:14: error: ‘EAI_ADDRFAMILY’ undeclared (first use in this function); did you…
adyavanapalli
  • 490
  • 6
  • 17
2
votes
1 answer

Calling getaddrinfo directly from Python: ai_addr is null pointer

I'm trying to call getaddrinfo from Python, through ctypes / libc, on Mac OS, in order to find the IP address of a domain. The call appears to succeed: no error code is returned, and ai_addrlen is set to 28, which I understand is the appropriate…
Michal Charemza
  • 25,940
  • 14
  • 98
  • 165
2
votes
1 answer

Is ::ffff:127.0.0.1 localhost?

I'm getting introduced into IPv6 and I've read that IPv4 addresses can be mapped to IPv6 by using the ::ffff: prefix. This led me to think whether address ::ffff:127.0.0.1 refers to localhost, so I wrote a simple C program that uses getaddrinfo()…
Claudi
  • 5,224
  • 17
  • 30
2
votes
1 answer

getaddrinfo sorting IPv4 before IPv6 for localhost?

I wrote a very simple test program for getaddrinfo: #include #include #include #include #include int main() { struct addrinfo hints; struct addrinfo *res, *rp; char…
David Gloe
  • 86
  • 1
  • 4
2
votes
0 answers

getaddrinfo returns previous fixed IP address

Context: My C++ application needs to know on which computer it is running in order to do specific behavior. So my application gets the IP address of the computer and then check that address in a configuration file with an IP list in order to…
ZulKaz
  • 53
  • 1
  • 5
2
votes
0 answers

GetAddrInfo fails with subdomains

I was wondering if you knew why GetAddrInfo fails with subdomains? Example: www.support.hostgator.com Return value from WSAGetLastError() is 11001 No such host is known I looked around on MSDN and didn't find anything about how to handle this.…
Trevin Corkery
  • 651
  • 7
  • 19
2
votes
0 answers

Error: getaddrinfo ENOTFOUND Node.js request-promise

I am using the request-promise module in Node.js to produce lots of parallel requests (>1000), and I am getting the following error after about half of them (500) have completed: Error: getaddrinfo ENOTFOUND I saw this github issue:…
user6517436
  • 111
  • 1
  • 5
2
votes
1 answer

Service port is missed when using getaddrinfo to convert IPv4 addr to IPv6 addr

I am testing IPv6 in Mac OS X 10.11.2 and I find a strange problem. I use getaddrinfo to resolve hostname to IPv6 addr : #include #include #include #include #include int main(int argc, const…
Maverick
  • 21
  • 1
2
votes
1 answer

Rails Heroku SocketError: getaddrinfo: Name or service not known

I am on a heroku app, Ruby 2.2.0, Rails 4.0.12 and using the geokit-rails gem. When I do a IpGeocoder.geocode(request.remote_ip) I get the error: Caught an error during Ip geocoding call: getaddrinfo: Name or service not known I searched online…
user2911232
2
votes
0 answers

NodeJS mongo client cannot resolve DNS name

NodeJS v5.7.0 is with mongodb driver 2.1.2 used on CentOS6. Many times I get the following error trying to boot my nodejs server: [2016-03-05 17:33:01.355] [INFO] [default] - TestGM online Connecting to…
rlib
  • 7,444
  • 3
  • 32
  • 40