【问题标题】:DNSServiceNATPortMappingCreate always returning error code -65540DNSServiceNATPortMappingCreate 总是返回错误代码 -65540
【发布时间】:2013-07-15 13:17:34
【问题描述】:

我正在做一个 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") ;
}

【问题讨论】:

    标签: ios upnp


    【解决方案1】:

    根据DNSServiceDiscovery 的文档,错误代码-65540 表示kDNSServiceErr_BadParam

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      • 2019-06-14
      • 2019-09-26
      • 2012-02-26
      • 2014-05-29
      相关资源
      最近更新 更多