00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <eyedbconfig.h>
00025
00026 #include <eyedblib/xdr.h>
00027 #include <eyedblib/rpc_lib.h>
00028
00029 #ifndef XDR_MACROS
00030 eyedblib::int16
00031 h2x_16(eyedblib::int16 x)
00032 {
00033 return htons(x);
00034 }
00035
00036 eyedblib::uint16
00037 h2x_u16(eyedblib::uint16 x)
00038 {
00039 return (eyedblib::uint16)h2x_16((eyedblib::uint16)x);
00040 }
00041
00042 eyedblib::int32
00043 h2x_32(eyedblib::int32 x)
00044 {
00045 return htonl(x);
00046 }
00047
00048 eyedblib::uint16
00049 h2x_u32(eyedblib::uint32 x)
00050 {
00051 return (eyedblib::uint32)h2x_32((eyedblib::uint32)x);
00052 }
00053
00054 eyedblib::int64
00055 h2x_64(eyedblib::int64 x)
00056 {
00057 #ifdef EYEDBLIB_BIG_ENDIAN
00058 #error __FILE__ __LINE__ EYEDBLIB_BIG_ENDIAN is defined
00059 return x;
00060 #else
00061 return ((unsigned long long)htonl(l)) << 32 | htonl((x >> 32) & 0xffffffff);
00062 #endif
00063 }
00064
00065 eyedblib::uint16
00066 h2x_u64(eyedblib::uint64 x)
00067 {
00068 return (eyedblib::uint64)h2x_64((eyedblib::uint64)x);
00069 }
00070
00071 eyedblib::int16
00072 x2h_16(eyedblib::int16 x)
00073 {
00074 return ntohs(x);
00075 }
00076
00077 eyedblib::uint16
00078 x2h_u16(eyedblib::uint16 x)
00079 {
00080 return (eyedblib::uint16)x2h_16((eyedblib::uint16)x);
00081 }
00082
00083 eyedblib::int32
00084 x2h_32(eyedblib::int32 x)
00085 {
00086 return ntohl(x);
00087 }
00088
00089 eyedblib::uint16
00090 x2h_u32(eyedblib::uint32 x)
00091 {
00092 return (eyedblib::uint32)x2h_32((eyedblib::uint32)x);
00093 }
00094
00095 eyedblib::int64
00096 x2h_64(eyedblib::int64 x)
00097 {
00098 #ifdef EYEDBLIB_BIG_ENDIAN
00099 #error __FILE__ __LINE__ EYEDBLIB_BIG_ENDIAN is defined
00100 return x;
00101 #else
00102 return ((unsigned long long)ntohl(l)) << 32 | ntohl((x >> 32) & 0xffffffff);
00103 #endif
00104 }
00105
00106 eyedblib::uint16
00107 x2h_u64(eyedblib::uint64 x)
00108 {
00109 return (eyedblib::uint64)x2h_64((eyedblib::uint64)x);
00110 }
00111
00112
00113 #endif
00114
00115 eyedblib::float32
00116 h2x_f32(eyedblib::float32 x)
00117 {
00118 eyedblib::int32 ix;
00119 eyedblib_mcp(&ix, &x, sizeof(ix));
00120 ix = h2x_32(ix);
00121 eyedblib_mcp(&x, &ix, sizeof(ix));
00122 return x;
00123 }
00124
00125 eyedblib::float64
00126 h2x_f64(eyedblib::float64 x)
00127 {
00128 eyedblib::int64 ix;
00129 eyedblib_mcp(&ix, &x, sizeof(ix));
00130 ix = h2x_64(ix);
00131 eyedblib_mcp(&x, &ix, sizeof(ix));
00132 return x;
00133 }
00134
00135 eyedblib::float32
00136 x2h_f32(eyedblib::float32 x)
00137 {
00138 eyedblib::int32 ix;
00139 eyedblib_mcp(&ix, &x, sizeof(ix));
00140 ix = x2h_32(ix);
00141 eyedblib_mcp(&x, &ix, sizeof(ix));
00142 return x;
00143 }
00144
00145 eyedblib::float64
00146 x2h_f64(eyedblib::float64 x)
00147 {
00148 eyedblib::int64 ix;
00149 eyedblib_mcp(&ix, &x, sizeof(ix));
00150 ix = x2h_64(ix);
00151 eyedblib_mcp(&x, &ix, sizeof(ix));
00152 return x;
00153 }
00154
00155 #ifndef XDR_MACROS
00156
00157 void
00158 h2x_16_cpy(void *to, const void *from)
00159 {
00160 #ifdef EYEDBLIB_BIG_ENDIAN
00161 #error __FILE__ __LINE__ EYEDBLIB_BIG_ENDIAN is defined
00162 if (from)
00163 eyedblib_mcp(to, from, sizeof(eyedblib::int16));
00164 #else
00165 eyedblib::int16 sx;
00166 if (!from) from = to;
00167 eyedblib_mcp(&sx, from, sizeof(sx));
00168 sx = h2x_16(sx);
00169 eyedblib_mcp(to, &sx, sizeof(sx));
00170 #endif
00171 }
00172
00173 void
00174 h2x_32_cpy(void *to, const void *from)
00175 {
00176 #ifdef EYEDBLIB_BIG_ENDIAN
00177 #error __FILE__ __LINE__ EYEDBLIB_BIG_ENDIAN is defined
00178 if (from)
00179 eyedblib_mcp(to, from, sizeof(eyedblib::int32));
00180 #else
00181 eyedblib::int32 sx;
00182 if (!from) from = to;
00183 eyedblib_mcp(&sx, from, sizeof(sx));
00184 sx = h2x_32(sx);
00185 eyedblib_mcp(to, &sx, sizeof(sx));
00186 #endif
00187 }
00188
00189 void
00190 h2x_64_cpy(void *to, const void *from)
00191 {
00192 #ifdef EYEDBLIB_BIG_ENDIAN
00193 #error __FILE__ __LINE__ EYEDBLIB_BIG_ENDIAN is defined
00194 if (from)
00195 eyedblib_mcp(to, from, sizeof(eyedblib::int64));
00196 #else
00197 eyedblib::int64 sx;
00198 if (!from) from = to;
00199 eyedblib_mcp(&sx, from, sizeof(sx));
00200 sx = h2x_64(sx);
00201 eyedblib_mcp(to, &sx, sizeof(sx));
00202 #endif
00203 }
00204
00205
00206 void
00207 x2h_16_cpy(void *to, const void *from)
00208 {
00209 #ifdef EYEDBLIB_BIG_ENDIAN
00210 #error __FILE__ __LINE__ EYEDBLIB_BIG_ENDIAN is defined
00211 if (from)
00212 eyedblib_mcp(to, from, sizeof(eyedblib::int16));
00213 #else
00214 eyedblib::int16 sx;
00215 if (!from) from = to;
00216 eyedblib_mcp(&sx, from, sizeof(sx));
00217 sx = x2h_16(sx);
00218 eyedblib_mcp(to, &sx, sizeof(sx));
00219 #endif
00220 }
00221
00222 void
00223 x2h_32_cpy(void *to, const void *from)
00224 {
00225 #ifdef EYEDBLIB_BIG_ENDIAN
00226 #error __FILE__ __LINE__ EYEDBLIB_BIG_ENDIAN is defined
00227 if (from)
00228 eyedblib_mcp(to, from, sizeof(eyedblib::int32));
00229 #else
00230 eyedblib::int32 sx;
00231 if (!from) from = to;
00232 eyedblib_mcp(&sx, from, sizeof(sx));
00233 sx = x2h_32(sx);
00234 eyedblib_mcp(to, &sx, sizeof(sx));
00235 #endif
00236 }
00237
00238 void
00239 x2h_64_cpy(void *to, const void *from)
00240 {
00241 #ifdef EYEDBLIB_BIG_ENDIAN
00242 #error __FILE__ __LINE__ EYEDBLIB_BIG_ENDIAN is defined
00243 if (from)
00244 eyedblib_mcp(to, from, sizeof(eyedblib::int64));
00245 #else
00246 eyedblib::int64 sx;
00247 if (!from) from = to;
00248 eyedblib_mcp(&sx, from, sizeof(sx));
00249 sx = x2h_64(sx);
00250 eyedblib_mcp(to, &sx, sizeof(sx));
00251 #endif
00252 }
00253 #endif
00254
00255 #ifdef INTERNAL_XDR
00256
00257
00258
00259 #ifndef NEUTRAL_XDR
00260 typedef struct {
00261 char x[4];
00262 } x32;
00263 #endif
00264
00265 unsigned int htonl(unsigned int hostlong)
00266 {
00267 #ifndef NEUTRAL_XDR
00268 x32 *x = (x32 *)&hostlong;
00269 char c = x->x[0];
00270 x->x[0] = x->x[3];
00271 x->x[3] = c;
00272 c = x->x[1];
00273 x->x[1] = x->x[2];
00274 x->x[2] = c;
00275 memcpy(&hostlong, x, sizeof(hostlong));
00276 #endif
00277 return hostlong;
00278 }
00279
00280 unsigned short
00281 int htons(unsigned short int hostshort)
00282 {
00283 return hostshort;
00284 }
00285
00286 unsigned
00287 int ntohl(unsigned int netlong)
00288 {
00289 return htonl(netlong);
00290 }
00291
00292 unsigned short
00293 int ntohs(unsigned short int netshort)
00294 {
00295 return netshort;
00296 }
00297 #endif