Пример #1
0
static void SetDefaultEndpointModes(EndpointRef ep , void *data )
	// This routine sets the supplied endpoint into the default
	// mode used in this application.  The specifics are:
	// blocking, synchronous, and using synch idle events with
	// the standard YieldingNotifier.
{
	OSStatus junk = kOTNoError ;
	OTAssert ("SetDefaultEndpointModes:invalid ref", ep != kOTInvalidEndpointRef ) ;
	junk = OTSetAsynchronous(ep);
	OTAssert("SetDefaultEndpointModes: Could not set asynchronous", junk == noErr);
/*
	junk = OTSetBlocking(ep);
	OTAssert("SetDefaultEndpointModes: Could not set blocking", junk == noErr);
	junk = OTSetSynchronous(ep);
	OTAssert("SetDefaultEndpointModes: Could not set synchronous", junk == noErr);
	junk = OTSetBlocking(ep);
	OTAssert("SetDefaultEndpointModes: Could not set blocking", junk == noErr);
*/
	junk = OTInstallNotifier(ep, gOTNotifierUPP, data);
	OTAssert("SetDefaultEndpointModes: Could not install notifier", junk == noErr);
/*
	junk = OTUseSyncIdleEvents(ep, true);
	OTAssert("SetDefaultEndpointModes: Could not use sync idle events", junk == noErr);
*/
}
Пример #2
0
int
commScanAddr(
	commScanAddrReq_t *		req,	// Request
	commScanAddrResp_t *	resp)	// Response (or NULL)
{
	commScanAddrReq_t	reqDummy;
	commScanAddrResp_t	respDummy;
	ip_adr_t* 			adr;
	OSStatus			err;
	InetHostInfo		theHost;

	if (req == NULL)
		req = (commScanAddrReq_t *)memset(&reqDummy, 0, sizeof(*req));
	if (resp == NULL)
		resp = &respDummy;

	DPRINT(("@TRUMP commScanAddr(%s):\n", req->printable));

	if (req->size < sizeof(ip_adr_t)) {
		resp->status = comm_STATUS_FULL;
		return FALSE;
	}

	adr = (ip_adr_t*) req->address;

	//	convert the dotted decimal address or host name to an IP address (we do
	//	this sync.)

	OTSetSynchronous(gInetService);
	err = OTInetStringToAddress(gInetService, req->printable, &theHost);
	OTSetAsynchronous(gInetService);
	if (err != noErr) {

		//{
		//	Str255	theString;
		//
		//	NumToString(err, theString);
		//	DebugStr(theString);
		//}

		DPRINT(("@TRUMP commScanAddr: resolve failed!\n"));
		resp->status = comm_STATUS_BAD;
	    return FALSE;
	}

	*adr = theHost.addrs[0];		//	we only want the first address

	//	return the length of the address

	resp->length = sizeof(ip_adr_t);
	resp->status = comm_STATUS_OK;

	return (TRUE);
}
Пример #3
0
void _MD_InitNetAccess()
{
	OSErr		err;
	OSStatus    errOT;
	PRBool 		hasOTTCPIP = PR_FALSE;
	PRBool 		hasOT = PR_FALSE;
	long 		gestaltResult;
	PRThread *me = _PR_MD_CURRENT_THREAD();
	
	err = Gestalt(gestaltOpenTpt, &gestaltResult);
	if (err == noErr)
		if (gestaltResult & GESTALT_OPEN_TPT_PRESENT)
			hasOT = PR_TRUE;
	
	if (hasOT)
		if (gestaltResult & GESTALT_OPEN_TPT_TCP_PRESENT)
			hasOTTCPIP = PR_TRUE;
		
	PR_ASSERT(hasOTTCPIP == PR_TRUE);

	errOT = InitOpenTransport();
	PR_ASSERT(err == kOTNoError);

	sSvcRef = OTOpenInternetServices(kDefaultInternetServicesPath, NULL, &errOT);
	if (errOT != kOTNoError) return;	/* no network -- oh well */
	PR_ASSERT((sSvcRef != NULL) && (errOT == kOTNoError));

    /* Install notify function for DNR Address To String completion */
	errOT = OTInstallNotifier(sSvcRef, NotifierRoutine, me);
	PR_ASSERT(errOT == kOTNoError);

    /* Put us into async mode */
	errOT = OTSetAsynchronous(sSvcRef);
	PR_ASSERT(errOT == kOTNoError);

/* XXX Does not handle absence of open tpt and tcp yet! */
}
Пример #4
0
static int DoDialogItem(DialogPtr dlog, short itemHit) {
		short type,okay=FALSE,keepGoing=TRUE,val;
		Handle hndl; Rect box; Point pt;
		unsigned char *p,str[256];

		if (itemHit<1 || itemHit>=LASTITEM)
			return(keepGoing);				/* Only legal items, please */

		GetDialogItem(dlog,itemHit,&type,&hndl,&box);
		switch(type) {
			case ctrlItem+btnCtrl:
				switch(itemHit) {
					case BUT1_OK:

						//	the default is that we're done

						keepGoing = FALSE; okay = TRUE;

						//	check to see if the name that has been entered can be resolved

						{
							extern InetSvcRef	gInetService;

							Str255				theString;
							InetHostInfo		theHost;
							short				aShort;
							OSStatus			err;

							GetDlgString(dlog, EDIT5, theString);		//	machine name
							ParamText(theString, "\p", "\p", "\p");		//	show the name in the dialog
							p2cstr(theString);

							OTSetSynchronous(gInetService);
							err = OTInetStringToAddress(gInetService, theString, &theHost);
							OTSetAsynchronous(gInetService);
							if (err != noErr) {

								//	the name cannot be looked up, ask the user if they want
								//	to add the entry anyway

								aShort = CautionAlert(1501, nil);		//	returns 1 if OK to add
								if (aShort != 1) {
									keepGoing = TRUE; okay = FALSE;
								}

							}

						}

						break;
					case BUT2_Cancel:
						keepGoing = FALSE;
						break;
					}
				break;
			case ctrlItem+chkCtrl:
				break;
			case ctrlItem+radCtrl:
				break;
			case ctrlItem+resCtrl:
				break;
			case statText:
				switch(itemHit) {
					case STXT3_Host:		/* NOT Enabled */
						break;
					case STXT4_Notes:		/* NOT Enabled */
						break;
					case STXT7_Enter:		/* NOT Enabled */
						break;
					}
				break;
			case editText:
				switch(itemHit) {
					case EDIT5:
						break;
					case EDIT6:
						break;
					}
				break;
			case iconItem:
				break;
			case picItem:
				break;
			case userItem:
				break;
			}

		if (okay) keepGoing = AnyBadValues(dlog);
		return(keepGoing);
	}
