Esempio n. 1
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;
}
Esempio n. 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;
}
Esempio n. 3
0
PR_IMPLEMENT(unsigned long) inet_addr(const char *cp)
{
	OSStatus err;
	InetHost host;	

	err = OTInetStringToHost((char*) cp, &host);
	PR_ASSERT(err == kOTNoError);
	
	return host;
}
Esempio n. 4
0
/*
 * inet_aton() - converts an IP address in dotted string notation to a 32 bit IPv4 address
 *               Function returns 1 on success and 0 on failure.
 */
int inet_aton(const char *str, struct in_addr *addr)
{
	InetHost host;
	OSStatus theError;

	if((str == NULL) || (addr == NULL)){
		return( INET_FAILURE);
	}
  
	theError = OTInetStringToHost((char *) str, &host);
	if(theError != kOTNoError){
		ncbi_SetErrno( theError);
		return( INET_FAILURE);
	}
	addr->s_addr = host;
	return(INET_SUCCESS);  
}
Esempio n. 5
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() */