static void EmulatedDomainEnumerationCallBack( DNSServiceDomainEnumerationReplyResultType inResult, const char * inDomain, DNSServiceDiscoveryReplyFlags inFlags, void * inContext ) { DNS_UNUSED( inFlags ); DNS_UNUSED( inContext ); if( inResult == DNSServiceDomainEnumerationReplyAddDomain ) { fprintf( stdout, "\"%s\" domain added emulated\n", inDomain ); } else if( inResult == DNSServiceDomainEnumerationReplyAddDomainDefault ) { fprintf( stdout, "\"%s\" default domain added emulated\n", inDomain ); } else if( inResult == DNSServiceDomainEnumerationReplyRemoveDomain ) { fprintf( stdout, "\"%s\" domain removed emulated\n", inDomain ); } else { fprintf( stdout, "### unknown emulated domain enumeration callback result (%d)\n", inResult ); } }
static void RegistrationCallBack( void * inContext, DNSRegistrationRef inRef, DNSStatus inStatusCode, const DNSRegistrationEvent * inEvent ) { DNS_UNUSED( inContext ); DNS_UNUSED( inRef ); DNS_UNUSED( inStatusCode ); switch( inEvent->type ) { case kDNSRegistrationEventTypeRelease: break; case kDNSRegistrationEventTypeRegistered: fprintf( stdout, "name registered and active\n" ); break; case kDNSRegistrationEventTypeNameCollision: fprintf( stdout, "name in use, please choose another name\n" ); break; default: break; } }
static void EmulatedBrowserCallBack( DNSServiceBrowserReplyResultType inResult, const char * inName, const char * inType, const char * inDomain, DNSServiceDiscoveryReplyFlags inFlags, void * inContext ) { DNS_UNUSED( inFlags ); DNS_UNUSED( inContext ); if( inResult == DNSServiceBrowserReplyAddInstance ) { fprintf( stdout, "\"%s.%s%s\" service added emulated\n", inName, inType, inDomain ); } else if( inResult == DNSServiceBrowserReplyRemoveInstance ) { fprintf( stdout, "\"%s.%s%s\" service removed emulated\n", inName, inType, inDomain ); } else { fprintf( stdout, "### unknown emulated browser callback result (%d)\n", inResult ); } }
static void EmulatedResolverCallBack( struct sockaddr * inInterfaceAddr, struct sockaddr * inAddr, const char * inTextRecord, DNSServiceDiscoveryReplyFlags inFlags, void * inContext ) { struct sockaddr_in * ifSin4; struct sockaddr_in * sin4; char ifIP[ 64 ]; char ip[ 64 ]; DNS_UNUSED( inFlags ); DNS_UNUSED( inContext ); ifSin4 = (struct sockaddr_in *) inInterfaceAddr; sin4 = (struct sockaddr_in *) inAddr; fprintf( stdout, "service resolved to %s:%d on interface %s with text \"%s\"\n", IPv4ToString( *( (DNSOpaque32 *) &sin4->sin_addr.s_addr ), ip ), ntohs( sin4->sin_port ), IPv4ToString( *( (DNSOpaque32 *) &ifSin4->sin_addr.s_addr ), ifIP ), inTextRecord ? inTextRecord : "" ); }
DNS_LOCAL void DNSServiceBrowserPrivateCallBack( void * inContext, DNSBrowserRef inRef, DNSStatus inStatusCode, const DNSBrowserEvent * inEvent ) { dns_service_discovery_ref obj; DNSServiceBrowserReply callback; DNS_UNUSED( inRef ); DNS_UNUSED( inStatusCode ); check( inContext ); obj = (dns_service_discovery_ref) inContext; check( obj->callback ); callback = (DNSServiceBrowserReply) obj->callback; switch( inEvent->type ) { case kDNSBrowserEventTypeAddService: debugf( DEBUG_NAME "add service \"%s.%s%s\"\n", inEvent->data.addService.name, inEvent->data.addService.type, inEvent->data.addService.domain ); if( callback ) { callback( DNSServiceBrowserReplyAddInstance, inEvent->data.addService.name, inEvent->data.addService.type, inEvent->data.addService.domain, DNSServiceDiscoverReplyFlagsFinished, obj->context ); } break; case kDNSBrowserEventTypeRemoveService: debugf( DEBUG_NAME "remove service \"%s.%s%s\"\n", inEvent->data.removeService.name, inEvent->data.removeService.type, inEvent->data.removeService.domain ); if( callback ) { callback( DNSServiceBrowserReplyRemoveInstance, inEvent->data.removeService.name, inEvent->data.removeService.type, inEvent->data.removeService.domain, DNSServiceDiscoverReplyFlagsFinished, obj->context ); } break; default: break; } }
DNSServiceRegistrationReplyErrorType DNSServiceRegistrationRemoveRecord( dns_service_discovery_ref inRef, DNSRecordReference inRecordRef ) { DNS_UNUSED( inRef ); DNS_UNUSED( inRecordRef ); debugf( DEBUG_NAME "DNSServiceRegistrationRemoveRecord is currently not supported\n" ); return( kDNSServiceDiscoveryUnsupportedErr ); }
DNS_LOCAL void DNSServiceDomainEnumerationPrivateCallBack( void * inContext, DNSBrowserRef inRef, DNSStatus inStatusCode, const DNSBrowserEvent * inEvent ) { dns_service_discovery_ref obj; DNSServiceDomainEnumerationReply callback; DNS_UNUSED( inRef ); DNS_UNUSED( inStatusCode ); check( inContext ); obj = (dns_service_discovery_ref) inContext; check( obj->callback ); callback = (DNSServiceDomainEnumerationReply) obj->callback; switch( inEvent->type ) { case kDNSBrowserEventTypeAddDomain: debugf( DEBUG_NAME "add domain \"%s\"\n", inEvent->data.addDomain.domain ); if( callback ) { callback( DNSServiceDomainEnumerationReplyAddDomain, inEvent->data.addDomain.domain, DNSServiceDiscoverReplyFlagsFinished, obj->context ); } break; case kDNSBrowserEventTypeAddDefaultDomain: debugf( DEBUG_NAME "add default domain \"%s\"\n", inEvent->data.addDefaultDomain.domain ); if( callback ) { callback( DNSServiceDomainEnumerationReplyAddDomainDefault, inEvent->data.addDefaultDomain.domain, DNSServiceDiscoverReplyFlagsFinished, obj->context ); } break; case kDNSBrowserEventTypeRemoveDomain: debugf( DEBUG_NAME "add default domain \"%s\"\n", inEvent->data.removeDomain.domain ); if( callback ) { callback( DNSServiceDomainEnumerationReplyRemoveDomain, inEvent->data.removeDomain.domain, DNSServiceDiscoverReplyFlagsFinished, obj->context ); } break; default: break; } }
DNS_LOCAL void DNSServiceResolverPrivateCallBack( void * inContext, DNSResolverRef inRef, DNSStatus inStatusCode, const DNSResolverEvent * inEvent ) { dns_service_discovery_ref obj; DNSServiceResolverReply callback; struct sockaddr_in interfaceAddr; struct sockaddr_in addr; DNS_UNUSED( inRef ); DNS_UNUSED( inStatusCode ); check( inContext ); obj = (dns_service_discovery_ref) inContext; check( obj->callback ); callback = (DNSServiceResolverReply) obj->callback; switch( inEvent->type ) { case kDNSResolverEventTypeResolved: debugf( DEBUG_NAME "resolved \"%s.%s%s\"\n", inEvent->data.resolved.name, inEvent->data.resolved.type, inEvent->data.resolved.domain ); memset( &interfaceAddr, 0, sizeof( interfaceAddr ) ); interfaceAddr.sin_family = AF_INET; interfaceAddr.sin_port = 0; interfaceAddr.sin_addr.s_addr = inEvent->data.resolved.interfaceIP.u.ipv4.addr.v32; memset( &addr, 0, sizeof( addr ) ); addr.sin_family = AF_INET; addr.sin_port = inEvent->data.resolved.address.u.ipv4.port.v16; addr.sin_addr.s_addr = inEvent->data.resolved.address.u.ipv4.addr.v32; if( callback ) { callback( (struct sockaddr *) &interfaceAddr, (struct sockaddr *) &addr, inEvent->data.resolved.textRecord, DNSServiceDiscoverReplyFlagsFinished, obj->context ); } break; default: break; } }
mach_port_t DNSServiceDiscoveryMachPort( dns_service_discovery_ref inRef ) { DNS_UNUSED( inRef ); debugf( DEBUG_NAME "DNSServiceDiscoveryMachPort is not supported\n" ); return( 0 ); }
static void SigIntHandler( int inSignalNumber ) { DNS_UNUSED( inSignalNumber ); signal( SIGINT, SIG_DFL ); CFRunLoopStop( CFRunLoopGetCurrent() ); }
DNSServiceRegistrationReplyErrorType DNSServiceRegistrationUpdateRecord( dns_service_discovery_ref inRef, DNSRecordReference inRecordRef, uint16_t inRDLength, const char * inRData, uint32_t inTTL ) { DNS_UNUSED( inRef ); DNS_UNUSED( inRecordRef ); DNS_UNUSED( inRDLength ); DNS_UNUSED( inRData ); DNS_UNUSED( inTTL ); debugf( DEBUG_NAME "DNSServiceRegistrationUpdateRecord is currently not supported\n" ); return( kDNSServiceDiscoveryUnsupportedErr ); }
DNSRecordReference DNSServiceRegistrationAddRecord( dns_service_discovery_ref inRef, uint16_t inRRType, uint16_t inRDLength, const char * inRData, uint32_t inTTL ) { DNS_UNUSED( inRef ); DNS_UNUSED( inRRType ); DNS_UNUSED( inRDLength ); DNS_UNUSED( inRData ); DNS_UNUSED( inTTL ); debugf( DEBUG_NAME "DNSServiceRegistrationAddRecord is currently not supported\n" ); return( 0 ); }
DNS_LOCAL void DNSServiceRegistrationPrivateCallBack( void * inContext, DNSRegistrationRef inRef, DNSStatus inStatusCode, const DNSRegistrationEvent * inEvent ) { dns_service_discovery_ref obj; DNSServiceRegistrationReply callback; DNS_UNUSED( inRef ); DNS_UNUSED( inStatusCode ); check( inContext ); obj = (dns_service_discovery_ref) inContext; check( obj->callback ); callback = (DNSServiceRegistrationReply) obj->callback; switch( inEvent->type ) { case kDNSRegistrationEventTypeRegistered: debugf( DEBUG_NAME "name registered and active\n" ); if( callback ) { callback( kDNSServiceDiscoveryNoError, obj->context ); } break; case kDNSRegistrationEventTypeNameCollision: debugf( DEBUG_NAME "name in use, please choose another name\n" ); if( callback ) { callback( kDNSServiceDiscoveryNameConflict, obj->context ); } break; default: break; } }
static void EmulatedRegistrationCallBack( DNSServiceRegistrationReplyErrorType inResult, void *inContext ) { DNS_UNUSED( inContext ); if( inResult == kDNSServiceDiscoveryNoError ) { fprintf( stdout, "service name registered successfully\n" ); } else { fprintf( stdout, "service registration failed( %d)\n", inResult ); } }
static void HostRegistrationCallBack( void * inContext, DNSHostRegistrationRef inRef, DNSStatus inStatusCode, void * inData ) { DNS_UNUSED( inContext ); DNS_UNUSED( inRef ); DNS_UNUSED( inData ); if( inStatusCode == kDNSNoErr ) { fprintf( stdout, "host name registered and active\n" ); } else if( inStatusCode == kDNSNameConflictErr ) { fprintf( stdout, "host name in use, please choose another name\n" ); } else { fprintf( stdout, "unknown host registration status (%ld)\n", inStatusCode ); } }
void DNSServiceDiscovery_handleReply( void *inReplyMessage ) { DNS_UNUSED( inReplyMessage ); debugf( DEBUG_NAME "DNSServiceDiscovery_handleReply is not supported\n" ); }
static void ResolverCallBack( void *inContext, DNSResolverRef inRef, DNSStatus inStatusCode, const DNSResolverEvent *inEvent ) { char ifIP[ 32 ]; char ip[ 32 ]; DNS_UNUSED( inContext ); DNS_UNUSED( inRef ); DNS_UNUSED( inStatusCode ); switch( inEvent->type ) { case kDNSResolverEventTypeResolved: { const uint8_t * p; const uint8_t * end; int i; fprintf( stdout, "resolved \"%s.%s%s\" to \"%s\" (%s:%u) on interface 0x%p (%s)%s\n", inEvent->data.resolved.name, inEvent->data.resolved.type, inEvent->data.resolved.domain, inEvent->data.resolved.hostName, IPv4ToString( inEvent->data.resolved.address.u.ipv4.addr, ip ), ( inEvent->data.resolved.address.u.ipv4.port.v8[ 0 ] << 8 ) | inEvent->data.resolved.address.u.ipv4.port.v8[ 1 ], (int) inEvent->data.resolved.interfaceID, IPv4ToString( inEvent->data.resolved.interfaceIP.u.ipv4.addr, ifIP ), ( inEvent->data.resolved.textRecordRawSize > 0 ) ? " with text:" : "" ); p = (const uint8_t *) inEvent->data.resolved.textRecordRaw; end = p + inEvent->data.resolved.textRecordRawSize; i = 0; if( gPrintTXTRecords ) { while( p < end ) { uint8_t size; size = *p++; if( ( p + size ) > end ) { fprintf( stdout, "\n### MALFORMED TXT RECORD (length byte too big for record)\n\n" ); break; } fprintf( stdout, "%5d (%3d bytes): \"%.*s\"\n", i, size, size, p ); p += size; ++i; } fprintf( stdout, "\n" ); } break; } case kDNSResolverEventTypeRelease: break; default: break; } }