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
0 answers

getaddrinfo returning error -2 while fetching ipv6 (getaddrinfo: Name or service not known)

I am trying to write a client-server program for ipv6. I am facing issue when I am trying to call getaddrinfo function. It returns -2 (getaddrinfo: Name or service not known). This works fine on Windows system, but fails on Linux. $ ifconfig |grep…
kaps
  • 186
  • 4
  • 18
1
vote
2 answers

How to verify which version of getaddrinfo is in an executable

My company sells linux-based devices with a number of executables. One of these applications is hanging every few days in the newest version of our product. We are using glibc 2.19 and gcc 4.8.3 and Linux kernel version 3.16.38. We are building…
echawkes
  • 447
  • 2
  • 12
1
vote
1 answer

Send UDP packet with fixed source port number using getaddrinfo and bind

Using BJ's talker.c code as a template: http://beej.us/guide/bgnet/examples/talker.c #include #include #include #include #include #include #include #include…
Frak
  • 832
  • 1
  • 11
  • 32
1
vote
1 answer

getaddrinfo ignores trailing data?

Scenario: command line arguments need to be validated and converted to a socket/TCP addresses. The arguments can be any mix of IPv4 addresses, IPv6 addresses, and host-names. Currently we're using getaddrinfo. It picks up every error I can think of…
Underhill
  • 408
  • 2
  • 13
1
vote
1 answer

Memory management with `addrinfo` structures

I've just started to work with UDP sockets in C and I have a question relating to memory management. Often examples show something of the following struct addrinfo *result; //to store results struct addrinfo hints; //to indicate information…
ThatsRightJack
  • 721
  • 6
  • 29
1
vote
1 answer

Scapy import error 'socket.gaierror: [Errno 11001] getaddrinfo failed'

Im trying to install Scapy on windows 10, python 2.7.11, and stuck on this error: >>> from scapy.all import * Traceback (most recent call last): File "", line 1, in File "C:\tools\python\lib\site-packages\scapy\all.py", line 25,…
Idan
  • 69
  • 11
1
vote
2 answers

Pointer to pointer to struct causing segfault using getaddrinfo()

I'm using the getaddrinfo() function that requires a struct addrinfo ** to populate with a linked list of results, but I'm getting a segfault when I try the following code... int main() { struct addrinfo **results; getaddrinfo("localhost",…
CS Student
  • 1,613
  • 6
  • 24
  • 40
1
vote
4 answers

Sockaddr union and getaddrinfo()

I'm writing a UDP socket program which is provided an address from the command line. To make sending and writing easier, I'm using getaddrinfo to convert the address to a sockaddr struct: either sockaddr_in or sockaddr_in6. Now I understand that I…
m_highlanderish
  • 499
  • 1
  • 6
  • 16
1
vote
0 answers

Tracing `getaddrinfo()` on OSX

There's a program that is spending a long time in getaddrinfo(). Is there any way on OSX to see what address it is looking up? I've tried using this DTrace script but unfortunately I get this error: dtrace: failed to compile script…
Timmmm
  • 88,195
  • 71
  • 364
  • 509
1
vote
1 answer

Linux c++: getaddrinfo failed with EAI_AGAIN, curl could not resolve host

I open a GSM connection over ppp and try to download a file from a URL with curl. With few devices I get a CURLE_COULDNT_RESOLVE_HOST error from curl and getaddrinfo results in EAI_AGAIN. In route my ppp0 interface is registered correct. resolv.conf…
yakana
  • 41
  • 5
1
vote
0 answers

getaddrinfoW returns 11001 for any hostname but works if IP entered

Im using Delphi XE5 over Indy and one client is getting Socket Error # 11001 Host not found. The same call on my machine works fine for both SMTP and FTP Ping and nslookup both work on that machine if i enter either the IP or hostname I have…
Dangas56
  • 849
  • 1
  • 8
  • 32
1
vote
0 answers

is `freeaddrinfo` safe/needed when `getaddrinfo` return non-zero on linux?

what might the **res be if getaddrinfo return non-zero ? Is it safe, to call freeaddrinfo, with all possible values might be given by getaddrinfo ?(exp. null) Is it needed, to call freeaddrinfo, if getaddrinfo return non-zero ? Or, is there a…
1
vote
2 answers

getaddrinfo() with IPv6 not making sense

I don't understand why getaddrinfo is not returning a valid IPv6 address. On my system the code below is printing 22:B8:00:00:00:00:00:00:00:00:00:00:00:00, but I expected a 01 somewhere, since localhost should resolve to ::1. At the same time,…
user541686
  • 205,094
  • 128
  • 528
  • 886
1
vote
1 answer

Need help in understanding Sockets getaddrinfo

I have been trying to learn sockets programming, and came across this website: http://beej.us/guide/bgnet/output/html/multipage/index.html which is really good. I was able to understand, but after writing a test program myself I ended up with a…
Dinesh G
  • 129
  • 7
1
vote
0 answers

Loopback 3 connector soap getaddrinfo ENOTFOUND

I just started a new LoopbackJS 3 App and would like to use the soap connector plugin. I'm trying to connect to a Soap server and here's my server/datasource.json config. { "db": { "name": "db", "connector": "memory" }, "ppsrSoapDS":…
user1828473
  • 61
  • 1
  • 4