Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
rmisk
Posts: 64
Registered: ‎02-21-2012
My Device: Blackberry Playbook
My Carrier: None
Accepted Solution

netstatus_get_interfaces invalid argument error

When playing around with the Network Status example I was trying to get a list of interfaces using the following snippet with the essence of where I am having the problem:

 

netstatus_interface_list_t *interface_list;

 

if (netstatus_get_interfaces(interface_list) == BPS_FAILURE)
   fprintf(stderr, "Get interfaces error # %d \n", errno);

 

Which prints out error #22 – an invalid argument error

 

Would someone please provide some suggestions as to what I am going wrong?

 

Roger

Please use plain text.
BlackBerry Development Advisor
jhoffmann
Posts: 38
Registered: ‎10-26-2011
My Device: BlackBerry Bold 9900
My Carrier: Rogers

Re: netstatus_get_interfaces invalid argument error

[ Edited ]

netstatus_get_interfaces() doesn't allocate memory for the netstatus_interface_list_t structure, only its contents.

 

Do one of the following:

 

1. Allocate memory for netstatus_interface_list_t on the heap using malloc() and use free() when done with it.

 

2. Declare interface_list on the stack and pass its address to netstatus_get_interfaces().

 

Please use plain text.
Developer
rmisk
Posts: 64
Registered: ‎02-21-2012
My Device: Blackberry Playbook
My Carrier: None

Re: netstatus_get_interfaces invalid argument error

[ Edited ]

Thanks, I had assumed it allocated memory.  Since it doesn't how much memory should I allocate as it appears the size is dependent on the number of interfaces found and the length of the associated interface names?

 

An after thought:

 

If it doesn't allocate memory why is netstatus_free_interfaces(interface_list) required?

Please use plain text.
BlackBerry Development Advisor
jhoffmann
Posts: 38
Registered: ‎10-26-2011
My Device: BlackBerry Bold 9900
My Carrier: Rogers

Re: netstatus_get_interfaces invalid argument error

[ Edited ]

Actually the size of the struct doesn't change, so use sizeof(netstatus_interface_list_t).

 

netstatus_free_interfaces() frees the array inside the struct.

Please use plain text.
Developer
rmisk
Posts: 64
Registered: ‎02-21-2012
My Device: Blackberry Playbook
My Carrier: None

Re: netstatus_get_interfaces invalid argument error

Thanks,

 

I used 

 

netstatus_interface_list_t interface_list;

 

with appropriate references and it worked.

 

Please use plain text.