我试图了解getaddrinfo函数返回的内容:
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
int main (int argc, char *argv[])
{
struct addrinfo *res = 0 ;
getaddrinfo("localhost", NULL ,NULL,&res);
printf("ai_flags -> %i\n", res->ai_flags) ;
printf("ai_family -> %i\n", res->ai_family) ;
printf("ai_socktype -> %i\n", res->ai_socktype) ;
printf("ai_protocol -> %i\n", res->ai_protocol) ;
printf("ai_addrlen -> %i\n", res->ai_addrlen) ;
struct sockaddr_in* saddr = (struct sockaddr_in*)res->ai_addr;
printf("ai_addr hostname -> %s\n", inet_ntoa(saddr->sin_addr));
freeaddrinfo(res);
return 0 ;
}
Run Code Online (Sandbox Code Playgroud)
结果:
ai_flags -> 40
ai_family -> 2
ai_socktype -> 1
ai_protocol -> …Run Code Online (Sandbox Code Playgroud) 你知道在哪里可以获得Common Lisp中谓词的来源吗?(如果您愿意,谓词的内容.)例如,setq的源代码,字符串=等.
谢谢 !
我正在寻找一个以 IPv6 地址作为参数并返回域名的函数。
明确地说,2a00:1450:8006::68 返回 ipv6.google.com。
(目的是将该域名提供给 getaddrinfo 函数。)
谢谢 :-)
edit1:我已经尝试过getaddrinfo("2a00:1450:8006::68", "http", NULL, &result);,它返回“不支持主机名的地址系列”并getaddrinfo("ipv6.google.com", "http", NULL, &result);返回错误“没有地址与热名关联”。
EDIT2:我同意你的观点,我的 IPV6 系统有问题,我尝试过http://test-ipv6.com/,看来我没有 IPV6 地址,但ifconfig它返回:
adr inet6: fe80::15b:fcff:fe65:d516/64 Scope:Lien
Run Code Online (Sandbox Code Playgroud) 我在哪里可以找到关于unix命令(ls,sleep,cd等)的源文件(用C语言编写).
我已经下载了内核linux-2.6.39-rc3,但没有关于linux命令的来源.
谢谢你的帮助 :-)
c ×2
getaddrinfo ×2
ipv6 ×2
common-lisp ×1
ipv4 ×1
linux ×1
lisp ×1
networking ×1
predicate ×1
ubuntu ×1