Пример #5
0
int
commInit(
	commInitReq_t *		req,		// Request (or NULL)
	commInitResp_t *	resp)		// Response (or NULL)
{
	commInitReq_t		reqDummy;
	commInitResp_t		respDummy;
	ip_adr_t adr_broadcast;
	ip_adr_t *padr;
	OSStatus			err;
	extern Str255	gSavedSelection;
//	DebugStr ( "\pcommInit()" );
	DPRINT(("@TRUMP commInit(): "));

	if (req == NULL)
		req = (commInitReq_t *)memset(&reqDummy, 0, sizeof(*req));
	if (resp == NULL)
		resp = &respDummy;

	scratch_flat = malloc(MAX_RAW_PKTLEN);
	//scratch_flat = my_dos_malloc(MAX_RAW_PKTLEN, &scratch_seg, &scratch_off, &scratch_selector);
	if (!scratch_flat) {
		DPRINT(("commInit: couldn't allocate DOS memory!\n"));
		resp->status = comm_STATUS_BAD;
		return FALSE;
	}

	//	check for the existanct of OpenTransport
	if(!OpenTransportExists() || !OpenTransportInetExists()) {
		//DebugStr("\pOpen Transport Does Not Exist");
		DPRINT(("commInit: UDP ABI not found\n"));
		resp->status = comm_STATUS_NETWORK_NOT_PRESENT;
		free(scratch_flat);
		return FALSE;
	}

	//	Initialize OpenTransport
	err = InitOpenTransport();
	if (err != noErr) {
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);
		return FALSE;
	}

	//	initialize Internet Services

	gInetService = OTOpenInternetServices(kDefaultInternetServicesPath, 0, &err);
	if (err != noErr) {
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);
		return FALSE;
	}

	//	open an endpoint for sending and recieving data

	err = CreateAndConfigUDP(&gUDPEndpoint);
	if (err != noErr) {
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);

		ShutDownUDP();

		return FALSE;
	}

	//	create the peer table

	peertab = assoctab_create(sizeof(ip_adr_t));
	if (!peertab) {
		// ABORT! Out of Memory
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);

		ShutDownUDP();

		return FALSE;
	}

	//	Get information about the Internet

	err = OTInetGetInterfaceInfo(&gInetInfo, kDefaultInetInterface);
	if (err != noErr) {
		//DebugStr("\pCannot Get Information About Default Interface");
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);

		ShutDownUDP();

		return FALSE;
	}

	// Store our address in the peer table under the bogus ME handle
	padr = (ip_adr_t *)assoctab_subscript_grow(peertab, trump_HDL_ME);
	if (!padr) {
		DPRINT(("commInit: couldn't grow peer table\n"));
		resp->status = comm_STATUS_BAD;
		free(scratch_flat);
		assoctab_destroy(peertab);

		ShutDownUDP();

		return FALSE;
	}
	dprint_peertab(peertab);
	DPRINT(("commInit: saving handle %d adr %x at %p\n", trump_HDL_ME, gInetInfo.fAddress, padr));
	memcpy(padr, &gInetInfo.fAddress, sizeof(ip_adr_t));
	dprint_peertab(peertab);

	// Open a handle good for receiving packets on the standard port
	// SRC = (*,*)
	// DEST = (localhost, pt->port)
	adr_broadcast = 0xffffffff;
	hdl_rx = trump_adr2hdl(adr_broadcast, SOCKET_MW2, SOCKET_MW2, TRUE);
	if (hdl_rx == trump_HDL_NONE) {
		DPRINT(("commInit: couldn't open handle for listening\n"));
		resp->status = comm_STATUS_BUSY;
		free(scratch_flat);
		assoctab_destroy(peertab);

		ShutDownUDP();

		return FALSE;
	}
	/*
	if ((req->flags & comm_INIT_FLAGS_RESUME) == 0) {
		if (!DoHostListDialog()) {
			resp->status = comm_STATUS_EMPTY;
			free(scratch_flat);
			assoctab_destroy(peertab);

			ShutDownUDP();

			return FALSE;
		}
	} else {

		//	we need to load the last string selected when we are resuming

		OpenPrefsFile();
		p2cstr(gSavedSelection);		//	the apps like C-strings
		ClosePrefsFile();

	}
	*/
	//	initialize our address list to nothing

	InitAddressList();

	//	add our own address to the beginning of the list (it MUST Be the first
	//	address in our list - we broadcast to all _other_ addresses in our list)

	AddAddressToList(gInetInfo.fAddress);

	//	add the address from the dialog to our broadcast list if the user chose one

	if (gSavedSelection[0] != 0) {
		InetHostInfo	theHostInfo;

		OTSetSynchronous(gInetService);
		err = OTInetStringToAddress(gInetService, gSavedSelection, &theHostInfo);
		OTSetAsynchronous(gInetService);

		if (err == noErr) {
			AddAddressToList(theHostInfo.addrs[0]);
		}
	}

	resp->status = comm_STATUS_OK;
	DPRINT(("commInit: success\n"));
	return TRUE;
}
Пример #6
0
NMErr
OTIPEnumerator::StartEnumeration(void)
{
	TEndpointInfo	info;
	NMErr			status = kNMNoError;
	TBind			request;
	TOption			optBuf;
	//NMUInt8			optBuf[64];
	//NMUInt8			fooBuf[32];
	TOptMgmt		cmd;
	//NMUInt8 			*foo = fooBuf;

	
	//	If they don't want us to actively get the enumeration, there is nothing to do
	if (! bActive)
		return kNMNoError;
	
	//	first clear out any current items
	(mCallback)(mContext, kNMEnumClear, NULL);	// [Edmark/PBE] 11/16/99 added

	bFirstIdle = true;
	
	//	Create an OT endpoint
	mEP = OTOpenEndpoint(OTCreateConfiguration(kUDPName), 0, &info, &status);
	if (status)
		goto error;

	// fill in the option request
	cmd.flags = T_NEGOTIATE;
	cmd.opt.len = kOTFourByteOptionSize;
	cmd.opt.maxlen = kOTFourByteOptionSize;
	cmd.opt.buf = (NMUInt8*)&optBuf;

	// fill in the toption struct
	optBuf.len = sizeof(TOption);
	optBuf.level = INET_IP;
	optBuf.name = kIP_BROADCAST;
	optBuf.status = 0;
	optBuf.value[0] = 1;

/*
	cmd.opt.len = 0;
	cmd.opt.maxlen = 64;
	cmd.opt.buf = (NMUInt8*)optBuf;
	cmd.flags = T_NEGOTIATE;

	//	Option management kinda sucks
	strcpy((char *) fooBuf, "Broadcast = 1");
	status = OTCreateOptions(kRawIPName, (char **)&foo, &cmd.opt);
*/

	status = OTOptionManagement(mEP, &cmd, &cmd);
	if (status)
		goto error;
	
	//	Allocate the buffer for receiving the endpoint
	mIncomingData.udata.buf = (NMUInt8 *) InterruptSafe_alloc(info.tsdu);
	if (mIncomingData.udata.buf == NULL){
		status = kNSpMemAllocationErr;
		goto error;
	}
	
	mIncomingData.udata.maxlen = info.tsdu;
	
	//	Bind it
	request.addr.buf = NULL;
	request.addr.len = 0;
	request.addr.maxlen = 0;
	request.qlen = 0;
	
	status = OTBind(mEP, &request, NULL);
	if (status)
		goto error;

	OTSetNonBlocking(mEP);
	
	//	Get our interface info (for the broadcast address)
	//	Do this after we bind so that we know the interface is live
	if (! bGotInterfaceInfo)
	{
		status = OTInetGetInterfaceInfo(&mInterfaceInfo, kDefaultInetInterface);
		if (status)
			goto error;
		
		bGotInterfaceInfo = true;
	}
	
	//	Install notifier
	status = OTInstallNotifier(mEP, mNotifier.fUPP, this);
	if (status)
		goto error;
	
	//	Make is asynchronous
	status = OTSetAsynchronous(mEP);
	if (status)
		goto error;
	
	//	Send out the query
	mEnumPeriod = 250;
	status = SendQuery();

error:
	if (status)
	{
		if (mEP)
		{
			OTCloseProvider(mEP);			// ignore errors
			mEP = kOTInvalidEndpointRef;
		}
	}
	return status;
}