/* build with cl -I"C:\Program Files\Rendezvous\Include" rendezvous.c $(LDLOADLIBS) "C:\Program Files\Rendezvous\lib\dnssd.lib" */ #include "dns_sd.h" #include "dns_sd.h" #include // For stdout, stderr #include // For exit() #include // For strlen(), strcpy(), bzero() #include // For errno, EINTR #include typedef union { unsigned char b[2]; unsigned short NotAnInteger; } Opaque16; static DNSServiceRef client = NULL; int stopNow = 0; int timeOut = 100000000; static void DNSSD_API reg_reply(DNSServiceRef client, DNSServiceFlags flags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) { (void)client; // Unused (void)flags; // Unused (void)context; // Unused printf("Got a reply for %s.%s%s: ", name, regtype, domain); switch (errorCode) { case kDNSServiceErr_NoError: printf("Name now registered and active\n"); break; case kDNSServiceErr_NameConflict: printf("Name in use, please choose another\n"); exit(-1); default: printf("Error %d\n", errorCode); return; } } void myTimerCallBack(void) { } static void HandleEvents(void) { int dns_sd_fd = DNSServiceRefSockFD(client); int nfds = dns_sd_fd + 1; fd_set readfds; struct timeval tv; int result; printf("fd: %d\n", dns_sd_fd); while (!stopNow) { // 1. Set up the fd_set as usual here. // This example client has no file descriptors of its own, // but a real application would call FD_SET to add them to the set here FD_ZERO(&readfds); // 2. Add the fd for our client(s) to the fd_set FD_SET(dns_sd_fd, &readfds); // 3. Set up the timeout. tv.tv_sec = timeOut; tv.tv_usec = 0; result = select(nfds, &readfds, (fd_set*)NULL, (fd_set*)NULL, &tv); printf("got result: %d\n", result); if (result > 0) { if (FD_ISSET(dns_sd_fd, &readfds)) DNSServiceProcessResult(client); } else if (result == 0) myTimerCallBack(); else { printf("select() returned %d errno %d %s\n", result, errno, strerror(errno)); if (errno != EINTR) stopNow = 1; } } } int main(int argc, char **argv) { const char *name = "Astoria"; const char *type = "_daap._tcp"; const char *domain = "local"; uint16_t port = 8181; Opaque16 registerPort = { { port << 8, port & 0xff } }; DNSServiceErrorType err; err = DNSServiceRegister(&client, 0, 0, name, type, domain, NULL, registerPort.NotAnInteger, 0, NULL, reg_reply, NULL); HandleEvents(); DNSServiceRefDeallocate(client); return 0; } #include "dns_sd.h" #include // For stdout, stderr #include // For exit() #include // For strlen(), strcpy(), bzero() #include // For errno, EINTR #include typedef union { unsigned char b[2]; unsigned short NotAnInteger; } Opaque16; static DNSServiceRef client = NULL; int stopNow = 0; int timeOut = 100000000; static void DNSSD_API reg_reply(DNSServiceRef client, DNSServiceFlags flags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) { (void)client; // Unused (void)flags; // Unused (void)context; // Unused printf("Got a reply for %s.%s%s: ", name, regtype, domain); switch (errorCode) { case kDNSServiceErr_NoError: printf("Name now registered and active\n"); break; case kDNSServiceErr_NameConflict: printf("Name in use, please choose another\n"); exit(-1); default: printf("Error %d\n", errorCode); return; } } void myTimerCallBack(void) { } static void HandleEvents(void) { int dns_sd_fd = DNSServiceRefSockFD(client); int nfds = dns_sd_fd + 1; fd_set readfds; struct timeval tv; int result; printf("fd: %d\n", dns_sd_fd); while (!stopNow) { // 1. Set up the fd_set as usual here. // This example client has no file descriptors of its own, // but a real application would call FD_SET to add them to the set here FD_ZERO(&readfds); // 2. Add the fd for our client(s) to the fd_set FD_SET(dns_sd_fd, &readfds); // 3. Set up the timeout. tv.tv_sec = timeOut; tv.tv_usec = 0; result = select(nfds, &readfds, (fd_set*)NULL, (fd_set*)NULL, &tv); printf("got result: %d\n", result); if (result > 0) { if (FD_ISSET(dns_sd_fd, &readfds)) DNSServiceProcessResult(client); } else if (result == 0) myTimerCallBack(); else { printf("select() returned %d errno %d %s\n", result, errno, strerror(errno)); if (errno != EINTR) stopNow = 1; } } } int main(int argc, char **argv) { const char *name = "Astoria"; const char *type = "_daap._tcp"; const char *domain = "local"; uint16_t port = 8181; Opaque16 registerPort = { { port << 8, port & 0xff } }; DNSServiceErrorType err; err = DNSServiceRegister(&client, 0, 0, name, type, domain, NULL, registerPort.NotAnInteger, 0, NULL, reg_reply, NULL); HandleEvents(); DNSServiceRefDeallocate(client); return 0; }