gpt4 book ai didi

c - udp套接字到底接收什么?

转载 作者:行者123 更新时间:2023-11-30 14:34:02 25 4
gpt4 key购买 nike

  #include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/udp.h>

udp_socket = socket(AF_INET, SOCK_DGRAM, 0);

当我使用 UDP 套接字时,我是只接收有效负载还是也接收 UDP header ?

最佳答案

您可以或不能访问的内容取决于套接字的创建方式。

以下是与您的问题相关的文档中的评论:

The recv() function shall receive a message from a connection-mode or connectionless-mode socket. It is normally used with connected sockets because it does not permit the application to retrieve the source address of received data.

(强调我的)

read more here ...

编辑:如果您想要访问 header 信息,请阅读此链接和以下链接。

...You cannot create a raw socket with IPPROTO_UDP and manipulate the UDP header; likewise with TCP. To manipulate the IP header as well as either the TCP or UDP header (or any other protocol encapsulated in IP), you must use the IP_HDRINCL socket option with a raw socket. ...

阅读more on the topic ...

关于c - udp套接字到底接收什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59071571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com