setsockopt
ipv6 也是可以的 实测可以
SO_BINDTODEVICE
Bind this socket to a particular device like “eth0”, as specified in the passed interface name. If the name is an
empty string or the option length is zero, the socket device binding is removed. The passed option is a variable-
length null-terminated interface name string with the maximum size of IFNAMSIZ. If a socket is bound to an inter‐
face, only packets received from that particular interface are processed by the socket. Note that this works only
for some socket types, particularly AF_INET sockets. It is not supported for packet sockets (use normal bind(2)
there).
connect()
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
这个东西是 UDP的话,addr 表示默认的发送地址, 但只接收这个地址的报文
如果addr 为空也就是 ::
那么 将会绑定到 ::1 这个地址
udp6 0 0 2000:bb::56:1121 ::1:1111
DESCRIPTION
The connect() system call connects the socket referred to by the file descriptor sockfd to the address specified by addr.
The addrlen argument specifies the size of addr. The format of the address in addr is determined by the address space of
the socket sockfd; see socket(2) <