1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 Change History (most recent first):
19 $Log: DNSServiceBrowser.m,v $
20 Revision 1.35 2006/11/27 08:27:49 mkrochma
23 Revision 1.34 2006/11/24 05:41:07 mkrochma
24 More cleanup and more service types
26 Revision 1.33 2006/11/24 01:34:24 mkrochma
27 Display interface index and query for IPv6 addresses even when there's no IPv4
29 Revision 1.32 2006/11/24 00:25:31 mkrochma
30 <rdar://problem/4084652> Tools: DNS Service Browser contains some bugs
32 Revision 1.31 2006/08/14 23:23:55 cheshire
33 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
35 Revision 1.30 2005/01/27 17:46:16 cheshire
38 Revision 1.29 2004/06/04 20:58:36 cheshire
39 Move DNSServiceBrowser from mDNSMacOSX directory to Clients directory
41 Revision 1.28 2004/05/18 23:51:26 cheshire
42 Tidy up all checkin comments to use consistent "<rdar://problem/xxxxxxx>" format for bug numbers
44 Revision 1.27 2003/11/19 18:49:48 rpantos
45 <rdar://problem/3282283> couple of little tweaks to previous checkin
47 Revision 1.26 2003/11/07 19:35:20 rpantos
48 <rdar://problem/3282283> Display multiple IP addresses. Connect using host rather than IP addr.
50 Revision 1.25 2003/10/29 05:16:54 rpantos
51 Checkpoint: transition from DNSServiceDiscovery.h to dns_sd.h
53 Revision 1.24 2003/10/28 02:25:45 rpantos
54 <rdar://problem/3282283> Cancel pending resolve when focus changes or service disappears.
56 Revision 1.23 2003/10/28 01:29:15 rpantos
57 <rdar://problem/3282283> Restructure a bit to make arrow keys work & views behave better.
59 Revision 1.22 2003/10/28 01:23:27 rpantos
60 <rdar://problem/3282283> Bail if mDNS cannot be initialized at startup.
62 Revision 1.21 2003/10/28 01:19:45 rpantos
63 <rdar://problem/3282283> Do not put a trailing '.' on service names. Handle PATH for HTTP txtRecords.
65 Revision 1.20 2003/10/28 01:13:49 rpantos
66 <rdar://problem/3282283> Remove filter when displaying browse results.
68 Revision 1.19 2003/10/28 01:10:14 rpantos
69 <rdar://problem/3282283> Change 'compare' to 'caseInsensitiveCompare' to fix sort order.
71 Revision 1.18 2003/08/12 19:55:07 cheshire
76 #import <Cocoa/Cocoa.h>
77 #include <sys/types.h>
78 #include <sys/socket.h>
80 #include <arpa/inet.h>
82 #include <sys/select.h>
83 #include <netinet/in.h>
87 @class ServiceController; // holds state corresponding to outstanding DNSServiceRef
89 @interface BrowserController : NSObject
91 IBOutlet id nameField;
92 IBOutlet id typeField;
94 IBOutlet id serviceDisplayTable;
95 IBOutlet id typeColumn;
96 IBOutlet id nameColumn;
97 IBOutlet id serviceTypeField;
98 IBOutlet id serviceNameField;
100 IBOutlet id hostField;
101 IBOutlet id ipAddressField;
102 IBOutlet id ip6AddressField;
103 IBOutlet id portField;
104 IBOutlet id interfaceField;
105 IBOutlet id textField;
107 NSMutableArray *_srvtypeKeys;
108 NSMutableArray *_srvnameKeys;
109 NSMutableArray *_sortedServices;
110 NSMutableDictionary *_servicesDict;
112 ServiceController *_serviceBrowser;
113 ServiceController *_serviceResolver;
114 ServiceController *_ipv4AddressResolver;
115 ServiceController *_ipv6AddressResolver;
118 - (void)notifyTypeSelectionChange:(NSNotification*)note;
119 - (void)notifyNameSelectionChange:(NSNotification*)note;
121 - (IBAction)connect:(id)sender;
123 - (IBAction)handleTableClick:(id)sender;
124 - (IBAction)removeSelected:(id)sender;
125 - (IBAction)addNewService:(id)sender;
127 - (IBAction)update:(NSString *)Type;
129 - (void)updateBrowseWithName:(const char *)name type:(const char *)resulttype domain:(const char *)domain interface:(uint32_t)interface flags:(DNSServiceFlags)flags;
130 - (void)resolveClientWitHost:(NSString *)host port:(uint16_t)port interfaceIndex:(uint32_t)interface txtRecord:(const char*)txtRecord txtLen:(uint16_t)txtLen;
131 - (void)updateAddress:(uint16_t)rrtype addr:(const void *)buff addrLen:(uint16_t)addrLen host:(const char*)host interfaceIndex:(uint32_t)interface more:(boolean_t)moreToCome;
133 - (void)_cancelPendingResolve;
134 - (void)_clearResolvedInfo;
138 // The ServiceController manages cleanup of DNSServiceRef & runloop info for an outstanding request
139 @interface ServiceController : NSObject
141 DNSServiceRef fServiceRef;
142 CFSocketRef fSocketRef;
143 CFRunLoopSourceRef fRunloopSrc;
146 - (id)initWithServiceRef:(DNSServiceRef)ref;
147 - (void)addToCurrentRunLoop;
148 - (DNSServiceRef)serviceRef;
151 @end // interface ServiceController
155 ProcessSockData(CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void *data, void *info)
157 DNSServiceRef serviceRef = (DNSServiceRef)info;
158 DNSServiceErrorType err = DNSServiceProcessResult(serviceRef);
159 if (err != kDNSServiceErr_NoError) {
160 printf("DNSServiceProcessResult() returned an error! %d\n", err);
166 ServiceBrowseReply(DNSServiceRef sdRef, DNSServiceFlags servFlags, uint32_t interfaceIndex, DNSServiceErrorType errorCode,
167 const char *serviceName, const char *regtype, const char *replyDomain, void *context)
169 if (errorCode == kDNSServiceErr_NoError) {
170 [(BrowserController*)context updateBrowseWithName:serviceName type:regtype domain:replyDomain interface:interfaceIndex flags:servFlags];
172 printf("ServiceBrowseReply got an error! %d\n", errorCode);
178 ServiceResolveReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode,
179 const char *fullname, const char *hosttarget, uint16_t port, uint16_t txtLen, const char *txtRecord, void *context)
181 if (errorCode == kDNSServiceErr_NoError) {
182 [(BrowserController*)context resolveClientWitHost:[NSString stringWithUTF8String:hosttarget] port:port interfaceIndex:interfaceIndex txtRecord:txtRecord txtLen:txtLen];
184 printf("ServiceResolveReply got an error! %d\n", errorCode);
190 QueryRecordReply(DNSServiceRef DNSServiceRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode,
191 const char *fullname, uint16_t rrtype, uint16_t rrclass, uint16_t rdlen, const void *rdata, uint32_t ttl, void *context)
193 if (errorCode == kDNSServiceErr_NoError) {
194 [(BrowserController*)context updateAddress:rrtype addr:rdata addrLen:rdlen host:fullname interfaceIndex:interfaceIndex more:(flags & kDNSServiceFlagsMoreComing)];
196 printf("QueryRecordReply got an error! %d\n", errorCode);
202 InterfaceIndexToName(uint32_t interface, char *interfaceName)
204 assert(interfaceName);
206 if (interface == kDNSServiceInterfaceIndexAny) {
207 // All active network interfaces.
208 strlcpy(interfaceName, "all", IF_NAMESIZE);
209 } else if (interface == kDNSServiceInterfaceIndexLocalOnly) {
210 // Only available locally on this machine.
211 strlcpy(interfaceName, "local", IF_NAMESIZE);
213 // Converts interface index to interface name.
214 if_indextoname(interface, interfaceName);
219 @implementation BrowserController //Begin implementation of BrowserController methods
221 - (void)registerDefaults
223 NSMutableDictionary *regDict = [NSMutableDictionary dictionary];
225 NSArray *typeArray = [NSArray arrayWithObjects:@"_afpovertcp._tcp",
239 NSArray *nameArray = [NSArray arrayWithObjects:@"AppleShare Servers",
247 @"AirPort Base Stations",
253 [regDict setObject:typeArray forKey:@"SrvTypeKeys"];
254 [regDict setObject:nameArray forKey:@"SrvNameKeys"];
256 [[NSUserDefaults standardUserDefaults] registerDefaults:regDict];
266 _serviceBrowser = nil;
267 _serviceResolver = nil;
268 _ipv4AddressResolver = nil;
269 _ipv6AddressResolver = nil;
270 _sortedServices = [[NSMutableArray alloc] init];
271 _servicesDict = [[NSMutableDictionary alloc] init];
279 [typeField sizeLastColumnToFit];
280 [nameField sizeLastColumnToFit];
281 [nameField setDoubleAction:@selector(connect:)];
283 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notifyTypeSelectionChange:) name:NSTableViewSelectionDidChangeNotification object:typeField];
284 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notifyNameSelectionChange:) name:NSTableViewSelectionDidChangeNotification object:nameField];
286 _srvtypeKeys = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"SrvTypeKeys"] mutableCopy];
287 _srvnameKeys = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"SrvNameKeys"] mutableCopy];
289 if (!_srvtypeKeys || !_srvnameKeys) {
290 [_srvtypeKeys release];
291 [_srvnameKeys release];
292 [self registerDefaults];
293 _srvtypeKeys = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"SrvTypeKeys"] mutableCopy];
294 _srvnameKeys = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"SrvNameKeys"] mutableCopy];
297 [typeField reloadData];
303 [_srvtypeKeys release];
304 [_srvnameKeys release];
305 [_servicesDict release];
306 [_sortedServices release];
311 -(void)tableView:(NSTableView *)theTableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(int)row
317 - (int)numberOfRowsInTableView:(NSTableView *)theTableView //Begin mandatory TableView methods
319 if (theTableView == typeField) {
320 return [_srvnameKeys count];
322 if (theTableView == nameField) {
323 return [_servicesDict count];
325 if (theTableView == serviceDisplayTable) {
326 return [_srvnameKeys count];
332 - (id)tableView:(NSTableView *)theTableView objectValueForTableColumn:(NSTableColumn *)theColumn row:(int)rowIndex
334 if (theTableView == typeField) {
335 return [_srvnameKeys objectAtIndex:rowIndex];
337 if (theTableView == nameField) {
338 return [[_servicesDict objectForKey:[_sortedServices objectAtIndex:rowIndex]] name];
340 if (theTableView == serviceDisplayTable) {
341 if (theColumn == typeColumn) {
342 return [_srvtypeKeys objectAtIndex:rowIndex];
344 if (theColumn == nameColumn) {
345 return [_srvnameKeys objectAtIndex:rowIndex];
354 - (void)notifyTypeSelectionChange:(NSNotification*)note
356 [self _cancelPendingResolve];
358 int index = [[note object] selectedRow];
360 [self update:[_srvtypeKeys objectAtIndex:index]];
367 - (void)notifyNameSelectionChange:(NSNotification*)note
369 [self _cancelPendingResolve];
371 int index = [[note object] selectedRow];
376 // Get the currently selected service
377 NSNetService *service = [_servicesDict objectForKey:[_sortedServices objectAtIndex:index]];
379 DNSServiceRef serviceRef;
380 DNSServiceErrorType err = DNSServiceResolve(&serviceRef,
382 kDNSServiceInterfaceIndexAny,
383 (const char *)[[service name] UTF8String],
384 (const char *)[[service type] UTF8String],
385 (const char *)[[service domain] UTF8String],
386 (DNSServiceResolveReply)ServiceResolveReply,
389 if (kDNSServiceErr_NoError == err) {
390 _serviceResolver = [[ServiceController alloc] initWithServiceRef:serviceRef];
391 [_serviceResolver addToCurrentRunLoop];
396 - (IBAction)update:(NSString *)theType
398 [_servicesDict removeAllObjects];
399 [_sortedServices removeAllObjects];
400 [nameField reloadData];
402 // get rid of the previous browser if one exists
403 if (_serviceBrowser != nil) {
404 [_serviceBrowser release];
405 _serviceBrowser = nil;
409 DNSServiceRef serviceRef;
410 DNSServiceErrorType err = DNSServiceBrowse(&serviceRef, (DNSServiceFlags)0, 0, [theType UTF8String], NULL, ServiceBrowseReply, self);
411 if (kDNSServiceErr_NoError == err) {
412 _serviceBrowser = [[ServiceController alloc] initWithServiceRef:serviceRef];
413 [_serviceBrowser addToCurrentRunLoop];
419 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
425 - (void)updateBrowseWithName:(const char *)name type:(const char *)type domain:(const char *)domain interface:(uint32_t)interface flags:(DNSServiceFlags)flags
427 NSString *key = [NSString stringWithFormat:@"%s.%s%s%d", name, type, domain, interface];
428 NSNetService *service = [[NSNetService alloc] initWithDomain:[NSString stringWithUTF8String:domain] type:[NSString stringWithUTF8String:type] name:[NSString stringWithUTF8String:name]];
430 if (flags & kDNSServiceFlagsAdd) {
431 [_servicesDict setObject:service forKey:key];
433 [_servicesDict removeObjectForKey:key];
436 // If not expecting any more data, then reload (redraw) TableView with newly found data
437 if (!(flags & kDNSServiceFlagsMoreComing)) {
439 // Save the current TableView selection
440 int index = [nameField selectedRow];
441 NSString *selected = (index != -1) ? [[_sortedServices objectAtIndex:index] copy] : nil;
443 [_sortedServices release];
444 _sortedServices = [[_servicesDict allKeys] mutableCopy];
445 [_sortedServices sortUsingSelector:@selector(caseInsensitiveCompare:)];
446 [nameField reloadData];
448 // Restore the previous TableView selection
449 index = selected ? [_sortedServices indexOfObject:selected] : NSNotFound;
450 if (index != NSNotFound) {
451 [nameField selectRowIndexes:[NSIndexSet indexSetWithIndex:index] byExtendingSelection:NO];
452 [nameField scrollRowToVisible:index];
464 - (void)resolveClientWitHost:(NSString *)host port:(uint16_t)port interfaceIndex:(uint32_t)interface txtRecord:(const char*)txtRecord txtLen:(uint16_t)txtLen
466 DNSServiceRef serviceRef;
468 if (_ipv4AddressResolver) {
469 [_ipv4AddressResolver release];
470 _ipv4AddressResolver = nil;
473 if (_ipv6AddressResolver) {
474 [_ipv6AddressResolver release];
475 _ipv6AddressResolver = nil;
478 // Start an async lookup for IPv4 addresses
479 DNSServiceErrorType err = DNSServiceQueryRecord(&serviceRef, (DNSServiceFlags)0, interface, [host UTF8String], kDNSServiceType_A, kDNSServiceClass_IN, QueryRecordReply, self);
480 if (err == kDNSServiceErr_NoError) {
481 _ipv4AddressResolver = [[ServiceController alloc] initWithServiceRef:serviceRef];
482 [_ipv4AddressResolver addToCurrentRunLoop];
485 // Start an async lookup for IPv6 addresses
486 err = DNSServiceQueryRecord(&serviceRef, (DNSServiceFlags)0, interface, [host UTF8String], kDNSServiceType_AAAA, kDNSServiceClass_IN, QueryRecordReply, self);
487 if (err == kDNSServiceErr_NoError) {
488 _ipv6AddressResolver = [[ServiceController alloc] initWithServiceRef:serviceRef];
489 [_ipv6AddressResolver addToCurrentRunLoop];
492 char interfaceName[IF_NAMESIZE];
493 InterfaceIndexToName(interface, interfaceName);
495 [hostField setStringValue:host];
496 [interfaceField setStringValue:[NSString stringWithUTF8String:interfaceName]];
497 [portField setIntValue:ntohs(port)];
499 // kind of a hack: munge txtRecord so it's human-readable
501 char *readableText = (char*) malloc(txtLen);
502 if (readableText != nil) {
503 ByteCount index, subStrLen;
504 memcpy(readableText, txtRecord, txtLen);
505 for (index=0; index < txtLen - 1; index += subStrLen + 1) {
506 subStrLen = readableText[index];
507 readableText[index] = ' ';
509 [textField setStringValue:[NSString stringWithCString:&readableText[1] length:txtLen - 1]];
516 - (void)updateAddress:(uint16_t)rrtype addr:(const void *)buff addrLen:(uint16_t)addrLen host:(const char*) host interfaceIndex:(uint32_t)interface more:(boolean_t)moreToCome
520 if (rrtype == kDNSServiceType_A) {
521 inet_ntop(AF_INET, buff, addrBuff, sizeof(addrBuff));
522 if ([[ipAddressField stringValue] length] > 0) {
523 [ipAddressField setStringValue:[NSString stringWithFormat:@"%@, ", [ipAddressField stringValue]]];
525 [ipAddressField setStringValue:[NSString stringWithFormat:@"%@%s", [ipAddressField stringValue], addrBuff]];
528 [_ipv4AddressResolver release];
529 _ipv4AddressResolver = nil;
531 } else if (rrtype == kDNSServiceType_AAAA) {
532 inet_ntop(AF_INET6, buff, addrBuff, sizeof(addrBuff));
533 if ([[ip6AddressField stringValue] length] > 0) {
534 [ip6AddressField setStringValue:[NSString stringWithFormat:@"%@, ", [ip6AddressField stringValue]]];
536 [ip6AddressField setStringValue:[NSString stringWithFormat:@"%@%s", [ip6AddressField stringValue], addrBuff]];
539 [_ipv6AddressResolver release];
540 _ipv6AddressResolver = nil;
546 - (void)connect:(id)sender
548 NSString *host = [hostField stringValue];
549 NSString *txtRecord = [textField stringValue];
550 int port = [portField intValue];
552 int index = [nameField selectedRow];
553 NSString *selected = (index >= 0) ? [_sortedServices objectAtIndex:index] : nil;
554 NSString *type = [[_servicesDict objectForKey:selected] type];
556 if ([type isEqual:@"_http._tcp."]) {
557 NSString *pathDelim = @"path=";
560 // If the TXT record specifies a path, extract it.
561 where = [txtRecord rangeOfString:pathDelim options:NSCaseInsensitiveSearch];
563 NSRange targetRange = { where.location + where.length, [txtRecord length] - where.location - where.length };
564 NSRange endDelim = [txtRecord rangeOfString:@"\n" options:kNilOptions range:targetRange];
566 if (endDelim.length) // if a delimiter was found, truncate the target range
567 targetRange.length = endDelim.location - targetRange.location;
569 NSString *path = [txtRecord substringWithRange:targetRange];
570 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%d%@", host, port, path]]];
572 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%d", host, port]]];
575 else if ([type isEqual:@"_ftp._tcp."]) [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"ftp://%@:%d/", host, port]]];
576 else if ([type isEqual:@"_ssh._tcp."]) [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"ssh://%@:%d/", host, port]]];
577 else if ([type isEqual:@"_afpovertcp._tcp."]) [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"afp://%@:%d/", host, port]]];
578 else if ([type isEqual:@"_smb._tcp."]) [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"smb://%@:%d/", host, port]]];
579 else if ([type isEqual:@"_rfb._tcp."]) [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"vnc://%@:%d/", host, port]]];
585 - (IBAction)handleTableClick:(id)sender
587 //populate the text fields
591 - (IBAction)removeSelected:(id)sender
593 // remove the selected row and force a refresh
595 int selectedRow = [serviceDisplayTable selectedRow];
599 [_srvtypeKeys removeObjectAtIndex:selectedRow];
600 [_srvnameKeys removeObjectAtIndex:selectedRow];
602 [[NSUserDefaults standardUserDefaults] setObject:_srvtypeKeys forKey:@"SrvTypeKeys"];
603 [[NSUserDefaults standardUserDefaults] setObject:_srvnameKeys forKey:@"SrvNameKeys"];
605 [typeField reloadData];
606 [serviceDisplayTable reloadData];
611 - (IBAction)addNewService:(id)sender
613 // add new entries from the edit fields to the arrays for the defaults
614 NSString *newType = [serviceTypeField stringValue];
615 NSString *newName = [serviceNameField stringValue];
617 // 3282283: trim trailing '.' from service type field
618 if ([newType length] && [newType hasSuffix:@"."])
619 newType = [newType substringToIndex:[newType length] - 1];
621 if ([newType length] && [newName length]) {
622 [_srvtypeKeys addObject:newType];
623 [_srvnameKeys addObject:newName];
625 [[NSUserDefaults standardUserDefaults] setObject:_srvtypeKeys forKey:@"SrvTypeKeys"];
626 [[NSUserDefaults standardUserDefaults] setObject:_srvnameKeys forKey:@"SrvNameKeys"];
628 [typeField reloadData];
629 [serviceDisplayTable reloadData];
634 - (void)_cancelPendingResolve
636 [_ipv4AddressResolver release];
637 _ipv4AddressResolver = nil;
639 [_ipv6AddressResolver release];
640 _ipv6AddressResolver = nil;
642 [_serviceResolver release];
643 _serviceResolver = nil;
645 [self _clearResolvedInfo];
649 - (void)_clearResolvedInfo
651 [hostField setStringValue:@""];
652 [ipAddressField setStringValue:@""];
653 [ip6AddressField setStringValue:@""];
654 [portField setStringValue:@""];
655 [interfaceField setStringValue:@""];
656 [textField setStringValue:@""];
659 @end // implementation BrowserController
662 @implementation ServiceController : NSObject
664 DNSServiceRef fServiceRef;
665 CFSocketRef fSocketRef;
666 CFRunLoopSourceRef fRunloopSrc;
670 - (id)initWithServiceRef:(DNSServiceRef)ref
682 - (void)addToCurrentRunLoop
684 CFSocketContext context = { 0, (void*)fServiceRef, NULL, NULL, NULL };
686 fSocketRef = CFSocketCreateWithNative(kCFAllocatorDefault, DNSServiceRefSockFD(fServiceRef), kCFSocketReadCallBack, ProcessSockData, &context);
688 // Prevent CFSocketInvalidate from closing DNSServiceRef's socket.
689 CFOptionFlags sockFlags = CFSocketGetSocketFlags(fSocketRef);
690 CFSocketSetSocketFlags(fSocketRef, sockFlags & (~kCFSocketCloseOnInvalidate));
691 fRunloopSrc = CFSocketCreateRunLoopSource(kCFAllocatorDefault, fSocketRef, 0);
694 CFRunLoopAddSource(CFRunLoopGetCurrent(), fRunloopSrc, kCFRunLoopDefaultMode);
696 printf("Could not listen to runloop socket\n");
701 - (DNSServiceRef)serviceRef
710 CFSocketInvalidate(fSocketRef); // Note: Also closes the underlying socket
711 CFRelease(fSocketRef);
713 // Workaround that gives time to CFSocket's select thread so it can remove the socket from its
714 // FD set before we close the socket by calling DNSServiceRefDeallocate. <rdar://problem/3585273>
719 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), fRunloopSrc, kCFRunLoopDefaultMode);
720 CFRelease(fRunloopSrc);
723 DNSServiceRefDeallocate(fServiceRef);
729 @end // implementation ServiceController
731 int main(int argc, const char *argv[])
733 return NSApplicationMain(argc, argv);