Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Linux Programming
  4. Using ba2str fails - why ?

Using ba2str fails - why ?

Scheduled Pinned Locked Moved Linux Programming
c++helpdata-structurestutorialquestion
10 Posts 4 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    This is pretty simple function and compiles and works fine on X86. Same usage , with same parameters passed to it, fails on ARM. Description Resource Path Location Type cannot convert ‘sockaddr_rc’ to ‘char*’ for argument ‘2’ to ‘int ba2str(const bdaddr_t*, char*)’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem I am at lost and could use some help to make it work. It it helps, here is the code

    for (i = 0; i < num\_rsp; i++) {
                // convert bdaddr to array addr for print 
    	ba2str(&(ii + i)->bdaddr, addr);  FAILS HERE 
    	memset(name, 0, sizeof(name));
    	if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr,
    			sizeof(name), name, 0) < 0)
    		strcpy(name, "\[unknown\]");
    	printf("remote address  %s  remote name  %s\\n", addr, name);
    }
    

    Bluetooth addresses are a 6-byte hex number similar to an Ethernet MAC address. BlueZ provides convenience functions for converting between a 6-byte string in the format 00:11:22:33:44:55 and the bdaddr_t struct. Here are the function prototypes:

    int ba2str(const bdaddr\_t \*ba, char \*str);
    int str2ba(const char \*str, bdaddr\_t \*ba);
    

    The function ba2str converts from the internal bdaddr_t to a zero-terminated string (the str parameter should have at least 18 bytes), and str2ba provides the opposite conversion. The first example makes use of the ba2str function.

    Z K L V 4 Replies Last reply
    0
    • V Vaclav_

      This is pretty simple function and compiles and works fine on X86. Same usage , with same parameters passed to it, fails on ARM. Description Resource Path Location Type cannot convert ‘sockaddr_rc’ to ‘char*’ for argument ‘2’ to ‘int ba2str(const bdaddr_t*, char*)’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem I am at lost and could use some help to make it work. It it helps, here is the code

      for (i = 0; i < num\_rsp; i++) {
                  // convert bdaddr to array addr for print 
      	ba2str(&(ii + i)->bdaddr, addr);  FAILS HERE 
      	memset(name, 0, sizeof(name));
      	if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr,
      			sizeof(name), name, 0) < 0)
      		strcpy(name, "\[unknown\]");
      	printf("remote address  %s  remote name  %s\\n", addr, name);
      }
      

      Bluetooth addresses are a 6-byte hex number similar to an Ethernet MAC address. BlueZ provides convenience functions for converting between a 6-byte string in the format 00:11:22:33:44:55 and the bdaddr_t struct. Here are the function prototypes:

      int ba2str(const bdaddr\_t \*ba, char \*str);
      int str2ba(const char \*str, bdaddr\_t \*ba);
      

      The function ba2str converts from the internal bdaddr_t to a zero-terminated string (the str parameter should have at least 18 bytes), and str2ba provides the opposite conversion. The first example makes use of the ba2str function.

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      I don't see a question.

      Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

      V 1 Reply Last reply
      0
      • V Vaclav_

        This is pretty simple function and compiles and works fine on X86. Same usage , with same parameters passed to it, fails on ARM. Description Resource Path Location Type cannot convert ‘sockaddr_rc’ to ‘char*’ for argument ‘2’ to ‘int ba2str(const bdaddr_t*, char*)’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem I am at lost and could use some help to make it work. It it helps, here is the code

        for (i = 0; i < num\_rsp; i++) {
                    // convert bdaddr to array addr for print 
        	ba2str(&(ii + i)->bdaddr, addr);  FAILS HERE 
        	memset(name, 0, sizeof(name));
        	if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr,
        			sizeof(name), name, 0) < 0)
        		strcpy(name, "\[unknown\]");
        	printf("remote address  %s  remote name  %s\\n", addr, name);
        }
        

        Bluetooth addresses are a 6-byte hex number similar to an Ethernet MAC address. BlueZ provides convenience functions for converting between a 6-byte string in the format 00:11:22:33:44:55 and the bdaddr_t struct. Here are the function prototypes:

        int ba2str(const bdaddr\_t \*ba, char \*str);
        int str2ba(const char \*str, bdaddr\_t \*ba);
        

        The function ba2str converts from the internal bdaddr_t to a zero-terminated string (the str parameter should have at least 18 bytes), and str2ba provides the opposite conversion. The first example makes use of the ba2str function.

        K Offline
        K Offline
        k5054
        wrote on last edited by
        #3

        There's absolutely no way to tell given what you've shown us. You have given us no details on where, when or how its failing for your use case. Nor have you told us wht "fails" means in your context. Most likely, you have a bad baddr_t* passed in to ba2str(), or you have passed in a const char *, but have cast away const-ness somewhere. Does ba2str() produce any diagnostics (e.g. set an error code like errno, or indicate failure reason in its return code) that would help narrow down why it "fails"?

        1 Reply Last reply
        0
        • V Vaclav_

          This is pretty simple function and compiles and works fine on X86. Same usage , with same parameters passed to it, fails on ARM. Description Resource Path Location Type cannot convert ‘sockaddr_rc’ to ‘char*’ for argument ‘2’ to ‘int ba2str(const bdaddr_t*, char*)’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem I am at lost and could use some help to make it work. It it helps, here is the code

          for (i = 0; i < num\_rsp; i++) {
                      // convert bdaddr to array addr for print 
          	ba2str(&(ii + i)->bdaddr, addr);  FAILS HERE 
          	memset(name, 0, sizeof(name));
          	if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr,
          			sizeof(name), name, 0) < 0)
          		strcpy(name, "\[unknown\]");
          	printf("remote address  %s  remote name  %s\\n", addr, name);
          }
          

          Bluetooth addresses are a 6-byte hex number similar to an Ethernet MAC address. BlueZ provides convenience functions for converting between a 6-byte string in the format 00:11:22:33:44:55 and the bdaddr_t struct. Here are the function prototypes:

          int ba2str(const bdaddr\_t \*ba, char \*str);
          int str2ba(const char \*str, bdaddr\_t \*ba);
          

          The function ba2str converts from the internal bdaddr_t to a zero-terminated string (the str parameter should have at least 18 bytes), and str2ba provides the opposite conversion. The first example makes use of the ba2str function.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You just need to cast the addr parameter to a char* as mentioned in the error message. See also https://people.csail.mit.edu/albert/bluez-intro/c404.html[^], where addr is a char array. So you can change to

          for (i = 0; i < num_rsp; i++) {
          // convert bdaddr to array addr for print
          ba2str(&(ii + i)->bdaddr, (char*)addr); // cast addr to a char* : but this may still be a problem
          memset(name, 0, sizeof(name));
          if (hci_read_remote_name(dev_descriptor, &(ii + i)->bdaddr,
          sizeof(name), name, 0) < 0)
          strcpy(name, "[unknown]");
          printf("remote address %s remote name %s\n", addr, name);
          }

          V 1 Reply Last reply
          0
          • Z ZurdoDev

            I don't see a question.

            Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

            V Offline
            V Offline
            Vaclav_
            wrote on last edited by
            #5

            len = 8;
            max_rsp = 255;
            flags = IREQ_CACHE_FLUSH;
            ii = (inquiry_info*) malloc(max_rsp * sizeof(inquiry_info));
            cout << "TASK run hci_inquiry same as hcitoo scan - takes time @line "
            << dec << __LINE__ << endl;
            num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
            perror("STATUS hci_inquiry");
            errno = 0; // reset !

            if (num\_rsp < 0)
            	perror("FAILED (?) hci\_inquiry");
            
            for (i = 0; i < num\_rsp; i++) {
            	**ba2str(&(ii + i)->bdaddr, addr);**
            	memset(name, 0, sizeof(name));
            	if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr,
            			sizeof(name), name, 0) < 0)
            		strcpy(name, "\[unknown\]");
            	printf("remote address  %s  remote name  %s\\n", addr, name);
            }
            

            the question is WHY does highlighted code throws an error

            Z K 2 Replies Last reply
            0
            • L Lost User

              You just need to cast the addr parameter to a char* as mentioned in the error message. See also https://people.csail.mit.edu/albert/bluez-intro/c404.html[^], where addr is a char array. So you can change to

              for (i = 0; i < num_rsp; i++) {
              // convert bdaddr to array addr for print
              ba2str(&(ii + i)->bdaddr, (char*)addr); // cast addr to a char* : but this may still be a problem
              memset(name, 0, sizeof(name));
              if (hci_read_remote_name(dev_descriptor, &(ii + i)->bdaddr,
              sizeof(name), name, 0) < 0)
              strcpy(name, "[unknown]");
              printf("remote address %s remote name %s\n", addr, name);
              }

              V Offline
              V Offline
              Vaclav_
              wrote on last edited by
              #6

              Richard, there is something else wrong here. After I cast (char*) addr it complains abut wrong type. I need to go and check the ba2str source , perhaps read the results of hci_inquiry before converting to addr. It is puzzling why it works on X86, hope it is not yet another "64 bits / 32 bits " issue.

              Description Resource Path Location Type
              invalid cast from type ‘sockaddr_rc’ to type ‘char*’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem

              L 1 Reply Last reply
              0
              • V Vaclav_

                len = 8;
                max_rsp = 255;
                flags = IREQ_CACHE_FLUSH;
                ii = (inquiry_info*) malloc(max_rsp * sizeof(inquiry_info));
                cout << "TASK run hci_inquiry same as hcitoo scan - takes time @line "
                << dec << __LINE__ << endl;
                num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
                perror("STATUS hci_inquiry");
                errno = 0; // reset !

                if (num\_rsp < 0)
                	perror("FAILED (?) hci\_inquiry");
                
                for (i = 0; i < num\_rsp; i++) {
                	**ba2str(&(ii + i)->bdaddr, addr);**
                	memset(name, 0, sizeof(name));
                	if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr,
                			sizeof(name), name, 0) < 0)
                		strcpy(name, "\[unknown\]");
                	printf("remote address  %s  remote name  %s\\n", addr, name);
                }
                

                the question is WHY does highlighted code throws an error

                Z Offline
                Z Offline
                ZurdoDev
                wrote on last edited by
                #7

                No idea, because you have not told us what the error is.

                Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

                1 Reply Last reply
                0
                • V Vaclav_

                  len = 8;
                  max_rsp = 255;
                  flags = IREQ_CACHE_FLUSH;
                  ii = (inquiry_info*) malloc(max_rsp * sizeof(inquiry_info));
                  cout << "TASK run hci_inquiry same as hcitoo scan - takes time @line "
                  << dec << __LINE__ << endl;
                  num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
                  perror("STATUS hci_inquiry");
                  errno = 0; // reset !

                  if (num\_rsp < 0)
                  	perror("FAILED (?) hci\_inquiry");
                  
                  for (i = 0; i < num\_rsp; i++) {
                  	**ba2str(&(ii + i)->bdaddr, addr);**
                  	memset(name, 0, sizeof(name));
                  	if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr,
                  			sizeof(name), name, 0) < 0)
                  		strcpy(name, "\[unknown\]");
                  	printf("remote address  %s  remote name  %s\\n", addr, name);
                  }
                  

                  the question is WHY does highlighted code throws an error

                  K Offline
                  K Offline
                  k5054
                  wrote on last edited by
                  #8

                  in

                  ba2str(&(ii + i)->bdaddr, addr);

                  what is the type of addr? It should be of type char \*, but your compiler is telling you its of type sockaddr_rc. Have you managed to "shadow" the addr varialbe (e.g)

                  char addr[18];
                  // ...
                  for( /* ... \*/ ) {
                  sockaddr_rc addr;
                  // ...
                  ba2str(/* ... */ );
                  }
                  // ...

                  Maybe try adding -Wshadow to your compiler options to find out.

                  1 Reply Last reply
                  0
                  • V Vaclav_

                    Richard, there is something else wrong here. After I cast (char*) addr it complains abut wrong type. I need to go and check the ba2str source , perhaps read the results of hci_inquiry before converting to addr. It is puzzling why it works on X86, hope it is not yet another "64 bits / 32 bits " issue.

                    Description Resource Path Location Type
                    invalid cast from type ‘sockaddr_rc’ to type ‘char*’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Sorry, I missed the fact that addr is not a pointer (as shown in that link I gave you). Try:

                    ba2str(&(ii + i)->bdaddr, (char\*)&addr); // cast &addr to a char\* : but this may still be a problem
                    

                    Or better still use a char array as in the example.

                    1 Reply Last reply
                    0
                    • V Vaclav_

                      This is pretty simple function and compiles and works fine on X86. Same usage , with same parameters passed to it, fails on ARM. Description Resource Path Location Type cannot convert ‘sockaddr_rc’ to ‘char*’ for argument ‘2’ to ‘int ba2str(const bdaddr_t*, char*)’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem I am at lost and could use some help to make it work. It it helps, here is the code

                      for (i = 0; i < num\_rsp; i++) {
                                  // convert bdaddr to array addr for print 
                      	ba2str(&(ii + i)->bdaddr, addr);  FAILS HERE 
                      	memset(name, 0, sizeof(name));
                      	if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr,
                      			sizeof(name), name, 0) < 0)
                      		strcpy(name, "\[unknown\]");
                      	printf("remote address  %s  remote name  %s\\n", addr, name);
                      }
                      

                      Bluetooth addresses are a 6-byte hex number similar to an Ethernet MAC address. BlueZ provides convenience functions for converting between a 6-byte string in the format 00:11:22:33:44:55 and the bdaddr_t struct. Here are the function prototypes:

                      int ba2str(const bdaddr\_t \*ba, char \*str);
                      int str2ba(const char \*str, bdaddr\_t \*ba);
                      

                      The function ba2str converts from the internal bdaddr_t to a zero-terminated string (the str parameter should have at least 18 bytes), and str2ba provides the opposite conversion. The first example makes use of the ba2str function.

                      V Offline
                      V Offline
                      Vaclav_
                      wrote on last edited by
                      #10

                      Mea culpa! I need to get this client / server code mess under control. Way too many "addresses" and yet another "shadow" error. Thanks to all of you it is fixed! I need to pay better attention to the complier errors - this time it pointed me to "shadows". Adding the check for it as standard complier option from now on. Cheers

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups