在 iOS 项目中使用绑定功能时,它给了我错误“无法分配请求的地址”(#49)
这是代码:
struct sockaddr_in sin;
sin.sin_family = AF_INET;
sin.sin_port = htons(local_port);
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
socklen_t sinlen = sizeof(sin);
char sockopt = 1;
setsockopt (listensock, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(sockopt));
//setsockopt (listensock, SOL_SOCKET, SO_USELOOPBACK, &sockopt, sizeof(sockopt));
if (::bind(listensock, (struct sockaddr *)&sin, sinlen) == -1)
{
BOOST_LOG(lg) << bf("bind error: %s (%d)", strerror(errno), errno) << std::endl;
throw std::runtime_error ("Error establishing tunnel: -3");
}
请帮忙。