getaddrinfo

gai_cancel() takes a really long time to succeed

血红的双手。 提交于 2021-02-10 13:46:12
问题 I am trying to look up domain asynchronously in c++. The reason is I want to be able to effectively add a time out period in case the system can't look up the domain. I came across the getaddrinfo_a() command so I decided to give it a try. However cancelling any dns look up that will not succeed (such as when there is no internet connection) will never take less than 20 seconds on my machine. Here is a simple example of this: #include <iostream> #include <netdb.h> #include <string.h> #include

名字与地址转换(摘抄自网络)

▼魔方 西西 提交于 2020-01-23 18:23:23
一、gethostbyname()函数说明——用域名或主机名获取IP地址 包含头文件 #include <netdb.h> #include <sys/socket.h> 函数原型 struct hostent *gethostbyname(const char *name); 这个函数的传入值是域名或者主机名,例如"www.google.cn"等等。传出值,是一个hostent的结构。如果函数调用失败,将返回NULL。 返回hostent结构体类型指针 hostent->h_name 表示的是主机的规范名。例如www.google.com的规范名其实是www.l.google.com。 hostent->h_aliases 表示的是主机的别名.www.google.com就是google他自己的别名。有的时候,有的主机可能有好几个别名,这些,其实都是为了易于用户记忆而为自己的网站多取的名字。 hostent->h_addrtype 表示的是主机ip地址的类型,到底是ipv4(AF_INET),还是pv6(AF_INET6) hostent->h_length 表示的是主机ip地址的长度 hostent->h_addr_lisst 表示的是主机的ip地址,注意,这个是以网络字节序存储的。千万不要直接用printf带%s参数来打这个东西,会有问题的哇。所以到真正需要打印出这个IP的话

How to use 'getaddrinfo' to choose default free port for all interfaces?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-13 17:58:32
问题 I'm trying to make a server to listen on both IPv4 and IPv6 in dual stack mode. I want the same port number for both IPv4 and IPv6 servers, and I want it to be on a random selection of port (using port "0") when I bind, each server get different port, and I want it to be the same. so I thought it should be done by the getaddrinfo function. But when I give it the "0" port it stays "0" in the addrinfo results, what cause each bind to give me different port number. My question : Is there a way

MongoDB on Vagrant via Port Forwarding issue

≯℡__Kan透↙ 提交于 2020-01-11 03:57:05
问题 I've recently installed mongodb on my CentOS 6 VM running on Vagrant. I added port forwarding to Vagrantfile to forward the mongo port config.vm.forward_port 27017, 127017 I configured mongod to start automatically when the server starts and have confirmed that the service starts as intended. however when i run mongo localhost:127017 from my host machine (not vagrant) i get the following error MongoDB shell version: 1.8.2 connecting to: localhost:127017/test Fri Jan 20 13:58:28 getaddrinfo(

Implicit declaration of function 'getaddrinfo' on MinGW

时光怂恿深爱的人放手 提交于 2020-01-11 03:10:49
问题 I have a C program that uses getaddrinfo() . It works as expected on Linux and Mac OS X. I'm in the middle of porting it to Windows. When I compile it (with MinGW gcc) I get the following warnings: ext/socket/socket.c: In function 'sl_tcp_socket_init': ext/socket/socket.c:98:5: warning implicit declaration of function 'getaddrinfo' [-Wimplicit-function-declaration] ext/socket/socket.c:104:9: warning implicit declaration of function 'freeaddrinfo' [-Wimplicit-function-declaration] Then the

usage of Unix getaddrinfo C function to start set the server

拟墨画扇 提交于 2020-01-06 12:37:47
问题 I am building a client-server application in C with the source code taken from the book Advanced Programming in Unix Environment. In the server it is doing the following: struct addrinfo hint; memset(&hint, 0, sizeof(hint)); hint.ai_flags = AI_CANONNAME; hint.ai_socktype = SOCK_STREAM; hint.ai_addr = NULL; hint.ai_next = NULL; .... if ((n = sysconf(_SC_HOST_NAME_MAX))<0) { n = HOST_NAME_MAX; } if((host = malloc(n)) == NULL) { printf("malloc error\n"); exit(1); } if (gethostname(host, n)<0) {

getaddrinfo sorting IPv4 before IPv6 for localhost?

一个人想着一个人 提交于 2020-01-04 05:22:50
问题 I wrote a very simple test program for getaddrinfo: #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <stdio.h> #include <string.h> int main() { struct addrinfo hints; struct addrinfo *res, *rp; char hoststr[64], servstr[8]; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; getaddrinfo(NULL, "9998", &hints, &res); for (rp = res; rp != NULL; rp = rp->ai_next) { getnameinfo(rp->ai_addr, rp->ai

How to fix getaddrinfo-failure for python on windows

大城市里の小女人 提交于 2019-12-29 09:03:01
问题 if a start python in a command prompt terminal and try to open some url, I get the following result, despite the name being resolveable through DNS: C:\Windows\system32>nslookup www.google.de Nicht-autorisierende Antwort: Name: www-cctld.l.google.com Address: 173.194.69.94 Aliases: www.google.de C:\Windows\system32>C:\Python27\python.exe Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>

How to fix getaddrinfo-failure for python on windows

我怕爱的太早我们不能终老 提交于 2019-12-29 09:02:07
问题 if a start python in a command prompt terminal and try to open some url, I get the following result, despite the name being resolveable through DNS: C:\Windows\system32>nslookup www.google.de Nicht-autorisierende Antwort: Name: www-cctld.l.google.com Address: 173.194.69.94 Aliases: www.google.de C:\Windows\system32>C:\Python27\python.exe Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>

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

谁说胖子不能爱 提交于 2019-12-25 06:36:40
问题 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 = getaddrinfo("www.domain.com", PORT, &hints, &servinfo)) != 0) { ...but no matter what I try, I get name or service unknown . Calling domain.com/signalr:8080 will not work. I tried leaving PORT null This is running on Raspbian (Debian) if that matters. Any