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
1
vote
1 answer

getaddrinfo() fails continuously with EAI_AGAIN

In my code I am using the code as follows. do { r = getaddrinfo(host, service, &hints, ret); } while (r == EAI_AGAIN); when testing getaddrinfo() continuously fails thus loop not terminates properly. Do you see any way to improve the code? can…
Naga
  • 487
  • 2
  • 7
  • 23
1
vote
0 answers

Error fetching extensions. getaddrinfo ENOTFOUND open-vsx.org

Trying to add an extension to Eclipse Theia Blueprint but I keep getting this error Error fetching extensions. getaddrinfo ENOTFOUND open-vsx.org
Adem kriouane
  • 381
  • 20
1
vote
0 answers

"[Errono 11003] getaddrinfo failed" occurs only when running the pyinstaller .exec file on the company's internal network PC

All of the following cases were performed normally. home PC + python code home PC + pyinstaller .exe company's internal network PC + python code "[Errono 11003] getaddrinfo failed" occurs only when running the pyinstaller .exec file on the…
imsimsi
  • 17
  • 4
1
vote
0 answers

getaddrinfo behaving differently for RHEL 8 and RHEL 7

After going through many articles and not finding anything useful I am writing here. I am getting an incorrect behavior for getaddrinfo function on two different RHEL variants. This is specifically for Ipv6 related functionality. By default on both…
1
vote
1 answer

getaddrinfo expiration value (Linux hostname entries)

I'm writing a linux userspace application that opens a stateless socket (ICMP/UDP) to an internet host The user specifies a hostname FQDN (www.google.com) and I use getaddrinfo (or the old deprecated gethostbyname) function to resolve to an IPv4…
1
vote
1 answer

getaddrinfo return -11(EAI_SYSTEM)

getaddrinfo function always return -11(EAI_SYSTEM) even if I typed "google.com" on my embedded linux. But nslookup command works well. The sample code has no problem because it works on Ubuntu. So I think it is linux system's problem. Also I checked…
Jacob
  • 67
  • 6
1
vote
1 answer

Why does getaddrinfo() return first IPv4 instead of IPv6 when AI_PASSIVE is set?

According to https://www.amazon.com/Unix-Network-Programming-Sockets-Networking/dp/0131411551: This statement in the POSIX specification also implies that if the AI_PASSIVE flag is specified without a hostname, then the IPv6 wildcard address…
milanHrabos
  • 2,010
  • 3
  • 11
  • 45
1
vote
1 answer

What type is socket type of value 0?

I cannot see a socke type of value 0 in enum __socket_type: socket_type.h: /* Types of sockets. */ enum __socket_type { SOCK_STREAM = 1, /* Sequenced, reliable, connection-based byte streams. */ #define SOCK_STREAM…
milanHrabos
  • 2,010
  • 3
  • 11
  • 45
1
vote
1 answer

Using Requests Over Tor Returns a getaddrinfo failed

Getting things out of the way: I'm building a social network which crosses Mastodon and Secure Scuttlebutt protocols. Scuttlebutt is too data intensive and doesn't allow for online communication. Mastodon is too centralized. My network assigns an…
KI4JGT
  • 471
  • 2
  • 5
  • 13
1
vote
0 answers

Memory leak in getaddrinfo()?

Valgrind report me memory leak when i use getaddrinfo() and it fails with EAI_NODATA. When getaddrinfo() success, no memory leak reported. My code: #include #include #include #include #include…
g0rbe
  • 33
  • 5
1
vote
1 answer

Why getaddrinfo( ) always cause segmentation fault?

#include #include #include int main(){ char buff[50]; char port[5]; printf("Enter address to lookup: "); fgets(buff, 50, stdin); printf("Enter Port: "); fgets(port, 5, stdin); struct…
KMG
  • 1,433
  • 1
  • 8
  • 19
1
vote
2 answers

How to assign an addr_in struct to an array of uint8_t

Consider the following code snippet: uint8_t addr[4]; inet_pton(AF_INET, args.gtp_bind_addr.c_str(), addr); The function inet_pton() takes an IP-address in dotted decimal form (args.gtp_bind_addr.c_str()), converts it into an in_addr struct and…
Luk
  • 1,009
  • 2
  • 15
  • 33
1
vote
1 answer

getaddrinfo() returns only ipv6 when using AF_UNSPEC

When i want to connect to a server (running locally) and don't know if the application uses ipv4, ipv6 or both, should I call getaddrinfo() twice, once with AF_INET and once with AF_INET6, and try all returned addresses? Some context: getaddrinfo()…
madmax1
  • 267
  • 1
  • 9
1
vote
1 answer

getaddrinfo, Segmentation Fault

I am getting Segmentation Fault with the codes below. What I need the program to do is, when an invalid/unknown name or service is entered as an argument, it displays an error only for that particular service and continues to work on the rest of the…
Calvin
  • 13
  • 4
1
vote
0 answers

Testing UDP example server in `man addrinfo`

In man addrinfo there is example code for an UDP server. I compiled that code, and run it on a terminal using a.out 9001. On a second terminal I run netcat 127.0.0.1 9001, hoping that that will open an interactive session with the local server. And…
Jsevillamol
  • 2,425
  • 2
  • 23
  • 46