const char * MyMachineName(void) { const struct hostent *myEntry; static char returnValue[100] = ""; /* If we have a value in returnValue, then we've already done the work. */ if(returnValue[0] == '\0') { /* try the simple case first */ if(gethostname(returnValue, sizeof(returnValue)) == -1) { return 0; } if(!strchr(returnValue, '.')) { /* Okay, that didn't work; take what we can get from the DNS. */ myEntry = LookupByName(returnValue); if(myEntry == NULL) { return NULL; } strncpy(returnValue, BestHostName(myEntry), sizeof(returnValue)); returnValue[sizeof(returnValue) - 1] = '\0'; } } return returnValue; }
int IPAddressValues(const char *machineOrAddress, IPAddress *addressList, unsigned int atMost) { const struct hostent *hostEntry; int i; int itsAnAddress; /* ** inet_addr() has the weird behavior of returning an unsigned quantity but ** using -1 as an error value. Furthermore, the value returned is sometimes ** int and sometimes long, complicating the test. Once inet_aton() is more ** widely available, we should switch to using it instead. */ itsAnAddress = (inet_addr(machineOrAddress) ^ -1) != 0; if(itsAnAddress && (atMost == 1)) { *addressList = inet_addr(machineOrAddress); return 1; } hostEntry = itsAnAddress ? LookupByAddress(inet_addr(machineOrAddress)) : LookupByName(machineOrAddress); if(hostEntry == NULL) { return 0; } else if(atMost == 0) { return 1; } for(i = 0; i < atMost; i++) { if(hostEntry->h_addr_list[i] == NULL) { break; } addressList[i] = ((struct in_addr **)hostEntry->h_addr_list)[i]->s_addr; } return i; }
int ttyioStringToParity(char *target) { static int notfound = TTYIO_PARITY_BAD; return LookupByName(target, ParityMap, notfound); }
int ttyioStringToFlow(char *target) { static int notfound = TTYIO_FLOW_BAD; return LookupByName(target, FlowMap, notfound); }