Ejemplo n.º 1
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);
}
Ejemplo n.º 2
0
PRInt32 _MD_closesocket(PRInt32 osfd)
{
	OSStatus err;
	EndpointRef endpoint = (EndpointRef) osfd;
	PRThread *me = _PR_MD_CURRENT_THREAD();

	if (endpoint == NULL) {
		err = kEBADFErr;
		goto ErrorExit;
	}
		
	if (me->io_pending && me->io_fd == osfd)
		me->io_pending = PR_FALSE;

#if 0
	{
	OTResult state;
	state = OTGetEndpointState(endpoint);
	
	err = OTSndOrderlyDisconnect(endpoint);
	if (err != kOTNoError && err != kOTOutStateErr)
		goto ErrorExit;

	state = OTGetEndpointState(endpoint);
	
	err = OTUnbind(endpoint);
	if (err != kOTNoError && err != kOTOutStateErr)
		goto ErrorExit;

	state = OTGetEndpointState(endpoint);

	err = OTSetSynchronous(endpoint);
	if (err != kOTNoError)
		goto ErrorExit;

	err = OTSetBlocking(endpoint);
	if (err != kOTNoError)
		goto ErrorExit;
	}
#endif

	(void) OTSndOrderlyDisconnect(endpoint);

	err = OTCloseProvider(endpoint);
	if (err != kOTNoError)
		goto ErrorExit;

	return kOTNoError;

ErrorExit:
	macsock_map_error(err);
    return -1;
}                               
Ejemplo n.º 3
0
OSStatus ot_DNRInit(void)
{
	OSStatus theError = kOTNoError;

	// First, check to see if we've already initialized.  If so, then just return...
	if( gDNRep != kOTInvalidProviderRef){
		return (kOTNoError);
	}

	// Next, check to see if any OT service has been used yet
	if (!gOTInited){
		theError = ot_OpenDriver();
	}

	// Get the internet services reference for DNS
	if( theError == kOTNoError){
#if TARGET_API_MAC_CARBON
		gDNRep = OTOpenInternetServicesInContext( kDefaultInternetServicesPath, 0, &theError, NULL);
#else
		gDNRep = OTOpenInternetServices( kDefaultInternetServicesPath, 0, &theError);
#endif
	}

	/* We have to choose to be synchronous or async, sync is simpler but
	 *	I think that async could be done in the future
	 */
	if( theError == kOTNoError){
		theError = OTSetSynchronous( gDNRep);
	}

	// Give OT a pointer to a notifier function that handles async events
	if( theError == kOTNoError){
		gDNRYieldNotifyUPP = NewOTNotifyUPP(DNRYieldNotifier);
		theError = OTInstallNotifier(gDNRep, gDNRYieldNotifyUPP, nil);
	}

	/* If we get idle events, then implementing a multi-threaded app shouldn't
	 *	be any big deal
	 */
	if( theError == kOTNoError){
		theError = OTUseSyncIdleEvents(gDNRep, true);
	}
	return( theError);
}
Ejemplo n.º 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);
	}
