This patch adds a generic Bluetooth helper function to allow getting
the adapter and device Bluetooth Address from Bluetooth sockets.
---
 plugins/bluez5.c | 22 ++++++++++++++++++++++
 plugins/bluez5.h |  3 +++
 2 files changed, 25 insertions(+)

diff --git a/plugins/bluez5.c b/plugins/bluez5.c
index d7e85f2..06629e1 100644
--- a/plugins/bluez5.c
+++ b/plugins/bluez5.c
@@ -52,6 +52,28 @@ int bt_ba2str(const bdaddr_t *ba, char *str)
                ba->b[5], ba->b[4], ba->b[3], ba->b[2], ba->b[1], ba->b[0]);
 }
 
+int bt_getsockpeers(int sock, struct sockaddr *src, struct sockaddr *dst,
+                                                               socklen_t len)
+{
+       socklen_t olen;
+
+       if (src) {
+               memset(src, 0, len);
+               olen = len;
+               if (getsockname(sock, src, &olen) < 0)
+                       return -errno;
+       }
+
+       if (dst) {
+               memset(dst, 0, len);
+               olen = len;
+               if (getpeername(sock, dst, &olen) < 0)
+                       return -errno;
+       }
+
+       return 0;
+}
+
 static void profile_register_cb(DBusPendingCall *call, gpointer user_data)
 {
        DBusMessage *reply;
diff --git a/plugins/bluez5.h b/plugins/bluez5.h
index 204c41d..2d70fbf 100644
--- a/plugins/bluez5.h
+++ b/plugins/bluez5.h
@@ -60,6 +60,9 @@ void bt_bacpy(bdaddr_t *dst, const bdaddr_t *src);
 
 int bt_ba2str(const bdaddr_t *ba, char *str);
 
+int bt_getsockpeers(int sock, struct sockaddr *src, struct sockaddr *dst,
+                                                               socklen_t len);
+
 int bluetooth_register_profile(DBusConnection *conn, const char *uuid,
                                        const char *name, const char *object);
 
-- 
1.7.11.7

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to