MCPcopy Create free account
hub / github.com/ValveSoftware/GameNetworkingSockets / ToString

Method ToString

src/tier1/netadr.cpp:26–63  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: Convert the given IP address to a string representation. Optionally will include the given port if punPort is not null. -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

24// Optionally will include the given port if punPort is not null.
25//-----------------------------------------------------------------------------
26void 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//-----------------------------------------------------------------------------

Callers 11

GetDefaultDestinationFunction · 0.45
BuildCandidateFunction · 0.45
CacheRouteAndPingMethod · 0.45
SetDescriptionMethod · 0.45
PrintRouteInfoFunction · 0.45
Test_identityFunction · 0.45
RunMethod · 0.45

Calls 4

V_strncpyFunction · 0.85
V_snprintfFunction · 0.85
IPv6IPToStringFunction · 0.85
IPv6AddrToStringFunction · 0.85

Tested by 2

PrintRouteInfoFunction · 0.36
Test_identityFunction · 0.36