2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 Change History (most recent first):
25 $Log: HAAutomounter.m,v $
26 Revision 1.4 2003/08/12 19:55:08 cheshire
31 #import "HAAutomounter.h"
33 #import <AppKit/AppKit.h>
35 #include <sys/types.h>
36 #include "arpa/inet.h"
37 #include <netinet/in.h>
39 @implementation HAAutomounter
45 browser = [[NSNetServiceBrowser alloc] init];
47 [browser setDelegate:self];
49 [browser searchForServicesOfType:@"_mountme._tcp." inDomain:@""];
51 [browser scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode: NSDefaultRunLoopMode];
56 - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
62 resolver = [[NSNetService alloc] initWithDomain:[aNetService domain] type:[aNetService type] name:[aNetService name]];
63 [resolver setDelegate:self];
64 [resolver scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode: NSDefaultRunLoopMode];
70 - (void)netServiceDidResolveAddress:(NSNetService *)sender;
72 if ([[sender addresses] count]) {
74 // URL mount the volume
75 NSData *addr = [[sender addresses] objectAtIndex:0];
76 struct sockaddr_in *address = CFDataGetBytePtr((CFDataRef)addr);
77 NSString *ipAddr = [NSString stringWithCString:inet_ntoa(((struct in_addr)((struct sockaddr_in *)address)->sin_addr))];
78 int port = ((struct sockaddr_in *)address)->sin_port;
79 NSArray *txtArray = [[sender protocolSpecificInformation] componentsSeparatedByString:@","];
81 if ([txtArray count] == 3) {
82 NSString *user = [txtArray objectAtIndex:0];
83 NSString *password = [txtArray objectAtIndex:1];
84 NSString *share = [txtArray objectAtIndex:2];
86 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"afp://%@:%@@%@:%d/%@", user, password, ipAddr, port, share]]];
88 NSLog(@"incompatible format for txt record, s/b user,password,share");
92 NSLog(@"No address %@", sender);
96 - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didRemoveService:(NSNetService *)aNetService moreComing:(BOOL)moreComing