From 0d6c3bd4b0bed5b3b3b13b487b674c4249b3ebb2 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 12 Aug 2004 16:22:01 +0000 Subject: [PATCH] hcidump: Use bt_get_unaligned() from bluetooth.h for unaligned access --- tools/parser/l2cap.c | 6 +++--- tools/parser/parser.h | 12 +++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/parser/l2cap.c b/tools/parser/l2cap.c index 587dd1bb1..6f913ce4d 100644 --- a/tools/parser/l2cap.c +++ b/tools/parser/l2cap.c @@ -137,9 +137,9 @@ static uint32_t get_val(uint8_t *ptr, uint8_t len) case 1: return *ptr; case 2: - return btohs(get_unaligned((uint16_t *) ptr)); + return btohs(bt_get_unaligned((uint16_t *) ptr)); case 4: - return btohl(get_unaligned((uint32_t *) ptr)); + return btohl(bt_get_unaligned((uint32_t *) ptr)); } return 0; } @@ -420,7 +420,7 @@ static void l2cap_parse(int level, struct frame *frm) if (p_filter(FILT_L2CAP)) return; - psm = btohs(get_unaligned((uint16_t*)frm->ptr)); + psm = btohs(bt_get_unaligned((uint16_t*)frm->ptr)); frm->len -= 2; p_indent(level, frm); diff --git a/tools/parser/parser.h b/tools/parser/parser.h index a79dc4e12..e95a209b0 100644 --- a/tools/parser/parser.h +++ b/tools/parser/parser.h @@ -27,6 +27,8 @@ #ifndef __PARSER_H #define __PARSER_H +#include + struct frame { void *data; int data_len; @@ -106,10 +108,6 @@ static inline void p_indent(int level, struct frame *f) /* get_uXX functions do byte swaping */ -/* use memmove to prevent gcc from using builtin memcpy */ -#define get_unaligned(p) \ - ({ __typeof__(*(p)) t; memmove(&t, (p), sizeof(t)); t; }) - static inline uint8_t get_u8(struct frame *frm) { uint8_t *u8_ptr = frm->ptr; @@ -123,7 +121,7 @@ static inline uint16_t get_u16(struct frame *frm) uint16_t *u16_ptr = frm->ptr; frm->ptr += 2; frm->len -= 2; - return ntohs(get_unaligned(u16_ptr)); + return ntohs(bt_get_unaligned(u16_ptr)); } static inline uint32_t get_u32(struct frame *frm) @@ -131,13 +129,13 @@ static inline uint32_t get_u32(struct frame *frm) uint32_t *u32_ptr = frm->ptr; frm->ptr += 4; frm->len -= 4; - return ntohl(get_unaligned(u32_ptr)); + return ntohl(bt_get_unaligned(u32_ptr)); } static inline uint64_t get_u64(struct frame *frm) { uint64_t *u64_ptr = frm->ptr; - uint64_t u64 = get_unaligned(u64_ptr), tmp; + uint64_t u64 = bt_get_unaligned(u64_ptr), tmp; frm->ptr += 8; frm->len -= 8; tmp = ntohl(u64 & 0xffffffff); -- 2.47.3