Reputation: 249
I'm trying to write a google native client (pNacl) module.
The Client is supposed to get some data from a remote server.
The calling of the function from the module works fine.
I'm at the very beginning and cannot manage to make the client send any data at all. Even a very basic lookup of the IP address with getaddrinfo does not work.
When I dump the network traffic with wireshark, I can see that no packets are being sent.
The errno refers to getaddrinfo with "Function not implemented." Even this simple code won't work. It does work though as a stand alone client, not as a native client module.
The browser also gives an error:
** Signal 4 from untrusted code: pc=6d98000b3360
Does anybody have a clue what I'm doing wrong?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <errno.h>
void foo(){
int rc;
struct addrinfo hints, *info;
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_DGRAM;
hints.ai_family = AF_INET;
fprintf(stderr, "Trying: www.google.com\n");
rc = getaddrinfo("www.google.com", "80", &hints, &info);
if(rc != 0) {
fprintf(stdout, "getaddrinfo: %s\n", gai_strerror(rc));
fprintf(stdout, "Error: %s\n", strerror(errno));
}
freeaddrinfo(info);
}
Upvotes: 0
Views: 108
Reputation: 249
So I got it working after all.
Main problem was, that the function was called on the main thread.
I used nacl_io library, which has to be called in a background thread and which needed to be properly initialised with nacl_io_init_ppapi(...)
. The initialisation via nacl_io_init()
did not work for some reason.
So I added both to the constructor of the pp::Instance class. Adding the thread inside of function foo()
did not work either. Looks like it has to be called at the beginning.
#include <pthread.h>
#include <nacl_io.h>
...
pthread_t handle_msg_thread;
void *handleMsgThreadFunc(void * data); // Calls function foo()
class MyInstance : public pp::Instance {
public:
explicit MyInstance(PP_Instance instance) :pp::Instance(instance) {
nacl_io_init_ppapi(instance, pp::Module::Get()->get_browser_interface());
pthread_create(&handle_msg_thread, NULL, &handleMsgThreadFunc, NULL);
}
...
}
Upvotes: 1
Reputation: 1137
Your network access is going through the NaClIO layer, which calls PPAPI (Pepper Plugin API) in its implementation. These APIs require special permissions - TCP/UDP is not exposed to the open web for security reasons.
See this thread: https://groups.google.com/forum/#!topic/native-client-discuss/NmIUvpLZ1uI
Upvotes: 0