Exemple #1
0
/* MacOS implementation by Roy Wood
 */
const char *SDLNet_ResolveIP(IPaddress *ip)
{
	if (ip != nil)
	{
	InetHost				theIP;
	static InetDomainName	theInetDomainName;
	OSStatus				theOSStatus;
	
		
		/*	Default result will be null string */
		
		theInetDomainName[0] = '\0';	
		
		
		/*	Do a reverse DNS lookup */
		
		theIP = ip->host;
		
		theOSStatus = OTInetAddressToName(dnsStatus.dns,theIP,theInetDomainName);
		
		/*	If successful, return the result */
			
		if (theOSStatus == kOTNoError)
		{
			while( dnsStatus.stat != dnsResolved )
				{ /*should we yield or what ? */ }
			return(theInetDomainName);
		}
	}
	
	SDLNet_SetError("Can't perform reverse DNS lookup");
	
	return(NULL);
}
Exemple #2
0
GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t sbuf)
{
  InetDomainName name ;
  if ( GSocket_Verify_Inited() == FALSE )
    return GSOCK_IOERR ;

  assert(address != NULL);
  CHECK_ADDRESS(address, INET, GSOCK_INVADDR);

  OTInetAddressToName( gInetSvcRef , address->m_host , name ) ;
  strncpy( hostname , name , sbuf ) ;
  return GSOCK_NOERROR;
}
Exemple #3
0
struct hostent *
gethostbyaddr( InetHost *addrP, int len, int type)
{
	extern EndpointRef gDNRep;
	OSStatus	theErr = noErr;
	char	addrString[255];
	int		l;
  
	// Check that the arguments are appropriate
	if( len != INADDRSZ || (type != AF_INET /* && type != AF_UNSPEC */)){
		ncbi_SetErrno( EAFNOSUPPORT);
		return( NULL);
	}
  
	// open or get the current resolver reference
	if( gDNRep == kOTInvalidEndpointRef){
		theErr = ot_DNRInit();
		if( theErr != kOTNoError){
			ncbi_SetErrno( theErr);
			return (NULL);
		}
	}

#if NETDB_DEBUG >= 5
	printf("gethostbyaddr: Looking up hostname for address 0x%8x\n", *addrP);
#endif

	/*  OpenTransport call to get the address as a string */
	theErr = OTInetAddressToName( gDNRep, *(InetHost*)addrP, addrString);
	if( theErr == noErr){
		// for some reason the names have a trailing "."???  
		// Next couple of lines remove it
		l = strlen( addrString);
		if( addrString[l-1] == '.'){
			addrString[l-1] = '\0';
		}
		// with the full name, use gethostbyname to fill in all the blanks...
		return (gethostbyname(addrString) );
	}
	else{
		ncbi_SetErrno( theErr);
	}
	return( NULL);
}
Exemple #4
0
int IpAddr2Name(char *hostname)
{
#if !TARGET_API_MAC_CARBON
  struct hostInfo hInfoMacTCP;
  OSErr err;
  int cnt, tmp;
  char *cptr;
  Boolean done;
#endif
  OSStatus lStatus;
  InetHost lHostAddr;

  if (!slNetChecked) {
    slNetPresent = OpenNetwork();
    slNetChecked = 1;
  }

  if (slNetPresent == 1) {

    /* turn ascii with periods into a long */
    lStatus = OTInetStringToHost(hostname, &lHostAddr);
    if (lStatus != noErr) return 0;

    /* turn the long into a reverse-resolved name */
    sSvcRef.done=false;
    lStatus=OTInetAddressToName(sSvcRef.ref,lHostAddr,hostname);
    if (!lStatus) {
      do {
	MacIdle();
      } while (!sSvcRef.done);
      lStatus=sSvcRef.result;
    }
    if (!lStatus) {
      if (hostname[strlen(hostname)-1]=='.') hostname[strlen(hostname)-1]=0;
      return(1);
    }
  }
#if !TARGET_API_MAC_CARBON
  else if (slNetPresent==2) {
    lHostAddr=0;
    cptr=hostname;
    for (cnt=0; cnt<4; ++cnt) {
      if (!ISDIGIT(*cptr)) return(0);
      tmp=atoi(cptr);
      if (tmp<0 || tmp>255) return(0);
      lHostAddr=(lHostAddr<<8)|tmp;
      while (ISDIGIT(*cptr)) ++cptr;
      if (cnt!=3 && *cptr!='.') return(0);
      ++cptr;
    }
    memset(&hInfoMacTCP, 0, sizeof(hInfoMacTCP));
    done=false;
    err = AddrToName(lHostAddr, &hInfoMacTCP, gMacTCPDNRResultProcUPP,
		     (char*)&done);
    if (err == cacheFault) {
      while (!done) MacIdle();
      err = hInfoMacTCP.rtnCode;
    }
    if (err == noErr) {
      hInfoMacTCP.cname[254] = 0;
      (void)strcpy(hostname, hInfoMacTCP.cname);
      if (hostname[strlen(hostname)-1]=='.') hostname[strlen(hostname)-1]=0;
      return(1);
    }
  }
#endif
  return 0;
} /* end IpAddr2Name() */