c - C中sendto()和recvfrom()之间的形式参数区别
问题描述
我正在使用recvfrom()
andsendto()
来接收和发送 UDP 数据包。
我注意到recvfrom()
最后一个参数需要一个指向存储服务器地址长度的变量的指针,而sendto()
需要存储客户端地址长度的变量。
为什么会有这种差异?
解决方案
我注意到 recvfrom() 作为最后一个参数需要一个指向存储服务器地址长度的变量的指针,而 sendto() 需要存储客户端地址长度的变量。
你实际上回答了你自己的问题
recvfrom() as last parameter requires a pointer to
the variable storing the length of server address.
while sendto() requires the variable that stores
the length of the client address.
recvfrom()
需要指针,因为它将值存储到该指针指向的位置。由于c
没有所谓的引用调用,因此您需要传递指针来模拟引用调用行为。
推荐阅读
- php - 此帐户未设置 PayPal Express Checkout
- java - 如何引用 src/main/resources 文件夹中的 .wsdl 文件?
- protocol-buffers - 反编译protobufs-net的bin文件
- c - fork 后子进程永远不会执行
- visual-studio-2019 - VS2019 .editorconfig 不受尊重
- php - 查询必须匹配的数组
- android - android listView裁剪和无法滚动
- python - 何塞加密返回二进制字符串,但用解码后的字符串解密会在 python 中出错
- python-3.x - 没有名为 airfow.gcp 的模块 - 如何运行使用 python3/beam 2.15 的数据流作业?
- android - 几天后删除房间数据库记录