diff --git a/cmUdpPort.c b/cmUdpPort.c index a9a04fc..199cbbc 100644 --- a/cmUdpPort.c +++ b/cmUdpPort.c @@ -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; +} diff --git a/cmUdpPort.h b/cmUdpPort.h index 33c2dca..618256c 100644 --- a/cmUdpPort.h +++ b/cmUdpPort.h @@ -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