00001 /* 00002 * WiPal - A library and a set of tools to manipulate wireless traces. 00003 * Copyright (C) 2007 Universite Pierre et Marie Curie - Paris 6 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00018 * MA 02110-1301 USA 00019 * 00020 * Author: Thomas Claveirole <thomas.claveirole@lip6.fr> 00021 */ 00022 #ifndef TOOL_ENDIANNESS_HH_ 00023 # define TOOL_ENDIANNESS_HH_ 00024 00025 extern "C" 00026 { 00027 # include <inttypes.h> 00028 } 00029 00030 namespace tool 00031 { 00032 00034 namespace endian 00035 { 00037 enum endianness 00038 { 00039 big, 00040 little, 00041 raw, 00042 swap, 00043 guess 00044 }; 00045 00052 bool need_swap(endianness tag, bool guess_swap); 00053 } 00054 00055 00056 /*-------. 00057 | Shorts | 00058 `-------*/ 00059 00061 uint16_t 00062 extract_unswapped_short(const void* p); 00063 00065 uint16_t 00066 extract_swapped_short(const uint16_t s); 00067 00070 uint16_t 00071 extract_swapped_short(const void* p); 00072 00074 uint16_t 00075 extract_short(const uint16_t s, bool swapped); 00076 00078 uint16_t 00079 extract_short(const void* p, bool swapped); 00080 00082 uint16_t 00083 extract_big_endian_short(const void* p); 00084 00085 00086 /*------. 00087 | Longs | 00088 `------*/ 00089 00091 uint32_t 00092 extract_swapped_long_u(const uint32_t l); 00093 00095 int32_t 00096 extract_swapped_long_s(const int32_t l); 00097 00099 uint32_t 00100 extract_long_u(const uint32_t l, bool swapped); 00101 00103 int32_t 00104 extract_long_s(const int32_t l, bool swapped); 00105 00107 uint32_t 00108 extract_little_endian_long_u(const uint32_t l); 00109 00110 } // End of namespace tool. 00111 00112 # include "endianness.hxx" 00113 00114 #endif // ! TOOL_ENDIANNESS_HH_