我有这个代码:
bool CBSocketConnect(uint64_t socketID,uint8_t * IP,bool IPv6,uint16_t port){
// Create sockaddr_in6 information for a IPv6 address
int res;
if (IPv6) {
struct sockaddr_in6 address;
memset(&address, 0, sizeof(address)); // Clear structure.
address.sin6_family = AF_INET6;
memcpy(&address.sin6_addr, IP, 16); // Move IP address into place.
address.sin6_port = htons(port); // Port number to network order
res = connect((evutil_socket_t)socketID, (struct sockaddr *)&address, sizeof(address));
}else{
struct sockaddr_in address;
memset(&address, 0, sizeof(address)); // Clear structure.
address.sin_family = AF_INET;
memcpy(&address.sin_addr, IP + 12, 4); // Move IP address into place. Last 4 bytes for IPv4.
address.sin_port = htons(port); // Port number to network order
res = connect((evutil_socket_t)socketID, (struct sockaddr *)&address, sizeof(address));
}
if (NOT res || errno == EINPROGRESS)
return true;
return false;
}
IPv6 设置为 false,IP 设置为 ::ffff:127.0.0.1(IPv4 环回地址),端口号设置为 45562,res 设置为 -1,errno 设置为 ENOENT (2)。为什么会这样?
我所在的平台是 OSX Mountain Lion。我正在使用带有 libevent 版本“2.0.19-stable”的套接字。
谢谢你。