Пример #1
0
PR_IMPLEMENT(struct hostent *) gethostbyname(const char * name)
{
	OSStatus err;
	PRUint32 index;
	PRThread *me = _PR_MD_CURRENT_THREAD();

	PrepareThreadForAsyncIO(me, sSvcRef, NULL);    

    err = OTInetStringToAddress(sSvcRef, (char *)name, &sHostInfo);
	if (err != kOTNoError)
		goto ErrorExit;

	WaitOnThisThread(me, PR_INTERVAL_NO_TIMEOUT);

	err = me->md.osErrCode;
	if (err != kOTNoError)
		goto ErrorExit;

	sHostEnt.h_name = sHostInfo.name;
	for (index=0; index<kMaxHostAddrs && sHostInfo.addrs[index] != NULL; index++)
		sAddresses[index] = &sHostInfo.addrs[index];
	sAddresses[index] = NULL;	
	sHostEnt.h_addr_list = (char **)sAddresses;

	return (&sHostEnt);

ErrorExit:
	macsock_map_error(err);
    return NULL;
}
Пример #2
0
/* Open Transport helper procedures */
static int LookUpInetHost(char *name, InetHost *result) {
	OSStatus err;

	// If the hostname is dots and numbers, like "128.32.122.13", we don't neet DNR
	err = OTInetStringToHost(name, result);
	if (err != noErr) {
		// We do need DNR.
		InetSvcRef tcpipProvider;
		InetHostInfo hinfo;
		
		tcpipProvider = OTOpenInternetServices(kDefaultInternetServicesPath, 0, &err);
		
		if (err != noErr) {
			post("е otudp: Error %d from OTOpenInternetServices().", err);
			return 0;
		}
		
		err = OTInetStringToAddress(tcpipProvider, name, &hinfo);
		OTCloseProvider(tcpipProvider);
		if (err != noErr) {
			post("е otudp: Error %d from OTInetStringToAddress", err);
			return 0;
		}
		*result = hinfo.addrs[0];
	}
	return 1;
}
Пример #3
0
static int LookUpInetHost(char *name, InetHost *result) {
	OSStatus err;

	// If the hostname is dots and numbers, like "128.32.122.13", we don't neet DNR
	err = OTInetStringToHost(name, result);
	if (err != noErr) {
		// We do need DNR.
		InetSvcRef tcpipProvider;
		InetHostInfo hinfo;
		
		tcpipProvider = OTOpenInternetServicesInContext(kDefaultInternetServicesPath, 0, &err, OTContext);
		
		if (err != noErr) {
			error("¥ otudp: Error %d from OTOpenInternetServices().", err);
			return 0;
		}
		
		err = OTInetStringToAddress(tcpipProvider, name, &hinfo);
		OTCloseProvider(tcpipProvider);
		if (err == kOTBadNameErr) {
			error("¥ otudp: Bad host name \"%s\"; not changing.", name);
		} else if (err != noErr) {
			error("¥ otudp: Error %d from OTInetStringToAddress; not changing host.", err);
			return 0;
		}
		*result = hinfo.addrs[0];
	}
	return 1;
}
Пример #4
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);
}
Пример #5
0
/* Resolve a host name and port to an IP address in network form */
int SDLNet_ResolveHost(IPaddress *address, const char *host, Uint16 port)
{
	int retval = 0;

	/* Perform the actual host resolution */
	if ( host == NULL ) {
		address->host = INADDR_ANY;
	} else {
/*		int a[4];

		address->host = INADDR_NONE;
		
		if ( sscanf(host, "%d.%d.%d.%d", a, a+1, a+2, a+3) == 4 ) {
			if ( !(a[0] & 0xFFFFFF00) && !(a[1] & 0xFFFFFF00) &&
			     !(a[2] & 0xFFFFFF00) && !(a[3] & 0xFFFFFF00) ) {
				address->host = ((a[0] << 24) |
				                 (a[1] << 16) |
				                 (a[2] <<  8) | a[3]);
				if ( address->host == 0x7F000001 ) {
					address->host = OTlocalhost;
				}
			}
		}
		
		if ( address->host == INADDR_NONE ) {*/
			InetHostInfo hinfo;
			
			/* Check for special case - localhost */
			if ( strcmp(host, "localhost") == 0 )
				return(SDLNet_ResolveHost(address, "127.0.0.1", port));

			/* Have OpenTransport resolve the hostname for us */
			retval = OTInetStringToAddress(dnsStatus.dns, (char *)host, &hinfo);
			if (retval == noErr) {
				while( dnsStatus.stat != dnsResolved )
					{WaitNextEvent(everyEvent, 0, 1, NULL );}
				address->host = hinfo.addrs[0];
			}
		//}
	}
	
	address->port = SDL_SwapBE16(port);

	/* Return the status */
	return(retval);
}
Пример #6
0
/*---------------------------------------------------------------------------*/
ExportFunc uint32 AGNetGetHostAddr(AGNetCtx *ctx, char *name) 
{
    OSStatus err;
    InetHostInfo response;
    
    if (NULL == ctx || NULL == name)
        return 0;

    bzero(&response, sizeof(InetHostInfo));

    err = OTInetStringToAddress(ctx->inet_services, name, &response);
    
    if (err == noErr)
        return response.addrs[0];

    return 0;
}
Пример #7
0
GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
{
  InetHostInfo hinfo ;
  OSStatus ret ;

 if ( GSocket_Verify_Inited() == FALSE )
    return GSOCK_IOERR ;

  assert(address != NULL);

  CHECK_ADDRESS(address, INET, GSOCK_INVADDR);
  ret = OTInetStringToAddress( gInetSvcRef , (char*) hostname , &hinfo ) ;
  if ( ret != kOTNoError )
  {
  	address->m_host = INADDR_NONE ;
    address->m_error = GSOCK_NOHOST;
    return GSOCK_NOHOST;
  }
  address->m_host = hinfo.addrs[0] ;
  return GSOCK_NOERROR;
}
Пример #8
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);
	}
