From 353deeee5d4d2345ae596adac6c9fb5f3d617f41 Mon Sep 17 00:00:00 2001 From: kpl Date: Fri, 26 Apr 2013 15:33:13 -0700 Subject: [PATCH] cmUdpPort.h/c:Added cmHostName(). --- cmUdpPort.c | 17 +++++++++++++++++ cmUdpPort.h | 5 +++++ 2 files changed, 22 insertions(+) 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