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
0
votes
1 answer

Unexpected socket.getaddrinfo behavior in Python using SOCK_STREAM

I'm busy trying to use socket.getaddrinfo() to resolve a domain name. When I pass in: host = 'www.google.com', port = 80, family = socket.AF_INET, type = 0, proto = 0, flags = 0 I get a pair of socket infos like you'd expect, one with…
dputtick
  • 21
  • 2
0
votes
1 answer

Opinion on Glibc getaddrinfo

InetAddress.java is using Glibc function getaddrinfo() and according to CVE-2016-3706, getaddrinfo() is not safe any more. Does that mean that all the applications which use InetAddress class are not safe. What can be the solution to this problem?
nilan59
  • 1,006
  • 9
  • 24
0
votes
0 answers

how can I make getaddrinfo return 'sctp' protocol?

struct addrinfo hint, *result; int res, sfd; memset(&hint, 0, sizeof(struct addrinfo)); hint.ai_family = AF_INET; hint.ai_socktype = SOCK_STREAM; res = getaddrinfo(NULL, port, &hint, &result); I think getaddrinfo should return two addrinfo when…
Pengcheng
  • 439
  • 1
  • 4
  • 14
0
votes
1 answer

Why does getaddrinfo sometimes behave differently with "example.com" and "www.example.com"?

This is a code example from MSDN: getaddrinfo. You can use "baidu.com" and "www.baidu.com" to test.
0
votes
1 answer

My node.js http request worked for the first time and now it is showing some error

I am using node.js 'request' module for making http request. This code worked for the first time. But now it shows some error. var request = require('request'); request('http://www.google.com', function (error, response, body) { if (!error &&…
0
votes
1 answer

getaddrinfo always connect. even when no passive-open connection listen on that port

I'm writing a server client program using socket programming c++ in Ubuntu. This is the code connect client to server. void setParent(string name,int parentPort){ struct addrinfo hints, *serverInfo , *rp; int errcode; char addrstr[100]; …
amir.sh
  • 193
  • 6
  • 18
0
votes
1 answer

mysqlnd php_network_getaddresses: getaddrinfo failed: No such host is known

I followed this tutorial http://www.clusterdb.com/mysql-cluster/creating-a-simple-cluster-on-a-single-linux-host using this download from mysql site: mysql-cluster-gpl-7.3.10-linux-glibc2.5-x86_64.tar.gz I have this up and running on a Ubuntu…
Salvatore
  • 1
  • 1
0
votes
1 answer

WinSock function - Passing argc & argv exception

I'm trying to setup a simple TCP client. I don't want the full setup and connect code in my main() so I'm trying to move it to a function but keep getting a Access Violation Error in VS2015, all includes are correct. The function is a straight copy…
HyperionX
  • 1,332
  • 2
  • 17
  • 31
0
votes
0 answers

Unix C sockets: accept is listening but connection refused

I am trying to develop a simple UNIX server, that is not limited to IPv4. However, my sample code "hangs" on accept() call and when I try to telnet, I get "Connection refused" on both 127.0.0.1 and ::1. My code (I marked what I considered most…
eghuro
  • 11
  • 3
0
votes
1 answer

Need to understand the structure returned by getaddrinfo()

I'm trying to build a simple webserver which is IP version agnostic. This is my sample code snippet hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version hints.ai_flags = AI_PASSIVE; // fill in my IP for me hints.ai_socktype =…
Gaurav Suman
  • 515
  • 1
  • 3
  • 17
0
votes
1 answer

Is there a way to programmatically limit name resolution to entries present in /etc/hosts?

Usually, I could ask getaddrinfo for the address of google.com and it will do some DNS queries and finally return me the results. But now I have a scenario where I want to avoid the DNS lookup but limit the functionality to reading /etc/hosts (or…
eckes
  • 64,417
  • 29
  • 168
  • 201
0
votes
0 answers

Unable to resolve hostname if device is not booted with ethernet?

I'm using netplugd to monitor the plug and unplug events of my ethernet. Also using udhcpc to get IP from DHCP whenever plug in event is got, configuring static IP in case udhcpc fails in 5 retries to do so. Here the problem is that in case the…
0
votes
1 answer

socket programming confusion of getaddrinfo function

In getaddrinfo("www.example.net","1234", &hints, &server_info) What is the use of the hints parameter?
Jiaming Li
  • 207
  • 1
  • 5
0
votes
1 answer

C++ - getaddrinfo() - getting own external IP with dynamic dns fails

I'm currently working on a program that tells me, among other things, my external IP. To achieve this, I'm using the function getaddrinfo(). For testing purpose I passed google.com as node name, it worked fine. If I'm passing my dynamic dns to the…
Daniel
  • 83
  • 1
  • 2
  • 13
0
votes
1 answer

getaddrinfo not resolving fqdn with more than two levels depth

getaddrinfo resolves google.com fine but when tries to resolve www.google.com (or any fqdn with more than two levels) it fails: "hostname nor servname provided, or not known". When getaddrinfo tries to resolve www.google.com (for example), in the…
Ernesto
  • 1
  • 1