#import <servers/netname.h>
#import "ListenerAdditions.h"

@implementation Listener(PublicPort)

/*
 * This method should be used INSTEAD OF -checkInAs:, not in addition to it.
 * Using both may lead to problems later if checked in again under the same 
 * name.
 */
- (int)publicCheckInAs:(const char *)name
{
	kern_return_t result;
	
	if (![self listenPort]) {
		/* 
		 * Causes Listener to alloc a port.
		 */
		[self usePrivatePort];
    }
    
	/*
	 * Now register the port with the Network Name Server.
	 */
	result = netname_check_in(name_server_port,
		(char *)name,[self signaturePort],[self listenPort]);
    if (result != NETNAME_SUCCESS)
		return result;
	
	/*
	 * Set my portName to be the registed name.
	 */
	free(portName);
	portName = NXCopyStringBufferFromZone(name, [self zone]);
	return 0;
}

@end
