int main()
	{
	mStatus err;
	Boolean DoneSetup = false;

	SIOUXSettings.asktosaveonclose = false;
	SIOUXSettings.userwindowtitle = "\pMulticast DNS Responder";

	printf("Multicast DNS Responder\n\n");
	printf("This software reports errors using MacsBug breaks,\n");
	printf("so if you don't have MacsBug installed your Mac may crash.\n\n");
	printf("******************************************************************************\n");

	err = InitOpenTransport();
	if (err) { debugf("InitOpenTransport failed %d", err); return(err); }

	err = mDNS_Init(&m, &p, mDNS_Init_NoCache, mDNS_Init_ZeroCacheSize,
		mDNS_Init_AdvertiseLocalAddresses, mDNS_Init_NoInitCallback, mDNS_Init_NoInitCallbackContext);
	if (err) return(err);

	while (!YieldSomeTime(35))
		{
#if MDNS_ONLYSYSTEMTASK
		// For debugging, use "#define MDNS_ONLYSYSTEMTASK 1" and call mDNSPlatformIdle() periodically.
		// For shipping code, don't define MDNS_ONLYSYSTEMTASK, and you don't need to call mDNSPlatformIdle()
		extern void mDNSPlatformIdle(mDNS *const m);
		mDNSPlatformIdle(&m);	// Only needed for debugging version
#endif
		if (m.mDNSPlatformStatus == mStatus_NoError && !DoneSetup)
			{
			DoneSetup = true;
			printf("\nListening for mDNS queries...\n");
			mDNSResponderTestSetup(&m);
			}
		}
	
	if (p1.RR_SRV.resrec.RecordType  ) mDNS_DeregisterService(&m, &p1);
	if (p2.RR_SRV.resrec.RecordType  ) mDNS_DeregisterService(&m, &p2);
	if (afp.RR_SRV.resrec.RecordType ) mDNS_DeregisterService(&m, &afp);
	if (http.RR_SRV.resrec.RecordType) mDNS_DeregisterService(&m, &http);
	if (njp.RR_SRV.resrec.RecordType ) mDNS_DeregisterService(&m, &njp);

	mDNS_Close(&m);
	
	return(0);
	}
Ejemplo n.º 2
0
int main()
	{
	mStatus err;
	Boolean DoneSetup = false;
	mDNSs32 nextAvail, nextBusy;

	SIOUXSettings.asktosaveonclose = false;
	SIOUXSettings.userwindowtitle = "\pMulticast DNS Responder";

	printf("Multicast DNS Responder\n\n");
	printf("This software reports errors using MacsBug breaks,\n");
	printf("so if you don't have MacsBug installed your Mac may crash.\n\n");
	printf("******************************************************************************\n");

	err = InitOpenTransport();
	if (err) { debugf("InitOpenTransport failed %d", err); return(err); }

	err = mDNS_Init(&m, &p, mDNS_Init_NoCache, mDNS_Init_ZeroCacheSize,
		mDNS_Init_AdvertiseLocalAddresses, mDNS_Init_NoInitCallback, mDNS_Init_NoInitCallbackContext);
	if (err) return(err);

	while (!YieldSomeTime(35))
		{
#if MDNS_ONLYSYSTEMTASK
		// For debugging, use "#define MDNS_ONLYSYSTEMTASK 1" and call mDNSPlatformIdle() periodically.
		// For shipping code, don't define MDNS_ONLYSYSTEMTASK, and you don't need to call mDNSPlatformIdle()
		extern void mDNSPlatformIdle(mDNS *const m);
		mDNSPlatformIdle(&m);	// Only needed for debugging version
#endif
		if (m.mDNSPlatformStatus == mStatus_NoError && !DoneSetup)
			{
			DoneSetup = true;
			printf("\nListening for mDNS queries...\n");
			mDNSResponderTestSetup(&m);
			mDNSResponderSetAvail(&m, &availRec1, &p1);
			availRec2Active = false;
			nextAvail = mDNS_TimeNow(&m) + mDNSPlatformOneSecond * 10;
			nextBusy  = mDNS_TimeNow(&m) + mDNSPlatformOneSecond * 15;
			}

		if (DoneSetup)
			{
			// We check availRec2.RecordType because we don't want to re-register this record
			// if the previous mDNS_Deregister() has not yet completed
			if (mDNS_TimeNow(&m) - nextAvail > 0 && !availRec2Active)
				{
				printf("Setting Two now available\n");
				availRec2Active = true;
				mDNSResponderSetAvail(&m, &availRec2, &p2);
				nextAvail = nextBusy + mDNSPlatformOneSecond * 10;
				}
			else if (mDNS_TimeNow(&m) - nextBusy > 0)
				{
				printf("Setting Two now busy\n");
				mDNS_Deregister(&m, &availRec2);
				nextBusy = nextAvail + mDNSPlatformOneSecond * 5;
				}
			}
		}
	
	if (p1.RR_SRV.resrec.RecordType) mDNS_DeregisterService(&m, &p1);
	if (p2.RR_SRV.resrec.RecordType) mDNS_DeregisterService(&m, &p2);
	if (availRec1.resrec.RecordType) mDNS_Deregister(&m, &availRec1);
	if (availRec2Active)             mDNS_Deregister(&m, &availRec2);

	mDNS_Close(&m);
	
	return(0);
	}