在我的 iOS 应用程序中,我使用的是 libssh2 库。我正在尝试使用 ipv6 地址进行 ssh,但是套接字没有创建和获取 nil 套接字。它与 ipv4 地址一起工作正常。
static CFSocketRef _CreateSocketConnectedToHost(NSString* name, UInt16 port, CFOptionFlags callBackTypes, CFSocketCallBack callback, const CFSocketContext* context, CFTimeInterval timeOut)
我已经搜索过这个但没有找到关于 libssh2 的 ipv6 支持的任何结果。
请帮帮我,libssh2 不支持 ipv6 吗?我们可以使用 libssh2 让它工作吗?
最佳答案
只需要在套接字中使用 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];
关于ios - 带有 ipv6 的 libssh2 lib 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27055610/