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
36
votes
8 answers

nodejs httprequest with data - getting error getaddrinfo ENOENT

Update - Answered by self I see one has to make sure that the DNS is resolved properly from the machine, check out the node documentation to make sure that domain is resolvable. Original Question i am writing a nodes based program,in which the user…
Brij Raj Singh - MSFT
  • 4,903
  • 7
  • 36
  • 55
33
votes
8 answers

PHP php_network_getaddresses: getaddrinfo failed: No such host is known

I am having DNS issues with a certain target domain. I am using fopen() (but same issue with other functions) to retreive an image, but I get this error: Warning: fopen(): php_network_getaddresses: getaddrinfo failed: No such host is known I am…
Richard
  • 4,341
  • 5
  • 35
  • 55
20
votes
4 answers

getaddrinfo and IPv6

I'm trying to understand what the getaddrinfo function returns : #include #include #include #include #include int main (int argc, char *argv[]) { struct addrinfo *res = 0 ; …
lilawood
  • 333
  • 2
  • 4
  • 10
19
votes
2 answers

Obtaining local IP address using getaddrinfo() C function?

I'm trying to obtain my local (not the external) IP address using the getaddrinfo() function, but I saw the examples provided here, and they where too complex for my needs. Also saw other posts and most of them really wanted to get the external IP,…
Goles
  • 11,599
  • 22
  • 79
  • 140
18
votes
3 answers

How to catch getaddrinfo ENOTFOUND

I have a list of links that I need to check before processing some data. Checking headers with http.get returns error: events.js:72 throw er; // Unhandled 'error' event ^ Error: getaddrinfo ENOTFOUND at…
Maxali
  • 1,934
  • 2
  • 16
  • 25
17
votes
3 answers

getaddrinfo memory leak

I have this code for getting information about IPv4 address: struct addrinfo hints, *info = NULL; char addr4[INET_ADDRSTRLEN]; memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; hints.ai_family = AF_INET; if…
Petr Přikryl
  • 1,641
  • 4
  • 22
  • 34
11
votes
1 answer

using getaddrinfo() only checks nscd cache first time if DNS times out

If I get an initial "Name or service not known" (EAI_NONAME), the next call to getaddrinfo() seems to go straight to the dns instead of checking the cache first (nscd logs show no lookup attempts, tcpdump shows traffic to DNS server). If the first…
colin.mc
  • 111
  • 1
  • 4
10
votes
5 answers

Is it necessary to attempt to connect to all addresses returned by getaddrinfo()?

Beej's Simple Client example code iterates over all IP addresses returned from getaddrinfo(), until it can connect to the first one. See the code below. Is this always necessary, or is it OK to assume that we only have to try to connect to the first…
Phillip Ngan
  • 15,482
  • 8
  • 63
  • 79
9
votes
2 answers

getaddrinfo: nodename nor servname provided, or not known (SocketError)

I'm developing a Shopify theme and I'm using https://github.com/Shopify/shopify_theme to update my files into Shopify. Unfortunately, I can't get it to work... When I try to upload/update a file, I get an error…
user1821591
  • 101
  • 1
  • 4
8
votes
0 answers

GetAddrInfo (C++) on Windows not handling IPv6 correctly, returning error code 11004 for domains that resolve fine through other means

Note: I looked extensively at a similar (but not duplicate) question here: GetAddrInfo cannot resolve ipv6.google.com (but nslookup can). This question is 9 years old, the OP is not experiencing the exact same behavior as I am, and the…
Nick Williams
  • 2,864
  • 5
  • 29
  • 43
8
votes
1 answer

If getaddrinfo fails once, it fails forever (even after network is ready)

I am writing a C application which is run as a systemd service on boot (distro: Arch Linux) and which shall connect to a server. Because the application is run on boot it eventually happens that the network connection is not yet established. This…
kassiopeia
  • 615
  • 1
  • 9
  • 23
8
votes
1 answer

How to use getaddrinfo to connect to a server using the external IP?

I'm writing a small C client/server application, but I cannot make the connection work when using the external IP address. The code for both client and server is taken from here, in particular the clients do: char *default_server_name =…
Bakuriu
  • 98,325
  • 22
  • 197
  • 231
8
votes
2 answers

Is struct addrinfo **res allocated when getaddrinfo() returns a non-zero value?

I am having some memory leaking troubles in an embedded application and while looking in the code, I see I do not freeaddrinfo() when getaddrinfo() returns non-zero: s = getaddrinfo(hostname, port, &hints, &result); if (s != 0) { log_error(); }…
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
7
votes
1 answer

Why are there multiple results from getaddrinfo?

I am trying to create a simple program that gets the IP address given a certain hostname: My code snipped is attached below: #include #include #include #include #include #include…
ahat
  • 343
  • 3
  • 9
7
votes
0 answers

Large Number of Requests - Error: getaddrinfo ENOTFOUND

When making a large number of requests in node (using version 6.3.0, but this has also occurred on other versions), I get the error getaddrinfo ENOTFOUND. Researching this problem I found the following github issue for older versions of node:…
user6517436
  • 111
  • 1
  • 5
1
2 3
16 17