added ipAddrToHostName
This commit is contained in:
@@ -55,48 +55,24 @@ void bsdSockRelease()
|
||||
}
|
||||
|
||||
/*
|
||||
* ipAddrToA()
|
||||
* (convert IP address to ASCII host name)
|
||||
* ipAddrToHostName
|
||||
*/
|
||||
void epicsShareAPI ipAddrToA
|
||||
(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
|
||||
epicsShareFunc unsigned epicsShareAPI ipAddrToHostName
|
||||
(const struct in_addr *pAddr, char *pBuf, unsigned bufSize)
|
||||
{
|
||||
char *pString;
|
||||
struct hostent *ent;
|
||||
# define maxPortDigits 5u
|
||||
|
||||
if (bufSize<1) {
|
||||
return;
|
||||
if (bufSize<1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (paddr->sin_family!=AF_INET) {
|
||||
strncpy(pBuf, "<Ukn Addr Type>", bufSize-1);
|
||||
/*
|
||||
* force null termination
|
||||
*/
|
||||
pBuf[bufSize-1] = '\0';
|
||||
}
|
||||
else {
|
||||
ent = gethostbyaddr((char *) &paddr->sin_addr,
|
||||
sizeof(paddr->sin_addr), AF_INET);
|
||||
if(ent){
|
||||
pString = ent->h_name;
|
||||
}
|
||||
else{
|
||||
pString = inet_ntoa (paddr->sin_addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* allow space for the port number
|
||||
*/
|
||||
if (bufSize>maxPortDigits+strlen(pString)) {
|
||||
sprintf (pBuf, "%.*s:%u", bufSize-maxPortDigits-1,
|
||||
pString, ntohs(paddr->sin_port));
|
||||
}
|
||||
else {
|
||||
sprintf (pBuf, "%.*s", bufSize-1, pString);
|
||||
}
|
||||
ent = gethostbyaddr((char *) pAddr, sizeof (*pAddr), AF_INET);
|
||||
if (ent) {
|
||||
strncpy (pBuf, ent->h_name, bufSize);
|
||||
pBuf[bufSize-1] = '\0';
|
||||
return strlen (pBuf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user