cmUdpPort.h/c:Added cmUdpAddrToString().

This commit is contained in:
kevin 2013-04-12 13:07:50 -07:00
parent 4364f23d22
commit 6074e052f0
2 changed files with 20 additions and 0 deletions

View File

@ -42,6 +42,7 @@ typedef struct
unsigned recvCnt; unsigned recvCnt;
unsigned queCbCnt; unsigned queCbCnt;
unsigned errCnt; unsigned errCnt;
cmChar_t ntopBuf[ INET_ADDRSTRLEN+1 ]; // use INET6_ADDRSTRLEN for IPv6
} cmUdp_t; } cmUdp_t;
cmUdpH_t cmUdpNullHandle = cmSTATIC_NULL_HANDLE; cmUdpH_t cmUdpNullHandle = cmSTATIC_NULL_HANDLE;
@ -545,3 +546,19 @@ cmUdpRC_t cmUdpInitAddr( cmUdpH_t h, const char* addrStr, cmUdpPort_t portNumber
cmUdp_t* p = _cmUdpHandleToPtr(h); cmUdp_t* p = _cmUdpHandleToPtr(h);
return _cmUdpInitAddr(p,addrStr,portNumber,retAddrPtr); return _cmUdpInitAddr(p,addrStr,portNumber,retAddrPtr);
} }
const cmChar_t* cmUdpAddrToString( cmUdpH_t h, const struct sockaddr_in* addr )
{
cmUdp_t* p = _cmUdpHandleToPtr(h);
_cmUdpClear_errno();
if( inet_ntop(AF_INET, addr, p->ntopBuf, INET_ADDRSTRLEN) == NULL)
{
cmErrSysMsg(&p->err,kNtoPFailUdpRC,errno, "Network address to string conversion failed." );
return NULL;
}
p->ntopBuf[INET_ADDRSTRLEN]=0;
return p->ntopBuf;
}

View File

@ -19,6 +19,7 @@ extern "C" {
kSockRecvFailUdpRC, kSockRecvFailUdpRC,
kSockSelectFailUdpRC, kSockSelectFailUdpRC,
kPtoNFailUdpRC, kPtoNFailUdpRC,
kNtoPFailUdpRC,
kNotConnectedUdpRC, kNotConnectedUdpRC,
kThreadFailUdpRC, kThreadFailUdpRC,
kQueueFailUdpRC, kQueueFailUdpRC,
@ -115,6 +116,8 @@ extern "C" {
// Prepare a struct sockadddr_in for use with cmUdpSendTo() // Prepare a struct sockadddr_in for use with cmUdpSendTo()
cmUdpRC_t cmUdpInitAddr( cmUdpH_t h, const char* addrStr, cmUdpPort_t portNumber, struct sockaddr_in* retAddrPtr ); cmUdpRC_t cmUdpInitAddr( cmUdpH_t h, const char* addrStr, cmUdpPort_t portNumber, struct sockaddr_in* retAddrPtr );
const cmChar_t* cmUdpAddrToString( cmUdpH_t h, const struct sockaddr_in* addr );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif