1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved.
3219820Sjeff * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5219820Sjeff *
6219820Sjeff * This software is available to you under a choice of one of two
7219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
8219820Sjeff * General Public License (GPL) Version 2, available from the file
9219820Sjeff * COPYING in the main directory of this source tree, or the
10219820Sjeff * OpenIB.org BSD license below:
11219820Sjeff *
12219820Sjeff *     Redistribution and use in source and binary forms, with or
13219820Sjeff *     without modification, are permitted provided that the following
14219820Sjeff *     conditions are met:
15219820Sjeff *
16219820Sjeff *      - Redistributions of source code must retain the above
17219820Sjeff *        copyright notice, this list of conditions and the following
18219820Sjeff *        disclaimer.
19219820Sjeff *
20219820Sjeff *      - Redistributions in binary form must reproduce the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer in the documentation and/or other materials
23219820Sjeff *        provided with the distribution.
24219820Sjeff *
25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32219820Sjeff * SOFTWARE.
33219820Sjeff *
34219820Sjeff */
35219820Sjeff
36219820Sjeff/*
37219820Sjeff * Abstract:
38219820Sjeff *	provides byteswapping utilities. Basic functions are obtained from
39219820Sjeff *  platform specific implementations from byteswap_osd.h.
40219820Sjeff */
41219820Sjeff
42219820Sjeff#ifndef _CL_BYTESWAP_H_
43219820Sjeff#define _CL_BYTESWAP_H_
44219820Sjeff
45219820Sjeff#include <string.h>
46219820Sjeff#include <complib/cl_byteswap_osd.h>
47219820Sjeff
48219820Sjeff#ifdef __cplusplus
49219820Sjeff#  define BEGIN_C_DECLS extern "C" {
50219820Sjeff#  define END_C_DECLS   }
51219820Sjeff#else				/* !__cplusplus */
52219820Sjeff#  define BEGIN_C_DECLS
53219820Sjeff#  define END_C_DECLS
54219820Sjeff#endif				/* __cplusplus */
55219820Sjeff
56219820SjeffBEGIN_C_DECLS
57219820Sjeff/****h* Component Library/Byte Swapping
58219820Sjeff* NAME
59219820Sjeff*	Byte Swapping
60219820Sjeff*
61219820Sjeff* DESCRIPTION
62219820Sjeff*	The byte swapping functions and macros allow swapping bytes from network
63219820Sjeff*	byte order to host byte order.
64219820Sjeff*
65219820Sjeff*	All data transmitted between systems should be in network byte order.
66219820Sjeff*	In order to utilize such data, it must be converted to host byte order
67219820Sjeff*	before use.
68219820Sjeff*
69219820Sjeff* SEE ALSO
70219820Sjeff*	Functions:
71219820Sjeff*		cl_ntoh16, cl_hton16, cl_ntoh32, cl_hton32, cl_ntoh64, cl_hton64,
72219820Sjeff*		cl_ntoh
73219820Sjeff*
74219820Sjeff*	Macros:
75219820Sjeff*		CL_NTOH16, CL_HTON16, CL_NTOH32, CL_HTON32, CL_NTOH64, CL_HTON64
76219820Sjeff*********/
77219820Sjeff/*
78219820Sjeff * The byteswap_osd.h provides the following macros.
79219820Sjeff *		__LITTLE_ENDIAN
80219820Sjeff *		__BIG_ENDIAN
81219820Sjeff *		__BYTE_ORDER
82219820Sjeff *
83219820Sjeff * If the platform provides byte swapping functions, byteswap_osd.h also
84219820Sjeff * provides the following macros.
85219820Sjeff *		ntoh16, hton16
86219820Sjeff *		ntoh32, hton32
87219820Sjeff *		ntoh64, hton64
88219820Sjeff */
89219820Sjeff
90219820Sjeff#ifndef __BYTE_ORDER
91219820Sjeff#error "__BYTE_ORDER macro undefined. Missing in endian.h?"
92219820Sjeff#endif
93219820Sjeff#if __BYTE_ORDER == __LITTLE_ENDIAN
94219820Sjeff#define CPU_LE		1
95219820Sjeff#define CPU_BE		0
96219820Sjeff#else
97219820Sjeff#define CPU_LE		0
98219820Sjeff#define CPU_BE		1
99219820Sjeff#endif
100219820Sjeff/****d* Component Library: Byte Swapping/CL_NTOH16
101219820Sjeff* NAME
102219820Sjeff*	CL_NTOH16
103219820Sjeff*
104219820Sjeff* DESCRIPTION
105219820Sjeff*	The CL_NTOH16 macro converts a 16-bit value from network byte order to
106219820Sjeff*	host byte order.  The CL_NTOH16 macro will cause constant values to be
107219820Sjeff*	swapped by the pre-processor.  For variables, CL_NTOH16 is less efficient
108219820Sjeff*	than the cl_ntoh16 function.
109219820Sjeff*
110219820Sjeff* SYNOPSIS
111219820Sjeff*	CL_NTOH16( val );
112219820Sjeff*
113219820Sjeff* PARAMETERS
114219820Sjeff*	val
115219820Sjeff*		[in] 16-bit value to swap from network byte order to host byte order.
116219820Sjeff*
117219820Sjeff* RESULT
118219820Sjeff*	Value of val converted to host byte order.
119219820Sjeff*
120219820Sjeff* NOTES
121219820Sjeff*	This macro is analogous to CL_HTON16.
122219820Sjeff*
123219820Sjeff* SEE ALSO
124219820Sjeff*	Byte Swapping, CL_HTON16, CL_NTOH32, CL_NTOH64,
125219820Sjeff*	cl_ntoh16, cl_ntoh32, cl_ntoh64, cl_ntoh
126219820Sjeff*********/
127219820Sjeff/****d* Component Library: Byte Swapping/CL_HTON16
128219820Sjeff* NAME
129219820Sjeff*	CL_HTON16
130219820Sjeff*
131219820Sjeff* DESCRIPTION
132219820Sjeff*	The CL_HTON16 macro converts a 16-bit value from host byte order to
133219820Sjeff*	network byte order.  The CL_HTON16 macro will cause constant values to be
134219820Sjeff*	swapped by the pre-processor.  For variables, CL_HTON16 is less efficient
135219820Sjeff*	than the cl_hton16 function.
136219820Sjeff*
137219820Sjeff* SYNOPSIS
138219820Sjeff*	CL_HTON16( val );
139219820Sjeff*
140219820Sjeff* PARAMETERS
141219820Sjeff*	val
142219820Sjeff*		[in] 16-bit value to swap from host byte order to network byte order.
143219820Sjeff*
144219820Sjeff* RESULT
145219820Sjeff*	Value of val converted to network byte order.
146219820Sjeff*
147219820Sjeff* NOTES
148219820Sjeff*	This macro is analogous to CL_NTOH16.
149219820Sjeff*
150219820Sjeff* SEE ALSO
151219820Sjeff*	Byte Swapping, CL_NTOH16, CL_HTON32, CL_HTON64,
152219820Sjeff*	cl_hton16, cl_hton32, cl_hton64, cl_ntoh
153219820Sjeff*********/
154219820Sjeff#if CPU_LE
155219820Sjeff#define CL_NTOH16( x )		(uint16_t)(		\
156219820Sjeff			(((uint16_t)(x) & 0x00FF) << 8) |		\
157219820Sjeff			(((uint16_t)(x) & 0xFF00) >> 8) )
158219820Sjeff#else
159219820Sjeff#define CL_NTOH16( x )	(x)
160219820Sjeff#endif
161219820Sjeff#define CL_HTON16				CL_NTOH16
162219820Sjeff/****f* Component Library: Byte Swapping/cl_ntoh16
163219820Sjeff* NAME
164219820Sjeff*	cl_ntoh16
165219820Sjeff*
166219820Sjeff* DESCRIPTION
167219820Sjeff*	The cl_ntoh16 function converts a 16-bit value from network byte order to
168219820Sjeff*	host byte order.
169219820Sjeff*
170219820Sjeff* SYNOPSIS
171219820Sjeff*	uint16_t
172219820Sjeff*	cl_ntoh16(
173219820Sjeff*		IN	const uint16_t	val );
174219820Sjeff*
175219820Sjeff* PARAMETERS
176219820Sjeff*	val
177219820Sjeff*		[in] Value to swap from network byte order to host byte order.
178219820Sjeff*
179219820Sjeff* RETURN VALUE
180219820Sjeff*	Value of val converted to host byte order.
181219820Sjeff*
182219820Sjeff* NOTES
183219820Sjeff*	This function is analogous to cl_hton16.
184219820Sjeff*
185219820Sjeff* SEE ALSO
186219820Sjeff*	Byte Swapping, cl_hton16, cl_ntoh32, cl_ntoh64, cl_ntoh
187219820Sjeff*********/
188219820Sjeff/****f* Component Library: Byte Swapping/cl_hton16
189219820Sjeff* NAME
190219820Sjeff*	cl_hton16
191219820Sjeff*
192219820Sjeff* DESCRIPTION
193219820Sjeff*	The cl_hton16 function converts a 16-bit value from host byte order to
194219820Sjeff*	network byte order.
195219820Sjeff*
196219820Sjeff* SYNOPSIS
197219820Sjeff*	uint16_t
198219820Sjeff*	cl_hton16(
199219820Sjeff*		IN	const uint16_t	val );
200219820Sjeff*
201219820Sjeff* PARAMETERS
202219820Sjeff*	val
203219820Sjeff*		[in] Value to swap from host byte order to network byte order .
204219820Sjeff*
205219820Sjeff* RETURN VALUE
206219820Sjeff*	Value of val converted to network byte order.
207219820Sjeff*
208219820Sjeff* NOTES
209219820Sjeff*	This function is analogous to cl_ntoh16.
210219820Sjeff*
211219820Sjeff* SEE ALSO
212219820Sjeff*	Byte Swapping, cl_ntoh16, cl_hton32, cl_hton64, cl_ntoh
213219820Sjeff*********/
214219820Sjeff#ifndef cl_ntoh16
215219820Sjeff#define cl_ntoh16	CL_NTOH16
216219820Sjeff#define cl_hton16	CL_HTON16
217219820Sjeff#endif
218219820Sjeff/****d* Component Library: Byte Swapping/CL_NTOH32
219219820Sjeff* NAME
220219820Sjeff*	CL_NTOH32
221219820Sjeff*
222219820Sjeff* DESCRIPTION
223219820Sjeff*	The CL_NTOH32 macro converts a 32-bit value from network byte order to
224219820Sjeff*	host byte order.  The CL_NTOH32 macro will cause constant values to be
225219820Sjeff*	swapped by the pre-processor.  For variables, CL_NTOH32 is less efficient
226219820Sjeff*	than the cl_ntoh32 function.
227219820Sjeff*
228219820Sjeff* SYNOPSIS
229219820Sjeff*	CL_NTOH32( val );
230219820Sjeff*
231219820Sjeff* PARAMETERS
232219820Sjeff*	val
233219820Sjeff*		[in] 32-bit value to swap from network byte order to host byte order.
234219820Sjeff*
235219820Sjeff* RESULT
236219820Sjeff*	Value of val converted to host byte order.
237219820Sjeff*
238219820Sjeff* NOTES
239219820Sjeff*	This macro is analogous to CL_HTON32.
240219820Sjeff*
241219820Sjeff* SEE ALSO
242219820Sjeff*	Byte Swapping, CL_HTON32, CL_NTOH16, CL_NTOH64,
243219820Sjeff*	cl_ntoh16, cl_ntoh32, cl_ntoh64, cl_ntoh
244219820Sjeff*********/
245219820Sjeff/****d* Component Library: Byte Swapping/CL_HTON32
246219820Sjeff* NAME
247219820Sjeff*	CL_HTON32
248219820Sjeff*
249219820Sjeff* DESCRIPTION
250219820Sjeff*	The CL_HTON32 macro converts a 32-bit value from host byte order to
251219820Sjeff*	network byte order.  The CL_HTON32 macro will cause constant values to be
252219820Sjeff*	swapped by the pre-processor.  For variables, CL_HTON32 is less efficient
253219820Sjeff*	than the cl_hton32 function.
254219820Sjeff*
255219820Sjeff* SYNOPSIS
256219820Sjeff*	CL_HTON32( val );
257219820Sjeff*
258219820Sjeff* PARAMETERS
259219820Sjeff*	val
260219820Sjeff*		[in] 32-bit value to swap from host byte order to network byte order.
261219820Sjeff*
262219820Sjeff* RESULT
263219820Sjeff*	Value of val converted to network byte order.
264219820Sjeff*
265219820Sjeff* NOTES
266219820Sjeff*	This macro is analogous to CL_NTOH32.
267219820Sjeff*
268219820Sjeff* SEE ALSO
269219820Sjeff*	Byte Swapping, CL_NTOH32, CL_HTON16, CL_HTON64,
270219820Sjeff*	cl_hton16, cl_hton32, cl_hton64, cl_ntoh
271219820Sjeff*********/
272219820Sjeff#if CPU_LE
273219820Sjeff#define CL_NTOH32( x )		(uint32_t)(			\
274219820Sjeff			(((uint32_t)(x) & 0x000000FF) << 24) |	\
275219820Sjeff			(((uint32_t)(x) & 0x0000FF00) << 8) |	\
276219820Sjeff			(((uint32_t)(x) & 0x00FF0000) >> 8) |	\
277219820Sjeff			(((uint32_t)(x) & 0xFF000000) >> 24) )
278219820Sjeff#else
279219820Sjeff#define CL_NTOH32( x )		(x)
280219820Sjeff#endif
281219820Sjeff#define CL_HTON32	CL_NTOH32
282219820Sjeff/****f* Component Library: Byte Swapping/cl_ntoh32
283219820Sjeff* NAME
284219820Sjeff*	cl_ntoh32
285219820Sjeff*
286219820Sjeff* DESCRIPTION
287219820Sjeff*	The cl_ntoh32 function converts a 32-bit value from network byte order to
288219820Sjeff*	host byte order.
289219820Sjeff*
290219820Sjeff* SYNOPSIS
291219820Sjeff*	uint32_t
292219820Sjeff*	cl_ntoh32(
293219820Sjeff*		IN	const uint32_t	val );
294219820Sjeff*
295219820Sjeff* PARAMETERS
296219820Sjeff*	val
297219820Sjeff*		[in] Value to swap from network byte order to host byte order.
298219820Sjeff*
299219820Sjeff* RETURN VALUE
300219820Sjeff*	Value of val converted in host byte order.
301219820Sjeff*
302219820Sjeff* NOTES
303219820Sjeff*	This function is analogous to cl_hton32.
304219820Sjeff*
305219820Sjeff* SEE ALSO
306219820Sjeff*	Byte Swapping, cl_hton32, cl_ntoh16, cl_ntoh64, cl_ntoh
307219820Sjeff*********/
308219820Sjeff/****f* Component Library: Byte Swapping/cl_hton32
309219820Sjeff* NAME
310219820Sjeff*	cl_hton32
311219820Sjeff*
312219820Sjeff* DESCRIPTION
313219820Sjeff*	The cl_hton32 function converts a 32-bit value from host byte order to
314219820Sjeff*	network byte order.
315219820Sjeff*
316219820Sjeff* SYNOPSIS
317219820Sjeff*	uint32_t
318219820Sjeff*	cl_hton32(
319219820Sjeff*		IN	const uint32_t	val );
320219820Sjeff*
321219820Sjeff* PARAMETERS
322219820Sjeff*	val
323219820Sjeff*		[in] Value to swap from host byte order to network byte order .
324219820Sjeff*
325219820Sjeff* RETURN VALUE
326219820Sjeff*	Value of val converted to network byte order.
327219820Sjeff*
328219820Sjeff* NOTES
329219820Sjeff*	This function is analogous to cl_ntoh32.
330219820Sjeff*
331219820Sjeff* SEE ALSO
332219820Sjeff*	Byte Swapping, cl_ntoh32, cl_hton16, cl_hton64, cl_ntoh
333219820Sjeff*********/
334219820Sjeff#ifndef cl_ntoh32
335219820Sjeff#define cl_ntoh32	CL_NTOH32
336219820Sjeff#define cl_hton32	CL_HTON32
337219820Sjeff#endif
338219820Sjeff/****d* Component Library: Byte Swapping/CL_NTOH64
339219820Sjeff* NAME
340219820Sjeff*	CL_NTOH64
341219820Sjeff*
342219820Sjeff* DESCRIPTION
343219820Sjeff*	The CL_NTOH64 macro converts a 64-bit value from network byte order to
344219820Sjeff*	host byte order.  The CL_NTOH64 macro will cause constant values to be
345219820Sjeff*	swapped by the pre-processor.  For variables, CL_NTOH64 is less efficient
346219820Sjeff*	than the cl_ntoh64 function.
347219820Sjeff*
348219820Sjeff* SYNOPSIS
349219820Sjeff*	CL_NTOH64( val );
350219820Sjeff*
351219820Sjeff* PARAMETERS
352219820Sjeff*	val
353219820Sjeff*		[in] 64-bit value to swap from network byte order to host byte order.
354219820Sjeff*
355219820Sjeff* RESULT
356219820Sjeff*	Value of val converted to host byte order.
357219820Sjeff*
358219820Sjeff* NOTES
359219820Sjeff*	This macro is analogous to CL_HTON64.
360219820Sjeff*
361219820Sjeff* SEE ALSO
362219820Sjeff*	Byte Swapping, CL_HTON64, CL_NTOH16, CL_NTOH32,
363219820Sjeff*	cl_ntoh16, cl_ntoh32, cl_ntoh64, cl_ntoh
364219820Sjeff*********/
365219820Sjeff/****d* Component Library: Byte Swapping/CL_HTON64
366219820Sjeff* NAME
367219820Sjeff*	CL_HTON64
368219820Sjeff*
369219820Sjeff* DESCRIPTION
370219820Sjeff*	The CL_HTON64 macro converts a 64-bit value from host byte order to
371219820Sjeff*	network byte order.  The CL_HTON64 macro will cause constant values to be
372219820Sjeff*	swapped by the pre-processor.  For variables, CL_HTON64 is less efficient
373219820Sjeff*	than the cl_hton64 function.
374219820Sjeff*
375219820Sjeff* SYNOPSIS
376219820Sjeff*	CL_HTON64( val );
377219820Sjeff*
378219820Sjeff* PARAMETERS
379219820Sjeff*	val
380219820Sjeff*		[in] 64-bit value to swap from host byte order to network byte order.
381219820Sjeff*
382219820Sjeff* RESULT
383219820Sjeff*	Value of val converted to network byte order.
384219820Sjeff*
385219820Sjeff* NOTES
386219820Sjeff*	This macro is analogous to CL_NTOH64.
387219820Sjeff*
388219820Sjeff* SEE ALSO
389219820Sjeff*	Byte Swapping, CL_NTOH64, CL_HTON16, CL_HTON32,
390219820Sjeff*	cl_hton16, cl_hton32, cl_hton64, cl_ntoh
391219820Sjeff*********/
392219820Sjeff#if CPU_LE
393219820Sjeff#define CL_NTOH64( x )		(uint64_t)(					\
394219820Sjeff			(((uint64_t)(x) & 0x00000000000000FFULL) << 56) |	\
395219820Sjeff			(((uint64_t)(x) & 0x000000000000FF00ULL) << 40) |	\
396219820Sjeff			(((uint64_t)(x) & 0x0000000000FF0000ULL) << 24) |	\
397219820Sjeff			(((uint64_t)(x) & 0x00000000FF000000ULL) << 8 ) |	\
398219820Sjeff			(((uint64_t)(x) & 0x000000FF00000000ULL) >> 8 ) |	\
399219820Sjeff			(((uint64_t)(x) & 0x0000FF0000000000ULL) >> 24) |	\
400219820Sjeff			(((uint64_t)(x) & 0x00FF000000000000ULL) >> 40) |	\
401219820Sjeff			(((uint64_t)(x) & 0xFF00000000000000ULL) >> 56) )
402219820Sjeff#else
403219820Sjeff#define CL_NTOH64( x )		(x)
404219820Sjeff#endif
405219820Sjeff#define CL_HTON64				CL_NTOH64
406219820Sjeff/****f* Component Library: Byte Swapping/cl_ntoh64
407219820Sjeff* NAME
408219820Sjeff*	cl_ntoh64
409219820Sjeff*
410219820Sjeff* DESCRIPTION
411219820Sjeff*	The cl_ntoh64 function converts a 64-bit value from network byte order to
412219820Sjeff*	host byte order.
413219820Sjeff*
414219820Sjeff* SYNOPSIS
415219820Sjeff*	uint64_t
416219820Sjeff*	cl_ntoh64(
417219820Sjeff*		IN	const uint64_t	val );
418219820Sjeff*
419219820Sjeff* PARAMETERS
420219820Sjeff*	val
421219820Sjeff*		[in] Value to swap from network byte order to host byte order.
422219820Sjeff*
423219820Sjeff* RETURN VALUE
424219820Sjeff*	Value of val converted in host byte order.
425219820Sjeff*
426219820Sjeff* NOTES
427219820Sjeff*	This function is analogous to cl_hton64.
428219820Sjeff*
429219820Sjeff* SEE ALSO
430219820Sjeff*	Byte Swapping, cl_hton64, cl_ntoh16, cl_ntoh32, cl_ntoh
431219820Sjeff*********/
432219820Sjeff/****f* Component Library: Byte Swapping/cl_hton64
433219820Sjeff* NAME
434219820Sjeff*	cl_hton64
435219820Sjeff*
436219820Sjeff* DESCRIPTION
437219820Sjeff*	The cl_hton64 function converts a 64-bit value from host byte order to
438219820Sjeff*	network byte order.
439219820Sjeff*
440219820Sjeff* SYNOPSIS
441219820Sjeff*	uint64_t
442219820Sjeff*	cl_hton64(
443219820Sjeff*		IN	const uint64_t	val );
444219820Sjeff*
445219820Sjeff* PARAMETERS
446219820Sjeff*	val
447219820Sjeff*		[in] Value to swap from host byte order to network byte order .
448219820Sjeff*
449219820Sjeff* RETURN VALUE
450219820Sjeff*	Value of val converted to network byte order.
451219820Sjeff*
452219820Sjeff* NOTES
453219820Sjeff*	This function is analogous to cl_ntoh64.
454219820Sjeff*
455219820Sjeff* SEE ALSO
456219820Sjeff*	Byte Swapping, cl_ntoh64, cl_hton16, cl_hton32, cl_ntoh
457219820Sjeff*********/
458219820Sjeff#ifndef cl_ntoh64
459219820Sjeff#define cl_ntoh64	CL_NTOH64
460219820Sjeff#define cl_hton64	CL_HTON64
461219820Sjeff#endif
462219820Sjeff/****f* Component Library: Byte Swapping/cl_ntoh
463219820Sjeff* NAME
464219820Sjeff*	cl_ntoh
465219820Sjeff*
466219820Sjeff* DESCRIPTION
467219820Sjeff*	The cl_ntoh function converts a value from network byte order to
468219820Sjeff*	host byte order.
469219820Sjeff*
470219820Sjeff* SYNOPSIS
471219820Sjeff*/
472219820Sjeffstatic inline void
473219820Sjeffcl_ntoh(OUT char *const p_dest,
474219820Sjeff	IN const char *const p_src, IN const uint8_t size)
475219820Sjeff{
476219820Sjeff#if CPU_LE
477219820Sjeff	uint8_t i;
478219820Sjeff	char temp;
479219820Sjeff
480219820Sjeff	if (p_src == p_dest) {
481219820Sjeff		/* Swap in place if source and destination are the same. */
482219820Sjeff		for (i = 0; i < size / 2; i++) {
483219820Sjeff			temp = p_dest[i];
484219820Sjeff			p_dest[i] = p_src[size - 1 - i];
485219820Sjeff			p_dest[size - 1 - i] = temp;
486219820Sjeff		}
487219820Sjeff	} else {
488219820Sjeff		for (i = 0; i < size; i++)
489219820Sjeff			p_dest[i] = p_src[size - 1 - i];
490219820Sjeff	}
491219820Sjeff#else
492219820Sjeff	/*
493219820Sjeff	 * If the source and destination are not the same, copy the source to
494219820Sjeff	 * the destination.
495219820Sjeff	 */
496219820Sjeff	if (p_src != p_dest)
497219820Sjeff		memcpy(p_dest, p_src, size);
498219820Sjeff#endif
499219820Sjeff}
500219820Sjeff
501219820Sjeff/*
502219820Sjeff* PARAMETERS
503219820Sjeff*	p_dest
504219820Sjeff*		[in] Pointer to a byte array to contain the converted value of p_src.
505219820Sjeff*
506219820Sjeff*	p_src
507219820Sjeff*		[in] Pointer to a byte array to be converted from network byte
508219820Sjeff*		ordering.
509219820Sjeff*
510219820Sjeff*	size
511219820Sjeff*		[in] Number of bytes to swap.p_dest
512219820Sjeff*
513219820Sjeff* RETURN VALUE
514219820Sjeff*	This function does not return a value.
515219820Sjeff*
516219820Sjeff* NOTES
517219820Sjeff*	cl_ntoh can perform in place swapping if both p_src and p_dest point to
518219820Sjeff*	the same buffer.
519219820Sjeff*
520219820Sjeff* SEE ALSO
521219820Sjeff*	Byte Swapping, cl_ntoh16, cl_ntoh32, cl_ntoh64
522219820Sjeff*********/
523219820Sjeff
524219820SjeffEND_C_DECLS
525219820Sjeff#endif				/* _CL_BYTESWAP_H_ */
526