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.

244 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,463
  • 6
  • 32
  • 54
34
votes
6 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,038
  • 5
  • 30
  • 50
19
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
  • 313
  • 2
  • 4
  • 10
18
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
  • 10,959
  • 21
  • 75
  • 135
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,443
  • 2
  • 19
  • 32
16
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,752
  • 2
  • 15
  • 23
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
  • 12,647
  • 5
  • 61
  • 70
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
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
  • 554
  • 1
  • 7
  • 22
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
7
votes
1 answer

getaddrinfo, I am not getting any canonname

I am trying to read all the information about specific host and print out every information. I can read and print out all the addresses but I am not reading any ai_canonname! First I thought my examples(www.google.com|www.irs.gov|...) don't have…
Younes Nj
  • 532
  • 6
  • 16
7
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
  • 85,459
  • 18
  • 168
  • 202
6
votes
2 answers

Permanent gaierror 'Temporary failure in name resolution' after running for a few hours

I have a long running python script, launched with upstart. This script makes quite a lot of requests. Everything works well at first, however after a few hours I start permanently getting the following error for each request: File…
lipka
  • 1,162
  • 11
  • 19
6
votes
2 answers

Usage of getaddrinfo() with AI_PASSIVE

The getaddrinfo() function not only allows for client programs to efficiently find the correct data for creating a socket to a given host, it also allows for servers to bind to the correct socket - in theory. I just learned about that and started to…
glglgl
  • 81,640
  • 11
  • 130
  • 202
1
2 3
16 17