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

How to print ip address from getaddrinfo

I am studying this client example from man7, in the first for loop for (rp = result; rp != NULL; rp = rp->ai_next) { sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); …
0
votes
1 answer

Should I think about linked list returned by getaddrinfo when I get addrinfo for my "home" server

I created a server using sockets that runs on my home network. socket address=192.168.88.123:7777 When I call getaddrinfo() function I put "192.168.88.123" as first parameter and "7777" as second and also some hints (AF_INET, SOCK_STREAM) and…
0
votes
0 answers

Embedded Segger embOS: getaddrinfo translation in gethostbyname

I am working on a project with an embedded TCP/IP-socket implementation. My problem is my overlaying SDK needs needs the function: getaddrinfo( PCSTR pNodeName, PCSTR pServiceName, const ADDRINFOA *pHints, PADDRINFOA …
0
votes
1 answer

Forking a multi-threaded process

I have an application that has two threads. One thread forks on an event and other thread is doing something which results into a lot of getaddrinfo() calls. I am facing an issue where in some cases forked child hangs on a mutex inside getaddrinfo()…
wabbit
  • 133
  • 1
  • 8
0
votes
1 answer

C null pointer check fails in ai_next linked list

Background: I'm following Beej's Guide to Network Programming on how to listen for and accept incoming connections using C sockets. Problem: The problem I'm having is I'm getting segmentation faults when traversing the linked list of addresses to…
Dylan Landry
  • 1,150
  • 11
  • 27
0
votes
0 answers

A macOS getaddrinfo() bug related to the use of AI_V4MAPPED?

I noticed a strange behaviour of the simple program showip.c (https://beej.us/guide/bgnet/examples/showip.c) when run on Linux (3.13.0) and macOS (10.15.7) The same program gives two different results (obviously I am not referring to the different…
diciotto
  • 69
  • 3
0
votes
0 answers

Why am I getting 'getaddrinfo failed' while connecting to remote server?

I am using the socket module in python to connect to a remote server at https://vedant-chatroom.glitch.me/chat.html?user=python. This is my code (test.py): import socket web_socket = socket.socket(socket.AF_INET,…
Vedant Jumle
  • 133
  • 2
  • 11
0
votes
1 answer

getaddrinfo, bind, localhost and INADDR_ANY

I'm learning socket programing and pretty new to this... My question is, I want to write a UDP server that is able to receive packets from both remote server and local host via a OS-assigned socket. I know I should somehow pass INADDR_ANY to bind()…
Crystina
  • 990
  • 1
  • 5
  • 16
0
votes
0 answers

How to change gethostbyname into getaddrinfo?

I am writing a function to connect client-server. And i cannot use gethostbyname. This function is simple to use. Now i don't know how to use getaddrinfo. How can i change gethostbyname into getaddrinfo. Thank you so much! void ConnectSocket() { …
0
votes
1 answer

Why does FETCH command error: BAD [b'Could not parse command'] fail occur?

import imaplib import email import socket socket.getaddrinfo('127.0.0.1', 8080) def read_email_from_gmail(): try: mail = imaplib.IMAP4_SSL('imap.gmail.com', 993) mail.login('your email', 'your password') …
0
votes
1 answer

getaddrinfo() returns 0 (success) but sets errno to EINVAL (22)

I'm having problems with the following piece of code: #include #include #include #include #include #include [...] struct protoent *tcp; struct addrinfo hint = {0}; …
0
votes
0 answers

c++ convert domain name to IP address with getaddrinfo

Hello i created a function using the depreciated gethostbyname to convert a domain name to an IP address and it works great, however this causes lots of warnings and my work wants me to use the newer getaddrinfo. While i am able to get getaddrinfo…
Edwin Martin
  • 319
  • 3
  • 15
0
votes
1 answer

Duplicate calling inet_ntop() function

Please help me! I need to translate (or convert) domain names (for example google.com) to IP address. For that purpose I have found code on interet, which work perfectly, but I don't understand, why there is called function inet_ntop() two times.…
Petr Marek
  • 59
  • 1
  • 7
0
votes
1 answer

inet_ntop cause Segmentation fault

I have problem. I have code where I need to convert domain name to IP. For that purpose I am using function getaddrinfo(). But it seems, that when I call another function (AFTER GETADDRINFO()), that my program falls (getaddrinfo return error and…
Petr Marek
  • 59
  • 1
  • 7
0
votes
1 answer

Do I need to iterate over getaddrinfo()?

There are similar questions for that but I can't find the answer for which I'm looking. #include int getaddrinfo (const char *hostname, const char *service, const struct addrinfo *hints, …