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
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x
Accepted Solution

socket() gives an error

Hello,

can anybody explain please why socket() returns -1 with "Operation not permitted"

Thanks.

Developer
Posts: 137
Registered: ‎10-26-2010
My Device: Bold 9900 + PlayBook
My Carrier: Rogers

Re: socket() gives an error

Did you put the appropriate permission for network access in the XML descriptor file? If you did, did you grant the app the access network permission when it was run for the first time?
--------
Taylor Byrnes
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: socket() gives an error

I thought about it, I did put 'internet access' in xml descriptor file but when I run the app it does not ask me to grant this permission.. very puzzled..

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: socket() gives an error

by the way tried exec("/usr/bin/ping"... etc ...); and got the same results. Something is preventing me from accessing network -(

Developer
Posts: 137
Registered: ‎10-26-2010
My Device: Bold 9900 + PlayBook
My Carrier: Rogers

Re: socket() gives an error

It seems like a permission issue. Each app I believe is sandboxed into its own user account, so if the user account doesn't have network access permission then ping won't work either. If you go into options on the device you can edit the permissions for apps, double check that yours is listed and what permissions it has. Also double check the XML file, make sure there isn't a typo.
--------
Taylor Byrnes
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: socket() gives an error

I do not see my app in device security options -> permission. To get in this list the app should ask user to grant a permission and as soon as User clicks ok it gets in the list, then you can modify it. I tried to make my app request 'device id' permission and when I start the app I do see pop-up dialog requesting this permission for the app.

I double-thripple checked spelling. The problem is 'Network access' permission request does not pop up on simulator(or device) when I start the app in either Debug or Run mode.

Btw I checked with Adobe AIR SDK, the same problem, "Network access" permission never asked.

 

Can somebody please check that when you set up your bar-descriptor.xml with 

<action>access_internet</action>

 then your app requests user to grant this permission.

Thanks a lot!

BlackBerry Development Advisor
Posts: 417
Registered: ‎10-27-2010
My Device: PlayBook

Re: socket() gives an error

ping binary does not work because you need to be a root to run it, it is on purpose to prevent some security hole. So you cannot execute this from app.

How do you run your socket command? Are you trying to listen on port? On unix to listen on ports 0-1000 you need to root, so pick port which is not in this range.

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: socket() gives an error

Yes, I would assume that exec("ping") would not work, that is why I want to use sockets inside my app.

The code is very primitive, just want to get a sense of what NDK can propose in terms of networking.

int s;
struct protoent * ProtEnt;
ProtEnt = getprotobyname("icmp");
if ( !ProtEnt ){
	printf( "Error when calling getprotobyname.");
	fflush(stdout);
	return -1;
}
if ((s = socket(AF_INET, SOCK_RAW, ProtEnt->p_proto)) == -1){
        perror("Error when creating socket");
        MyExit(1);
}

 Getprotobyname() works flawlessly. As you can see I am failing to create raw socket for ICMP, so no listening ports...

BlackBerry Development Advisor
Posts: 417
Registered: ‎10-27-2010
My Device: PlayBook

Re: socket() gives an error

You have to be 'root' to open a SOCK_RAW socket. Which you cannot be.
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: socket() gives an error

I am sorry for annoyance I cause... but where does this "you have to be 'root' to open a SOCK_RAW socket" come from?

Is it specific PlayBook implementation of networking stack? On ordinary QNX box you can be anybody to create these types of sockets -) Anyway is there any documentation on "what you can do and what you can't (need root)" on PlayBook?

 

have to addmit that I am a bit upset, it's like showing a candy to a kid and saying, you can watch it but can't eat -)))

 

Thanks for your replies though, Елена Ласковая!