Linux bluetooth development
 help / color / mirror / Atom feed
* PATCH [1/2] batostr(): Switch byte order before converting
@ 2011-02-16 13:07 David Herrmann
  2011-02-17 19:04 ` Johan Hedberg
  0 siblings, 1 reply; 3+ messages in thread
From: David Herrmann @ 2011-02-16 13:07 UTC (permalink / raw)
  To: linux-bluetooth

[-- Attachment #1: Type: text/plain, Size: 826 bytes --]

The library function batostr() computes incorrect results because it
does not swap byte-ordering before converting the address. This patch
fixes this behaviour. It tries to make batostr() look like ba2str() to
be consistent.

Patch is also attached as x-patch file. Patch is done against most
recent git version.


diff --git a/lib/bluetooth.c b/lib/bluetooth.c
index 4af2ef6..dd7ca06 100644
--- a/lib/bluetooth.c
+++ b/lib/bluetooth.c
@@ -50,13 +50,14 @@ void baswap(bdaddr_t *dst, const bdaddr_t *src)

 char *batostr(const bdaddr_t *ba)
 {
+	uint8_t b[6];
 	char *str = bt_malloc(18);
 	if (!str)
 		return NULL;

+	baswap((bdaddr_t *) b, ba);
 	sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
-		ba->b[0], ba->b[1], ba->b[2],
-		ba->b[3], ba->b[4], ba->b[5]);
+		b[0], b[1], b[2], b[3], b[4], b[5]);

 	return str;
 }

[-- Attachment #2: bluez1.diff --]
[-- Type: text/x-patch, Size: 514 bytes --]

diff --git a/lib/bluetooth.c b/lib/bluetooth.c
index 4af2ef6..dd7ca06 100644
--- a/lib/bluetooth.c
+++ b/lib/bluetooth.c
@@ -50,13 +50,14 @@ void baswap(bdaddr_t *dst, const bdaddr_t *src)
 
 char *batostr(const bdaddr_t *ba)
 {
+	uint8_t b[6];
 	char *str = bt_malloc(18);
 	if (!str)
 		return NULL;
 
+	baswap((bdaddr_t *) b, ba);
 	sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
-		ba->b[0], ba->b[1], ba->b[2],
-		ba->b[3], ba->b[4], ba->b[5]);
+		b[0], b[1], b[2], b[3], b[4], b[5]);
 
 	return str;
 }

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-02-17 23:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-16 13:07 PATCH [1/2] batostr(): Switch byte order before converting David Herrmann
2011-02-17 19:04 ` Johan Hedberg
2011-02-17 23:10   ` David Herrmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox