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

getaddrinfo returns information whereas ping.exe says ip is unreachable

I work on a problem where I want to avoid a system to launch a connection retry when the target ip is not reachable. (The target ip can be on and off at different times in the day). I can see that ping.exe returns correctly that host is…
Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169
0
votes
1 answer

client address is null on the server side

I am trying a simple client-server program. On the client side I bind to a specific address. On the server side when I accept a connection, the client address is received as NULL. I am using getaddrinfo on the client and server side to fetch the IP…
user50891
  • 21
  • 3
0
votes
1 answer

Cron Jobs | getaddrinfo Error for file_get_contents method in PHP

I have set up a cron job which fetches the JSON response from a website, process it and saves it into the database. The Cron Job will be running for more than a week. I am facing 2 problems: I expect my cron job to continously run for more than a…
user1262479
  • 497
  • 3
  • 6
0
votes
3 answers

Calling socket::connect, socket::bind, socket::listen without using getaddrinfo( ) function before it

In all the example including Beej's Guide, the IP address is provided in dot notation and then it's fed to ::getaddrinfo(). This post doesn't answer my question. After which the addrinfo struct is used for socket related functions (e.g. connect(),…
iammilind
  • 68,093
  • 33
  • 169
  • 336
0
votes
0 answers

How to make sure getaddrinfo( ) sends out DNS query everytime it is called

I am working on a project with android phones(language C) and I am using getaddrinfo() to check that the phone is able to speak to the nameserver assigned to it. But I think getaddrinfo is reading the cached values from resolv.conf. How can I send…
mbpram
  • 1
  • 1
0
votes
1 answer

getaddrinfo() returning very slowly on failure

I try to use getaddrinfo() in my application which should determine whether I am connected to the internet. As long as getaddinfo() is able to return successfully everything is OK. But as soon as I disconnect my computer from the router the…
ThunderStorm
  • 766
  • 8
  • 24
0
votes
1 answer

c++ socket programming with url:port/url in getaddrinfo

Relearning C++ and fairly new to sockets. I have a Python app that connects properly and a .NET app that works. The URL I need to call is domain.com:8080/signalr. I'm following what seems to be a standard example, e.g.: if ((rv =…
VirtualLife
  • 402
  • 5
  • 14
0
votes
2 answers

getaddrinfo fails to resolve address in hosts file when using mocha

Node.js 0.10.26 OS X 10.9.2 (also on ubuntu vagrant box) In two different modules on my system, when I run tests using mocha, I get this error: { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' } Which…
joshuten
  • 1
  • 2
0
votes
1 answer

Yii Error 500: php_network_getaddresses: getaddrinfo failed: Name or service not known

yesterday some pages have returned this error: Error 500: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known I tried to search this problem in relation with Yii framework but I did not found no solutions to…
bit
  • 427
  • 1
  • 6
  • 14
0
votes
0 answers

Windows getaddrinfo hangs; won't return

Trying to implement a system-independend socket api in assembler as private project, I wrote the following code to resolve a string address (DNS or direct IP) to a sockaddr record. MSDN told me to use getaddrinfo. [import getaddrinfo…
Lars M.
  • 179
  • 10
0
votes
0 answers

get ip addresses of all active routers in the network programmatically

As for the part of my final year project I want to get a list of IP addresses of all the active routers in the network so that I can obtain it IPv6 status via getaddrinfo with the AI_ADDRCONFIG flag. The current implementation of getaddrinfo works…
Hasitha Shan
  • 2,900
  • 6
  • 42
  • 83
0
votes
3 answers

How to get the interface I am connected to

I am trying to implement an application which receives a packet(ICMP maybe) on a tap interface. I have the code something like this. strcpy(ifName, "tap0"); if ((sockfd = socket(PF_PACKET, SOCK_RAW,0) == -1) { perror("ERROR: socket"); …
Curious Guy 007
  • 561
  • 2
  • 6
  • 17
0
votes
1 answer

getaddrinfo behavior during reconnect

I noticed some curious behavior with python's socket.getaddrinfo(). If I am connected to wifi and call socket.getaddrinfo(), it works (of course it does!): In [3]: socket.getaddrinfo('charlesleifer.com', 80) Out[3]: [...] If I disconnect, then I…
coleifer
  • 24,887
  • 6
  • 60
  • 75
0
votes
1 answer

An issue of getaddrinfo() function call on Linux platform

Recently, I'm working on development of the network application which is base on Linux platform(2.6.32). My scenario is that the device need to send data to server periodically. Every time the network code calls the function getaddinfo() firstly, it…
gtv
  • 21
  • 1
  • 3
0
votes
1 answer

getaddrinfo doesnt work with network address

I have a network address eg - 192.168.74.0/24. Trying to get the network address translation using getaddrinfo, doesnt seem to work. name here is 192.168.74.0/24. return value from getaddrindo is -2. Works well for ipv4 address without…
user1060517
  • 355
  • 1
  • 5
  • 17
1 2 3
16
17