sendto的最大缓冲区长度? [英] Maximum buffer length for sendto?

查看:409
本文介绍了sendto的最大缓冲区长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取作为UDP端口打开的套接字可以传递给sendto(..)调用的最大字节数?

How do you get the maximum number of bytes that can be passed to a sendto(..) call for a socket opened as a UDP port?

推荐答案

使用getsockopt(). 此网站很好地细分了用法和可检索的选项.

Use getsockopt(). This site has a good breakdown of the usage and options you can retrieve.

在Windows中,您可以执行以下操作:

In Windows, you can do:


int optlen = sizeof(int);
int optval;
getsockopt(socket, SOL_SOCKET, SO_MAX_MSG_SIZE, (int *)&optval, &optlen);

对于Linux,根据UDP手册页,内核将使用MTU发现(它将检查此处和目标之间的最大UDP数据包大小,然后选择该值),或者如果MTU发现已关闭,则为将为接口MTU设置最大大小,并对更大的片段进行分段.如果通过以太网发送,则典型的MTU为1500字节.

For Linux, according to the UDP man page, the kernel will use MTU discovery (it will check what the maximum UDP packet size is between here and the destination, and pick that), or if MTU discovery is off, it'll set the maximum size to the interface MTU and fragment anything larger. If you're sending over Ethernet, the typical MTU is 1500 bytes.

这篇关于sendto的最大缓冲区长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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