Ejemplo n.º 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;
}
Ejemplo n.º 6
0
int connect_chuukei_server(char *prf_name)
{
#ifndef MACINTOSH

#ifdef WINDOWS
	WSADATA wsaData;
	WORD wVersionRequested = (WORD) (( 1) |  ( 1 << 8));
#endif

	struct sockaddr_in ask;
	struct hostent *hp;

	if (read_chuukei_prf(prf_name) < 0)
	{
		printf("Wrong prf file\n");
		return (-1);
	}

	if (init_buffer() < 0)
	{
		printf("Malloc error\n");
		return (-1);
	}

#ifdef WINDOWS
	if (WSAStartup(wVersionRequested, &wsaData))
	{
		msg_print("Report: WSAStartup failed.");
		return (-1);
	}
#endif

	printf("server = %s\nport = %d\n", server_name, server_port);

	if ((hp = gethostbyname(server_name)) != NULL)
	{
		memset(&ask, 0, sizeof(ask));
		memcpy(&ask.sin_addr, hp->h_addr_list[0], hp->h_length);
	}
	else
	{
		if ((ask.sin_addr.s_addr=inet_addr(server_name)) == 0)
		{
			printf("Bad hostname\n");
			return (-1);
		}
	}

	ask.sin_family = AF_INET;
	ask.sin_port = htons((unsigned short)server_port);

#ifndef WINDOWS
	if ((sd=socket(PF_INET,SOCK_STREAM, 0)) < 0)
#else
	if ((sd=socket(PF_INET,SOCK_STREAM, 0)) == INVALID_SOCKET)
#endif
	{
		printf("Can't create socket\n");
		return (-1);
	}

	if (connect(sd, (struct sockaddr *)&ask, sizeof(ask)) < 0)
	{
		close(sd);
		printf("Can't connect %s port %d\n", server_name, server_port);
		return (-1);
	}

	return (0);
#else	/* MACINTOSH */
	OSStatus err;
	InetHostInfo 	response;
	InetHost 		host_addr;
	InetAddress 	inAddr;
	TCall 			sndCall;
	Boolean			bind	= false;
	OSStatus 	junk;

	if (read_chuukei_prf(prf_name) < 0){
		printf("Wrong prf file\n");
		return (-1);
	}
	
	init_buffer();
	
	printf("server = %s\nport = %d\n", server_name, server_port);


#if TARGET_API_MAC_CARBON
	err = InitOpenTransportInContext(kInitOTForApplicationMask, NULL);
#else
	err = InitOpenTransport();
#endif

	memset(&response, 0, sizeof(response));


#if TARGET_API_MAC_CARBON
	inet_services = OTOpenInternetServicesInContext(kDefaultInternetServicesPath, 0, &err, NULL);
#else
	inet_services = OTOpenInternetServices(kDefaultInternetServicesPath, 0, &err);
#endif
	
	if (err == noErr) {
		err = OTInetStringToAddress(inet_services, (char *)server_name, &response);
		
		if (err == noErr) {
			host_addr = response.addrs[0];
		} else {
			printf("Bad hostname\n");
		}
		
#if TARGET_API_MAC_CARBON
		ep = (void *)OTOpenEndpointInContext(OTCreateConfiguration(kTCPName), 0, nil, &err, NULL);
#else
		ep = (void *)OTOpenEndpoint(OTCreateConfiguration(kTCPName), 0, nil, &err);
#endif

		if (err == noErr) {
			err = OTBind(ep, nil, nil);
			bind = (err == noErr);
	    }
	    if (err == noErr){
		OTInitInetAddress(&inAddr, server_port, host_addr);
			
			sndCall.addr.len 	= sizeof(InetAddress);				
			sndCall.addr.buf	= (unsigned char*) &inAddr;
			sndCall.opt.buf 	= nil;		/* no connection options */
			sndCall.opt.len 	= 0;
			sndCall.udata.buf 	= nil;		/* no connection data */
			sndCall.udata.len 	= 0;
			sndCall.sequence 	= 0;		/* ignored by OTConnect */
			
			err = OTConnect(ep, &sndCall, NULL);
			
			if( err != noErr ){
				printf("Can't connect %s port %d\n", server_name, server_port);
			}
		}
		
		err = OTSetSynchronous(ep);
		if (err == noErr)		
			err = OTSetBlocking(ep);
		
	}
	
	if( err != noErr ){
		if( bind ){
			OTUnbind(ep);
		}
		/* Clean up. */
		if (ep != kOTInvalidEndpointRef) {
			OTCloseProvider(ep);
			ep = nil;
		}
		if (inet_services != nil) {
			OTCloseProvider(inet_services);
			inet_services = nil;
		}
	
		return -1;
	}
	
	return 0;

#endif
}