目前我做以下任何可用的端口上侦听所有接口:如何动态地将套接字绑定到一个网络接口?
// 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);
}
我想动态绑定到只有一个接口,该系统的非回送接口。
我该怎么做呢?
网站关闭,缓存副本在这里:http://web.archive.org/web/20090812134009/http://tuxology.net/tag/interface – 2014-09-06 14:30:41