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
5
votes
2 answers

How to use getaddrinfo()?

Im trying to make a simple program that takes in a string like www.google.com and returns the ip address... What i have so far: char* hostname = new char[www.size()+1]; std::copy(www.begin(), www.end(), hostname); hostname[www.size()] =…
Kelvin
  • 233
  • 1
  • 4
  • 13
5
votes
1 answer

"Name or service not known (SocketError)" error when runs in many threads

I have made a program that parses text file and download data in parallel. When runs download method in 9 or less threads, the program doesn't have error. But when runs the method in 10 or more threads, the program throws "`initialize': getaddrinfo:…
Tagussan
  • 203
  • 4
  • 9
4
votes
1 answer

getaddrinfo() function returns the wrong IP address

I am trying to resolve a URL's IP address using getaddrinfo(), but it always returns the wrong IP address, I have tried with several URL's and the result is same. any help wold be greatly appreciated. The program returnes the ip address :…
Ashwin
  • 57
  • 1
  • 1
  • 2
4
votes
1 answer

getaddrinfo returns EAI_ADDRFAMILY on a distribution built with Yocto

We are currently using Oat++ (https://oatpp.io/) as a webserver for an embedded project. It is working wonder with several environments: docker container, ubuntu VM, Raspberry Pi 3. However, for this project we have our own linux distribution built…
ThmX
  • 149
  • 2
  • 6
4
votes
1 answer

getting Error: getaddrinfo ENOTFOUND while performing rest api call in node.js using http.request

i have created api in node.js which consume set of api hosted at http://dev.abc.co.in:20081 not every time but randomly sometimes it throws the error Error: getaddrinfo ENOTFOUND dev.abc.co.in at GetAddrInfoReqWrap.onlookup [as oncomplete]…
Ashish Patel
  • 921
  • 1
  • 10
  • 26
4
votes
0 answers

Why `getaddrinfo` doesn't support aliases?

Unlike gethostbyname, the function getaddrinfo does not return a list of alias names for a hostname. What was the reason to not include this information in the getaddrinfo result? I searched for a reference to this decision in: IETF mail…
Christian Ammer
  • 7,464
  • 6
  • 51
  • 108
4
votes
2 answers

getaddrinfo not returning ipv6 details

I am facing issues in getting ipv6 using getaddrinfo(): #include #include #include #include #include #include #include #include #include…
kaps
  • 186
  • 4
  • 18
4
votes
1 answer

Connecting a socket, using getaddrinfo, times out

I spent hours trying to find out my issue, just found the solution as I was writing my question (it always help when you need to formalize your issue and explain it). I post it, hopefully it helps someone. Using getaddrinfo, if I try to connect a…
Pellekrino
  • 346
  • 2
  • 14
4
votes
2 answers

Is getaddrinfo() a system call?

I was reading http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#syscalls when I found that getaddrinfo() is listed under the System Calls or Bust chapter. I wanted to check if it really is a system call on my Debian 8 Linux system. But I…
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
4
votes
2 answers

Want my client program to connect to over IPv4 or IPv6

Currently, the following program only connects using an IPv4 address. I want it to be modified to connect to a server(compatible of accepting IPv4 and IPv6 clients) using any of IPv6 or IPv4 address of the server. #include
ramnarayanan
  • 117
  • 2
  • 10
4
votes
0 answers

What can be expected in the field ai_canonname when calling getaddrinfo

#include #include #include #include #include #include int main(void) { int ret; struct addrinfo hints; struct addrinfo *res; struct addrinfo *p; …
hel
  • 581
  • 10
  • 26
4
votes
0 answers

getaddrinfo ENOTFOUND when making request to kubernetes services

I'm running 10 nodes and about 160 pods in our cluster. The cluster is up for a month and suddenly this error happened frequently when making request among services in cluster "response": { "err": { "code": "ENOTFOUND", "errno":…
Quyen Nguyen Tuan
  • 1,677
  • 17
  • 23
4
votes
2 answers

Wrong output inet_ntop

I'm trying to print an ip address from inet_ntop, but the output seems pretty weird. The program seems to work well, I succeed to connect the socket but it print this: H��H9�u�H�[]A\A]A^A_�ff.� Here is my code: #include #include…
jehutyy
  • 364
  • 3
  • 11
4
votes
0 answers

getaddrinfo resolves hostname incorrectly

I try to use getaddrinfo function (http://man7.org/linux/man-pages/man3/getaddrinfo.3.html) to get in_addr structure of IP address, but as far as I see, something is wrong, or I do something wrong. Consider following code snippet. bool resolve_host…
Artur Pyszczuk
  • 1,920
  • 1
  • 16
  • 23
4
votes
1 answer

getaddrinfo(3) with specified hints->ai_socktype doesn't return IPv6 addresses

Suppose the following code, which mimics the basic functionality of the resolveip utility: #define _POSIX_SOURCE /* getaddrinfo() */ #include /* getaddrinfo(), struct addrinfo, struct sockaddr */ #include /*…
Witiko
  • 3,167
  • 3
  • 25
  • 43
1 2
3
16 17