Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DNSServiceQueryRecord



 > Can you post a code snippet. It sounds like you're doing everything 
right.
 > -Marc

Here's the code gutted. I had to remove a lot to get through the 
mailing list quota which is in holding. I hope there's enough left to 
find the problem.

Thanks,
Eric

/* struct to save resolve callback info, to pass to query */
struct resolve_callback_userdata
{
	uint16_t port;
	struct sockaddr_in address;
	char fullname[kDNSServiceMaxDomainName]; /* 1005 bytes */
};

void resolve_callback(
/* snip ... */
	)
{
	struct resolve_callback_userdata* udata;
	/* Save the port and full name into the user data for later */
	udata = (struct resolve_callback_userdata*)context;
	udata->port = port;
	strncpy(udata->fullname, fullname,  kDNSServiceMaxDomainName);
}

int main(int argc, char * argv[])
{
	struct resolve_callback_userdata query_data;

         /* Browse stuff snipped out */


	dns_error = DNSServiceResolve(
			&resolve_ref,
			0,
			rdata_array[0].interfaceIndex,
			rdata_array[0].name,
			rdata_array[0].regtype,
			rdata_array[0].domain,
			&resolve_callback,
			&query_data
		);
	/* Select loop for DNSServiceProcessResult cut  */
		
	dns_error = DNSServiceQueryRecord(
					&query_ref,
					0,
					0,
					query_data.fullname,
					1,
					1,
					&query_record_callback,
					&query_data
	);
	/* Do I cancel the resolve now, or do I wait for query to end?
	   DNSServiceRefDeallocate(resolve_ref);
	 */
	/* One more select loop for query */
	{
		struct timeval tv;
		fd_set readfds;
		int result;

		fprintf(stderr, "Testing userdata return\n");
		fprintf(stderr, "Testing Port userdata return: %d\n", 
ntohs(query_data.port));
		/* I don't want to wait around forever trying to resolve this */
		tv.tv_sec = 30;
		tv.tv_usec = 500000;

		query_socket = DNSServiceRefSockFD(query_ref);
		if(query_socket < 0)
		{
			die("Error on DNSServiceRefSockFD\n");
		}
		FD_ZERO(&readfds);
		FD_SET(query_socket, &readfds);

		fprintf(stderr, "Hoping to ProcessResult (stuck here)\n");

		result = select(query_socket+1, &readfds, NULL, NULL, &tv);
		if(result == 0)
		{
			die("Result is 0...timeout\n");
		}
		else if(result < 0)
		{
			fprintf(stderr, "Result is < 0: %d, errnoo %d %s\n", result, errno, 
strerror(errno));
			die("Bailed\n");
		}

		if (FD_ISSET(query_socket, &readfds))
		{
			dns_error = DNSServiceProcessResult(query_ref);
			if( dns_error < 0)
			{
				die("Aborted at DNSServiceProcessResult\n");

			}
		}
	}

	   DNSServiceRefDeallocate(query_ref);
}
_______________________________________________
rendezvous mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/rendezvous
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.