gpt4 book ai didi

c - socket编程中getaddrinfo函数的困惑

转载 作者:行者123 更新时间:2023-11-30 15:24:58 25 4
gpt4 key购买 nike

getaddrinfo("www.example.net","1234", &hints, &server_info)

hints参数有什么用?

最佳答案

getaddrinfo 记录在 man page 中,其中关于提示参数有这样的说法:

The hints argument points to an addrinfo structure that specifies criteria for selecting the socket address structures returned in the list pointed to by res. If hints is not NULL it points to an addrinfo structure whose ai_family, ai_socktype, and ai_protocol specify criteria that limit the set of socket addresses returned by getaddrinfo()

所以它是一个根据给定标准限制结果的参数。使用 addrinfo 结构给出标准:

struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
socklen_t ai_addrlen;
struct sockaddr *ai_addr;
char *ai_canonname;
struct addrinfo *ai_next;
};

您可以在同一手册页上了解该结构体的每个参数。

关于c - socket编程中getaddrinfo函数的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28141779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com