How can I get the Bluetooth Address??

  • liuyaxin

    liuyaxin - 2008-08-27

    I want to do an application using openobex.
    I want to use it for sending and receiving files. And I want to know the sender's or the receiver's bluetooth address. I have checked the openobex apidocs very detailed. But I didn't find some functions that I can get it. So who can help me?? Or give me some hint??:)

    • Christian W. Zuckschwerdt

      It's been discussed on the list before. In summary:
      use  OBEX_GetFD() to get the socket, then getpeername() to retrieve the sockaddr.
      HTH. Let me know if this solves the problem.

      • liuyaxin

        liuyaxin - 2008-08-28

        It works.
        But I have a new problem.
        When a new connection is accepted, I use OBEX_GetFD and getpeername to retrieve the sockaddr. The sockaddr isn't exactly the real address It has some differences.
        For example, the real address is '00:1A:16:C0:51:B4'. But the address in my program is '00:0A:00:1A:16:C0'. I don't know why? Can you help me??

        • Christian W. Zuckschwerdt

          Sounds like you are programming a server. If you use this on a listening socket you'll get the address of your local hci. You need to call it on the established connection.

          • liuyaxin

            liuyaxin - 2008-09-01

            Yes, I am programming a server.
            But I didn't use this on a listening socket. It's on the accepted socket.
            And I use another method to solve this problem.

            int get_bdaddr(obex_t *handle, char *str) {
                    int fd;
                    unsigned char name[100];
                    int i;
                    fd = OBEX_GetFD(handle);
                    if( fd < 0 ){
                            return 0;
                    if( getpeername(fd, (struct sockaddr *)name, &len) ){
                            return 0;

            The bluetooth address is on the range 2-7 of the array name.


Log in to post a comment.