udp套接字到底接收什么?

What exactly does a udp socket receive?

  #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 信息是您想要做的,请阅读此内容和以下内容 link。

...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...