在接受函数的地址长度大小上述< SYS / socket.h中> [英] The address size length of the accept function in <sys/socket.h>

查看:137
本文介绍了在接受函数的地址长度大小上述< SYS / socket.h中>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SYS / socket.h中,它定义函数:

in "sys/socket.h" it defines the function:

int accept (int socket, struct sockaddr *address, socklen_t *address_len);

我的问题有 socklen_t的做* address_len 这基础上,手册指向 socklen_t的该输入指定提供的的sockaddr 结构的长度,并在输出指定存储地址的长度。

My question has to do with socklen_t *address_len which based on the manual points to a socklen_t which on input specifies the length of the supplied sockaddr structure, and on output specifies the length of the stored address.

在什么情况下会在 address_len 输入尺寸从输出不同?

Under what conditions will the address_len size input be different from output?

我需要这个,所以我可以效仿我已为 SOCKADDR_IN 结构中创建一个包装一个测试用例。

I need this so I can emulate a test case on a wrapper I have created for the sockaddr_in structure.

非常感谢!

推荐答案

它不可能是多个(输入长度​​是一个界限到prevent溢出),但它可能是较少的某些插座类型,例如UNIX域套接字的地址基本上是路径名。对于IP(V4或V6)插槽,它永远是相应的 SOCKADDR_IN 体sockaddr_in6 结构的公称尺寸。

It can never be more (the input length is a bounds to prevent overflows), but it could be less for certain socket types, for instance unix domain sockets whose addresses are essentially pathnames. For IP (v4 or v6) sockets, it will always be the nominal size of the corresponding sockaddr_in or sockaddr_in6 structure.

另外请注意,有可能使用这样的一些接口不知道涉及何种类型的地址/协议族的。例如,你可能有一个功能是采用未知类型的插座和电话接受它与 sockaddr_storage 结构中的库code的一部分。它可能会发现一个IPv4地址和IPv6地址,或别的东西完全取决于调用者做了什么。

Also note that it's possible to use some interfaces like this without knowing what type of address/protocol family is involved. For instance you might have a function as part of your library code that takes a socket of unknown type and calls accept on it with a sockaddr_storage structure. It might find an IPv4 address, and IPv6 address, or something else entirely, depending on what the caller did.

这使用率是相当不典型接受,但它是 getpeername 很多更可能它使用同样的界面风格。事实上,这是这样的,从的inetd 运行,这要知道远程地址必须经营的所有守护进程。

This usage is fairly non-typical for accept, but it's a lot more likely for getpeername which uses the same interface style. In fact this is the way all daemons that run from inetd and which want to know the remote address must operate.

这篇关于在接受函数的地址长度大小上述< SYS / socket.h中>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