`recv` 是否适用于字节或八位字节,或者它们在 POSIX 文档的上下文中是否相同?

发布于 2024-12-15 07:42:40 字数 775 浏览 5 评论 0原文

阅读套接字 send 的 POSIX 参考 http:// pubs.opengroup.org/onlinepubs/009695399/functions/send.html 我想知道,“字节”到底是什么意思 - 它的传统/历史含义,其隐含/流行的含义,还是完全不同的东西?我正在开发一个二进制 TCP/IP 支持的网络协议客户端-服务器程序,我想正确声明我用来传递给 recv 的缓冲区,并能够正确解包其数据。

是的,我知道这几乎是假设的问题,并且可能有百万分之一的机会遇到真正的问题,但我想安全总比后悔好。

那么,POSIX 人员的意思是真的八位字节,还是真的暗示对于一个字节为 7 位的平台,send 将处理粒度为 7*N 的数组?或者它可能只是简单地逐位传输所有数据(大小粒度 (7 * n_bytes) 位)?我的意思是,因为它需要一个 void * 缓冲区...

我的 recv 缓冲区的哪个声明在架构和编译器中最稳定?

我使用带有以下标志的 GCC(C99、POSIX):

cc -g -Wall -Wextra -std=c99 -pedantic -fexec-charset=ISO-8859-1 -DDEBUG -D_POSIX_C_SOURCE

Reading the POSIX reference for socket send at http://pubs.opengroup.org/onlinepubs/009695399/functions/send.html I wonder, what exactly do they mean by "byte" - its traditional/historical meaning, its implied/popular meaning, or something else entirely? I am developing a binary TCP/IP-supported network protocol client-server program, and I would like to properly declare my buffer that I use to pass to recv, and being able to properly unpack its data.

Yes, I know it's almost hypothetical issue and probably a chance in a million to hit real problems, but better safe than sorry I guess.

So, do the POSIX guys mean octets really, or are they really implying that for platforms where a byte is say, 7 bits, send will deal with arrays with granularity of 7*N? Or maybe it will simply transfer all data bit by bit (size granularity (7 * n_bytes) bits)? I mean, since it expects a void * buffer...

Which declaration for my recv buffer would be most stable across architectures and compilers?

I am using GCC with the following flags (C99, POSIX):

cc -g -Wall -Wextra -std=c99 -pedantic -fexec-charset=ISO-8859-1 -DDEBUG -D_POSIX_C_SOURCE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三寸金莲 2024-12-22 07:42:40

POSIX 将字节定义为八位字节的大小,并将八位字节定义为 8 个连续位。这些定义位于 POSIX 标准的第 3 章中,最新的 POSIX 标准 (2008) 位于 http:// pubs.opengroup.org/onlinepubs/9699919799/

POSIX defines a byte as being the size of an octet, and defines an octet as 8 contiguous bits. This definitions are in chapter 3 of the POSIX standard, the latest POSIX standard (2008) is at http://pubs.opengroup.org/onlinepubs/9699919799/

甜是你 2024-12-22 07:42:40

我相信 byte 是 C 的 char 类型,是系统支持的保存字符的最小可能的小整数。 (也许一些奇怪的编译器+目标系统确实有非8位char)。

octet表示一个8位的字节。

如果您考虑 TCP/IP,我相信 (IIRC) 它以 8 位字节定义了各种协议。 TCP 由多个 8 位字节的传输组成。

但实际上,你不应该那么在意。也许用位来记录你的协议会有所帮助。很多事情都会使您的协议变得过时(只需考虑 IPv6)。如果您的协议确实有价值、有用且有据可查,那么就会有人让它生效并进行调整。

I believe that byte is the char type of C, the smallest possible small integer holding a characater, as supported by the system. (perhaps some strange compiler + target system do have non 8 bits char).

octet means a byte of 8 bits.

If you think in term of TCP/IP, I believe (IIRC) that it defines the various protocols in terms of 8 bit bytes. TCP is made of transmission of multiple of 8 bit bytes.

But in reality, you should not care that much. Perhaps documenting your prococol in terms of bits could help. A lot of things can make your protocol obsolete (just think of IPv6). If you protocol is really valuable and useful, and well documented, someone will make it live and adapt it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文