----------------------------------------------------------------------------- Purpose: Convert the given IP address to a string representation. Optionally will include the given port if punPort is not null. -----------------------------------------------------------------------------
| 24 | // Optionally will include the given port if punPort is not null. |
| 25 | //----------------------------------------------------------------------------- |
| 26 | void CIPAddress::ToString( char *pchBuffer, uint32 unBufferSize, const uint16 *punPort ) const |
| 27 | { |
| 28 | if (m_usType == k_EIPTypeLoopbackDeprecated) |
| 29 | { |
| 30 | V_strncpy (pchBuffer, "loopback", unBufferSize ); |
| 31 | } |
| 32 | else if (m_usType == k_EIPTypeBroadcastDeprecated) |
| 33 | { |
| 34 | V_strncpy (pchBuffer, "broadcast", unBufferSize ); |
| 35 | } |
| 36 | else if (m_usType == k_EIPTypeV4) |
| 37 | { |
| 38 | if ( !punPort ) |
| 39 | { |
| 40 | V_snprintf(pchBuffer, unBufferSize, "%i.%i.%i.%i", m_IPv4Bytes.b1, m_IPv4Bytes.b2, m_IPv4Bytes.b3, m_IPv4Bytes.b4 ); |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | V_snprintf(pchBuffer, unBufferSize, "%i.%i.%i.%i:%i", m_IPv4Bytes.b1, m_IPv4Bytes.b2, m_IPv4Bytes.b3, m_IPv4Bytes.b4, *punPort ); |
| 45 | } |
| 46 | } |
| 47 | else if (m_usType == k_EIPTypeV6) |
| 48 | { |
| 49 | // Format IP into a temp that we know is big enough |
| 50 | char temp[ k_cchMaxIPV6AddrStringWithPort ]; |
| 51 | if ( !punPort ) |
| 52 | IPv6IPToString( temp, m_rgubIPv6 ); |
| 53 | else |
| 54 | IPv6AddrToString( temp, m_rgubIPv6, *punPort, m_unIPv6Scope ); |
| 55 | |
| 56 | // Now put into caller's buffer, and handle truncation |
| 57 | V_strncpy( pchBuffer, temp, unBufferSize ); |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | V_strncpy(pchBuffer, "unknown", unBufferSize ); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | |
| 66 | //----------------------------------------------------------------------------- |