目前我执行以下操作来监听所有接口(interface)上的任何可用端口:
// hints struct for the getaddrinfo call
struct addrinfo hints, *res;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
// Fill in addrinfo with getaddrinfo
if (getaddrinfo(NULL, "0", &hints, &res) != 0) {
cerr << "Couldn't getaddrinfo." << endl;
exit(-1);
}
我只想动态绑定(bind)一个接口(interface),系统的非环回接口(interface)。
我该怎么做?
最佳答案
看看 SO_BINDTODEVICE。 Tuxology 有一个 good description这个
关于c++ - 如何将套接字动态绑定(bind)到一个网络接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1119401/