cmUdpPort.h/c:Added cmHostName().

This commit is contained in:
kpl 2013-04-26 15:33:13 -07:00
parent c6a3496639
commit 353deeee5d
2 changed files with 22 additions and 0 deletions

View File

@ -562,3 +562,20 @@ const cmChar_t* cmUdpAddrToString( cmUdpH_t h, const struct sockaddr_in* addr )
p->ntopBuf[INET_ADDRSTRLEN]=0;
return p->ntopBuf;
}
unsigned cmUdpHostNameMaxCharCount()
{ return HOST_NAME_MAX+1; }
cmUdpRC_t cmUdpHostName( cmChar_t* buf, unsigned bufByteCnt )
{
if( bufByteCnt > 0 )
buf[0] = 0;
if( bufByteCnt < cmUdpHostNameMaxCharCount() )
return kBufTooSmallUdpRC;
if( gethostname(buf,bufByteCnt-1) != 0 )
return kHostNameFailUdpRC;
return kOkUdpRC;
}

View File

@ -24,6 +24,8 @@ extern "C" {
kThreadFailUdpRC,
kQueueFailUdpRC,
kRecvBufOverflowUdpRC,
kBufTooSmallUdpRC,
kHostNameFailUdpRC,
kTimeOutUdpRC
};
@ -118,6 +120,9 @@ extern "C" {
const cmChar_t* cmUdpAddrToString( cmUdpH_t h, const struct sockaddr_in* addr );
unsigned cmUdpHostNameMaxCharCount();
cmUdpRC_t cmUdpHostName( cmChar_t* buf, unsigned bufByteCnt );
#ifdef __cplusplus
}
#endif