read() 形成一个未绑定的套接字?

read() form an unbinded socket?

如果从未绑定的套接字读取数据会怎样?更具体地说是关于 UDP 套接字?

如果套接字已用于发送信息,套接字将绑定到一个端口(和地址),因此我们将监听该端口(地址,端口),但如果套接字完全未绑定,那么什么是预期的行为? 在这种情况下,套接字将如何响应 select/epoll 进行读取操作?

有多种规定,也有不规定的。

来自 man 7 udp (Linux):

In order to receive packets, the socket can be bound to a local address first by using bind(2). Otherwise the socket layer will automatically assign a free local port out of the range defined by /proc/sys/net/ipv4/ip_local_port_range and bind the socket to INADDR_ANY.

来自 MSDN recv() function:

The local address of the socket must be known. For server applications, use an explicit bind function or an implicit accept or WSAAccept function. Explicit binding is discouraged for client applications. For client applications, the socket can become bound implicitly to a local address using connect, WSAConnect, sendto, WSASendTo, or WSAJoinLeaf.

WSAEINVAL: The socket has not been bound with bind, ...

我无法回答 BSD、Solaris、HP-UX、AIX...