struct hostent *gethostbyname(const char *name)
请注意,hostent.h_addr_list 是一个具有可变长度的字段。
gethostbyname
函数如何实现返回一个指向结构体的指针而不要求调用者释放资源?
R. Stevens 着名的 Unix Network Programming Vol 1 中使用的所有示例都不包含释放那些返回指针的代码,我认为这些不是无知。 MSDN 中的一个示例也做同样的事情 example of usage
最佳答案
您链接到的 man
页面包含答案:
When non-NULL, the return value may point at static data, see the notes below.
稍后:
The functions gethostbyname() and gethostbyaddr() may return pointers to static data, which may be overwritten by later calls.
关于c - `gethostbyname`如何在不要求调用者释放资源的情况下返回 `struct hostent *`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11544411/