gpt4 book ai didi

ios - DNSServiceNATPortMappingCreate 总是返回错误代码 -65540

转载 作者:行者123 更新时间:2023-11-29 13:09:52 26 4
gpt4 key购买 nike

我正在做一个 ios 应用程序,它启动一个服务器并监听传入的连接,运行该应用程序的设备可能在路由器后面,所以我需要转发一个端口。我正在尝试使用 DNSServiceNATPortMappingCreate 转发端口,但它总是返回错误代码 -65540

DNSServiceRef *sdRef = NULL ;
void ( *DNSServiceNATPortMappingReply) (DNSServiceRef sdRef,
DNSServiceFlags flags,
uint32_t interfaceIndex,
DNSServiceErrorType errorCode,
uint32_t externalAddress,
DNSServiceProtocol protocol,
uint16_t internalPort,
uint16_t externalPort,
uint32_t ttl,
void *context );

DNSServiceNATPortMappingReply = &DNSServiceNATPortMappingCreate_callback ;

DNSServiceErrorType error = DNSServiceNATPortMappingCreate(sdRef,
0,
0,
kDNSServiceProtocol_TCP,
htons(2000),
htons(5000),
0,
DNSServiceNATPortMappingReply,
NULL
) ;

这是回调

void DNSServiceNATPortMappingCreate_callback(
DNSServiceRef sdRef,
DNSServiceFlags flags,
uint32_t interfaceIndex,
DNSServiceErrorType errorCode,
uint32_t externalAddress,
DNSServiceProtocol protocol,
uint16_t internalPort,
uint16_t externalPort,
uint32_t ttl,
void *context )
{
printf("in callback\n") ;
}

最佳答案

基于 DNSServiceDiscovery 的文档,错误代码 -65540 表示 kDNSServiceErr_BadParam

DNSServiceNATPortMappingCreate 的文档建议您必须为作为第一个参数传递的 DNSServiceRef 分配存储空间。即你需要改变

DNSServiceRef *sdRef = NULL ;
DNSServiceErrorType error = DNSServiceNATPortMappingCreate(sdRef, ...

DNSServiceRef sdRef;
DNSServiceErrorType error = DNSServiceNATPortMappingCreate(&sdRef, ...

关于ios - DNSServiceNATPortMappingCreate 总是返回错误代码 -65540,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17655183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com