2 * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 unsigned int htons_(unsigned int hostshort)
25 pBuffer = (LPBYTE)&hostshort;
26 nResult = (((pBuffer[0] << 8) & 0xFF00) | (pBuffer[1] & 0x00FF));
31 DWORD htonl_(DWORD hostlong)
33 DWORD nResult = hostlong >> 16;
34 unsigned int upper = (unsigned int)nResult & 0x0000FFFF;
35 unsigned int lower = (unsigned int)hostlong & 0x0000FFFF;
37 upper = htons_(upper);
38 lower = htons_(lower);
39 nResult = 0x10000 * lower + upper;
44 INT64 _hton64( INT64 n64host )
51 static int isLittleEndian = -1;
53 if( isLittleEndian == -1 )
68 if( isLittleEndian == 1 )
70 n32Low = (INT32)( n64host & 0xFFFFFFFF );
71 n32High = (INT32)( n64host >> 32 );
73 n32Low = htonl_( n32Low );
74 n32High = htonl_( n32High );
76 result = ( (INT64)n32Low << 32 ) | n32High;