目前我做以下任何可用的端口上偵聽所有接口:如何動態地將套接字綁定到一個網絡接口?
// 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