From 0dd7cdbbe9ca1b6aa057c76558a386a2e02c326a Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 1 May 2013 15:08:58 -0700 Subject: [PATCH] cmUdpPort.h/c:Added cmInvalidUdpPortNumber and check for definition of HOST_NAME_MAX. --- cmUdpPort.c | 7 +++++++ cmUdpPort.h | 13 ++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cmUdpPort.c b/cmUdpPort.c index 0048fbe..e981be6 100644 --- a/cmUdpPort.c +++ b/cmUdpPort.c @@ -18,6 +18,10 @@ #define cmUdp_SYS_ERR (-1) #define cmUdp_NULL_SOCK (-1) +#ifndef HOST_NAME_MAX +#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX +#endif + enum { kIsConnectedUdpFl = 0x01, @@ -99,6 +103,9 @@ cmUdpRC_t _cmUdpFree( cmUdp_t* p ) cmUdpRC_t _cmUdpInitAddr( cmUdp_t* p, const char* addrStr, cmUdpPort_t portNumber, struct sockaddr_in* retAddrPtr ) { memset(retAddrPtr,0,sizeof(struct sockaddr_in)); + + if( portNumber == kInvalidUdpPortNumber ) + return cmErrMsg(&p->err,kInvalidPortNumbUdpRC,"The port number %i cannot be used.",kInvalidUdpPortNumber); if( addrStr == NULL ) retAddrPtr->sin_addr.s_addr = htonl(INADDR_ANY); diff --git a/cmUdpPort.h b/cmUdpPort.h index 2d7cd48..6959f43 100644 --- a/cmUdpPort.h +++ b/cmUdpPort.h @@ -26,12 +26,13 @@ extern "C" { kRecvBufOverflowUdpRC, kBufTooSmallUdpRC, kHostNameFailUdpRC, + kInvalidPortNumbUdpRC, kTimeOutUdpRC }; - typedef cmRC_t cmUdpRC_t; - typedef cmHandle_t cmUdpH_t; - typedef u_short cmUdpPort_t; + typedef cmRC_t cmUdpRC_t; + typedef cmHandle_t cmUdpH_t; + typedef unsigned short cmUdpPort_t; extern cmUdpH_t cmUdpNullHandle; @@ -46,6 +47,12 @@ extern "C" { }; + enum + { + // port 0 is reserved by and is therefore a convenient invalid port number + kInvalidUdpPortNumber = 0 + }; + cmUdpRC_t cmUdpAlloc( cmCtx_t* ctx, cmUdpH_t* hp ); cmUdpRC_t cmUdpFree( cmUdpH_t* hp );