I'm trying to implement automatic port forwarding using apples bonjour services.
The specific function im using is: http://developer.apple.com/library/...ple_ref/c/func/DNSServiceNATPortMappingCreate
At the moment, all Im trying to do is call the function so that I can get my external ip address.
I call the function appropriately, it returns success, but my callback is never called. Without the callback, I cant get my external ip.
The calling code is:
	
	
	
		
Where externalIPServiceRef is just an uninitialized DNSServiceRef struct.
My callback looks like:
	
	
	
		
However, the callback is never called. Does anyone have any experience with using nat-pmp?
	
		
			
		
		
	
				
			The specific function im using is: http://developer.apple.com/library/...ple_ref/c/func/DNSServiceNATPortMappingCreate
At the moment, all Im trying to do is call the function so that I can get my external ip address.
I call the function appropriately, it returns success, but my callback is never called. Without the callback, I cant get my external ip.
The calling code is:
		Code:
	
	DNSServiceErrorType rError = DNSServiceNATPortMappingCreate(&externalIPServiceRef, 0, 0, 0, 0, 0, 0, portmap_cb, NULL);
    
    if(rError != kDNSServiceErr_NoError)
    {
        switch(rError)
        {
            case kDNSServiceErr_NATPortMappingDisabled:
                NSLog(@"Portmapping on your router is disabled");
                break;
            case kDNSServiceErr_NATPortMappingUnsupported:
                NSLog(@"Portmapping is unsupported on your router");
                break;
            case kDNSServiceErr_NoRouter:
                NSLog(@"You don't have a router");
                break;
            default:
                NSLog(@"Error Code: %d", rError);
        }
    }
	Where externalIPServiceRef is just an uninitialized DNSServiceRef struct.
My callback looks like:
		Code:
	
	void DC_PortmapReply(DNSServiceRef sdRef, 
                         DNSServiceFlags flags, 
                         uint32_t interfaceIndex, 
                         DNSServiceErrorType errorCode, 
                         uint32_t externalAddress, /* four byte IPv4 address in network byte order */
                         DNSServiceProtocol protocol, 
                         uint16_t internalPort, 
                         uint16_t externalPort, /* may be different than the requested port     */
                         uint32_t ttl, /* may be different than the requested ttl      */
                         void *context)
{    
    if(errorCode != kDNSServiceErr_NoError)
    {
        NSLog(@"Error in callback");
        return;
    }
    
    NSLog(@"In Portmap Reply");
    
    switch(protocol)
    {
        case 0:
        {
            char addrStr[INET_ADDRSTRLEN];
            inet_ntop(AF_INET, &externalAddress, addrStr, INET_ADDRSTRLEN);
            NSString *networkString = [[NSString alloc] initWithUTF8String:addrStr];
            NSNumber *hostNumber = [[NSNumber alloc] initWithUnsignedInteger:externalAddress];
            NSDictionary *d = [[NSDictionary alloc] initWithObjectsAndKeys:networkString, @"networkString", hostNumber, @"hostNumber", nil];
            [[NSNotificationCenter defaultCenter] postNotificationName:DCNetworkAddressNotification object:networkString userInfo:d];
            [networkString release];
            [hostNumber release];
            [d release];
        }
            break;
        case kDNSServiceProtocol_TCP:
            break;
    }
}
	However, the callback is never called. Does anyone have any experience with using nat-pmp?