Пример #9
0
struct hostent *
gethostbyname(const char *name)
{
	extern EndpointRef gDNRep;
	OSStatus	theErr;
	int i, l;

	// open or get the current resolver reference
	if( gDNRep == kOTInvalidEndpointRef){
		theErr = ot_DNRInit();
		if( theErr != kOTNoError){
			ncbi_SetOTErrno( theErr);
			return (NULL);
		}
	}

	// Call OT to resolve the address...
	theErr = OTInetStringToAddress( gDNRep, (char*) name, &hinfo);

	if( theErr != kOTNoError){
		ncbi_SetOTErrno( theErr);
		return( NULL);
	}

	// sometimes the hostname returned has a trailing dot?? (nuke it)
	l = strlen( hinfo.name);
	if( hinfo.name[l-1] == '.'){
		hinfo.name[l-1] = '\0';
	}

#if NETDB_DEBUG >= 5
	printf("gethostbyname: name '%s' returned the following addresses:\n", name);
	for( i = 0; i < kMaxHostAddrs; i++){
		if( hinfo.addrs[i] == 0) break;
		printf("%08x\n", hinfo.addrs[i]);
	}
#endif

	// copy the official hostname to the return struct and first alias
	strcpy( unixHost.h_name, hinfo.name);

	// copy the name passed in as the first alias
	strncpy( aliases[0], name, kMaxHostNameLen);
	aliases[0][kMaxHostNameLen] = '\0';

	// if the answer is different from the query, copy the query as another alias
	theErr = strcmp( name, hinfo.name);
	if( theErr != 0){
		strncpy( aliases[1], hinfo.name, kMaxHostNameLen);
		aliases[1][kMaxHostNameLen] = '\0';
	}

	// This block will not need to be changed if we find a way to determine
	// more aliases than are currently implemented
	for( i = 0; i <= MAXALIASES; i++){
		if( aliases[i][0] != '\0'){
			aliasPtrs[i] = &aliases[i][0];
		} else{
			aliasPtrs[i] = NULL;
		}
	}
	
	// copy all of the returned addresses
	for( i = 0; i < kMaxHostAddrs && hinfo.addrs[i] != 0; i++){
		addrPtrs[i] = &hinfo.addrs[i];
	}

	// make the rest NULL
	for( ; i < kMaxHostAddrs; i++){
		addrPtrs[i] = NULL;
	}
	return( &unixHost);
}
Пример #10
0
    for (s = ot.socklist; s !=NULL; s = s->next) {
	OTUnbind(s->ep);
	OTCloseProvider(s->ep);
    }

    CloseOpenTransport();
}

SockAddr ot_namelookup(char const *host, char **canonicalname)
{
    SockAddr ret = snew(struct SockAddr_tag);
    char *realhost;

    /* Casting away const -- hope OTInetStringToAddress is sensible */
    ret->error = OTInetStringToAddress(ot.inetsvc, (char *)host,
				       &ret->hostinfo);
    ret->resolved = TRUE;

    if (ret->error == kOTNoError)
	realhost = ret->hostinfo.name;
    else
	realhost = "";
    *canonicalname = snewn(1+strlen(realhost), char);
    strcpy(*canonicalname, realhost);
    return ret;
}

SockAddr ot_nonamelookup(char const *host)
{
    SockAddr ret = snew(struct SockAddr_tag);
    
Пример #11
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;
}
Пример #12
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
}