Пример #1
0
// PrintServiceInfo prints the service information to standard out
// A real application might want to do something else with the information
static void PrintServiceInfo(SearcherServices *services)
	{
	OTLink *link = OTReverseList(OTLIFOStealList(&services->serviceinfolist));
	
	while (link)
		{
		linkedServiceInfo *s = OTGetLinkObject(link, linkedServiceInfo, link);

		if (!services->headerPrinted)
			{
			printf("%-55s Type             Domain         Target Host     IP Address      Port Info\n", "Name");
			services->headerPrinted = true;
			}

		if (s->dom)
			{
			if (s->add) printf("%-55s available for browsing\n", s->domn);
			else        printf("%-55s no longer available for browsing\n", s->domn);
			}
		else
			{
			char ip[16];
			unsigned char *p = (unsigned char *)&s->address;
			sprintf(ip, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
			printf("%-55s %-16s %-14s ", s->name, s->type, s->domn);
			if (s->add) printf("%-15s %-15s %5d %s\n", s->host, ip, mDNSVal16(s->notAnIntPort), s->text);
			else        printf("Removed\n");
			}

		link = link->fNext;
		OTFreeMem(s);
		}
	}
Пример #2
0
NMErr
EndpointHander::GetStreamEP(void)
{
	DEBUG_ENTRY_EXIT("EndpointHander::GetStreamEP");

	CachedEP		*streamEP = NULL;
	OTLink			*acceptorLink = NULL;
	NMErr			status = kNMNoError;

	//Try_
	{
		//	Get a cached stream ep
		acceptorLink = OTLIFODequeue(&OTEndpoint::sStreamEPCache.Q);
	
		//if there was an available one in the cache
		if (acceptorLink)
		{
			OTAtomicAdd32(-1, &OTEndpoint::sStreamEPCache.readyCount);
			OTAtomicAdd32(-1, &OTEndpoint::sStreamEPCache.totalCount);
			//jacked up and good to go
			mState |= kGotStreamEP;
			
			//get the cache reloading itself
			OTEndpoint::ServiceEPCaches();
		}
		//otherwise, make one now
		else
		{
			return OTAsyncOpenEndpoint(OTCreateConfiguration(mListenerEP->GetStreamProtocolName()), 0, NULL, mNotifier.fUPP, this);
		}

		//	Get the pointer to the cached ep object
		streamEP = OTGetLinkObject(acceptorLink, CachedEP, link);
		op_assert(streamEP != NULL);
		
		//	Remove the notifier that was being used for cacheing and install the "normal" one
		OTRemoveNotifier(streamEP->ep);
		OTInstallNotifier(streamEP->ep, mNotifier.fUPP, this);
		
		mNewEP->mStreamEndpoint->mEP = streamEP->ep;

		delete streamEP;

	}
	//Catch_(code)
	error:
	if (status)
	{
		NMErr code = status;
		return code;
	}
	
	mState |= kStreamDone;
	
	return kNMNoError;
}
Пример #3
0
void
EndpointHander::CleanupEndpoints(void)
{
	OTLink			*list = OTLIFOStealList(gDeadEndpoints);
	OTLink			*link;
	EndpointHander	*endpoint;

	while ((link = list) != NULL) {
		list = link->fNext;
		endpoint = OTGetLinkObject(link, EndpointHander, mLink);
		delete endpoint;
	}
}
// PrintServiceInfo prints the service information to standard out
// A real application might want to do something else with the information
static void PrintServiceInfo(SearcherServices *services)
	{
	OTLink *link = OTReverseList(OTLIFOStealList(&services->serviceinfolist));
	
	while (link)
		{
		linkedServiceInfo *ls = OTGetLinkObject(link, linkedServiceInfo, link);
		ServiceInfo *s = &ls->i;

		if (!services->headerPrinted)
			{
			printf("%-55s Type             Domain         IP Address       Port Info\n", "Name");
			services->headerPrinted = true;
			}

		if (ls->dom)
			{
			char c_dom[MAX_ESCAPED_DOMAIN_NAME];
			ConvertDomainNameToCString(&s->name, c_dom);
			if (ls->add) printf("%-55s available for browsing\n", c_dom);
			else         printf("%-55s no longer available for browsing\n", c_dom);
			}
		else
			{
			domainlabel name;
			domainname type, domain;
			char c_name[MAX_DOMAIN_LABEL+1], c_type[MAX_ESCAPED_DOMAIN_NAME], c_dom[MAX_ESCAPED_DOMAIN_NAME], c_ip[20];
			DeconstructServiceName(&s->name, &name, &type, &domain);
			ConvertDomainLabelToCString_unescaped(&name, c_name);
			ConvertDomainNameToCString(&type, c_type);
			ConvertDomainNameToCString(&domain, c_dom);
			sprintf(c_ip, "%d.%d.%d.%d", s->ip.ip.v4.b[0], s->ip.ip.v4.b[1], s->ip.ip.v4.b[2], s->ip.ip.v4.b[3]);

			printf("%-55s %-16s %-14s ", c_name, c_type, c_dom);
			if (ls->add) printf("%-15s %5d %#s\n", c_ip, mDNSVal16(s->port), s->TXTinfo);
			else         printf("Removed\n");
			}

		link = link->fNext;
		OTFreeMem(ls);
		}
	}
Пример #5
0
NMErr
EndpointHander::GetDatagramEP(void)
{
	DEBUG_ENTRY_EXIT("EndpointHander::GetDatagramEP");

	CachedEP		*datagramEP = NULL;
	OTLink			*acceptorLink = NULL;
	NMErr		status = kNMNoError;

	//	if we're not in uber mode, there should be no datagram ep
	//	just jump to the notifier
	if (mNewEP->mMode != kNMNormalMode)
	{
		Notifier(this, T_BINDCOMPLETE, kNMNoError, NULL);
		return kNMNoError;
	}
		
	//Try_
	{
		//	Get a datagram endpoint from the cache
		acceptorLink = OTLIFODequeue(&OTEndpoint::sDatagramEPCache.Q);
		if (acceptorLink)
		{
			OTAtomicAdd32(-1, &OTEndpoint::sDatagramEPCache.readyCount);
			OTAtomicAdd32(-1, &OTEndpoint::sDatagramEPCache.totalCount);
			
			//jacked up and good to go
			mState |= kGotDatagramEP;
			
			//get the cache reloading itself
			OTEndpoint::ServiceEPCaches();
		}
		//if we couldn't get one off the cache, we'll make one after we have a stream endpoint
		// (one at a time for simplicity)
		else
		{
			if (mState & kGotStreamEP)
			{
				return OTAsyncOpenEndpoint(OTCreateConfiguration(mListenerEP->GetDatagramProtocolName()), 0, NULL, mNotifier.fUPP, this);
			}
			return kNMNoError; //we just wait for the stream endpoint to get done
		}

		//	Get the pointer to the cached ep object
		datagramEP = OTGetLinkObject(acceptorLink, CachedEP, link);
		op_assert(datagramEP != NULL);
		
		//	Remove the notifier that was being used for cacheing and install the "normal" one
		OTRemoveNotifier(datagramEP->ep);
		OTInstallNotifier(datagramEP->ep, mNotifier.fUPP, this);

		mNewEP->mDatagramEndpoint->mEP = datagramEP->ep;
		
		delete datagramEP;
		
		//if we got both endpoints, go ahead and bind here
		if (mState & kGotStreamEP)
		{
			//	Bind the endpoint.  Execution continues in the notifier for T_BINDCOMPLETE
			mBindReq.addr.len = 0;
			mBindReq.addr.buf = NULL;
			mBindRet.addr = mNewEP->mDatagramEndpoint->mLocalAddress;

			status = OTBind(mNewEP->mDatagramEndpoint->mEP,NULL, &mBindRet);
			//status = OTBind(mNewEP->mDatagramEndpoint->mEP,&mBindReq, &mBindRet);

			DEBUG_NETWORK_API(mNewEP->mDatagramEndpoint->mEP, "OTBind", status);					
			//ThrowIfOSErr_(status);
			if (status)
				goto error;
		}
	}
	//Catch_(code)
	error:
	if (status)
	{
		NMErr code = status;
		return code;
	}
	
	return kNMNoError;
}