libssh2 lib与ipv6无法正常工作

时间:2014-11-21 06:44:32

标签: ios objective-c ssh ipv6 libssh2

在我的iOS应用程序中,我正在使用libssh2库。我试图用ipv6地址ssh,但socket不创建并获得nil socket。它与ipv4地址一起工作正常。

static CFSocketRef _CreateSocketConnectedToHost(NSString* name, UInt16 port, CFOptionFlags callBackTypes, CFSocketCallBack callback, const CFSocketContext* context, CFTimeInterval timeOut)

我已经搜索了这个但没有找到任何关于libssh2的ipv6支持的结果。

请帮帮我,libssh2不支持ipv6吗?我们可以使用libssh2吗?

1 个答案:

答案 0 :(得分:1)

只需要在socket中使用ipv6属性而不是ipv4,你就可以使用ipv6地址创建套接字。

struct sockaddr_in6 ipAddress6;
CFSocketSignature           signature;

ipAddress6.sin6_port = htons(port);
signature.protocolFamily = AF_INET6;
signature.protocol = IPPROTO_IP;//IPPROTO_IPV6;
signature.address = (CFDataRef)[NSData dataWithBytes:&ipAddress6 length:ipAddress6.sin6_len];