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

Preventing php_network_getaddresses: getaddrinfo failed:

I am trying to call an URL with PHP to check if it exists and is reachable. My initial code was fopen('http://'.$this -> url, 'r'); But it throws the following errors every time an URL is unreachable: fopen(http://dwzegdzgwedzgew.com): failed to…
Daniele D
  • 838
  • 1
  • 8
  • 21
1
vote
3 answers

What to do with the results of getaddrinfo?

Using getaddrinfo to query a host, I get a number of results: struct addrinfo hints; hints.ai_flags = 0 hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = 0 hints.ai_addrlen = 0; hints.ai_addr =…
Rena
  • 606
  • 7
  • 21
1
vote
2 answers

Invalid readsize of 4 error from getaddrinfo()

Running Valgrind on my program generates an invalid read of size 4 error. I'm trying to locate it, but can't seem to find it. #define _GNU_SOURCE #include #include #include #include #include…
Deanie
  • 2,316
  • 2
  • 19
  • 35
1
vote
0 answers

Source code of implementation of getaddrinfo of gcc libc

This is a question similar as warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking. In runtime, getaddrinfo("localhost") will open /etc/resolv.conf, this is…
osexp2000
  • 2,910
  • 30
  • 29
1
vote
1 answer

socket.getaddrinfo() block forever when using with gevent

Using httplib2, I am sending multiple requests with gevent, after some time http.request() method of httplib2 is getting blocked forever. On checking I found that blocking function is socket.getaddrinfo() in httplib2 link.
1
vote
0 answers

getaddrinfo fails although ping works fine

I have following snippet of code, which is just trying to get address family of a server address. srv_addr is passed from other places to this piece of code. struct addrinfo dinfo, *dptr = NULL; int error; memset(&dinfo, 0,…
Ram
  • 1,153
  • 4
  • 16
  • 34
1
vote
1 answer

getaddrinfo on raspbian returns only loopback IP, same code on OS X multiple

I have a short test program to fetch the IP address of the local machine. On Raspbian, only the loopback address is returned, while the same code on OS X return both normal and loopback IPs. The code is #include #include…
RussK
  • 199
  • 1
  • 17
1
vote
0 answers

getaddrinfo Error code 11001

i am completely new to sockets in c++. So i already checked a few topics here, but i am not able to get it going. Please also don't judge about the code, it's mostly try and error for myself. So what i am basically try to do is to save the response…
Michael Thumm
  • 81
  • 1
  • 8
1
vote
1 answer

Is there any way to prevent getaddrinfo from revealing the true IP address of a hostname?

Let's say there is a program that opens up the HOSTS file to make sure that it isn't being rerouted somewhere. (It wants to connect to www.example.com but it makes sure you don't have an entry in the HOSTS file for that). So instead, you decide to…
jcao219
  • 2,808
  • 3
  • 21
  • 22
1
vote
1 answer

getaddrinfo failure in python

My python script uses getaddrinfo() to parse an address before it can 'bind()' to it. Snippet of the script: def fetch_ipv6_address(addr="::1"): # try to detect whether IPv6 is supported at the present system and # fetch the IPv6 address of…
Maddy
  • 1,319
  • 3
  • 22
  • 37
1
vote
0 answers

What is hints parameter for getaddrinfo?

I can't understand usage for hints parameter in getaddrinfo() getaddrinfo(node, service, &hints, &res); Same sample code for getadderinfo() like below doesn't read hints as if hints’ll never be set…
user1345414
  • 3,745
  • 9
  • 36
  • 56
1
vote
1 answer

Got local host name, working on windows, but not in Linux

I wrote a program to get local host name. if it is not obvious, I mean to get the host name of the local machine similar to gethostname method, not to get the string localhost I'm using getaddrinfo with NULL for host name and then call to…
SHR
  • 7,940
  • 9
  • 38
  • 57
1
vote
3 answers

Unable to connect to host using getaddrinfo()

Note: This is a project for homework, I will try to write the remaining code, but cannot figure out why this is unable to connect to an input URL. I was given skeleton code that I modified a bit to receive an input URL. Expected usage could be:…
asimes
  • 5,749
  • 5
  • 39
  • 76
1
vote
1 answer

Webdriver causes "SocketError: getaddrinfo: No such host is known" on IE10/Win7

We have a virtual Windows 7 image where our CI runs our functional tests on IE10. The functional tests are written in Ruby using Cucumber + Watir-Webdriver. Most of the time it works fine, but every now and then every test starts failing with the…
Sampo
  • 4,308
  • 6
  • 35
  • 51
1
vote
1 answer

socket control to accept multiple UDP connections

I'm breaking my mind trying to understand how make a client/server write by myself accept multiple socket connections. The connection is a datagram (UDP), for now was implemented based on getaddrinfo(3) man page works nice, but each client needs to…
ton
  • 3,827
  • 1
  • 42
  • 40