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

sockaddr value changes unexpectedly after calling getaddrinfo()

I am programming an UDP client. I want to bind the socket to a given port on the client machine, so that the same port is always used for all sends. I get the sockaddr for the server using getaddrinfo, and I do the same to get the sockaddr which I…
joanlofe
  • 3,360
  • 2
  • 26
  • 44
2
votes
0 answers

Valgrind reporting memory leak on getaddrinfo

I've stripped down my code to the bare minimum and, despite setting servinfo to NULL and excessively calling freeaddrinfo, I'm still seeing a memory leak with valgrind --leak-check=yes. I found this thread but I wasn't able to resolve the issue.…
user3007578
2
votes
2 answers

getaddrinfo and gethostbyname crashing when called from child thread?

We have created a multithreaded, single core application running on Ubuntu. When we call getaddrinfo and gethostbyname from the main process, it does not crash. However when we create a thread from the main process and the functions getaddrinfo and…
Syed Aslam
  • 79
  • 7
2
votes
1 answer

How to get actual size of ai_addr->sa_data returned by getaddrinfo()

getaddrinfo() fills struct addrinfo where actual packed address stored in struct sockaddr *ai_addr field. struct sockaddr has field char *sa_data with actual binary address representation. I want to copy this sa_data to another variable using…
Oleg G
  • 925
  • 4
  • 12
2
votes
2 answers

C Socket Error: "Name or service not known"

I'm trying to code a program in C that uses sockets to fetch webpages. My code currently prints successfully the HTML code at some webpages, but not all webpages. In the instances where it does not work I get the following error: Name or service…
user2977207
  • 21
  • 1
  • 2
2
votes
1 answer

getimagesize(): php_network_getaddresses: getaddrinfo failed in Yii

When I use function getimagesize or imagecreatefromjpeg for a link in my app it send me an error: getimagesize(): php_network_getaddresses: getaddrinfo failed: Name or service not known Here is my code: // tidy up by removing temporary…
ali abdzad
  • 130
  • 1
  • 10
2
votes
1 answer

C++ asynchronous hostname resolving

I have a epoll server which sometimes opens outgoing connections, using their hostnames representation. Because of high rate of incoming connections flow, I don't want to block somewhere like getaddrinfo() or gethostbyname(). Sure, I could…
pavelkolodin
  • 2,859
  • 3
  • 31
  • 74
2
votes
2 answers

Web2Py IOError: [Errno socket error] [Errno 11004] getaddrinfo failed error for sending email

I've been getting the following error: WARNING:web2py:Mail.send failure:[Errno 11004] getaddrinfo failed for the following code: mail = Mail() mail.settings.server = 'smtp.gmail.com:587' mail.settings.sender = 'email@gmail.com' mail.settings.login…
lovelejess
  • 86
  • 6
2
votes
1 answer

How to use getaddrinfo() on windows

I'm trying to build my APP with mingw+msys. My code usee winsock. When I compile it I take following error message: $ gcc -o sample sample.c -lws2_32 C:\Users\user\AppData\Local\Temp\ccsdWlQR.o:sample.c:(.text+0xeb): undefined reference to…
user1345414
  • 3,745
  • 9
  • 36
  • 56
2
votes
3 answers

How should I handle this HTTPS request in Python?

I am trying to use the Strava API v3 in Python, and I am afraid I am missing something. The docs say: This base URL is used for all Strava API requests: https://api.strava.com $ curl -i https://api.strava.com HTTP/1.1 200 OK Content-Type:…
heltonbiker
  • 26,657
  • 28
  • 137
  • 252
2
votes
0 answers

IOError: [Errno socket error] [Errno 11004] getaddrinfo failed on an accessable addr

I can open the url:http://www.bloomberg.com/markets/chart/data/1M/AAPL:AR in my brower but my code here comes out the result:I/O error(socket error):[Errno 11004] getaddrinfo failed : import urllib import…
ray
  • 71
  • 3
  • 11
2
votes
2 answers

getaddrinfo returns 2 results with localhost

I am trying to use the function getaddrinfo with a passive socket/listener instead of filling directly the old sockaddr structure. My purpose is to open a socket and bind it to a port. Essentially I am building a server. I don't know why but…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
2
votes
3 answers

Binding socket to computer's address for listening

I've created code designed to bind a new socket to the computer's addresses for listening for incoming connections on a specific port. I'm using getaddrinfo. Is this the best way? It seems pointless converting the port integer to a string. Is there…
Matthew Mitchell
  • 5,293
  • 14
  • 70
  • 122
1
vote
1 answer

'getaddrinfo()' function, it returns IP address from 'etc\hosts' file only ...?

I have dual stack Windows m/c, with IPv4 and IPv6 address. The etc\hosts contains only IPv4 address of that hostname. So whenever I call getaddrinfo() function, it returns IP address from etc\hosts file (i.e IPv4 only not IPv6 address). ipconfig…
Nilesh Shinge
  • 315
  • 1
  • 4
  • 9
1
vote
2 answers

Linux network programming:getaddrinfo() get wrong result

This is a simple program, I write it to find out all of a domain's A record. I complie it and get no errors nor warnings. Then I run it, I only found it give wrong IP, such as: ./a.out www.google.com 2.0.0.0 2.0.0.0 This is my code: #include…
thlgood
  • 1,275
  • 3
  • 18
  • 36