00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00048 #ifndef INETSTL_INCL_INETSTL_SHIMS_ACCESS_STRING_STD_HPP_IN_ADDR
00049 #define INETSTL_INCL_INETSTL_SHIMS_ACCESS_STRING_STD_HPP_IN_ADDR
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define INETSTL_VER_INETSTL_SHIMS_ACCESS_STRING_STD_HPP_IN_ADDR_MAJOR 1
00053 # define INETSTL_VER_INETSTL_SHIMS_ACCESS_STRING_STD_HPP_IN_ADDR_MINOR 0
00054 # define INETSTL_VER_INETSTL_SHIMS_ACCESS_STRING_STD_HPP_IN_ADDR_REVISION 6
00055 # define INETSTL_VER_INETSTL_SHIMS_ACCESS_STRING_STD_HPP_IN_ADDR_EDIT 10
00056 #endif
00057
00058
00059
00060
00061
00062 #ifndef INETSTL_INCL_INETSTL_H_INETSTL
00063 # include <inetstl/inetstl.h>
00064 #endif
00065 #ifndef INETSTL_INCL_INETSTL_INCLUDES_STD_H_IN_ADDR
00066 # include <inetstl/includes/std/in_addr.h>
00067 #endif
00068 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SHIM_STRING
00069 # include <stlsoft/string/shim_string.hpp>
00070 #endif
00071 #ifndef STLSOFT_INCL_STLSOFT_INTERNAL_H_SAFESTR
00072 # include <stlsoft/internal/safestr.h>
00073 #endif
00074
00075
00076
00077
00078
00079 #ifndef _INETSTL_NO_NAMESPACE
00080 # if defined(_STLSOFT_NO_NAMESPACE) || \
00081 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00082
00083 namespace inetstl
00084 {
00085 # else
00086
00087
00088 namespace stlsoft
00089 {
00090
00091 namespace inetstl_project
00092 {
00093
00094 # endif
00095 #endif
00096
00097
00098
00099
00100
00101 inline stlsoft::basic_shim_string<is_char_a_t, 16> c_str_data_a(struct in_addr const& addr)
00102 {
00103 stlsoft::basic_shim_string<is_char_a_t, 16> s(15);
00104
00105 is_uint32_t laddr = ntohl(addr.s_addr);
00106 unsigned b3 = (laddr & 0x000000ff) >> 0;
00107 unsigned b2 = (laddr & 0x0000ff00) >> 8;
00108 unsigned b1 = (laddr & 0x00ff0000) >> 16;
00109 unsigned b0 = (laddr & 0xff000000) >> 24;
00110 # ifdef STLSOFT_USING_SAFE_STR_FUNCTIONS
00111 int cch = ::_snprintf_s(
00112 s.data()
00113 , s.size() + 1u
00114 , _TRUNCATE
00115 # else
00116 int cch = ::sprintf(s.data()
00117 # endif
00118 , "%u.%u.%u.%u"
00119 , b0, b1, b2, b3
00120 );
00121
00122 if(cch < 0)
00123 {
00124 cch = 0;
00125 }
00126
00127 s.truncate(static_cast<is_size_t>(cch));
00128
00129 return s;
00130 }
00131
00132 inline is_size_t c_str_len_a(struct in_addr const& addr)
00133 {
00134
00135
00136 is_uint32_t laddr = addr.s_addr;
00137
00138 unsigned b0 = (laddr & 0x000000ff) >> 0;
00139 unsigned b1 = (laddr & 0x0000ff00) >> 8;
00140 unsigned b2 = (laddr & 0x00ff0000) >> 16;
00141 unsigned b3 = (laddr & 0xff000000) >> 24;
00142
00143 int cch = 3
00144 + 1 + (b0 > 9) + (b0 > 99)
00145 + 1 + (b1 > 9) + (b1 > 99)
00146 + 1 + (b2 > 9) + (b2 > 99)
00147 + 1 + (b3 > 9) + (b3 > 99)
00148 ;
00149
00150 return static_cast<is_size_t>(cch);
00151 }
00152
00153 inline stlsoft::basic_shim_string<is_char_a_t, 16> c_str_ptr_a(struct in_addr const& addr)
00154 {
00155 return c_str_data_a(addr);
00156 }
00157
00158 inline stlsoft::basic_shim_string<is_char_a_t, 16> c_str_data_a(struct in_addr const* addr)
00159 {
00160 typedef stlsoft::basic_shim_string<is_char_a_t, 16> shim_string_t;
00161
00162 if(NULL != addr)
00163 {
00164 return c_str_data_a(*addr);
00165 }
00166 else
00167 {
00168 return shim_string_t(is_size_t(0));
00169 }
00170 }
00171
00172 inline is_size_t c_str_len_a(struct in_addr const* addr)
00173 {
00174 typedef stlsoft::basic_shim_string<is_char_a_t, 16> shim_string_t;
00175
00176 if(NULL != addr)
00177 {
00178 return c_str_len_a(*addr);
00179 }
00180 else
00181 {
00182 return shim_string_t(is_size_t(0));
00183 }
00184 }
00185
00186 inline stlsoft::basic_shim_string<is_char_a_t, 16> c_str_ptr_a(struct in_addr const* addr)
00187 {
00188 return c_str_data_a(addr);
00189 }
00190
00191
00192
00193 #ifndef _INETSTL_NO_NAMESPACE
00194 # if defined(_STLSOFT_NO_NAMESPACE) || \
00195 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00196 }
00197 # else
00198 }
00199 }
00200 # endif
00201 #endif
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 #ifndef _INETSTL_NO_NAMESPACE
00212 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00213 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00214 namespace stlsoft
00215 {
00216 # else
00217
00218 # endif
00219
00220 using ::inetstl::c_str_data_a;
00221 using ::inetstl::c_str_len_a;
00222 using ::inetstl::c_str_ptr_a;
00223
00224 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00225 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00226 }
00227 # else
00228
00229 # endif
00230 #endif
00231
00232
00233
00234 #endif
00235
00236